Fix Amber timeout: increase to 3 minutes so user has time to approve in Amber and return

Co-authored-by: shakespeare.diy <assistant@shakespeare.diy>
This commit is contained in:
shakespeare.diy 2026-07-03 12:31:48 +07:00
parent bd149fdb2c
commit dfb60674c5

View file

@ -276,7 +276,7 @@ export const LoginDialog: React.FC<LoginDialogProps> = ({ isOpen, onClose, onLog
amberStepRef.current = 'waiting'; amberStepRef.current = 'waiting';
setAmberStep('waiting'); setAmberStep('waiting');
setAmberStatus('Waiting for Amber to approve...'); setAmberStatus('Approve in Amber, then come back here.');
// Live relay subscription (works on web/PWA; may be backgrounded in Capacitor) // Live relay subscription (works on web/PWA; may be backgrounded in Capacitor)
const pool = new SimplePool(); const pool = new SimplePool();
@ -316,10 +316,13 @@ export const LoginDialog: React.FC<LoginDialogProps> = ({ isOpen, onClose, onLog
); );
subRef.current = sub; subRef.current = sub;
// Timeout after 20 seconds — show error, let user retry // On Capacitor (native app) give 3 minutes — the visibility change handler does the real work
// after the user returns from Amber, so the live subscription just needs to stay alive.
// On web/PWA the live subscription fires instantly, so 3 min is still fine as a safety net.
const TIMEOUT_MS = isCapacitor ? 3 * 60 * 1000 : 3 * 60 * 1000;
setTimeout(() => { setTimeout(() => {
if (!controller.signal.aborted) { if (!controller.signal.aborted) {
console.warn('[Amber] Timed out after 20s — no response received'); console.warn('[Amber] Timed out — no response received');
controller.abort(); controller.abort();
cleanup(); cleanup();
if (amberStepRef.current === 'waiting') { if (amberStepRef.current === 'waiting') {
@ -328,7 +331,7 @@ export const LoginDialog: React.FC<LoginDialogProps> = ({ isOpen, onClose, onLog
setAmberStatus('Amber did not respond in time. Did you approve the connection?'); setAmberStatus('Amber did not respond in time. Did you approve the connection?');
} }
} }
}, 20 * 1000); }, TIMEOUT_MS);
}, [cleanup, completeLogin, toast]); }, [cleanup, completeLogin, toast]);
const handleBunkerLogin = async () => { const handleBunkerLogin = async () => {