Skip to content

Commit 9fd72c0

Browse files
committed
fixes
1 parent 8569a06 commit 9fd72c0

File tree

5 files changed

+122
-42
lines changed

5 files changed

+122
-42
lines changed

src/components/NavbarWallet/index.tsx

Lines changed: 18 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -118,17 +118,17 @@ const NavbarWalletComponent: FC = ({ includeUrl = [] }: INavbarWalletComponent)
118118
style={
119119
colorMode === 'dark'
120120
? {
121-
'--button-color': 'var(--consumer-orange)',
122-
'--button-text-color': 'var(--general-black)',
123-
'--button-color-hover': 'var(--general-white)',
124-
'--button-text-color-hover': 'var(--general-black)',
125-
}
121+
'--button-color': 'var(--consumer-orange)',
122+
'--button-text-color': 'var(--general-black)',
123+
'--button-color-hover': 'var(--general-white)',
124+
'--button-text-color-hover': 'var(--general-black)',
125+
}
126126
: {
127-
'--button-color': 'var(--consumer-orange)',
128-
'--button-text-color': 'var(--general-black)',
129-
'--button-color-hover': 'var(--general-black)',
130-
'--button-text-color-hover': 'var(--general-white)',
131-
}
127+
'--button-color': 'var(--consumer-orange)',
128+
'--button-text-color': 'var(--general-black)',
129+
'--button-color-hover': 'var(--general-black)',
130+
'--button-text-color-hover': 'var(--general-white)',
131+
}
132132
}
133133
/>
134134
) : (
@@ -200,6 +200,14 @@ const NavbarWallet = props => {
200200
const [loginEnabled, setLoginEnabled] = useState(false)
201201

202202
useEffect(() => {
203+
// Handle case where ldClient is null (when LaunchDarkly isn't initialized)
204+
if (!ldClient) {
205+
console.warn('LaunchDarkly client not available, disabling login feature');
206+
setLdReady(true);
207+
setLoginEnabled(false);
208+
return;
209+
}
210+
203211
ldClient.waitUntilReady().then(() => {
204212
setLoginEnabled(ldClient.variation(LOGIN_FF, false))
205213
setLdReady(true)
Lines changed: 53 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,52 +1,86 @@
11
/* eslint-disable no-plusplus */
22
function highlightStart(fileContent: string, variableName: string): string {
3-
const contentByLine = fileContent.split(`\n`);
3+
// Add defensive check for undefined fileContent
4+
if (!fileContent) {
5+
console.warn(`File content is undefined in highlightStart for variable: ${variableName}`)
6+
return ''
7+
}
8+
9+
const contentByLine = fileContent.split(`\n`)
410
for (let i = 0; i < contentByLine.length; i += 1) {
511
if (contentByLine[i].includes(`IMP START - ${variableName}`)) {
6-
contentByLine[i] = "// highlight-start";
12+
contentByLine[i] = '// highlight-start'
713
}
814
}
9-
return contentByLine.join("\n");
15+
return contentByLine.join('\n')
1016
}
17+
1118
function highlightEnd(fileContent: string, variableName: string): string {
12-
const contentByLine = fileContent.split(`\n`);
19+
// Add defensive check for undefined fileContent
20+
if (!fileContent) {
21+
console.warn(`File content is undefined in highlightEnd for variable: ${variableName}`)
22+
return ''
23+
}
24+
25+
const contentByLine = fileContent.split(`\n`)
1326
for (let i = 0; i < contentByLine.length; i += 1) {
1427
if (contentByLine[i].includes(`IMP END - ${variableName}`)) {
15-
contentByLine[i] = "// highlight-end";
28+
contentByLine[i] = '// highlight-end'
1629
}
1730
}
18-
return contentByLine.join("\n");
31+
return contentByLine.join('\n')
1932
}
2033

2134
function removeHighlightCode(fileContent: string): string {
35+
// Add defensive check for undefined fileContent
36+
if (!fileContent) {
37+
console.warn(`File content is undefined in removeHighlightCode`)
38+
return ''
39+
}
40+
2241
// 2. line that this occurs on
23-
const contentByLine = fileContent.split(`\n`);
42+
const contentByLine = fileContent.split(`\n`)
2443
for (let i = 0; i < contentByLine.length; i += 1) {
25-
if (contentByLine[i].includes("IMP")) {
26-
contentByLine.splice(i, 1);
44+
if (contentByLine[i].includes('IMP')) {
45+
contentByLine.splice(i, 1)
2746
}
2847
}
29-
return contentByLine.join("\n");
48+
return contentByLine.join('\n')
3049
}
3150

3251
function highlightSection(fileContent: string, variableName: string): string {
33-
const highlightStartFile = highlightStart(fileContent, variableName);
34-
const highlightedFile = highlightEnd(highlightStartFile, variableName);
35-
return removeHighlightCode(highlightedFile);
52+
// Add defensive check for undefined fileContent
53+
if (!fileContent) {
54+
console.warn(`File content is undefined in highlightSection for variable: ${variableName}`)
55+
return ''
56+
}
57+
58+
const highlightStartFile = highlightStart(fileContent, variableName)
59+
const highlightedFile = highlightEnd(highlightStartFile, variableName)
60+
return removeHighlightCode(highlightedFile)
3661
}
3762

3863
function highlight(stepIndex, filenames, files, steps) {
39-
const { pointer } = steps[stepIndex];
40-
const newFiles = files;
64+
// Add defensive checks for undefined parameters
65+
if (!steps || !steps[stepIndex] || !steps[stepIndex].pointer) {
66+
console.warn(`Invalid step data at index ${stepIndex}`)
67+
return files || {}
68+
}
69+
70+
const { pointer } = steps[stepIndex]
71+
const newFiles = files || {}
4172

4273
for (let i = 0; i < filenames.length; i++) {
4374
if (filenames[i] === pointer.filename) {
44-
newFiles[filenames[i]] = highlightSection(pointer.fileContent || files[filenames[i]], pointer.variableName);
75+
newFiles[filenames[i]] = highlightSection(
76+
pointer.fileContent || files[filenames[i]],
77+
pointer.variableName
78+
)
4579
}
46-
newFiles[filenames[i]] = removeHighlightCode(files[filenames[i]]);
80+
newFiles[filenames[i]] = removeHighlightCode(files[filenames[i]])
4781
}
4882

49-
return newFiles;
83+
return newFiles
5084
}
5185

52-
export default highlight;
86+
export default highlight

src/pages/quick-start/index.tsx

Lines changed: 43 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,8 @@ import IntegrationBuilderCodeView from "../../theme/IntegrationBuilderCodeView";
1616
import builder from "./builder";
1717
import styles from "./styles.module.css";
1818
import { getWindowLocation } from "../../theme/URLParams";
19+
import BrowserOnly from "@docusaurus/BrowserOnly";
20+
import { IntegrationStep } from "./interfaces";
1921

2022
const getDefaultBuilderOptions = () => {
2123
const defaultOpts = Object.fromEntries(
@@ -45,7 +47,30 @@ const getURLFromBuilderOptions = (opts: Record<string, string>, stepIndex): stri
4547
return url.toString();
4648
};
4749

48-
export default function IntegrationBuilderPage({ files }: { files: Record<string, any> }) {
50+
export default function IntegrationBuilderPage(props: { files?: any }) {
51+
// Get files from props (passed via Docusaurus modules)
52+
const [files, setFiles] = useState<Record<string, string>>({});
53+
const [filesLoaded, setFilesLoaded] = useState(false);
54+
55+
useEffect(() => {
56+
if (props.files) {
57+
try {
58+
// The files should be available directly from props
59+
const filesData = props.files.default || props.files;
60+
console.log('Loaded files from props, count:', Object.keys(filesData).length);
61+
setFiles(filesData);
62+
setFilesLoaded(true);
63+
} catch (error) {
64+
console.error('Error accessing files from props:', error);
65+
setFiles({});
66+
setFilesLoaded(true);
67+
}
68+
} else {
69+
console.log('No files found in props');
70+
setFilesLoaded(true);
71+
}
72+
}, [props.files]);
73+
4974
const [builderOptions, setBuilderOptions] = useState<Record<string, string>>(
5075
getDefaultBuilderOptions(),
5176
);
@@ -64,7 +89,7 @@ export default function IntegrationBuilderPage({ files }: { files: Record<string
6489
() => builder.build(builderOptions, files, stepIndex),
6590
[builderOptions, files, stepIndex],
6691
);
67-
const [selectedFilename, setSelectedFilename] = useState(integration.filenames[0]);
92+
const [selectedFilename, setSelectedFilename] = useState(integration.filenames[0] || "");
6893

6994
const delay = (ms) => new Promise((resolve) => setTimeout(resolve, ms));
7095
const ref = useRef(null);
@@ -85,7 +110,9 @@ export default function IntegrationBuilderPage({ files }: { files: Record<string
85110
// eslint-disable-next-line no-param-reassign
86111
index = steps.length - 1;
87112
}
88-
setSelectedFilename(steps[index].pointer!.filename);
113+
if (steps[index] && steps[index].pointer && steps[index].pointer.filename) {
114+
setSelectedFilename(steps[index].pointer.filename);
115+
}
89116
setStepIndex(index);
90117
};
91118

@@ -149,7 +176,11 @@ export default function IntegrationBuilderPage({ files }: { files: Record<string
149176
useEffect(() => {
150177
setStepIndex(integration.stepIndex);
151178
// Update selected file when either integration changed
152-
setSelectedFilename(integration.steps[integration.stepIndex].pointer!.filename);
179+
if (integration.steps && integration.steps[integration.stepIndex] && integration.steps[integration.stepIndex].pointer) {
180+
setSelectedFilename(integration.steps[integration.stepIndex].pointer.filename);
181+
} else if (integration.filenames && integration.filenames.length > 0) {
182+
setSelectedFilename(integration.filenames[0]);
183+
}
153184

154185
for (const optionKey in builderOptions) {
155186
if (builder.options[optionKey]) {
@@ -170,7 +201,7 @@ export default function IntegrationBuilderPage({ files }: { files: Record<string
170201
// Update the useEffect for initial navigation
171202
useEffect(() => {
172203
// Initialize to the step index from URL
173-
if (stepIndex > 0 && steps[stepIndex]) {
204+
if (stepIndex > 0 && steps && steps[stepIndex]) {
174205
const stepElements = document.getElementsByClassName(styles.stepContainer);
175206
if (stepElements && stepElements.length > stepIndex) {
176207
const element = stepElements[stepIndex] as HTMLElement;
@@ -318,7 +349,7 @@ export default function IntegrationBuilderPage({ files }: { files: Record<string
318349
<div className={styles.cols} ref={ref}>
319350
<div className={styles.leftCol} onScroll={onScrollLeft}>
320351
<MDXProvider components={MDXComponents}>
321-
{steps.map((step, index) => (
352+
{steps && steps.length > 0 ? steps.map((step, index) => (
322353
<div
323354
key={step.title}
324355
className={classNames(styles.stepContainer, {
@@ -333,7 +364,12 @@ export default function IntegrationBuilderPage({ files }: { files: Record<string
333364
<p className={styles.stepHeader}>{step.title}</p>
334365
<div className={styles.stepBody}>{step.content}</div>
335366
</div>
336-
))}
367+
)) : (
368+
<div className={styles.stepContainer}>
369+
<p className={styles.stepHeader}>Loading...</p>
370+
<div className={styles.stepBody}>Please wait while we load the integration steps.</div>
371+
</div>
372+
)}
337373
</MDXProvider>
338374
</div>
339375
<div className={styles.rightCol}>

src/plugins/docusaurus-plugin-virtual-files/index.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,11 +10,13 @@ const environment = process.env.IB_ENV || "development";
1010

1111
async function fetchHostedFile(filename) {
1212
try {
13-
response = await axios.get("https:/raw.githubusercontent.com/" + filename);
13+
console.log(`Fetching file: ${filename}`);
14+
const response = await axios.get("https://raw.githubusercontent.com/" + filename);
1415
var fileContent = response.data;
1516
if (typeof fileContent !== "string") {
1617
fileContent = JSON.stringify(fileContent, null, 2);
1718
}
19+
console.log(`Successfully fetched ${filename}, content length: ${fileContent.length}`);
1820
return fileContent;
1921
} catch (e) {
2022
console.log(`Error fetching ${filename}: ${e}`);

src/utils/IBfileLinks.json

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -27,9 +27,9 @@
2727
"VUE_HOME_VUE": "Web3Auth/web3auth-examples/refs/heads/main/quick-starts/vue-quick-start/src/Home.vue",
2828
"VUE_APP_VUE": "Web3Auth/web3auth-examples/refs/heads/main/quick-starts/vue-quick-start/src/App.vue",
2929
"VUE_WEB3AUTHCONTEXT_TSX": "Web3Auth/web3auth-examples/refs/heads/main/quick-starts/vue-quick-start/src/web3authContext.tsx",
30-
"VUE_GET_BALANCE_TSX": "Web3Auth/web3auth-examples/refs/heads/main/quick-starts/vue-quick-start/src/components/getBalance.tsx",
31-
"VUE_SEND_TRANSACTION_TSX": "Web3Auth/web3auth-examples/refs/heads/main/quick-starts/vue-quick-start/src/components/sendTransaction.tsx",
32-
"VUE_SWITCH_NETWORK_TSX": "Web3Auth/web3auth-examples/refs/heads/main/quick-starts/vue-quick-start/src/components/switchNetwork.tsx",
30+
"VUE_GET_BALANCE_TSX": "Web3Auth/web3auth-examples/refs/heads/main/quick-starts/vue-quick-start/src/components/Balance.vue",
31+
"VUE_SEND_TRANSACTION_TSX": "Web3Auth/web3auth-examples/refs/heads/main/quick-starts/vue-quick-start/src/components/SendTransaction.vue",
32+
"VUE_SWITCH_NETWORK_TSX": "Web3Auth/web3auth-examples/refs/heads/main/quick-starts/vue-quick-start/src/components/SwitchNetwork.vue",
3333
"PNP_UNITY_WEB3AUTHSCRIPT_CS": "Web3Auth/web3auth-unity-examples/refs/heads/main/unity-quick-start/Assets/Web3AuthScript.cs",
3434
"PNP_UNITY_ANDROID_MANIFEST": "Web3Auth/web3auth-unity-examples/refs/heads/main/unity-quick-start/Assets/Plugins/Android/AndroidManifest.xml",
3535
"PNP_UNITY_MANIFEST_JSON": "Web3Auth/web3auth-unity-examples/refs/heads/main/unity-quick-start/Packages/manifest.json",
@@ -48,11 +48,11 @@
4848
"PNP_FLUTTER_MAIN_DART": "Web3Auth/web3auth-flutter-examples/main/flutter-quick-start/lib/main.dart",
4949
"PNP_FLUTTER_BUILD_GRADLE": "Web3Auth/web3auth-flutter-examples/main/flutter-quick-start/android/app/build.gradle",
5050
"PNP_FLUTTER_PODFILE": "Web3Auth/web3auth-flutter-examples/main/flutter-quick-start/ios/Podfile",
51-
"PNP_FLUTTER_PUBSPEC_YAML": "Web3Auth/web3auth-pnp-examples/main/flutter-quick-start/pubspec.yaml",
51+
"PNP_FLUTTER_PUBSPEC_YAML": "Web3Auth/web3auth-flutter-examples/main/flutter-quick-start/pubspec.yaml",
5252
"PNP_ANDROID_MAINACTIVITY_KT": "Web3Auth/web3auth-android-examples/main/android-quick-start/app/src/main/java/com/sbz/web3authdemoapp/MainActivity.kt",
5353
"PNP_ANDROID_ANDROIDMANIFEST_XML": "Web3Auth/web3auth-android-examples/main/android-quick-start/app/src/main/AndroidManifest.xml",
5454
"PNP_ANDROID_BUILD_GRADLE": "Web3Auth/web3auth-android-examples/main/android-quick-start/app/build.gradle",
5555
"PNP_ANDROID_SETTINGS_GRADLE": "Web3Auth/web3auth-android-examples/main/android-quick-start/settings.gradle",
5656
"PNP_ANDROID_STRINGS_XML": "Web3Auth/web3auth-android-examples/main/android-quick-start/app/src/main/res/values/strings.xml",
5757
"PNP_ANDROID_ACTIVITY_MAIN_XML": "Web3Auth/web3auth-android-examples/main/android-quick-start/app/src/main/res/layout/activity_main.xml"
58-
}
58+
}

0 commit comments

Comments
 (0)