@swype-org/react-sdk 0.1.156 → 0.1.157
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 +90 -27
- package/dist/index.cjs.map +1 -1
- package/dist/index.js +90 -27
- 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,21 @@ 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
3486
|
onClick: async () => {
|
|
3466
3487
|
setConnecting(true);
|
|
3467
3488
|
try {
|
|
3468
|
-
|
|
3489
|
+
const session = preparedSession?.providerId === selectedProvider.id ? preparedSession : void 0;
|
|
3490
|
+
await onSelectProvider(selectedProvider.id, session);
|
|
3469
3491
|
} finally {
|
|
3470
3492
|
setConnecting(false);
|
|
3471
3493
|
}
|
|
3472
3494
|
},
|
|
3473
|
-
loading: connecting,
|
|
3474
|
-
|
|
3475
|
-
|
|
3476
|
-
selectedProvider.name,
|
|
3477
|
-
" to Link"
|
|
3478
|
-
]
|
|
3495
|
+
loading: connecting || preparing,
|
|
3496
|
+
disabled: preparing,
|
|
3497
|
+
children: preparing ? "Preparing..." : `Open ${selectedProvider.name} to Link`
|
|
3479
3498
|
}
|
|
3480
3499
|
),
|
|
3481
3500
|
/* @__PURE__ */ jsxRuntime.jsx(PoweredByFooter, {})
|
|
@@ -3554,7 +3573,7 @@ function WalletPickerScreen({
|
|
|
3554
3573
|
return /* @__PURE__ */ jsxRuntime.jsxs(
|
|
3555
3574
|
"button",
|
|
3556
3575
|
{
|
|
3557
|
-
onClick: () =>
|
|
3576
|
+
onClick: () => handleCardClick(p.id),
|
|
3558
3577
|
onMouseEnter: () => setHoveredId(p.id),
|
|
3559
3578
|
onMouseLeave: () => setHoveredId(null),
|
|
3560
3579
|
style: cardStyle(tokens, isHovered, isSelected),
|
|
@@ -5575,6 +5594,7 @@ function StepRenderer({
|
|
|
5575
5594
|
providers: state.providers,
|
|
5576
5595
|
pendingConnections,
|
|
5577
5596
|
loading: state.creatingTransfer,
|
|
5597
|
+
onPrepareProvider: handlers.onPrepareProvider,
|
|
5578
5598
|
onSelectProvider: handlers.onSelectProvider,
|
|
5579
5599
|
onContinueConnection: handlers.onContinueConnection,
|
|
5580
5600
|
onBack: () => handlers.onNavigate(state.activeCredentialId ? "deposit" : "create-passkey")
|
|
@@ -6521,23 +6541,14 @@ function useProviderHandlers(deps) {
|
|
|
6521
6541
|
reauthSessionIdRef,
|
|
6522
6542
|
reauthTokenRef
|
|
6523
6543
|
} = deps;
|
|
6524
|
-
const
|
|
6525
|
-
dispatch({ type: "SELECT_PROVIDER", providerId });
|
|
6544
|
+
const handlePrepareProvider = react.useCallback(async (providerId) => {
|
|
6526
6545
|
if (!activeCredentialId) {
|
|
6527
6546
|
dispatch({ type: "SET_ERROR", error: "Create or verify a passkey on this device before continuing." });
|
|
6528
6547
|
dispatch({ type: "NAVIGATE", step: "create-passkey" });
|
|
6529
|
-
return;
|
|
6548
|
+
return null;
|
|
6530
6549
|
}
|
|
6531
6550
|
const provider = providers.find((p) => p.id === providerId);
|
|
6532
6551
|
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
6552
|
try {
|
|
6542
6553
|
const token = await getAccessToken();
|
|
6543
6554
|
if (!token) throw new Error("Not authenticated");
|
|
@@ -6550,21 +6561,71 @@ function useProviderHandlers(deps) {
|
|
|
6550
6561
|
});
|
|
6551
6562
|
const session = account.authorizationSessions?.[0];
|
|
6552
6563
|
if (!session) throw new Error("No authorization session returned.");
|
|
6564
|
+
return { accountId: account.id, sessionId: session.id, uri: session.uri };
|
|
6565
|
+
} catch (err) {
|
|
6566
|
+
captureException(err);
|
|
6567
|
+
const msg = err instanceof Error ? err.message : "Failed to set up wallet";
|
|
6568
|
+
dispatch({ type: "PAY_ERROR", error: msg, fallbackStep: "wallet-picker" });
|
|
6569
|
+
onError?.(msg);
|
|
6570
|
+
return null;
|
|
6571
|
+
}
|
|
6572
|
+
}, [activeCredentialId, providers, apiBaseUrl, getAccessToken, onError, dispatch]);
|
|
6573
|
+
const handleSelectProvider = react.useCallback(async (providerId, preparedSession) => {
|
|
6574
|
+
dispatch({ type: "SELECT_PROVIDER", providerId });
|
|
6575
|
+
if (!activeCredentialId) {
|
|
6576
|
+
dispatch({ type: "SET_ERROR", error: "Create or verify a passkey on this device before continuing." });
|
|
6577
|
+
dispatch({ type: "NAVIGATE", step: "create-passkey" });
|
|
6578
|
+
return;
|
|
6579
|
+
}
|
|
6580
|
+
const provider = providers.find((p) => p.id === providerId);
|
|
6581
|
+
const providerName = provider?.name ?? "Wallet";
|
|
6582
|
+
const isMobile = !shouldUseWalletConnector({
|
|
6583
|
+
useWalletConnector: useWalletConnectorProp,
|
|
6584
|
+
userAgent: typeof navigator === "undefined" ? void 0 : navigator.userAgent
|
|
6585
|
+
});
|
|
6586
|
+
if (!isMobile) {
|
|
6587
|
+
dispatch({ type: "PAY_STARTED", isSetupRedirect: false });
|
|
6588
|
+
dispatch({ type: "NAVIGATE", step: "setup-status" });
|
|
6589
|
+
}
|
|
6590
|
+
try {
|
|
6591
|
+
let accountId;
|
|
6592
|
+
let sessionId;
|
|
6593
|
+
let sessionUri;
|
|
6594
|
+
if (preparedSession) {
|
|
6595
|
+
accountId = preparedSession.accountId;
|
|
6596
|
+
sessionId = preparedSession.sessionId;
|
|
6597
|
+
sessionUri = preparedSession.uri;
|
|
6598
|
+
} else {
|
|
6599
|
+
const token = await getAccessToken();
|
|
6600
|
+
if (!token) throw new Error("Not authenticated");
|
|
6601
|
+
const newAccountId = crypto.randomUUID();
|
|
6602
|
+
const account = await createAccount(apiBaseUrl, token, {
|
|
6603
|
+
id: newAccountId,
|
|
6604
|
+
name: providerName,
|
|
6605
|
+
credentialId: activeCredentialId,
|
|
6606
|
+
providerId
|
|
6607
|
+
});
|
|
6608
|
+
const session = account.authorizationSessions?.[0];
|
|
6609
|
+
if (!session) throw new Error("No authorization session returned.");
|
|
6610
|
+
accountId = account.id;
|
|
6611
|
+
sessionId = session.id;
|
|
6612
|
+
sessionUri = session.uri;
|
|
6613
|
+
}
|
|
6553
6614
|
if (isMobile) {
|
|
6554
6615
|
handlingMobileReturnRef.current = false;
|
|
6555
6616
|
mobileSetupFlowRef.current = true;
|
|
6556
|
-
setupAccountIdRef.current =
|
|
6617
|
+
setupAccountIdRef.current = accountId;
|
|
6557
6618
|
persistMobileFlowState({
|
|
6558
|
-
accountId
|
|
6559
|
-
sessionId
|
|
6560
|
-
deeplinkUri:
|
|
6619
|
+
accountId,
|
|
6620
|
+
sessionId,
|
|
6621
|
+
deeplinkUri: sessionUri,
|
|
6561
6622
|
providerId,
|
|
6562
6623
|
isSetup: true
|
|
6563
6624
|
});
|
|
6564
|
-
triggerDeeplink(
|
|
6565
|
-
dispatch({ type: "MOBILE_DEEPLINK_READY", deeplinkUri:
|
|
6625
|
+
triggerDeeplink(sessionUri);
|
|
6626
|
+
dispatch({ type: "MOBILE_DEEPLINK_READY", deeplinkUri: sessionUri });
|
|
6566
6627
|
} else {
|
|
6567
|
-
await authExecutor.executeSessionById(
|
|
6628
|
+
await authExecutor.executeSessionById(sessionId);
|
|
6568
6629
|
await reloadAccounts();
|
|
6569
6630
|
dispatch({ type: "NAVIGATE", step: "deposit" });
|
|
6570
6631
|
}
|
|
@@ -6794,6 +6855,7 @@ function useProviderHandlers(deps) {
|
|
|
6794
6855
|
reauthTokenRef
|
|
6795
6856
|
]);
|
|
6796
6857
|
return {
|
|
6858
|
+
handlePrepareProvider,
|
|
6797
6859
|
handleSelectProvider,
|
|
6798
6860
|
handleContinueConnection,
|
|
6799
6861
|
handleSelectAccount,
|
|
@@ -7652,6 +7714,7 @@ function SwypePaymentInner({
|
|
|
7652
7714
|
onRegisterPasskey: passkey.handleRegisterPasskey,
|
|
7653
7715
|
onCreatePasskeyViaPopup: passkey.handleCreatePasskeyViaPopup,
|
|
7654
7716
|
onVerifyPasskeyViaPopup: passkey.handleVerifyPasskeyViaPopup,
|
|
7717
|
+
onPrepareProvider: provider.handlePrepareProvider,
|
|
7655
7718
|
onSelectProvider: provider.handleSelectProvider,
|
|
7656
7719
|
onContinueConnection: provider.handleContinueConnection,
|
|
7657
7720
|
onSelectAccount: provider.handleSelectAccount,
|