Skip to content

Commit fb7c587

Browse files
committed
fix: add 10-second timeout to prevent infinite loading
1 parent b1a8f61 commit fb7c587

File tree

1 file changed

+26
-6
lines changed

1 file changed

+26
-6
lines changed

packages/web-wallet/src/contexts/WalletContext.tsx

Lines changed: 26 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -363,21 +363,41 @@ export const WalletProvider: React.FC<WalletProviderProps> = ({ children }) => {
363363

364364
// Check for existing connection on mount
365365
React.useEffect(() => {
366+
let timeoutId: NodeJS.Timeout;
367+
366368
// Add a small delay to avoid race condition with React StrictMode double-mount
367369
const timer = setTimeout(() => {
368-
checkExistingConnection().catch((error) => {
369-
console.error('Connection check failed:', error);
370-
// Ensure we reset the checking state on error
370+
// Set a timeout to prevent infinite hanging
371+
timeoutId = setTimeout(() => {
372+
console.error('Connection check timed out after 10 seconds');
371373
setState(prev => ({
372374
...prev,
373375
isCheckingConnection: false,
374376
loadingStep: '',
375-
error: 'Failed to check connection',
377+
error: null,
376378
}));
377-
});
379+
}, 10000);
380+
381+
checkExistingConnection()
382+
.catch((error) => {
383+
console.error('Connection check failed:', error);
384+
// Ensure we reset the checking state on error
385+
setState(prev => ({
386+
...prev,
387+
isCheckingConnection: false,
388+
loadingStep: '',
389+
error: 'Failed to check connection',
390+
}));
391+
})
392+
.finally(() => {
393+
clearTimeout(timeoutId);
394+
});
378395
}, 100);
379396

380-
return () => clearTimeout(timer);
397+
return () => {
398+
clearTimeout(timer);
399+
if (timeoutId) clearTimeout(timeoutId);
400+
};
381401
}, []);
382402

383403
// Sync MetaMask errors to wallet state

0 commit comments

Comments
 (0)