@swype-org/react-sdk 0.1.156 → 0.1.158
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/index.cjs +99 -32
- package/dist/index.cjs.map +1 -1
- package/dist/index.js +99 -32
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -3429,6 +3429,7 @@ function WalletPickerScreen({
|
|
|
3429
3429
|
providers,
|
|
3430
3430
|
pendingConnections,
|
|
3431
3431
|
loading,
|
|
3432
|
+
onPrepareProvider,
|
|
3432
3433
|
onSelectProvider,
|
|
3433
3434
|
onContinueConnection,
|
|
3434
3435
|
onBack
|
|
@@ -3438,6 +3439,26 @@ function WalletPickerScreen({
|
|
|
3438
3439
|
const [selectedProviderId, setSelectedProviderId] = useState(null);
|
|
3439
3440
|
const [cryptoExpanded, setCryptoExpanded] = useState(false);
|
|
3440
3441
|
const [connecting, setConnecting] = useState(false);
|
|
3442
|
+
const [preparedSession, setPreparedSession] = useState(null);
|
|
3443
|
+
const [preparing, setPreparing] = useState(false);
|
|
3444
|
+
const prepareIdRef = useRef(0);
|
|
3445
|
+
const handleCardClick = useCallback(async (providerId) => {
|
|
3446
|
+
setSelectedProviderId(providerId);
|
|
3447
|
+
setPreparedSession(null);
|
|
3448
|
+
setPreparing(true);
|
|
3449
|
+
const id = ++prepareIdRef.current;
|
|
3450
|
+
try {
|
|
3451
|
+
const session = await onPrepareProvider(providerId);
|
|
3452
|
+
if (prepareIdRef.current !== id) return;
|
|
3453
|
+
if (session) {
|
|
3454
|
+
setPreparedSession({ ...session, providerId });
|
|
3455
|
+
}
|
|
3456
|
+
} finally {
|
|
3457
|
+
if (prepareIdRef.current === id) {
|
|
3458
|
+
setPreparing(false);
|
|
3459
|
+
}
|
|
3460
|
+
}
|
|
3461
|
+
}, [onPrepareProvider]);
|
|
3441
3462
|
const hasPending = pendingConnections != null && pendingConnections.length > 0;
|
|
3442
3463
|
const displayProviders = providers.length > 0 ? providers : [
|
|
3443
3464
|
{ id: "metamask", name: "MetaMask" },
|
|
@@ -3456,23 +3477,23 @@ function WalletPickerScreen({
|
|
|
3456
3477
|
ScreenLayout,
|
|
3457
3478
|
{
|
|
3458
3479
|
footer: /* @__PURE__ */ jsxs(Fragment, { children: [
|
|
3459
|
-
selectedProvider && /* @__PURE__ */
|
|
3480
|
+
selectedProvider && /* @__PURE__ */ jsx(
|
|
3460
3481
|
PrimaryButton,
|
|
3461
3482
|
{
|
|
3462
|
-
onClick:
|
|
3463
|
-
|
|
3464
|
-
|
|
3465
|
-
|
|
3466
|
-
|
|
3467
|
-
|
|
3483
|
+
onClick: () => {
|
|
3484
|
+
const session = preparedSession?.providerId === selectedProvider.id ? preparedSession : void 0;
|
|
3485
|
+
if (session) {
|
|
3486
|
+
const opened = window.open(session.uri, "_blank");
|
|
3487
|
+
if (!opened && window === window.parent) {
|
|
3488
|
+
window.location.href = session.uri;
|
|
3489
|
+
}
|
|
3468
3490
|
}
|
|
3491
|
+
setConnecting(true);
|
|
3492
|
+
onSelectProvider(selectedProvider.id, session).finally(() => setConnecting(false));
|
|
3469
3493
|
},
|
|
3470
|
-
loading: connecting,
|
|
3471
|
-
|
|
3472
|
-
|
|
3473
|
-
selectedProvider.name,
|
|
3474
|
-
" to Link"
|
|
3475
|
-
]
|
|
3494
|
+
loading: connecting || preparing,
|
|
3495
|
+
disabled: preparing,
|
|
3496
|
+
children: preparing ? "Preparing..." : `Open ${selectedProvider.name} to Link`
|
|
3476
3497
|
}
|
|
3477
3498
|
),
|
|
3478
3499
|
/* @__PURE__ */ jsx(PoweredByFooter, {})
|
|
@@ -3551,7 +3572,7 @@ function WalletPickerScreen({
|
|
|
3551
3572
|
return /* @__PURE__ */ jsxs(
|
|
3552
3573
|
"button",
|
|
3553
3574
|
{
|
|
3554
|
-
onClick: () =>
|
|
3575
|
+
onClick: () => handleCardClick(p.id),
|
|
3555
3576
|
onMouseEnter: () => setHoveredId(p.id),
|
|
3556
3577
|
onMouseLeave: () => setHoveredId(null),
|
|
3557
3578
|
style: cardStyle(tokens, isHovered, isSelected),
|
|
@@ -5572,6 +5593,7 @@ function StepRenderer({
|
|
|
5572
5593
|
providers: state.providers,
|
|
5573
5594
|
pendingConnections,
|
|
5574
5595
|
loading: state.creatingTransfer,
|
|
5596
|
+
onPrepareProvider: handlers.onPrepareProvider,
|
|
5575
5597
|
onSelectProvider: handlers.onSelectProvider,
|
|
5576
5598
|
onContinueConnection: handlers.onContinueConnection,
|
|
5577
5599
|
onBack: () => handlers.onNavigate(state.activeCredentialId ? "deposit" : "create-passkey")
|
|
@@ -6518,23 +6540,14 @@ function useProviderHandlers(deps) {
|
|
|
6518
6540
|
reauthSessionIdRef,
|
|
6519
6541
|
reauthTokenRef
|
|
6520
6542
|
} = deps;
|
|
6521
|
-
const
|
|
6522
|
-
dispatch({ type: "SELECT_PROVIDER", providerId });
|
|
6543
|
+
const handlePrepareProvider = useCallback(async (providerId) => {
|
|
6523
6544
|
if (!activeCredentialId) {
|
|
6524
6545
|
dispatch({ type: "SET_ERROR", error: "Create or verify a passkey on this device before continuing." });
|
|
6525
6546
|
dispatch({ type: "NAVIGATE", step: "create-passkey" });
|
|
6526
|
-
return;
|
|
6547
|
+
return null;
|
|
6527
6548
|
}
|
|
6528
6549
|
const provider = providers.find((p) => p.id === providerId);
|
|
6529
6550
|
const providerName = provider?.name ?? "Wallet";
|
|
6530
|
-
const isMobile = !shouldUseWalletConnector({
|
|
6531
|
-
useWalletConnector: useWalletConnectorProp,
|
|
6532
|
-
userAgent: typeof navigator === "undefined" ? void 0 : navigator.userAgent
|
|
6533
|
-
});
|
|
6534
|
-
if (!isMobile) {
|
|
6535
|
-
dispatch({ type: "PAY_STARTED", isSetupRedirect: false });
|
|
6536
|
-
dispatch({ type: "NAVIGATE", step: "setup-status" });
|
|
6537
|
-
}
|
|
6538
6551
|
try {
|
|
6539
6552
|
const token = await getAccessToken();
|
|
6540
6553
|
if (!token) throw new Error("Not authenticated");
|
|
@@ -6547,21 +6560,73 @@ function useProviderHandlers(deps) {
|
|
|
6547
6560
|
});
|
|
6548
6561
|
const session = account.authorizationSessions?.[0];
|
|
6549
6562
|
if (!session) throw new Error("No authorization session returned.");
|
|
6563
|
+
return { accountId: account.id, sessionId: session.id, uri: session.uri };
|
|
6564
|
+
} catch (err) {
|
|
6565
|
+
captureException(err);
|
|
6566
|
+
const msg = err instanceof Error ? err.message : "Failed to set up wallet";
|
|
6567
|
+
dispatch({ type: "PAY_ERROR", error: msg, fallbackStep: "wallet-picker" });
|
|
6568
|
+
onError?.(msg);
|
|
6569
|
+
return null;
|
|
6570
|
+
}
|
|
6571
|
+
}, [activeCredentialId, providers, apiBaseUrl, getAccessToken, onError, dispatch]);
|
|
6572
|
+
const handleSelectProvider = useCallback(async (providerId, preparedSession) => {
|
|
6573
|
+
dispatch({ type: "SELECT_PROVIDER", providerId });
|
|
6574
|
+
if (!activeCredentialId) {
|
|
6575
|
+
dispatch({ type: "SET_ERROR", error: "Create or verify a passkey on this device before continuing." });
|
|
6576
|
+
dispatch({ type: "NAVIGATE", step: "create-passkey" });
|
|
6577
|
+
return;
|
|
6578
|
+
}
|
|
6579
|
+
const provider = providers.find((p) => p.id === providerId);
|
|
6580
|
+
const providerName = provider?.name ?? "Wallet";
|
|
6581
|
+
const isMobile = !shouldUseWalletConnector({
|
|
6582
|
+
useWalletConnector: useWalletConnectorProp,
|
|
6583
|
+
userAgent: typeof navigator === "undefined" ? void 0 : navigator.userAgent
|
|
6584
|
+
});
|
|
6585
|
+
if (!isMobile) {
|
|
6586
|
+
dispatch({ type: "PAY_STARTED", isSetupRedirect: false });
|
|
6587
|
+
dispatch({ type: "NAVIGATE", step: "setup-status" });
|
|
6588
|
+
}
|
|
6589
|
+
try {
|
|
6590
|
+
let accountId;
|
|
6591
|
+
let sessionId;
|
|
6592
|
+
let sessionUri;
|
|
6593
|
+
if (preparedSession) {
|
|
6594
|
+
accountId = preparedSession.accountId;
|
|
6595
|
+
sessionId = preparedSession.sessionId;
|
|
6596
|
+
sessionUri = preparedSession.uri;
|
|
6597
|
+
} else {
|
|
6598
|
+
const token = await getAccessToken();
|
|
6599
|
+
if (!token) throw new Error("Not authenticated");
|
|
6600
|
+
const newAccountId = crypto.randomUUID();
|
|
6601
|
+
const account = await createAccount(apiBaseUrl, token, {
|
|
6602
|
+
id: newAccountId,
|
|
6603
|
+
name: providerName,
|
|
6604
|
+
credentialId: activeCredentialId,
|
|
6605
|
+
providerId
|
|
6606
|
+
});
|
|
6607
|
+
const session = account.authorizationSessions?.[0];
|
|
6608
|
+
if (!session) throw new Error("No authorization session returned.");
|
|
6609
|
+
accountId = account.id;
|
|
6610
|
+
sessionId = session.id;
|
|
6611
|
+
sessionUri = session.uri;
|
|
6612
|
+
}
|
|
6550
6613
|
if (isMobile) {
|
|
6551
6614
|
handlingMobileReturnRef.current = false;
|
|
6552
6615
|
mobileSetupFlowRef.current = true;
|
|
6553
|
-
setupAccountIdRef.current =
|
|
6616
|
+
setupAccountIdRef.current = accountId;
|
|
6554
6617
|
persistMobileFlowState({
|
|
6555
|
-
accountId
|
|
6556
|
-
sessionId
|
|
6557
|
-
deeplinkUri:
|
|
6618
|
+
accountId,
|
|
6619
|
+
sessionId,
|
|
6620
|
+
deeplinkUri: sessionUri,
|
|
6558
6621
|
providerId,
|
|
6559
6622
|
isSetup: true
|
|
6560
6623
|
});
|
|
6561
|
-
|
|
6562
|
-
|
|
6624
|
+
if (!preparedSession) {
|
|
6625
|
+
triggerDeeplink(sessionUri);
|
|
6626
|
+
}
|
|
6627
|
+
dispatch({ type: "MOBILE_DEEPLINK_READY", deeplinkUri: sessionUri });
|
|
6563
6628
|
} else {
|
|
6564
|
-
await authExecutor.executeSessionById(
|
|
6629
|
+
await authExecutor.executeSessionById(sessionId);
|
|
6565
6630
|
await reloadAccounts();
|
|
6566
6631
|
dispatch({ type: "NAVIGATE", step: "deposit" });
|
|
6567
6632
|
}
|
|
@@ -6791,6 +6856,7 @@ function useProviderHandlers(deps) {
|
|
|
6791
6856
|
reauthTokenRef
|
|
6792
6857
|
]);
|
|
6793
6858
|
return {
|
|
6859
|
+
handlePrepareProvider,
|
|
6794
6860
|
handleSelectProvider,
|
|
6795
6861
|
handleContinueConnection,
|
|
6796
6862
|
handleSelectAccount,
|
|
@@ -7649,6 +7715,7 @@ function SwypePaymentInner({
|
|
|
7649
7715
|
onRegisterPasskey: passkey.handleRegisterPasskey,
|
|
7650
7716
|
onCreatePasskeyViaPopup: passkey.handleCreatePasskeyViaPopup,
|
|
7651
7717
|
onVerifyPasskeyViaPopup: passkey.handleVerifyPasskeyViaPopup,
|
|
7718
|
+
onPrepareProvider: provider.handlePrepareProvider,
|
|
7652
7719
|
onSelectProvider: provider.handleSelectProvider,
|
|
7653
7720
|
onContinueConnection: provider.handleContinueConnection,
|
|
7654
7721
|
onSelectAccount: provider.handleSelectAccount,
|