@enbox/browser 0.3.49 → 0.3.52
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/browser.mjs +39 -14
- package/dist/browser.mjs.map +3 -3
- package/dist/esm/dweb-connect-client.js +64 -9
- package/dist/esm/dweb-connect-client.js.map +1 -1
- package/dist/esm/dweb-connect-messages.js +7 -1
- package/dist/esm/dweb-connect-messages.js.map +1 -1
- package/dist/esm/dweb-connect-wallet.js +48 -2
- package/dist/esm/dweb-connect-wallet.js.map +1 -1
- package/dist/esm/index.js +1 -1
- package/dist/esm/index.js.map +1 -1
- package/dist/esm/relay-connect-runner.js +35 -2
- package/dist/esm/relay-connect-runner.js.map +1 -1
- package/dist/esm/ui/connect-modal.js +204 -85
- package/dist/esm/ui/connect-modal.js.map +1 -1
- package/dist/types/dweb-connect-client.d.ts +9 -0
- package/dist/types/dweb-connect-client.d.ts.map +1 -1
- package/dist/types/dweb-connect-messages.d.ts +14 -1
- package/dist/types/dweb-connect-messages.d.ts.map +1 -1
- package/dist/types/dweb-connect-wallet.d.ts +23 -1
- package/dist/types/dweb-connect-wallet.d.ts.map +1 -1
- package/dist/types/index.d.ts +2 -2
- package/dist/types/index.d.ts.map +1 -1
- package/dist/types/relay-connect-runner.d.ts +11 -1
- package/dist/types/relay-connect-runner.d.ts.map +1 -1
- package/dist/types/ui/connect-modal.d.ts +8 -7
- package/dist/types/ui/connect-modal.d.ts.map +1 -1
- package/package.json +6 -6
- package/src/dweb-connect-client.ts +61 -7
- package/src/dweb-connect-messages.ts +16 -1
- package/src/dweb-connect-wallet.ts +50 -1
- package/src/index.ts +2 -0
- package/src/relay-connect-runner.ts +42 -2
- package/src/ui/connect-modal.ts +231 -95
package/src/ui/connect-modal.ts
CHANGED
|
@@ -2,17 +2,18 @@
|
|
|
2
2
|
* Connect modal — the single surface that owns a whole connect session.
|
|
3
3
|
*
|
|
4
4
|
* One Shadow-DOM dialog whose stage morphs in place through the session:
|
|
5
|
-
* QR (phone path) → pairing code → connected, with the
|
|
6
|
-
* path and the wallet catalog folded in as in-place
|
|
7
|
-
* never chains into a second modal and stays mounted
|
|
8
|
-
* resolves (connected / denied / cancelled).
|
|
5
|
+
* QR / deep-link handoff (phone path) → pairing code → connected, with the
|
|
6
|
+
* in-browser popup path and the wallet catalog folded in as in-place
|
|
7
|
+
* alternates. The modal never chains into a second modal and stays mounted
|
|
8
|
+
* until the session resolves (connected / denied / cancelled).
|
|
9
9
|
*
|
|
10
10
|
* Layout: three zones —
|
|
11
11
|
*
|
|
12
12
|
* 1. **Header** — requesting app identity + close.
|
|
13
|
-
* 2. **Stage** — a height-stable region where states crossfade: the
|
|
14
|
-
*
|
|
15
|
-
*
|
|
13
|
+
* 2. **Stage** — a height-stable region where states crossfade: the
|
|
14
|
+
* clickable QR (joined by a Continue deep-link button on phones; both
|
|
15
|
+
* open the wallet in a new tab so this session stays alive underneath),
|
|
16
|
+
* the pairing-code input, progress, success, and error states.
|
|
16
17
|
* 3. **Footer** — the wallet identity row ("Connecting with" + the selected
|
|
17
18
|
* wallet and the next catalog wallets as tiles), a More tile that expands
|
|
18
19
|
* the remaining wallets as a matching grid (search + custom URL) in
|
|
@@ -57,8 +58,16 @@ export type ConnectMethod = 'phone' | 'browser';
|
|
|
57
58
|
/** localStorage key remembering the last successful method + wallet. */
|
|
58
59
|
const LAST_CHOICE_STORAGE_KEY = 'enbox:connect:lastChoice';
|
|
59
60
|
|
|
60
|
-
/**
|
|
61
|
-
|
|
61
|
+
/**
|
|
62
|
+
* Safety margin subtracted from the relay pointer TTL before re-minting.
|
|
63
|
+
*
|
|
64
|
+
* The pointer is single-use and its TTL starts at mint time, but the wallet
|
|
65
|
+
* only dereferences it after the user scans — and, on a locked wallet, after
|
|
66
|
+
* they finish the unlock ceremony. A scanned code must therefore carry
|
|
67
|
+
* enough remaining life to absorb that whole window, so re-mint well before
|
|
68
|
+
* the deadline rather than just ahead of it.
|
|
69
|
+
*/
|
|
70
|
+
const REMINT_SAFETY_MS = 120_000;
|
|
62
71
|
|
|
63
72
|
/** Minimum delay before an automatic re-mint. */
|
|
64
73
|
const REMINT_MIN_MS = 10_000;
|
|
@@ -418,6 +427,7 @@ export function runConnectModal(options: ConnectModalOptions): Promise<ConnectRe
|
|
|
418
427
|
let settled = false;
|
|
419
428
|
let relaySession: RelaySession | undefined;
|
|
420
429
|
let remintTimer: ReturnType<typeof setTimeout> | undefined;
|
|
430
|
+
let remintAt: number | undefined;
|
|
421
431
|
let popupBusy = false;
|
|
422
432
|
let pinResolve: ((pin: string) => void) | undefined;
|
|
423
433
|
const discoveryCache = new Map<string, Promise<string | undefined>>();
|
|
@@ -453,8 +463,9 @@ export function runConnectModal(options: ConnectModalOptions): Promise<ConnectRe
|
|
|
453
463
|
|
|
454
464
|
const cleanup = (): void => {
|
|
455
465
|
relaySession?.cancel();
|
|
456
|
-
|
|
466
|
+
clearRemint();
|
|
457
467
|
document.removeEventListener('keydown', onKeydown);
|
|
468
|
+
document.removeEventListener('visibilitychange', onVisibilityReturn);
|
|
458
469
|
systemDark?.removeEventListener?.('change', onSchemeChange);
|
|
459
470
|
try { document.body.removeChild(host); } catch { /* best effort */ }
|
|
460
471
|
};
|
|
@@ -501,31 +512,52 @@ export function runConnectModal(options: ConnectModalOptions): Promise<ConnectRe
|
|
|
501
512
|
setStage(el('div', 'spinner'), el('p', 'stage-caption', message));
|
|
502
513
|
};
|
|
503
514
|
|
|
515
|
+
/**
|
|
516
|
+
* Schedules the "finish in the wallet" morph after a handoff link is
|
|
517
|
+
* followed. Deferred one tick so the anchor's default new-tab navigation
|
|
518
|
+
* completes before the anchor is replaced, and guarded so a session that
|
|
519
|
+
* moved on meanwhile (re-mint, wallet response, settle) is never
|
|
520
|
+
* overwritten.
|
|
521
|
+
*/
|
|
522
|
+
const morphToAway = (walletName: string): void => {
|
|
523
|
+
const session = relaySession;
|
|
524
|
+
setTimeout((): void => {
|
|
525
|
+
if (settled || session !== relaySession || session?.active !== true || pinResolve !== undefined) {
|
|
526
|
+
return;
|
|
527
|
+
}
|
|
528
|
+
renderAway(walletName);
|
|
529
|
+
}, 0);
|
|
530
|
+
};
|
|
531
|
+
|
|
532
|
+
/**
|
|
533
|
+
* Builds one same-device handoff anchor for the wallet URI. The wallet
|
|
534
|
+
* opens in a new tab so this modal — and the relay session under it —
|
|
535
|
+
* stays alive, with the pairing-code entry waiting when the user
|
|
536
|
+
* switches back. `noopener` keeps the wallet tab from reaching back into
|
|
537
|
+
* this one.
|
|
538
|
+
*/
|
|
539
|
+
const buildHandoffLink = (handoff: WalletUriHandoff, walletName: string, className: string): HTMLAnchorElement => {
|
|
540
|
+
const link = document.createElement('a');
|
|
541
|
+
link.className = className;
|
|
542
|
+
link.href = handoff.walletUri;
|
|
543
|
+
link.target = '_blank';
|
|
544
|
+
link.rel = 'noopener noreferrer';
|
|
545
|
+
link.addEventListener('click', () => { morphToAway(walletName); });
|
|
546
|
+
return link;
|
|
547
|
+
};
|
|
548
|
+
|
|
504
549
|
const renderQr = (handoff: WalletUriHandoff): void => {
|
|
505
550
|
const wallet = walletUrl !== undefined ? walletByUrl(walletUrl) : undefined;
|
|
506
551
|
const walletName = wallet?.name ?? 'your wallet';
|
|
507
552
|
|
|
508
|
-
|
|
509
|
-
|
|
510
|
-
|
|
511
|
-
|
|
512
|
-
|
|
513
|
-
link.appendChild(buildWalletIcon(wallet));
|
|
514
|
-
}
|
|
515
|
-
link.appendChild(el('span', 'deep-link-label', `Continue in ${walletName}`));
|
|
516
|
-
setStage(
|
|
517
|
-
link,
|
|
518
|
-
el('p', 'stage-caption', `${walletName} opens to approve this connection.`),
|
|
519
|
-
el('p', 'stage-subline', 'Come back here when you’re done.'),
|
|
520
|
-
);
|
|
521
|
-
return;
|
|
522
|
-
}
|
|
523
|
-
|
|
524
|
-
const qrBox = document.createElement('div');
|
|
525
|
-
qrBox.className = 'qr-box';
|
|
553
|
+
// The QR card is itself a handoff link on every device: opening it on
|
|
554
|
+
// this device runs the exact handshake the camera path runs on another
|
|
555
|
+
// one, and scanning it keeps working either way.
|
|
556
|
+
const qrLink = buildHandoffLink(handoff, walletName, 'qr-box qr-link');
|
|
557
|
+
qrLink.setAttribute('aria-label', `Open ${walletName} on this device`);
|
|
526
558
|
// Fixed colors on the white card: dark-on-light QRs scan reliably in
|
|
527
559
|
// both appearances (inverted codes trip up some camera apps).
|
|
528
|
-
|
|
560
|
+
qrLink.replaceChildren(qrToSvg(encodeQr(handoff.walletUri), {
|
|
529
561
|
dark : '#14141f',
|
|
530
562
|
light : 'transparent',
|
|
531
563
|
quietZone : 2,
|
|
@@ -534,33 +566,70 @@ export function runConnectModal(options: ConnectModalOptions): Promise<ConnectRe
|
|
|
534
566
|
// The selected wallet's mark sits at the QR centre — the "this is the
|
|
535
567
|
// wallet you're connecting to" cue. The 44px plate over the ~180px
|
|
536
568
|
// symbol occludes ~5% of modules, well inside ECC level M's 15%
|
|
537
|
-
// recovery budget
|
|
569
|
+
// recovery budget (the compact variant scales the plate down to
|
|
570
|
+
// match).
|
|
538
571
|
if (wallet !== undefined) {
|
|
539
572
|
const logo = el('div', 'qr-logo');
|
|
540
573
|
logo.appendChild(buildWalletIcon(wallet));
|
|
541
|
-
|
|
574
|
+
qrLink.appendChild(logo);
|
|
575
|
+
}
|
|
576
|
+
|
|
577
|
+
if (isMobile) {
|
|
578
|
+
const link = buildHandoffLink(handoff, walletName, 'deep-link');
|
|
579
|
+
if (wallet !== undefined) {
|
|
580
|
+
link.appendChild(buildWalletIcon(wallet));
|
|
581
|
+
}
|
|
582
|
+
link.appendChild(el('span', 'deep-link-label', `Continue in ${walletName}`));
|
|
583
|
+
|
|
584
|
+
qrLink.classList.add('compact');
|
|
585
|
+
setStage(
|
|
586
|
+
link,
|
|
587
|
+
el('p', 'stage-subline', `${walletName} opens in a new tab — approve there, then come back for your code.`),
|
|
588
|
+
el('div', 'stage-divider', 'or scan with another phone'),
|
|
589
|
+
qrLink,
|
|
590
|
+
);
|
|
591
|
+
return;
|
|
542
592
|
}
|
|
543
593
|
|
|
544
594
|
setStage(
|
|
545
|
-
|
|
595
|
+
qrLink,
|
|
546
596
|
el('p', 'stage-caption', 'Scan with your phone’s camera'),
|
|
547
|
-
el('p', 'stage-subline', `${walletName} stays on your phone.`),
|
|
597
|
+
el('p', 'stage-subline', `${walletName} stays on your phone — or click the code to open it here.`),
|
|
598
|
+
);
|
|
599
|
+
};
|
|
600
|
+
|
|
601
|
+
/**
|
|
602
|
+
* Shown once a handoff link is followed on this device: the approval is
|
|
603
|
+
* happening in the wallet tab, this one waits for the code. "Start over"
|
|
604
|
+
* mints a fresh pointer — the right recovery, because the pointer the
|
|
605
|
+
* wallet tab carried away is single-use.
|
|
606
|
+
*/
|
|
607
|
+
const renderAway = (walletName: string): void => {
|
|
608
|
+
setStage(
|
|
609
|
+
el('div', 'spinner'),
|
|
610
|
+
el('p', 'stage-caption', `Finish in ${walletName}`),
|
|
611
|
+
el('p', 'stage-subline', isMobile
|
|
612
|
+
? `Approve the connection in the ${walletName} tab, then come back here for your code.`
|
|
613
|
+
: 'Approve the connection in the tab that just opened, then come back here for your code.'),
|
|
614
|
+
stageLinkButton('Start over', () => { void startPhone(); }),
|
|
548
615
|
);
|
|
549
616
|
};
|
|
550
617
|
|
|
551
618
|
const renderClaimed = (): void => {
|
|
619
|
+
const walletName = walletUrl !== undefined ? walletByUrl(walletUrl).name : 'your wallet';
|
|
552
620
|
const pulse = document.createElement('div');
|
|
553
621
|
pulse.className = 'claimed-pulse';
|
|
554
622
|
setStage(
|
|
555
623
|
pulse,
|
|
556
|
-
el('p', 'stage-caption',
|
|
557
|
-
el('p', 'stage-subline', '
|
|
624
|
+
el('p', 'stage-caption', `Request received — approve in ${walletName}`),
|
|
625
|
+
el('p', 'stage-subline', 'Once you approve, you’ll get a code to enter here.'),
|
|
558
626
|
);
|
|
559
627
|
};
|
|
560
628
|
|
|
561
629
|
const renderPin = (attempt: number, previousError?: Error): Promise<string> => {
|
|
562
630
|
return new Promise<string>((resolvePin) => {
|
|
563
631
|
pinResolve = resolvePin;
|
|
632
|
+
const walletName = walletUrl !== undefined ? walletByUrl(walletUrl).name : 'your wallet';
|
|
564
633
|
|
|
565
634
|
const boxes = document.createElement('div');
|
|
566
635
|
boxes.className = 'pin-row';
|
|
@@ -618,11 +687,11 @@ export function runConnectModal(options: ConnectModalOptions): Promise<ConnectRe
|
|
|
618
687
|
});
|
|
619
688
|
|
|
620
689
|
setStage(
|
|
621
|
-
el('p', 'stage-caption',
|
|
690
|
+
el('p', 'stage-caption', `Enter the code shown in ${walletName}`),
|
|
622
691
|
boxes,
|
|
623
692
|
...(previousError !== undefined
|
|
624
|
-
? [el('p', 'stage-error',
|
|
625
|
-
: [el('p', 'stage-subline', attempt === 1 ? '
|
|
693
|
+
? [el('p', 'stage-error', `That code doesn’t match — check ${walletName}.`)]
|
|
694
|
+
: [el('p', 'stage-subline', attempt === 1 ? 'This confirms you’re the one approving.' : '')]),
|
|
626
695
|
);
|
|
627
696
|
|
|
628
697
|
inputs[0].focus();
|
|
@@ -659,18 +728,24 @@ export function runConnectModal(options: ConnectModalOptions): Promise<ConnectRe
|
|
|
659
728
|
);
|
|
660
729
|
};
|
|
661
730
|
|
|
731
|
+
// The popup surface is a small window on desktop but a new tab on
|
|
732
|
+
// phones — the copy names whichever the visitor will actually see.
|
|
733
|
+
const popupSurface = isMobile ? 'tab' : 'window';
|
|
734
|
+
|
|
662
735
|
const renderPopupPrompt = (): void => {
|
|
663
736
|
setStage(
|
|
664
737
|
el('p', 'stage-caption', 'Connect with a wallet in this browser'),
|
|
665
|
-
el('p', 'stage-subline',
|
|
666
|
-
|
|
738
|
+
el('p', 'stage-subline', isMobile
|
|
739
|
+
? 'Your wallet opens in a new tab to approve this connection — no code needed.'
|
|
740
|
+
: 'Your wallet opens in a small window to approve this connection.'),
|
|
741
|
+
stageButton(isMobile ? 'Open wallet' : 'Open wallet window', () => { startPopup(); }),
|
|
667
742
|
);
|
|
668
743
|
};
|
|
669
744
|
|
|
670
745
|
const renderPopupWaiting = (): void => {
|
|
671
746
|
setStage(
|
|
672
747
|
el('div', 'spinner'),
|
|
673
|
-
el('p', 'stage-caption',
|
|
748
|
+
el('p', 'stage-caption', `Finish in the wallet ${popupSurface}`),
|
|
674
749
|
el('p', 'stage-subline', 'We’ll wrap up here as soon as you’re done.'),
|
|
675
750
|
);
|
|
676
751
|
};
|
|
@@ -678,10 +753,28 @@ export function runConnectModal(options: ConnectModalOptions): Promise<ConnectRe
|
|
|
678
753
|
const renderPopupInterrupted = (blocked: boolean): void => {
|
|
679
754
|
setStage(
|
|
680
755
|
el('p', 'stage-caption', blocked
|
|
681
|
-
?
|
|
682
|
-
:
|
|
683
|
-
stageButton(blocked ? 'Open it now' :
|
|
684
|
-
|
|
756
|
+
? `Your browser blocked the wallet ${popupSurface}.`
|
|
757
|
+
: `The wallet ${popupSurface} was closed.`),
|
|
758
|
+
stageButton(blocked ? 'Open it now' : `Reopen ${popupSurface}`, () => { startPopup(); }),
|
|
759
|
+
stageLinkButton(isMobile ? 'Use a code instead' : 'Use your phone instead', () => { void switchMethod('phone'); }),
|
|
760
|
+
);
|
|
761
|
+
};
|
|
762
|
+
|
|
763
|
+
const renderPopupFailure = (error: unknown): void => {
|
|
764
|
+
if (settled) { return; }
|
|
765
|
+
|
|
766
|
+
const failure = error instanceof Error ? error : new Error(String(error));
|
|
767
|
+
const popupBlocked = /popup blocked/i.test(failure.message);
|
|
768
|
+
if (error instanceof PopupWindowClosedError || popupBlocked) {
|
|
769
|
+
renderPopupInterrupted(popupBlocked);
|
|
770
|
+
return;
|
|
771
|
+
}
|
|
772
|
+
|
|
773
|
+
renderError(
|
|
774
|
+
/timed out/i.test(failure.message)
|
|
775
|
+
? 'That took too long, so we stopped for safety.'
|
|
776
|
+
: 'Something went wrong while connecting.',
|
|
777
|
+
failure,
|
|
685
778
|
);
|
|
686
779
|
};
|
|
687
780
|
|
|
@@ -698,20 +791,31 @@ export function runConnectModal(options: ConnectModalOptions): Promise<ConnectRe
|
|
|
698
791
|
return cached;
|
|
699
792
|
};
|
|
700
793
|
|
|
701
|
-
const
|
|
794
|
+
const clearRemint = (): void => {
|
|
702
795
|
clearTimeout(remintTimer);
|
|
796
|
+
remintAt = undefined;
|
|
797
|
+
};
|
|
798
|
+
|
|
799
|
+
const remintNow = (): void => {
|
|
800
|
+
// Never re-mint once the wallet has responded (pairing in progress).
|
|
801
|
+
if (!settled && pinResolve === undefined && method === 'phone') {
|
|
802
|
+
void startPhone();
|
|
803
|
+
}
|
|
804
|
+
};
|
|
805
|
+
|
|
806
|
+
const scheduleRemint = (expiresInSeconds: number): void => {
|
|
807
|
+
clearRemint();
|
|
703
808
|
const delay = Math.max(REMINT_MIN_MS, expiresInSeconds * 1_000 - REMINT_SAFETY_MS);
|
|
704
|
-
|
|
705
|
-
|
|
706
|
-
|
|
707
|
-
|
|
708
|
-
|
|
709
|
-
}, delay);
|
|
809
|
+
// The deadline is kept alongside the timer: background tabs (mobile
|
|
810
|
+
// especially) throttle or freeze timers, so the visibility handler
|
|
811
|
+
// re-checks it when the user returns.
|
|
812
|
+
remintAt = Date.now() + delay;
|
|
813
|
+
remintTimer = setTimeout(remintNow, delay);
|
|
710
814
|
};
|
|
711
815
|
|
|
712
816
|
const startPhone = async (): Promise<void> => {
|
|
713
817
|
relaySession?.cancel();
|
|
714
|
-
|
|
818
|
+
clearRemint();
|
|
715
819
|
|
|
716
820
|
if (walletUrl === undefined) {
|
|
717
821
|
renderError('No wallet is configured.');
|
|
@@ -750,14 +854,14 @@ export function runConnectModal(options: ConnectModalOptions): Promise<ConnectRe
|
|
|
750
854
|
},
|
|
751
855
|
onClaimed: (): void => {
|
|
752
856
|
if (session.active && !settled) {
|
|
753
|
-
// The
|
|
857
|
+
// The wallet has the request — stop re-minting (a new pointer
|
|
754
858
|
// would orphan the approval in progress) and show progress.
|
|
755
|
-
|
|
859
|
+
clearRemint();
|
|
756
860
|
renderClaimed();
|
|
757
861
|
}
|
|
758
862
|
},
|
|
759
863
|
requestPin: (attempt, previousError): Promise<string> => {
|
|
760
|
-
|
|
864
|
+
clearRemint();
|
|
761
865
|
return renderPin(attempt, previousError);
|
|
762
866
|
},
|
|
763
867
|
});
|
|
@@ -786,7 +890,7 @@ export function runConnectModal(options: ConnectModalOptions): Promise<ConnectRe
|
|
|
786
890
|
const startPopup = (): void => {
|
|
787
891
|
// Synchronous popup open inside the click's call stack.
|
|
788
892
|
relaySession?.cancel();
|
|
789
|
-
|
|
893
|
+
clearRemint();
|
|
790
894
|
|
|
791
895
|
if (walletUrl === undefined) {
|
|
792
896
|
renderError('No wallet is configured.');
|
|
@@ -797,55 +901,38 @@ export function runConnectModal(options: ConnectModalOptions): Promise<ConnectRe
|
|
|
797
901
|
method = 'browser';
|
|
798
902
|
renderFooter();
|
|
799
903
|
|
|
800
|
-
|
|
904
|
+
popupBusy = true;
|
|
905
|
+
renderPopupWaiting();
|
|
906
|
+
|
|
801
907
|
try {
|
|
802
|
-
|
|
908
|
+
deps.runPopup({
|
|
803
909
|
walletUrl,
|
|
804
910
|
permissionRequests : options.permissionRequests,
|
|
805
911
|
appName,
|
|
806
912
|
appIcon : options.appIcon,
|
|
807
913
|
timeoutMs : options.timeout,
|
|
808
|
-
})
|
|
914
|
+
})
|
|
915
|
+
.then((result) => {
|
|
916
|
+
if (settled) { return; }
|
|
917
|
+
if (result === undefined) {
|
|
918
|
+
renderDenied();
|
|
919
|
+
} else {
|
|
920
|
+
succeed(result);
|
|
921
|
+
}
|
|
922
|
+
})
|
|
923
|
+
.catch(renderPopupFailure)
|
|
924
|
+
.finally(() => { popupBusy = false; });
|
|
809
925
|
} catch (error) {
|
|
810
|
-
|
|
811
|
-
|
|
812
|
-
return;
|
|
926
|
+
popupBusy = false;
|
|
927
|
+
renderPopupFailure(error);
|
|
813
928
|
}
|
|
814
|
-
|
|
815
|
-
popupBusy = true;
|
|
816
|
-
renderPopupWaiting();
|
|
817
|
-
|
|
818
|
-
flow
|
|
819
|
-
.then((result) => {
|
|
820
|
-
if (settled) { return; }
|
|
821
|
-
if (result === undefined) {
|
|
822
|
-
renderDenied();
|
|
823
|
-
} else {
|
|
824
|
-
succeed(result);
|
|
825
|
-
}
|
|
826
|
-
})
|
|
827
|
-
.catch((error: unknown) => {
|
|
828
|
-
if (settled) { return; }
|
|
829
|
-
if (error instanceof PopupWindowClosedError) {
|
|
830
|
-
renderPopupInterrupted(false);
|
|
831
|
-
return;
|
|
832
|
-
}
|
|
833
|
-
const failure = error instanceof Error ? error : new Error(String(error));
|
|
834
|
-
renderError(
|
|
835
|
-
/timed out/i.test(failure.message)
|
|
836
|
-
? 'That took too long, so we stopped for safety.'
|
|
837
|
-
: 'Something went wrong while connecting.',
|
|
838
|
-
failure,
|
|
839
|
-
);
|
|
840
|
-
})
|
|
841
|
-
.finally(() => { popupBusy = false; });
|
|
842
929
|
};
|
|
843
930
|
|
|
844
931
|
const startMethod = async (): Promise<void> => {
|
|
845
932
|
if (method === 'browser') {
|
|
846
933
|
// window.open must stay inside a user gesture — prompt for the click.
|
|
847
934
|
relaySession?.cancel();
|
|
848
|
-
|
|
935
|
+
clearRemint();
|
|
849
936
|
renderFooter();
|
|
850
937
|
renderPopupPrompt();
|
|
851
938
|
} else {
|
|
@@ -878,14 +965,16 @@ export function runConnectModal(options: ConnectModalOptions): Promise<ConnectRe
|
|
|
878
965
|
if (method === 'phone') {
|
|
879
966
|
const alt = document.createElement('button');
|
|
880
967
|
alt.className = 'footer-link method-link';
|
|
881
|
-
|
|
968
|
+
// On a phone both methods open the wallet on this device — what the
|
|
969
|
+
// popup channel actually buys the visitor is skipping the code.
|
|
970
|
+
alt.textContent = isMobile ? 'Or connect without a code →' : 'No phone? Use this browser →';
|
|
882
971
|
// startPopup runs synchronously in this click handler.
|
|
883
972
|
alt.addEventListener('click', () => { startPopup(); });
|
|
884
973
|
row.appendChild(alt);
|
|
885
|
-
} else
|
|
974
|
+
} else {
|
|
886
975
|
const alt = document.createElement('button');
|
|
887
976
|
alt.className = 'footer-link method-link';
|
|
888
|
-
alt.textContent = 'Use your phone instead →';
|
|
977
|
+
alt.textContent = isMobile ? 'Use a code instead →' : 'Use your phone instead →';
|
|
889
978
|
alt.addEventListener('click', () => { void switchMethod('phone'); });
|
|
890
979
|
row.appendChild(alt);
|
|
891
980
|
}
|
|
@@ -1100,6 +1189,28 @@ export function runConnectModal(options: ConnectModalOptions): Promise<ConnectRe
|
|
|
1100
1189
|
};
|
|
1101
1190
|
document.addEventListener('keydown', onKeydown);
|
|
1102
1191
|
|
|
1192
|
+
// The visitor typically comes back from the wallet tab mid-session.
|
|
1193
|
+
const onVisibilityReturn = (): void => {
|
|
1194
|
+
if (document.visibilityState !== 'visible' || settled) {
|
|
1195
|
+
return;
|
|
1196
|
+
}
|
|
1197
|
+
|
|
1198
|
+
// Background tabs throttle (or freeze) timers, so a re-mint that came
|
|
1199
|
+
// due while the user was away fires now instead of never.
|
|
1200
|
+
if (remintAt !== undefined && Date.now() >= remintAt) {
|
|
1201
|
+
remintNow();
|
|
1202
|
+
return;
|
|
1203
|
+
}
|
|
1204
|
+
|
|
1205
|
+
// Returning with the code in hand: put the caret in the first empty
|
|
1206
|
+
// pairing-code box so they can type it straight away.
|
|
1207
|
+
if (pinResolve !== undefined) {
|
|
1208
|
+
const inputs = Array.from(shadow.querySelectorAll<HTMLInputElement>('.pin-input'));
|
|
1209
|
+
inputs.find((input) => input.value === '')?.focus();
|
|
1210
|
+
}
|
|
1211
|
+
};
|
|
1212
|
+
document.addEventListener('visibilitychange', onVisibilityReturn);
|
|
1213
|
+
|
|
1103
1214
|
overlay.appendChild(modal);
|
|
1104
1215
|
shadow.appendChild(overlay);
|
|
1105
1216
|
document.body.appendChild(host);
|
|
@@ -1363,6 +1474,31 @@ const MODAL_STYLES = `
|
|
|
1363
1474
|
.qr-logo .wallet-icon { width: 30px; height: 30px; }
|
|
1364
1475
|
.qr-logo .wallet-badge { border-radius: 8px; font-size: 15px; }
|
|
1365
1476
|
|
|
1477
|
+
/* The QR card doubles as the same-device handoff link. */
|
|
1478
|
+
a.qr-box { display: block; cursor: pointer; }
|
|
1479
|
+
.qr-box.qr-link:hover {
|
|
1480
|
+
border-color: var(--ec-accent);
|
|
1481
|
+
box-shadow: 0 0 0 3px var(--ec-accent-soft);
|
|
1482
|
+
}
|
|
1483
|
+
.qr-box.compact { width: 160px; height: 160px; }
|
|
1484
|
+
.qr-box.compact .qr-logo { width: 36px; height: 36px; }
|
|
1485
|
+
.qr-box.compact .qr-logo .wallet-icon { width: 24px; height: 24px; }
|
|
1486
|
+
|
|
1487
|
+
.stage-divider {
|
|
1488
|
+
display: flex;
|
|
1489
|
+
align-items: center;
|
|
1490
|
+
gap: 10px;
|
|
1491
|
+
width: 100%;
|
|
1492
|
+
color: var(--ec-muted);
|
|
1493
|
+
font-size: 12px;
|
|
1494
|
+
}
|
|
1495
|
+
.stage-divider::before, .stage-divider::after {
|
|
1496
|
+
content: '';
|
|
1497
|
+
flex: 1;
|
|
1498
|
+
height: 1px;
|
|
1499
|
+
background: var(--ec-border);
|
|
1500
|
+
}
|
|
1501
|
+
|
|
1366
1502
|
.claimed-pulse {
|
|
1367
1503
|
width: 64px; height: 64px; border-radius: 50%;
|
|
1368
1504
|
background: var(--ec-accent-soft); position: relative;
|