@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.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,21 @@ 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
3483
|
onClick: async () => {
|
|
3463
3484
|
setConnecting(true);
|
|
3464
3485
|
try {
|
|
3465
|
-
|
|
3486
|
+
const session = preparedSession?.providerId === selectedProvider.id ? preparedSession : void 0;
|
|
3487
|
+
await onSelectProvider(selectedProvider.id, session);
|
|
3466
3488
|
} finally {
|
|
3467
3489
|
setConnecting(false);
|
|
3468
3490
|
}
|
|
3469
3491
|
},
|
|
3470
|
-
loading: connecting,
|
|
3471
|
-
|
|
3472
|
-
|
|
3473
|
-
selectedProvider.name,
|
|
3474
|
-
" to Link"
|
|
3475
|
-
]
|
|
3492
|
+
loading: connecting || preparing,
|
|
3493
|
+
disabled: preparing,
|
|
3494
|
+
children: preparing ? "Preparing..." : `Open ${selectedProvider.name} to Link`
|
|
3476
3495
|
}
|
|
3477
3496
|
),
|
|
3478
3497
|
/* @__PURE__ */ jsx(PoweredByFooter, {})
|
|
@@ -3551,7 +3570,7 @@ function WalletPickerScreen({
|
|
|
3551
3570
|
return /* @__PURE__ */ jsxs(
|
|
3552
3571
|
"button",
|
|
3553
3572
|
{
|
|
3554
|
-
onClick: () =>
|
|
3573
|
+
onClick: () => handleCardClick(p.id),
|
|
3555
3574
|
onMouseEnter: () => setHoveredId(p.id),
|
|
3556
3575
|
onMouseLeave: () => setHoveredId(null),
|
|
3557
3576
|
style: cardStyle(tokens, isHovered, isSelected),
|
|
@@ -5572,6 +5591,7 @@ function StepRenderer({
|
|
|
5572
5591
|
providers: state.providers,
|
|
5573
5592
|
pendingConnections,
|
|
5574
5593
|
loading: state.creatingTransfer,
|
|
5594
|
+
onPrepareProvider: handlers.onPrepareProvider,
|
|
5575
5595
|
onSelectProvider: handlers.onSelectProvider,
|
|
5576
5596
|
onContinueConnection: handlers.onContinueConnection,
|
|
5577
5597
|
onBack: () => handlers.onNavigate(state.activeCredentialId ? "deposit" : "create-passkey")
|
|
@@ -6518,23 +6538,14 @@ function useProviderHandlers(deps) {
|
|
|
6518
6538
|
reauthSessionIdRef,
|
|
6519
6539
|
reauthTokenRef
|
|
6520
6540
|
} = deps;
|
|
6521
|
-
const
|
|
6522
|
-
dispatch({ type: "SELECT_PROVIDER", providerId });
|
|
6541
|
+
const handlePrepareProvider = useCallback(async (providerId) => {
|
|
6523
6542
|
if (!activeCredentialId) {
|
|
6524
6543
|
dispatch({ type: "SET_ERROR", error: "Create or verify a passkey on this device before continuing." });
|
|
6525
6544
|
dispatch({ type: "NAVIGATE", step: "create-passkey" });
|
|
6526
|
-
return;
|
|
6545
|
+
return null;
|
|
6527
6546
|
}
|
|
6528
6547
|
const provider = providers.find((p) => p.id === providerId);
|
|
6529
6548
|
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
6549
|
try {
|
|
6539
6550
|
const token = await getAccessToken();
|
|
6540
6551
|
if (!token) throw new Error("Not authenticated");
|
|
@@ -6547,21 +6558,71 @@ function useProviderHandlers(deps) {
|
|
|
6547
6558
|
});
|
|
6548
6559
|
const session = account.authorizationSessions?.[0];
|
|
6549
6560
|
if (!session) throw new Error("No authorization session returned.");
|
|
6561
|
+
return { accountId: account.id, sessionId: session.id, uri: session.uri };
|
|
6562
|
+
} catch (err) {
|
|
6563
|
+
captureException(err);
|
|
6564
|
+
const msg = err instanceof Error ? err.message : "Failed to set up wallet";
|
|
6565
|
+
dispatch({ type: "PAY_ERROR", error: msg, fallbackStep: "wallet-picker" });
|
|
6566
|
+
onError?.(msg);
|
|
6567
|
+
return null;
|
|
6568
|
+
}
|
|
6569
|
+
}, [activeCredentialId, providers, apiBaseUrl, getAccessToken, onError, dispatch]);
|
|
6570
|
+
const handleSelectProvider = useCallback(async (providerId, preparedSession) => {
|
|
6571
|
+
dispatch({ type: "SELECT_PROVIDER", providerId });
|
|
6572
|
+
if (!activeCredentialId) {
|
|
6573
|
+
dispatch({ type: "SET_ERROR", error: "Create or verify a passkey on this device before continuing." });
|
|
6574
|
+
dispatch({ type: "NAVIGATE", step: "create-passkey" });
|
|
6575
|
+
return;
|
|
6576
|
+
}
|
|
6577
|
+
const provider = providers.find((p) => p.id === providerId);
|
|
6578
|
+
const providerName = provider?.name ?? "Wallet";
|
|
6579
|
+
const isMobile = !shouldUseWalletConnector({
|
|
6580
|
+
useWalletConnector: useWalletConnectorProp,
|
|
6581
|
+
userAgent: typeof navigator === "undefined" ? void 0 : navigator.userAgent
|
|
6582
|
+
});
|
|
6583
|
+
if (!isMobile) {
|
|
6584
|
+
dispatch({ type: "PAY_STARTED", isSetupRedirect: false });
|
|
6585
|
+
dispatch({ type: "NAVIGATE", step: "setup-status" });
|
|
6586
|
+
}
|
|
6587
|
+
try {
|
|
6588
|
+
let accountId;
|
|
6589
|
+
let sessionId;
|
|
6590
|
+
let sessionUri;
|
|
6591
|
+
if (preparedSession) {
|
|
6592
|
+
accountId = preparedSession.accountId;
|
|
6593
|
+
sessionId = preparedSession.sessionId;
|
|
6594
|
+
sessionUri = preparedSession.uri;
|
|
6595
|
+
} else {
|
|
6596
|
+
const token = await getAccessToken();
|
|
6597
|
+
if (!token) throw new Error("Not authenticated");
|
|
6598
|
+
const newAccountId = crypto.randomUUID();
|
|
6599
|
+
const account = await createAccount(apiBaseUrl, token, {
|
|
6600
|
+
id: newAccountId,
|
|
6601
|
+
name: providerName,
|
|
6602
|
+
credentialId: activeCredentialId,
|
|
6603
|
+
providerId
|
|
6604
|
+
});
|
|
6605
|
+
const session = account.authorizationSessions?.[0];
|
|
6606
|
+
if (!session) throw new Error("No authorization session returned.");
|
|
6607
|
+
accountId = account.id;
|
|
6608
|
+
sessionId = session.id;
|
|
6609
|
+
sessionUri = session.uri;
|
|
6610
|
+
}
|
|
6550
6611
|
if (isMobile) {
|
|
6551
6612
|
handlingMobileReturnRef.current = false;
|
|
6552
6613
|
mobileSetupFlowRef.current = true;
|
|
6553
|
-
setupAccountIdRef.current =
|
|
6614
|
+
setupAccountIdRef.current = accountId;
|
|
6554
6615
|
persistMobileFlowState({
|
|
6555
|
-
accountId
|
|
6556
|
-
sessionId
|
|
6557
|
-
deeplinkUri:
|
|
6616
|
+
accountId,
|
|
6617
|
+
sessionId,
|
|
6618
|
+
deeplinkUri: sessionUri,
|
|
6558
6619
|
providerId,
|
|
6559
6620
|
isSetup: true
|
|
6560
6621
|
});
|
|
6561
|
-
triggerDeeplink(
|
|
6562
|
-
dispatch({ type: "MOBILE_DEEPLINK_READY", deeplinkUri:
|
|
6622
|
+
triggerDeeplink(sessionUri);
|
|
6623
|
+
dispatch({ type: "MOBILE_DEEPLINK_READY", deeplinkUri: sessionUri });
|
|
6563
6624
|
} else {
|
|
6564
|
-
await authExecutor.executeSessionById(
|
|
6625
|
+
await authExecutor.executeSessionById(sessionId);
|
|
6565
6626
|
await reloadAccounts();
|
|
6566
6627
|
dispatch({ type: "NAVIGATE", step: "deposit" });
|
|
6567
6628
|
}
|
|
@@ -6791,6 +6852,7 @@ function useProviderHandlers(deps) {
|
|
|
6791
6852
|
reauthTokenRef
|
|
6792
6853
|
]);
|
|
6793
6854
|
return {
|
|
6855
|
+
handlePrepareProvider,
|
|
6794
6856
|
handleSelectProvider,
|
|
6795
6857
|
handleContinueConnection,
|
|
6796
6858
|
handleSelectAccount,
|
|
@@ -7649,6 +7711,7 @@ function SwypePaymentInner({
|
|
|
7649
7711
|
onRegisterPasskey: passkey.handleRegisterPasskey,
|
|
7650
7712
|
onCreatePasskeyViaPopup: passkey.handleCreatePasskeyViaPopup,
|
|
7651
7713
|
onVerifyPasskeyViaPopup: passkey.handleVerifyPasskeyViaPopup,
|
|
7714
|
+
onPrepareProvider: provider.handlePrepareProvider,
|
|
7652
7715
|
onSelectProvider: provider.handleSelectProvider,
|
|
7653
7716
|
onContinueConnection: provider.handleContinueConnection,
|
|
7654
7717
|
onSelectAccount: provider.handleSelectAccount,
|