@swype-org/react-sdk 0.1.157 → 0.1.159

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 CHANGED
@@ -3483,14 +3483,16 @@ function WalletPickerScreen({
3483
3483
  selectedProvider && /* @__PURE__ */ jsxRuntime.jsx(
3484
3484
  PrimaryButton,
3485
3485
  {
3486
- onClick: async () => {
3487
- setConnecting(true);
3488
- try {
3489
- const session = preparedSession?.providerId === selectedProvider.id ? preparedSession : void 0;
3490
- await onSelectProvider(selectedProvider.id, session);
3491
- } finally {
3492
- setConnecting(false);
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
+ }
3493
3493
  }
3494
+ setConnecting(true);
3495
+ onSelectProvider(selectedProvider.id, session).finally(() => setConnecting(false));
3494
3496
  },
3495
3497
  loading: connecting || preparing,
3496
3498
  disabled: preparing,
@@ -6470,16 +6472,10 @@ function useMobileFlowHandlers(dispatch, polling, reloadAccounts, pollingTransfe
6470
6472
  clearMobileFlowState();
6471
6473
  try {
6472
6474
  await reloadAccounts();
6473
- loadingDataRef.current = false;
6474
- dispatch({ type: "MOBILE_SETUP_COMPLETE", transfer: authorizedTransfer });
6475
- } catch (err) {
6476
- handlingMobileReturnRef.current = false;
6477
- dispatch({
6478
- type: "SET_ERROR",
6479
- error: err instanceof Error ? err.message : "Wallet authorized, but we could not refresh your account yet."
6480
- });
6481
- dispatch({ type: "NAVIGATE", step: "open-wallet" });
6475
+ } catch {
6482
6476
  }
6477
+ loadingDataRef.current = false;
6478
+ dispatch({ type: "MOBILE_SETUP_COMPLETE", transfer: authorizedTransfer });
6483
6479
  return;
6484
6480
  }
6485
6481
  mobileSetupFlowRef.current = false;
@@ -6622,7 +6618,9 @@ function useProviderHandlers(deps) {
6622
6618
  providerId,
6623
6619
  isSetup: true
6624
6620
  });
6625
- triggerDeeplink(sessionUri);
6621
+ if (!preparedSession) {
6622
+ triggerDeeplink(sessionUri);
6623
+ }
6626
6624
  dispatch({ type: "MOBILE_DEEPLINK_READY", deeplinkUri: sessionUri });
6627
6625
  } else {
6628
6626
  await authExecutor.executeSessionById(sessionId);
@@ -6658,7 +6656,17 @@ function useProviderHandlers(deps) {
6658
6656
  const acct = accounts.find((a) => a.id === accountId);
6659
6657
  if (!acct) return;
6660
6658
  const matchedProvider = providers.find((p) => p.name === acct.name);
6661
- if (matchedProvider) {
6659
+ if (!matchedProvider) return;
6660
+ const pendingSession = acct.authorizationSessions?.find(
6661
+ (s) => s.status === "PENDING"
6662
+ );
6663
+ if (pendingSession) {
6664
+ handleSelectProvider(matchedProvider.id, {
6665
+ accountId: acct.id,
6666
+ sessionId: pendingSession.id,
6667
+ uri: pendingSession.uri
6668
+ });
6669
+ } else {
6662
6670
  handleSelectProvider(matchedProvider.id);
6663
6671
  }
6664
6672
  },
@@ -7095,8 +7103,25 @@ function usePaymentEffects(deps) {
7095
7103
  return;
7096
7104
  }
7097
7105
  if (resolved.step === "open-wallet" && persisted && persisted.accountId && !persisted.transferId) {
7098
- clearMobileFlowState();
7099
- dispatch({ type: "NAVIGATE", step: "deposit" });
7106
+ if (persisted.sessionId) {
7107
+ try {
7108
+ const session = await fetchAuthorizationSession(apiBaseUrl, persisted.sessionId);
7109
+ if (cancelled) return;
7110
+ if (session.status === "AUTHORIZED") {
7111
+ clearMobileFlowState();
7112
+ dispatch({ type: "NAVIGATE", step: "deposit" });
7113
+ return;
7114
+ }
7115
+ } catch {
7116
+ }
7117
+ }
7118
+ mobileSetupFlowRef.current = true;
7119
+ setupAccountIdRef.current = persisted.accountId;
7120
+ dispatch({
7121
+ type: "ENTER_MOBILE_FLOW",
7122
+ deeplinkUri: persisted.deeplinkUri,
7123
+ providerId: persisted.providerId
7124
+ });
7100
7125
  return;
7101
7126
  }
7102
7127
  if (resolved.step === "open-wallet" && persisted && persisted.transferId) {
@@ -7365,6 +7390,8 @@ function usePaymentEffects(deps) {
7365
7390
  const isReauth = !!reauthSessionIdRef.current;
7366
7391
  const sessionId = reauthSessionIdRef.current;
7367
7392
  const tokenSelection = reauthTokenRef.current;
7393
+ const persistedFlow = loadMobileFlowState();
7394
+ const setupSessionId = !isReauth ? persistedFlow?.sessionId : void 0;
7368
7395
  let cancelled = false;
7369
7396
  const POLL_INTERVAL_MS = 3e3;
7370
7397
  const pollReauthorization = async () => {
@@ -7391,6 +7418,17 @@ function usePaymentEffects(deps) {
7391
7418
  } catch {
7392
7419
  }
7393
7420
  };
7421
+ const completeSetup = async () => {
7422
+ cancelled = true;
7423
+ mobileSetupFlowRef.current = false;
7424
+ setupAccountIdRef.current = null;
7425
+ clearMobileFlowState();
7426
+ try {
7427
+ await reloadAccounts();
7428
+ } catch {
7429
+ }
7430
+ dispatch({ type: "MOBILE_SETUP_COMPLETE" });
7431
+ };
7394
7432
  const pollWalletActive = async () => {
7395
7433
  try {
7396
7434
  const token = await getAccessTokenRef.current();
@@ -7399,15 +7437,18 @@ function usePaymentEffects(deps) {
7399
7437
  if (cancelled) return;
7400
7438
  const hasActive = acct.wallets.some((w) => w.status === "ACTIVE");
7401
7439
  if (hasActive) {
7402
- cancelled = true;
7403
- mobileSetupFlowRef.current = false;
7404
- setupAccountIdRef.current = null;
7405
- clearMobileFlowState();
7440
+ await completeSetup();
7441
+ return;
7442
+ }
7443
+ if (setupSessionId) {
7406
7444
  try {
7407
- await reloadAccounts();
7445
+ const session = await fetchAuthorizationSession(apiBaseUrl, setupSessionId);
7446
+ if (cancelled) return;
7447
+ if (session.status === "AUTHORIZED") {
7448
+ await completeSetup();
7449
+ }
7408
7450
  } catch {
7409
7451
  }
7410
- dispatch({ type: "MOBILE_SETUP_COMPLETE" });
7411
7452
  }
7412
7453
  } catch {
7413
7454
  }