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