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