@swype-org/react-sdk 0.1.98 → 0.1.100

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.d.cts CHANGED
@@ -121,7 +121,6 @@ interface Transfer {
121
121
  amount: Amount;
122
122
  createDate: string;
123
123
  updateDate: string;
124
- authorizationSessions: AuthorizationSession[];
125
124
  signPayload?: TransferSignPayload | null;
126
125
  }
127
126
  /** Standard API error shape */
@@ -143,7 +142,7 @@ interface ActionExecutionResult {
143
142
  data?: unknown;
144
143
  }
145
144
  /** Source type discriminator for transfer creation */
146
- type SourceType = 'providerId' | 'accountId' | 'walletId' | 'tokenId';
145
+ type SourceType = 'accountId' | 'walletId' | 'tokenId';
147
146
  /** A chain+token option from the SELECT_SOURCE action metadata. */
148
147
  interface SourceOption {
149
148
  chainName: string;
@@ -298,6 +297,12 @@ declare function useSwypeDepositAmount(): {
298
297
  declare function fetchProviders(apiBaseUrl: string, token: string): Promise<Provider[]>;
299
298
  declare function fetchChains(apiBaseUrl: string, token: string): Promise<Chain[]>;
300
299
  declare function fetchAccounts(apiBaseUrl: string, token: string, credentialId: string): Promise<Account[]>;
300
+ interface CreateAccountParams {
301
+ name: string;
302
+ credentialId: string;
303
+ providerId: string;
304
+ }
305
+ declare function createAccount(apiBaseUrl: string, token: string, params: CreateAccountParams): Promise<Account>;
301
306
  interface CreateTransferParams {
302
307
  /** Caller-supplied UUID v4 for idempotency. If omitted, a random UUID is generated. */
303
308
  id?: string;
@@ -353,7 +358,9 @@ declare function updateUserConfigBySession(apiBaseUrl: string, sessionId: string
353
358
  }): Promise<void>;
354
359
  declare function reportActionCompletion(apiBaseUrl: string, actionId: string, result: Record<string, unknown>): Promise<AuthorizationSessionDetail>;
355
360
 
361
+ type api_CreateAccountParams = CreateAccountParams;
356
362
  type api_CreateTransferParams = CreateTransferParams;
363
+ declare const api_createAccount: typeof createAccount;
357
364
  declare const api_createTransfer: typeof createTransfer;
358
365
  declare const api_fetchAccounts: typeof fetchAccounts;
359
366
  declare const api_fetchAuthorizationSession: typeof fetchAuthorizationSession;
@@ -369,7 +376,7 @@ declare const api_signTransfer: typeof signTransfer;
369
376
  declare const api_updateUserConfig: typeof updateUserConfig;
370
377
  declare const api_updateUserConfigBySession: typeof updateUserConfigBySession;
371
378
  declare namespace api {
372
- export { type api_CreateTransferParams as CreateTransferParams, api_createTransfer as createTransfer, api_fetchAccounts as fetchAccounts, api_fetchAuthorizationSession as fetchAuthorizationSession, api_fetchChains as fetchChains, api_fetchMerchantPublicKey as fetchMerchantPublicKey, api_fetchProviders as fetchProviders, api_fetchTransfer as fetchTransfer, api_fetchUserConfig as fetchUserConfig, api_registerPasskey as registerPasskey, api_reportActionCompletion as reportActionCompletion, api_reportPasskeyActivity as reportPasskeyActivity, api_signTransfer as signTransfer, api_updateUserConfig as updateUserConfig, api_updateUserConfigBySession as updateUserConfigBySession };
379
+ export { type api_CreateAccountParams as CreateAccountParams, type api_CreateTransferParams as CreateTransferParams, api_createAccount as createAccount, api_createTransfer as createTransfer, api_fetchAccounts as fetchAccounts, api_fetchAuthorizationSession as fetchAuthorizationSession, api_fetchChains as fetchChains, api_fetchMerchantPublicKey as fetchMerchantPublicKey, api_fetchProviders as fetchProviders, api_fetchTransfer as fetchTransfer, api_fetchUserConfig as fetchUserConfig, api_registerPasskey as registerPasskey, api_reportActionCompletion as reportActionCompletion, api_reportPasskeyActivity as reportPasskeyActivity, api_signTransfer as signTransfer, api_updateUserConfig as updateUserConfig, api_updateUserConfigBySession as updateUserConfigBySession };
373
380
  }
374
381
 
375
382
  interface SwypePaymentProps {
@@ -554,7 +561,6 @@ interface UseAuthorizationExecutorResult {
554
561
  resolveSelectSource: (selection: SourceSelection) => void;
555
562
  /** Execute authorization by session id. */
556
563
  executeSessionById: (sessionId: string) => Promise<void>;
557
- executeSession: (transfer: Transfer) => Promise<void>;
558
564
  }
559
565
  interface UseAuthorizationExecutorOptions {
560
566
  /** Optional API base URL override when used outside SwypeProvider. */
package/dist/index.d.ts CHANGED
@@ -121,7 +121,6 @@ interface Transfer {
121
121
  amount: Amount;
122
122
  createDate: string;
123
123
  updateDate: string;
124
- authorizationSessions: AuthorizationSession[];
125
124
  signPayload?: TransferSignPayload | null;
126
125
  }
127
126
  /** Standard API error shape */
@@ -143,7 +142,7 @@ interface ActionExecutionResult {
143
142
  data?: unknown;
144
143
  }
145
144
  /** Source type discriminator for transfer creation */
146
- type SourceType = 'providerId' | 'accountId' | 'walletId' | 'tokenId';
145
+ type SourceType = 'accountId' | 'walletId' | 'tokenId';
147
146
  /** A chain+token option from the SELECT_SOURCE action metadata. */
148
147
  interface SourceOption {
149
148
  chainName: string;
@@ -298,6 +297,12 @@ declare function useSwypeDepositAmount(): {
298
297
  declare function fetchProviders(apiBaseUrl: string, token: string): Promise<Provider[]>;
299
298
  declare function fetchChains(apiBaseUrl: string, token: string): Promise<Chain[]>;
300
299
  declare function fetchAccounts(apiBaseUrl: string, token: string, credentialId: string): Promise<Account[]>;
300
+ interface CreateAccountParams {
301
+ name: string;
302
+ credentialId: string;
303
+ providerId: string;
304
+ }
305
+ declare function createAccount(apiBaseUrl: string, token: string, params: CreateAccountParams): Promise<Account>;
301
306
  interface CreateTransferParams {
302
307
  /** Caller-supplied UUID v4 for idempotency. If omitted, a random UUID is generated. */
303
308
  id?: string;
@@ -353,7 +358,9 @@ declare function updateUserConfigBySession(apiBaseUrl: string, sessionId: string
353
358
  }): Promise<void>;
354
359
  declare function reportActionCompletion(apiBaseUrl: string, actionId: string, result: Record<string, unknown>): Promise<AuthorizationSessionDetail>;
355
360
 
361
+ type api_CreateAccountParams = CreateAccountParams;
356
362
  type api_CreateTransferParams = CreateTransferParams;
363
+ declare const api_createAccount: typeof createAccount;
357
364
  declare const api_createTransfer: typeof createTransfer;
358
365
  declare const api_fetchAccounts: typeof fetchAccounts;
359
366
  declare const api_fetchAuthorizationSession: typeof fetchAuthorizationSession;
@@ -369,7 +376,7 @@ declare const api_signTransfer: typeof signTransfer;
369
376
  declare const api_updateUserConfig: typeof updateUserConfig;
370
377
  declare const api_updateUserConfigBySession: typeof updateUserConfigBySession;
371
378
  declare namespace api {
372
- export { type api_CreateTransferParams as CreateTransferParams, api_createTransfer as createTransfer, api_fetchAccounts as fetchAccounts, api_fetchAuthorizationSession as fetchAuthorizationSession, api_fetchChains as fetchChains, api_fetchMerchantPublicKey as fetchMerchantPublicKey, api_fetchProviders as fetchProviders, api_fetchTransfer as fetchTransfer, api_fetchUserConfig as fetchUserConfig, api_registerPasskey as registerPasskey, api_reportActionCompletion as reportActionCompletion, api_reportPasskeyActivity as reportPasskeyActivity, api_signTransfer as signTransfer, api_updateUserConfig as updateUserConfig, api_updateUserConfigBySession as updateUserConfigBySession };
379
+ export { type api_CreateAccountParams as CreateAccountParams, type api_CreateTransferParams as CreateTransferParams, api_createAccount as createAccount, api_createTransfer as createTransfer, api_fetchAccounts as fetchAccounts, api_fetchAuthorizationSession as fetchAuthorizationSession, api_fetchChains as fetchChains, api_fetchMerchantPublicKey as fetchMerchantPublicKey, api_fetchProviders as fetchProviders, api_fetchTransfer as fetchTransfer, api_fetchUserConfig as fetchUserConfig, api_registerPasskey as registerPasskey, api_reportActionCompletion as reportActionCompletion, api_reportPasskeyActivity as reportPasskeyActivity, api_signTransfer as signTransfer, api_updateUserConfig as updateUserConfig, api_updateUserConfigBySession as updateUserConfigBySession };
373
380
  }
374
381
 
375
382
  interface SwypePaymentProps {
@@ -554,7 +561,6 @@ interface UseAuthorizationExecutorResult {
554
561
  resolveSelectSource: (selection: SourceSelection) => void;
555
562
  /** Execute authorization by session id. */
556
563
  executeSessionById: (sessionId: string) => Promise<void>;
557
- executeSession: (transfer: Transfer) => Promise<void>;
558
564
  }
559
565
  interface UseAuthorizationExecutorOptions {
560
566
  /** Optional API base URL override when used outside SwypeProvider. */
package/dist/index.js CHANGED
@@ -156,6 +156,7 @@ function useSwypeDepositAmount() {
156
156
  // src/api.ts
157
157
  var api_exports = {};
158
158
  __export(api_exports, {
159
+ createAccount: () => createAccount,
159
160
  createTransfer: () => createTransfer,
160
161
  fetchAccounts: () => fetchAccounts,
161
162
  fetchAuthorizationSession: () => fetchAuthorizationSession,
@@ -203,6 +204,18 @@ async function fetchAccounts(apiBaseUrl, token, credentialId) {
203
204
  const data = await res.json();
204
205
  return data.items;
205
206
  }
207
+ async function createAccount(apiBaseUrl, token, params) {
208
+ const res = await fetch(`${apiBaseUrl}/v1/accounts`, {
209
+ method: "POST",
210
+ headers: {
211
+ "Content-Type": "application/json",
212
+ Authorization: `Bearer ${token}`
213
+ },
214
+ body: JSON.stringify(params)
215
+ });
216
+ if (!res.ok) await throwApiError(res);
217
+ return await res.json();
218
+ }
206
219
  async function createTransfer(apiBaseUrl, token, params) {
207
220
  if (!params.merchantAuthorization) {
208
221
  throw new Error("merchantAuthorization is required for transfer creation.");
@@ -1467,15 +1480,6 @@ function useAuthorizationExecutor(options) {
1467
1480
  },
1468
1481
  [apiBaseUrl, dispatchAction]
1469
1482
  );
1470
- const executeSession = useCallback(
1471
- async (transfer) => {
1472
- if (!transfer.authorizationSessions?.length) {
1473
- throw new Error("No authorization sessions available.");
1474
- }
1475
- await executeSessionById(transfer.authorizationSessions[0].id);
1476
- },
1477
- [executeSessionById]
1478
- );
1479
1483
  return {
1480
1484
  executing,
1481
1485
  results,
@@ -1483,8 +1487,7 @@ function useAuthorizationExecutor(options) {
1483
1487
  currentAction,
1484
1488
  pendingSelectSource,
1485
1489
  resolveSelectSource,
1486
- executeSessionById,
1487
- executeSession
1490
+ executeSessionById
1488
1491
  };
1489
1492
  }
1490
1493
  function useTransferSigning(pollIntervalMs = 2e3, options) {
@@ -1842,16 +1845,13 @@ function buildSelectSourceChoices(options) {
1842
1845
 
1843
1846
  // src/paymentReducer.ts
1844
1847
  function deriveSourceTypeAndId(state) {
1845
- if (state.connectingNewAccount) {
1846
- return { sourceType: "providerId", sourceId: state.selectedProviderId ?? "" };
1847
- }
1848
1848
  if (state.selectedWalletId) {
1849
1849
  return { sourceType: "walletId", sourceId: state.selectedWalletId };
1850
1850
  }
1851
1851
  if (state.selectedAccountId) {
1852
1852
  return { sourceType: "accountId", sourceId: state.selectedAccountId };
1853
1853
  }
1854
- return { sourceType: "providerId", sourceId: state.selectedProviderId ?? "" };
1854
+ return { sourceType: "accountId", sourceId: "" };
1855
1855
  }
1856
1856
  function createInitialState(config) {
1857
1857
  return {
@@ -1863,8 +1863,6 @@ function createInitialState(config) {
1863
1863
  loadingData: false,
1864
1864
  selectedAccountId: null,
1865
1865
  selectedWalletId: null,
1866
- selectedProviderId: null,
1867
- connectingNewAccount: false,
1868
1866
  amount: config.depositAmount != null ? config.depositAmount.toString() : "",
1869
1867
  transfer: null,
1870
1868
  creatingTransfer: false,
@@ -1929,8 +1927,6 @@ function paymentReducer(state, action) {
1929
1927
  if (action.defaults) {
1930
1928
  next.selectedAccountId = action.defaults.accountId;
1931
1929
  next.selectedWalletId = action.defaults.walletId;
1932
- } else if (action.fallbackProviderId && !state.connectingNewAccount) {
1933
- next.selectedProviderId = action.fallbackProviderId;
1934
1930
  }
1935
1931
  if (action.clearMobileState) {
1936
1932
  next.mobileFlow = false;
@@ -1952,7 +1948,6 @@ function paymentReducer(state, action) {
1952
1948
  if (action.defaults) {
1953
1949
  next.selectedAccountId = action.defaults.accountId;
1954
1950
  next.selectedWalletId = action.defaults.walletId;
1955
- next.connectingNewAccount = false;
1956
1951
  }
1957
1952
  return next;
1958
1953
  }
@@ -1960,16 +1955,13 @@ function paymentReducer(state, action) {
1960
1955
  case "SELECT_PROVIDER":
1961
1956
  return {
1962
1957
  ...state,
1963
- selectedProviderId: action.providerId,
1964
- selectedAccountId: null,
1965
- connectingNewAccount: true
1958
+ selectedAccountId: null
1966
1959
  };
1967
1960
  case "SELECT_ACCOUNT":
1968
1961
  return {
1969
1962
  ...state,
1970
1963
  selectedAccountId: action.accountId,
1971
1964
  selectedWalletId: action.walletId,
1972
- connectingNewAccount: false,
1973
1965
  step: "deposit"
1974
1966
  };
1975
1967
  // ── Transfer lifecycle ───────────────────────────────────────
@@ -2054,7 +2046,6 @@ function paymentReducer(state, action) {
2054
2046
  ...state,
2055
2047
  mobileFlow: true,
2056
2048
  deeplinkUri: action.deeplinkUri,
2057
- selectedProviderId: action.providerId,
2058
2049
  error: action.error ?? null,
2059
2050
  step: "open-wallet"
2060
2051
  };
@@ -2110,7 +2101,6 @@ function paymentReducer(state, action) {
2110
2101
  amount: action.depositAmount != null ? action.depositAmount.toString() : "",
2111
2102
  mobileFlow: false,
2112
2103
  deeplinkUri: null,
2113
- connectingNewAccount: false,
2114
2104
  selectedWalletId: null,
2115
2105
  selectedAccountId: action.firstAccountId
2116
2106
  };
@@ -5260,11 +5250,11 @@ function SwypePaymentInner({
5260
5250
  accounts: state.accounts,
5261
5251
  persistedMobileFlow: loadMobileFlowState(),
5262
5252
  mobileSetupInProgress: mobileSetupFlowRef.current,
5263
- connectingNewAccount: state.connectingNewAccount
5253
+ connectingNewAccount: false
5264
5254
  });
5265
5255
  if (resolved.clearPersistedFlow) clearMobileFlowState();
5266
5256
  dispatch({ type: "NAVIGATE", step: resolved.step });
5267
- }, [getAccessToken, apiBaseUrl, state.accounts, state.connectingNewAccount]);
5257
+ }, [getAccessToken, apiBaseUrl, state.accounts]);
5268
5258
  const handleRegisterPasskey = useCallback(async () => {
5269
5259
  dispatch({ type: "SET_REGISTERING_PASSKEY", value: true });
5270
5260
  dispatch({ type: "SET_ERROR", error: null });
@@ -5309,7 +5299,7 @@ function SwypePaymentInner({
5309
5299
  accounts: state.accounts,
5310
5300
  persistedMobileFlow: loadMobileFlowState(),
5311
5301
  mobileSetupInProgress: mobileSetupFlowRef.current,
5312
- connectingNewAccount: state.connectingNewAccount
5302
+ connectingNewAccount: false
5313
5303
  });
5314
5304
  if (resolved.clearPersistedFlow) clearMobileFlowState();
5315
5305
  dispatch({ type: "NAVIGATE", step: resolved.step });
@@ -5322,7 +5312,7 @@ function SwypePaymentInner({
5322
5312
  } finally {
5323
5313
  dispatch({ type: "SET_REGISTERING_PASSKEY", value: false });
5324
5314
  }
5325
- }, [user, getAccessToken, apiBaseUrl, state.accounts, state.connectingNewAccount]);
5315
+ }, [user, getAccessToken, apiBaseUrl, state.accounts]);
5326
5316
  const handleVerifyPasskeyViaPopup = useCallback(async () => {
5327
5317
  dispatch({ type: "SET_VERIFYING_PASSKEY", value: true });
5328
5318
  dispatch({ type: "SET_ERROR", error: null });
@@ -5346,7 +5336,7 @@ function SwypePaymentInner({
5346
5336
  accounts: state.accounts,
5347
5337
  persistedMobileFlow: loadMobileFlowState(),
5348
5338
  mobileSetupInProgress: mobileSetupFlowRef.current,
5349
- connectingNewAccount: state.connectingNewAccount
5339
+ connectingNewAccount: false
5350
5340
  });
5351
5341
  if (resolved.clearPersistedFlow) clearMobileFlowState();
5352
5342
  dispatch({ type: "NAVIGATE", step: resolved.step });
@@ -5365,7 +5355,7 @@ function SwypePaymentInner({
5365
5355
  } finally {
5366
5356
  dispatch({ type: "SET_VERIFYING_PASSKEY", value: false });
5367
5357
  }
5368
- }, [state.knownCredentialIds, getAccessToken, apiBaseUrl, state.accounts, state.connectingNewAccount]);
5358
+ }, [state.knownCredentialIds, getAccessToken, apiBaseUrl, state.accounts]);
5369
5359
  const reloadAccounts = useCallback(async () => {
5370
5360
  const token = await getAccessToken();
5371
5361
  if (!token || !state.activeCredentialId) return;
@@ -5417,8 +5407,7 @@ function SwypePaymentInner({
5417
5407
  dispatch({ type: "NAVIGATE", step: "create-passkey" });
5418
5408
  return;
5419
5409
  }
5420
- const isSetupRedirect = mobileSetupFlowRef.current;
5421
- dispatch({ type: "PAY_STARTED", isSetupRedirect });
5410
+ dispatch({ type: "PAY_STARTED", isSetupRedirect: false });
5422
5411
  processingStartedAtRef.current = Date.now();
5423
5412
  try {
5424
5413
  if (state.transfer?.status === "AUTHORIZED") {
@@ -5439,23 +5428,6 @@ function SwypePaymentInner({
5439
5428
  effectiveSourceId = activeWallet.id;
5440
5429
  }
5441
5430
  }
5442
- const isActiveWallet = effectiveSourceType === "walletId" && state.accounts.some(
5443
- (a) => a.wallets.some((w) => w.id === effectiveSourceId && w.status === "ACTIVE")
5444
- );
5445
- if (!isActiveWallet && !isSetupRedirect) {
5446
- let found = false;
5447
- for (const acct of state.accounts) {
5448
- for (const wallet of acct.wallets) {
5449
- if (wallet.status === "ACTIVE" && wallet.sources.some((s) => s.balance.available.amount >= payAmount)) {
5450
- effectiveSourceType = "walletId";
5451
- effectiveSourceId = wallet.id;
5452
- found = true;
5453
- break;
5454
- }
5455
- }
5456
- if (found) break;
5457
- }
5458
- }
5459
5431
  const t = await createTransfer(apiBaseUrl, token, {
5460
5432
  id: idempotencyKey,
5461
5433
  credentialId: state.activeCredentialId,
@@ -5466,28 +5438,6 @@ function SwypePaymentInner({
5466
5438
  amount: payAmount
5467
5439
  });
5468
5440
  dispatch({ type: "TRANSFER_CREATED", transfer: t });
5469
- if (t.authorizationSessions && t.authorizationSessions.length > 0) {
5470
- const useConnector = shouldUseWalletConnector({
5471
- useWalletConnector: useWalletConnectorProp,
5472
- userAgent: typeof navigator === "undefined" ? void 0 : navigator.userAgent
5473
- });
5474
- if (!useConnector) {
5475
- const uri = t.authorizationSessions[0].uri;
5476
- pollingTransferIdRef.current = t.id;
5477
- polling.startPolling(t.id);
5478
- dispatch({ type: "MOBILE_DEEPLINK_READY", deeplinkUri: uri });
5479
- persistMobileFlowState({
5480
- transferId: t.id,
5481
- deeplinkUri: uri,
5482
- providerId: sourceOverrides?.sourceType === "providerId" ? sourceOverrides.sourceId : state.selectedProviderId,
5483
- isSetup: mobileSetupFlowRef.current
5484
- });
5485
- triggerDeeplink(uri);
5486
- return;
5487
- } else {
5488
- await authExecutor.executeSession(t);
5489
- }
5490
- }
5491
5441
  const signedTransfer = await transferSigning.signTransfer(t.id);
5492
5442
  dispatch({ type: "TRANSFER_SIGNED", transfer: signedTransfer });
5493
5443
  polling.startPolling(t.id);
@@ -5497,7 +5447,7 @@ function SwypePaymentInner({
5497
5447
  dispatch({
5498
5448
  type: "PAY_ERROR",
5499
5449
  error: msg,
5500
- fallbackStep: isSetupRedirect ? "wallet-picker" : "deposit"
5450
+ fallbackStep: "deposit"
5501
5451
  });
5502
5452
  onError?.(msg);
5503
5453
  } finally {
@@ -5509,15 +5459,12 @@ function SwypePaymentInner({
5509
5459
  state.activeCredentialId,
5510
5460
  state.transfer,
5511
5461
  state.accounts,
5512
- state.selectedProviderId,
5513
5462
  destination,
5514
5463
  apiBaseUrl,
5515
5464
  getAccessToken,
5516
- authExecutor,
5517
5465
  transferSigning,
5518
5466
  polling,
5519
5467
  onError,
5520
- useWalletConnectorProp,
5521
5468
  idempotencyKey,
5522
5469
  merchantAuthorization
5523
5470
  ]);
@@ -5556,23 +5503,7 @@ function SwypePaymentInner({
5556
5503
  destination,
5557
5504
  amount: parsedAmount
5558
5505
  });
5559
- if (t.authorizationSessions && t.authorizationSessions.length > 0) {
5560
- const uri = t.authorizationSessions[0].uri;
5561
- pollingTransferIdRef.current = t.id;
5562
- mobileSetupFlowRef.current = true;
5563
- handlingMobileReturnRef.current = false;
5564
- polling.startPolling(t.id);
5565
- dispatch({ type: "INCREASE_LIMIT_DEEPLINK", transfer: t, deeplinkUri: uri });
5566
- persistMobileFlowState({
5567
- transferId: t.id,
5568
- deeplinkUri: uri,
5569
- providerId: state.selectedProviderId,
5570
- isSetup: true
5571
- });
5572
- triggerDeeplink(uri);
5573
- } else {
5574
- dispatch({ type: "TRANSFER_CREATED", transfer: t });
5575
- }
5506
+ dispatch({ type: "TRANSFER_CREATED", transfer: t });
5576
5507
  } catch (err) {
5577
5508
  captureException(err);
5578
5509
  const msg = err instanceof Error ? err.message : "Failed to increase limit";
@@ -5587,7 +5518,6 @@ function SwypePaymentInner({
5587
5518
  sourceType,
5588
5519
  state.activeCredentialId,
5589
5520
  state.accounts,
5590
- state.selectedProviderId,
5591
5521
  apiBaseUrl,
5592
5522
  getAccessToken,
5593
5523
  polling,
@@ -5624,21 +5554,65 @@ function SwypePaymentInner({
5624
5554
  polling.startPolling(transferIdToResume);
5625
5555
  }
5626
5556
  }, [handleAuthorizedMobileReturn, polling, state.transfer]);
5627
- const handleSelectProvider = useCallback((providerId) => {
5557
+ const handleSelectProvider = useCallback(async (providerId) => {
5628
5558
  dispatch({ type: "SELECT_PROVIDER", providerId });
5629
- const isMobile = !shouldUseWalletConnector({
5630
- useWalletConnector: useWalletConnectorProp,
5631
- userAgent: typeof navigator === "undefined" ? void 0 : navigator.userAgent
5632
- });
5633
- if (isMobile) {
5634
- handlingMobileReturnRef.current = false;
5635
- mobileSetupFlowRef.current = true;
5636
- const amount = depositAmount ?? 5;
5637
- handlePay(amount, { sourceType: "providerId", sourceId: providerId });
5638
- } else {
5639
- dispatch({ type: "NAVIGATE", step: "deposit" });
5559
+ if (!state.activeCredentialId) {
5560
+ dispatch({ type: "SET_ERROR", error: "Create a passkey on this device before continuing." });
5561
+ dispatch({ type: "NAVIGATE", step: "create-passkey" });
5562
+ return;
5563
+ }
5564
+ const provider = state.providers.find((p) => p.id === providerId);
5565
+ const providerName = provider?.name ?? "Wallet";
5566
+ dispatch({ type: "PAY_STARTED", isSetupRedirect: true });
5567
+ try {
5568
+ const token = await getAccessToken();
5569
+ if (!token) throw new Error("Not authenticated");
5570
+ const account = await createAccount(apiBaseUrl, token, {
5571
+ name: providerName,
5572
+ credentialId: state.activeCredentialId,
5573
+ providerId
5574
+ });
5575
+ const session = account.authorizationSessions?.[0];
5576
+ if (!session) throw new Error("No authorization session returned.");
5577
+ const isMobile = !shouldUseWalletConnector({
5578
+ useWalletConnector: useWalletConnectorProp,
5579
+ userAgent: typeof navigator === "undefined" ? void 0 : navigator.userAgent
5580
+ });
5581
+ if (isMobile) {
5582
+ handlingMobileReturnRef.current = false;
5583
+ mobileSetupFlowRef.current = true;
5584
+ persistMobileFlowState({
5585
+ accountId: account.id,
5586
+ sessionId: session.id,
5587
+ deeplinkUri: session.uri,
5588
+ providerId,
5589
+ isSetup: true
5590
+ });
5591
+ dispatch({ type: "MOBILE_DEEPLINK_READY", deeplinkUri: session.uri });
5592
+ triggerDeeplink(session.uri);
5593
+ } else {
5594
+ await authExecutor.executeSessionById(session.id);
5595
+ await reloadAccounts();
5596
+ dispatch({ type: "NAVIGATE", step: "deposit" });
5597
+ }
5598
+ } catch (err) {
5599
+ captureException(err);
5600
+ const msg = err instanceof Error ? err.message : "Failed to set up wallet";
5601
+ dispatch({ type: "PAY_ERROR", error: msg, fallbackStep: "wallet-picker" });
5602
+ onError?.(msg);
5603
+ } finally {
5604
+ dispatch({ type: "PAY_ENDED" });
5640
5605
  }
5641
- }, [useWalletConnectorProp, depositAmount, handlePay]);
5606
+ }, [
5607
+ state.activeCredentialId,
5608
+ state.providers,
5609
+ apiBaseUrl,
5610
+ getAccessToken,
5611
+ authExecutor,
5612
+ useWalletConnectorProp,
5613
+ reloadAccounts,
5614
+ onError
5615
+ ]);
5642
5616
  const handleContinueConnection = useCallback(
5643
5617
  (accountId) => {
5644
5618
  const acct = state.accounts.find((a) => a.id === accountId);
@@ -5748,7 +5722,7 @@ function SwypePaymentInner({
5748
5722
  connectingNewAccount: false
5749
5723
  });
5750
5724
  if (resolved.clearPersistedFlow) clearMobileFlowState();
5751
- if (resolved.step === "deposit" && persisted && persisted.isSetup) {
5725
+ if (resolved.step === "deposit" && persisted && persisted.isSetup && persisted.transferId) {
5752
5726
  try {
5753
5727
  const existingTransfer = await fetchTransfer(apiBaseUrl, token, persisted.transferId);
5754
5728
  if (cancelled) return;
@@ -5759,7 +5733,12 @@ function SwypePaymentInner({
5759
5733
  } catch {
5760
5734
  }
5761
5735
  }
5762
- if (resolved.step === "open-wallet" && persisted) {
5736
+ if (resolved.step === "open-wallet" && persisted && persisted.accountId && !persisted.transferId) {
5737
+ clearMobileFlowState();
5738
+ dispatch({ type: "NAVIGATE", step: "deposit" });
5739
+ return;
5740
+ }
5741
+ if (resolved.step === "open-wallet" && persisted && persisted.transferId) {
5763
5742
  try {
5764
5743
  const existingTransfer = await fetchTransfer(apiBaseUrl, token, persisted.transferId);
5765
5744
  if (cancelled) return;
@@ -5805,9 +5784,9 @@ function SwypePaymentInner({
5805
5784
  providerId: persisted.providerId,
5806
5785
  error: err instanceof Error ? err.message : "Unable to refresh wallet authorization status."
5807
5786
  });
5808
- pollingTransferIdRef.current = persisted.transferId;
5787
+ pollingTransferIdRef.current = persisted.transferId ?? null;
5809
5788
  mobileSetupFlowRef.current = persisted.isSetup;
5810
- pollingRef.current.startPolling(persisted.transferId);
5789
+ if (persisted.transferId) pollingRef.current.startPolling(persisted.transferId);
5811
5790
  return;
5812
5791
  }
5813
5792
  dispatch({
@@ -5815,9 +5794,9 @@ function SwypePaymentInner({
5815
5794
  deeplinkUri: persisted.deeplinkUri,
5816
5795
  providerId: persisted.providerId
5817
5796
  });
5818
- pollingTransferIdRef.current = persisted.transferId;
5797
+ pollingTransferIdRef.current = persisted.transferId ?? null;
5819
5798
  mobileSetupFlowRef.current = persisted.isSetup;
5820
- pollingRef.current.startPolling(persisted.transferId);
5799
+ if (persisted.transferId) pollingRef.current.startPolling(persisted.transferId);
5821
5800
  return;
5822
5801
  }
5823
5802
  dispatch({ type: "NAVIGATE", step: resolved.step });
@@ -5924,7 +5903,7 @@ function SwypePaymentInner({
5924
5903
  accounts: accts,
5925
5904
  persistedMobileFlow: persisted,
5926
5905
  mobileSetupInProgress: mobileSetupFlowRef.current,
5927
- connectingNewAccount: state.connectingNewAccount
5906
+ connectingNewAccount: false
5928
5907
  });
5929
5908
  const correctableSteps = ["deposit", "wallet-picker", "open-wallet"];
5930
5909
  dispatch({
@@ -5933,7 +5912,6 @@ function SwypePaymentInner({
5933
5912
  accounts: accts,
5934
5913
  chains: chn,
5935
5914
  defaults,
5936
- fallbackProviderId: !defaults && prov.length > 0 ? prov[0].id : null,
5937
5915
  resolvedStep: correctableSteps.includes(state.step) ? resolved.step : void 0,
5938
5916
  clearMobileState: resolved.clearPersistedFlow
5939
5917
  });
@@ -5965,8 +5943,7 @@ function SwypePaymentInner({
5965
5943
  apiBaseUrl,
5966
5944
  getAccessToken,
5967
5945
  state.activeCredentialId,
5968
- depositAmount,
5969
- state.connectingNewAccount
5946
+ depositAmount
5970
5947
  ]);
5971
5948
  useEffect(() => {
5972
5949
  if (!polling.transfer) return;