@swype-org/react-sdk 0.1.237 → 0.1.251

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
@@ -2004,16 +2004,41 @@ function isTransferInFlight(transfer) {
2004
2004
  if (!transfer) return false;
2005
2005
  return ["CREATED", "SENDING", "SENT"].includes(transfer.status);
2006
2006
  }
2007
+ function isGuestPreauthCompletedTransferPinPhase(phase) {
2008
+ switch (phase.step) {
2009
+ case "completed":
2010
+ case "select-source":
2011
+ case "one-tap-setup":
2012
+ case "token-picker":
2013
+ case "login":
2014
+ // otp-verify not pinned: after OTP, verificationTarget clears but phase can be stale until
2015
+ // resolvePhase runs; pinning would block passkey.
2016
+ case "passkey-create":
2017
+ case "passkey-verify":
2018
+ case "data-loading":
2019
+ return true;
2020
+ case "wallet-setup":
2021
+ return phase.mobile == null;
2022
+ default:
2023
+ return false;
2024
+ }
2025
+ }
2007
2026
  function resolvePhase(state) {
2008
2027
  const p = state.phase;
2009
- if (p.step === "select-source" && state.transfer?.status === "COMPLETED" && state.guestPreauthorizing) {
2028
+ if (state.guestPreauthSetupCompletePending && state.privyReady && state.privyAuthenticated) {
2029
+ return { step: "guest-setup-complete" };
2030
+ }
2031
+ if (state.transfer?.status === "COMPLETED" && state.guestPreauthorizing && !state.verificationTarget && isGuestPreauthCompletedTransferPinPhase(p)) {
2010
2032
  return p;
2011
2033
  }
2012
- if (state.transfer?.status === "COMPLETED" && state.guestPreauthorizing) {
2013
- return { step: "processing", transfer: state.transfer };
2034
+ if (state.transfer?.status === "COMPLETED" && state.isGuestFlow && state.guestPreauthSessionId && !state.guestPreauthorizing && !state.verificationTarget && !state.privyAuthenticated) {
2035
+ return { step: "login" };
2014
2036
  }
2015
- if (state.transfer?.status === "COMPLETED") {
2016
- return { step: "completed", transfer: state.transfer };
2037
+ if (state.transfer?.status === "COMPLETED" && !state.verificationTarget) {
2038
+ const needsPasskeyBootstrap = state.privyAuthenticated && !state.activeCredentialId;
2039
+ if (!needsPasskeyBootstrap) {
2040
+ return { step: "completed", transfer: state.transfer };
2041
+ }
2017
2042
  }
2018
2043
  if (state.transfer?.status === "FAILED") {
2019
2044
  return { step: "failed", transfer: state.transfer, error: state.error ?? "Transfer failed." };
@@ -2021,7 +2046,7 @@ function resolvePhase(state) {
2021
2046
  if (state.creatingTransfer || isTransferInFlight(state.transfer)) {
2022
2047
  return { step: "processing", transfer: state.transfer };
2023
2048
  }
2024
- if (p.step === "token-picker" || p.step === "one-tap-setup" || p.step === "select-source" || p.step === "confirm-sign" || p.step === "guest-token-picker") {
2049
+ if (!state.loginRequested && (p.step === "token-picker" || p.step === "one-tap-setup" || p.step === "select-source" || p.step === "confirm-sign" || p.step === "guest-token-picker")) {
2025
2050
  return p;
2026
2051
  }
2027
2052
  if (state.mobileFlow && state.deeplinkUri) {
@@ -2031,10 +2056,10 @@ function resolvePhase(state) {
2031
2056
  accountId: null
2032
2057
  };
2033
2058
  }
2034
- if (p.step === "wallet-setup" && p.mobile == null) {
2059
+ if (p.step === "wallet-setup" && p.mobile == null && state.guestPreauthorizing) {
2035
2060
  return p;
2036
2061
  }
2037
- if (state.isGuestFlow && state.selectedProviderId != null && !state.transfer) {
2062
+ if (state.isGuestFlow && state.selectedProviderId != null && !state.transfer && !state.guestPreauthAccountId) {
2038
2063
  return { step: "guest-token-picker" };
2039
2064
  }
2040
2065
  if (p.step === "wallet-picker" && !state.creatingTransfer && !(state.mobileFlow && state.deeplinkUri)) {
@@ -2046,7 +2071,7 @@ function resolvePhase(state) {
2046
2071
  if (state.privyAuthenticated && !state.activeCredentialId && !state.passkeyConfigLoaded) {
2047
2072
  return { step: "initializing" };
2048
2073
  }
2049
- if (state.verificationTarget) {
2074
+ if (state.verificationTarget && !state.privyAuthenticated) {
2050
2075
  return { step: "otp-verify", target: state.verificationTarget };
2051
2076
  }
2052
2077
  if (state.loginRequested) {
@@ -2118,13 +2143,26 @@ function createInitialState(config) {
2118
2143
  activePublicKey: null,
2119
2144
  loginRequested: false,
2120
2145
  guestPreauthorizing: false,
2146
+ guestPreauthSetupCompletePending: false,
2121
2147
  privyReady: false,
2122
2148
  privyAuthenticated: false
2123
2149
  };
2124
2150
  }
2125
2151
  function paymentReducer(state, action) {
2126
2152
  const next = applyAction(state, action);
2127
- return { ...next, phase: resolvePhase(next) };
2153
+ const phase = resolvePhase(next);
2154
+ if (action.type === "CODE_SENT") {
2155
+ console.debug("[Swype SDK] login code sent", {
2156
+ resolvedPhase: phase.step,
2157
+ verificationTargetKind: action.target.kind,
2158
+ guestPreauthorizing: next.guestPreauthorizing,
2159
+ transferStatus: next.transfer?.status ?? null,
2160
+ isGuestFlow: next.isGuestFlow,
2161
+ hasGuestPreauthSessionId: next.guestPreauthSessionId != null,
2162
+ loginRequested: next.loginRequested
2163
+ });
2164
+ }
2165
+ return { ...next, phase };
2128
2166
  }
2129
2167
  function applyAction(state, action) {
2130
2168
  switch (action.type) {
@@ -2385,13 +2423,20 @@ function applyAction(state, action) {
2385
2423
  case "ACCOUNT_OWNER_SET":
2386
2424
  return {
2387
2425
  ...state,
2426
+ transfer: null,
2388
2427
  guestPreauthAccountId: null,
2389
2428
  guestPreauthSessionId: null,
2390
2429
  activePublicKey: null,
2391
2430
  error: null,
2392
2431
  guestPreauthorizing: false,
2393
- phase: { step: "one-tap-setup", action: null }
2432
+ isGuestFlow: false,
2433
+ selectedProviderId: null,
2434
+ guestTransferId: null,
2435
+ guestSessionToken: null,
2436
+ guestPreauthSetupCompletePending: true
2394
2437
  };
2438
+ case "GUEST_PREAUTH_SETUP_COMPLETE_DISMISSED":
2439
+ return { ...state, guestPreauthSetupCompletePending: false };
2395
2440
  // ── User intent & error ──────────────────────────────────────
2396
2441
  case "SET_USER_INTENT":
2397
2442
  return { ...state, phase: action.intent };
@@ -2426,7 +2471,8 @@ function applyAction(state, action) {
2426
2471
  activePublicKey: null,
2427
2472
  loginRequested: false,
2428
2473
  oneTapLimitSavedDuringSetup: false,
2429
- guestPreauthorizing: false
2474
+ guestPreauthorizing: false,
2475
+ guestPreauthSetupCompletePending: false
2430
2476
  };
2431
2477
  case "LOGOUT":
2432
2478
  return {
@@ -2442,7 +2488,10 @@ function applyAction(state, action) {
2442
2488
  return {
2443
2489
  ...state,
2444
2490
  privyReady: action.ready,
2445
- privyAuthenticated: action.authenticated
2491
+ privyAuthenticated: action.authenticated,
2492
+ // OTP complete: Privy is source of truth; clear so resolvePhase can leave otp-verify
2493
+ // and guest-preauth pin rules cannot re-pin a stale otp-verify phase.
2494
+ ...action.authenticated ? { verificationTarget: null, loginRequested: false } : {}
2446
2495
  };
2447
2496
  case "SYNC_AMOUNT":
2448
2497
  return { ...state, amount: action.amount };
@@ -2508,7 +2557,10 @@ function screenForPhase(phase) {
2508
2557
  case "wallet-picker":
2509
2558
  return "wallet-picker";
2510
2559
  case "wallet-setup":
2511
- return phase.mobile ? "open-wallet" : "setup-status";
2560
+ if (phase.mobile || phase.guestDesktopExtension) {
2561
+ return "open-wallet";
2562
+ }
2563
+ return "setup-status";
2512
2564
  case "select-source":
2513
2565
  return phase.isDesktop ? "setup" : "select-source";
2514
2566
  case "one-tap-setup":
@@ -2526,6 +2578,8 @@ function screenForPhase(phase) {
2526
2578
  case "completed":
2527
2579
  case "failed":
2528
2580
  return "success";
2581
+ case "guest-setup-complete":
2582
+ return "guest-setup-complete";
2529
2583
  }
2530
2584
  }
2531
2585
  var MUTED = "#7fa4b0";
@@ -5995,6 +6049,60 @@ var emptyStyle = (color) => ({
5995
6049
  padding: "32px 0",
5996
6050
  lineHeight: 1.5
5997
6051
  });
6052
+ function GuestPreauthSetupCompleteScreen({
6053
+ onClose,
6054
+ onLogout
6055
+ }) {
6056
+ const { tokens } = useBlinkConfig();
6057
+ return /* @__PURE__ */ jsxRuntime.jsxs(
6058
+ ScreenLayout,
6059
+ {
6060
+ footer: /* @__PURE__ */ jsxRuntime.jsxs(jsxRuntime.Fragment, { children: [
6061
+ /* @__PURE__ */ jsxRuntime.jsx(PrimaryButton, { onClick: onClose, children: "Close" }),
6062
+ /* @__PURE__ */ jsxRuntime.jsx(PoweredByFooter, {})
6063
+ ] }),
6064
+ children: [
6065
+ /* @__PURE__ */ jsxRuntime.jsx(ScreenHeader, { onLogout }),
6066
+ /* @__PURE__ */ jsxRuntime.jsxs("div", { style: contentStyle9, children: [
6067
+ /* @__PURE__ */ jsxRuntime.jsx(IconCircle, { variant: "success", size: 64, children: /* @__PURE__ */ jsxRuntime.jsx("svg", { width: "32", height: "32", viewBox: "0 0 24 24", fill: "none", children: /* @__PURE__ */ jsxRuntime.jsx(
6068
+ "path",
6069
+ {
6070
+ d: "M9 16.17L4.83 12l-1.42 1.41L9 19 21 7l-1.41-1.41L9 16.17z",
6071
+ fill: tokens.success
6072
+ }
6073
+ ) }) }),
6074
+ /* @__PURE__ */ jsxRuntime.jsx("h2", { style: headingStyle12(tokens.text), children: "Setup complete" }),
6075
+ /* @__PURE__ */ jsxRuntime.jsx("p", { style: subtitleStyle10(tokens.textSecondary), children: "Your account is linked and ready. You can close this window or make another deposit." })
6076
+ ] })
6077
+ ]
6078
+ }
6079
+ );
6080
+ }
6081
+ var contentStyle9 = {
6082
+ display: "flex",
6083
+ flexDirection: "column",
6084
+ alignItems: "center",
6085
+ textAlign: "center",
6086
+ gap: 12,
6087
+ paddingTop: 8
6088
+ };
6089
+ function headingStyle12(color) {
6090
+ return {
6091
+ margin: 0,
6092
+ fontSize: 22,
6093
+ fontWeight: 600,
6094
+ color
6095
+ };
6096
+ }
6097
+ function subtitleStyle10(color) {
6098
+ return {
6099
+ margin: 0,
6100
+ fontSize: 15,
6101
+ lineHeight: 1.45,
6102
+ color,
6103
+ maxWidth: 320
6104
+ };
6105
+ }
5998
6106
  var LINK_SCREENS = /* @__PURE__ */ new Set([
5999
6107
  "create-passkey",
6000
6108
  "verify-passkey",
@@ -6045,7 +6153,8 @@ function StepRendererContent({
6045
6153
  pollingError,
6046
6154
  authExecutorError,
6047
6155
  transferSigningSigning,
6048
- transferSigningError
6156
+ transferSigningError,
6157
+ pendingSelectSource
6049
6158
  } = remote;
6050
6159
  const {
6051
6160
  pendingConnections,
@@ -6245,6 +6354,26 @@ function StepRendererContent({
6245
6354
  }
6246
6355
  case "token-picker": {
6247
6356
  if (!selectedAccount) {
6357
+ if (pendingSelectSource && selectSourceChoices.length > 0) {
6358
+ return /* @__PURE__ */ jsxRuntime.jsx(
6359
+ SelectSourceScreen,
6360
+ {
6361
+ choices: selectSourceChoices,
6362
+ selectedChainName: selectSourceChainName,
6363
+ selectedTokenSymbol: selectSourceTokenSymbol,
6364
+ recommended: selectSourceRecommended,
6365
+ onChainChange: handlers.onSelectSourceChainChange,
6366
+ onTokenChange: handlers.onSetSelectSourceTokenSymbol,
6367
+ onConfirm: handlers.onConfirmSelectSource,
6368
+ onBack: () => handlers.onSetPhase({
6369
+ step: "select-source",
6370
+ action: pendingSelectSource,
6371
+ isDesktop
6372
+ }),
6373
+ onLogout: handlers.onLogout
6374
+ }
6375
+ );
6376
+ }
6248
6377
  return /* @__PURE__ */ jsxRuntime.jsx(BlinkLoadingScreen, {});
6249
6378
  }
6250
6379
  return /* @__PURE__ */ jsxRuntime.jsx(
@@ -6275,6 +6404,14 @@ function StepRendererContent({
6275
6404
  onBack: handlers.onGuestBackFromTokenPicker
6276
6405
  }
6277
6406
  );
6407
+ case "guest-setup-complete":
6408
+ return /* @__PURE__ */ jsxRuntime.jsx(
6409
+ GuestPreauthSetupCompleteScreen,
6410
+ {
6411
+ onClose: handlers.onGuestSetupCompleteClose,
6412
+ onLogout: handlers.onLogout
6413
+ }
6414
+ );
6278
6415
  case "processing": {
6279
6416
  const polledStatus = pollingTransfer?.status;
6280
6417
  const transferPhase = state.creatingTransfer ? "creating" : polledStatus === "SENDING" || polledStatus === "SENT" ? "sent" : "verifying";
@@ -6368,7 +6505,7 @@ var PaymentErrorBoundary = class extends react.Component {
6368
6505
  /* @__PURE__ */ jsxRuntime.jsx("path", { d: "M12 8v5", stroke: "#ef4444", strokeWidth: "1.5", strokeLinecap: "round" }),
6369
6506
  /* @__PURE__ */ jsxRuntime.jsx("circle", { cx: "12", cy: "16", r: "0.75", fill: "#ef4444" })
6370
6507
  ] }) }),
6371
- /* @__PURE__ */ jsxRuntime.jsx("h2", { style: headingStyle12, children: "Something went wrong" }),
6508
+ /* @__PURE__ */ jsxRuntime.jsx("h2", { style: headingStyle13, children: "Something went wrong" }),
6372
6509
  /* @__PURE__ */ jsxRuntime.jsx("p", { style: messageStyle, children: "An unexpected error occurred. Please try again." }),
6373
6510
  /* @__PURE__ */ jsxRuntime.jsx("button", { type: "button", onClick: this.handleReset, style: buttonStyle3, children: "Try again" })
6374
6511
  ] });
@@ -6388,7 +6525,7 @@ var containerStyle9 = {
6388
6525
  var iconStyle3 = {
6389
6526
  marginBottom: 20
6390
6527
  };
6391
- var headingStyle12 = {
6528
+ var headingStyle13 = {
6392
6529
  fontSize: "1.25rem",
6393
6530
  fontWeight: 700,
6394
6531
  color: "#1a1a1a",
@@ -6842,15 +6979,15 @@ function useTransferHandlers(deps) {
6842
6979
  pollingTransferIdRef
6843
6980
  };
6844
6981
  }
6845
- function useSourceSelectionHandlers(dispatch, authExecutor) {
6982
+ function useSourceSelectionHandlers(dispatch, authExecutor, options) {
6846
6983
  const [selectSourceChainName, setSelectSourceChainName] = react.useState("");
6847
6984
  const [selectSourceTokenSymbol, setSelectSourceTokenSymbol] = react.useState("");
6848
6985
  const initializedSelectSourceActionRef = react.useRef(null);
6849
6986
  const pendingSelectSourceAction = authExecutor.pendingSelectSource;
6850
6987
  const selectSourceChoices = react.useMemo(() => {
6851
6988
  if (!pendingSelectSourceAction) return [];
6852
- const options = pendingSelectSourceAction.metadata?.options ?? [];
6853
- return buildSelectSourceChoices(options);
6989
+ const options2 = pendingSelectSourceAction.metadata?.options ?? [];
6990
+ return buildSelectSourceChoices(options2);
6854
6991
  }, [pendingSelectSourceAction]);
6855
6992
  const selectSourceRecommended = react.useMemo(() => {
6856
6993
  if (!pendingSelectSourceAction) return null;
@@ -6858,16 +6995,16 @@ function useSourceSelectionHandlers(dispatch, authExecutor) {
6858
6995
  }, [pendingSelectSourceAction]);
6859
6996
  const selectSourceAvailableBalance = react.useMemo(() => {
6860
6997
  if (!pendingSelectSourceAction) return 0;
6861
- const options = pendingSelectSourceAction.metadata?.options ?? [];
6998
+ const options2 = pendingSelectSourceAction.metadata?.options ?? [];
6862
6999
  const recommended = selectSourceRecommended;
6863
7000
  if (recommended) {
6864
- const match = options.find(
7001
+ const match = options2.find(
6865
7002
  (opt) => opt.chainName === recommended.chainName && opt.tokenSymbol === recommended.tokenSymbol
6866
7003
  );
6867
7004
  if (match) return Number(match.rawBalance) / Math.pow(10, match.decimals);
6868
7005
  }
6869
7006
  let max = 0;
6870
- for (const opt of options) {
7007
+ for (const opt of options2) {
6871
7008
  const bal = Number(opt.rawBalance) / Math.pow(10, opt.decimals);
6872
7009
  if (bal > max) max = bal;
6873
7010
  }
@@ -6887,11 +7024,34 @@ function useSourceSelectionHandlers(dispatch, authExecutor) {
6887
7024
  [selectSourceChoices, selectSourceRecommended]
6888
7025
  );
6889
7026
  const handleConfirmSelectSource = react.useCallback(() => {
7027
+ const guestPostPayPreauth = !!options?.guestPreauthSessionId && !!options?.isGuestFlow || !!options?.guestPreauthorizing && !!options?.isDesktop;
7028
+ if (guestPostPayPreauth) {
7029
+ dispatch({ type: "REQUEST_LOGIN" });
7030
+ if (options?.guestPreauthAccountId != null) {
7031
+ const intent = {
7032
+ step: "wallet-setup",
7033
+ mobile: null,
7034
+ accountId: options.guestPreauthAccountId,
7035
+ guestDesktopExtension: true
7036
+ };
7037
+ dispatch({ type: "SET_USER_INTENT", intent });
7038
+ }
7039
+ }
6890
7040
  authExecutor.resolveSelectSource({
6891
7041
  chainName: selectSourceChainName,
6892
7042
  tokenSymbol: selectSourceTokenSymbol
6893
7043
  });
6894
- }, [authExecutor, selectSourceChainName, selectSourceTokenSymbol]);
7044
+ }, [
7045
+ authExecutor,
7046
+ dispatch,
7047
+ options?.guestPreauthSessionId,
7048
+ options?.guestPreauthAccountId,
7049
+ options?.guestPreauthorizing,
7050
+ options?.isDesktop,
7051
+ options?.isGuestFlow,
7052
+ selectSourceChainName,
7053
+ selectSourceTokenSymbol
7054
+ ]);
6895
7055
  return {
6896
7056
  selectSourceChainName,
6897
7057
  selectSourceTokenSymbol,
@@ -8265,6 +8425,10 @@ function useProcessingEffect(deps) {
8265
8425
  } = deps;
8266
8426
  react.useEffect(() => {
8267
8427
  if (!polling.transfer) return;
8428
+ if (state.loginRequested || state.verificationTarget) return;
8429
+ if (!state.transfer && (polling.transfer.status === "COMPLETED" || polling.transfer.status === "FAILED")) {
8430
+ return;
8431
+ }
8268
8432
  if (polling.transfer.status === "COMPLETED") {
8269
8433
  clearMobileFlowState();
8270
8434
  dispatch({ type: "TRANSFER_COMPLETED", transfer: polling.transfer });
@@ -8274,7 +8438,15 @@ function useProcessingEffect(deps) {
8274
8438
  clearMobileFlowState();
8275
8439
  dispatch({ type: "TRANSFER_FAILED", transfer: polling.transfer, error: "Transfer failed." });
8276
8440
  }
8277
- }, [polling.transfer, onComplete, dispatch, reloadAccounts]);
8441
+ }, [
8442
+ polling.transfer,
8443
+ state.transfer,
8444
+ state.loginRequested,
8445
+ state.verificationTarget,
8446
+ onComplete,
8447
+ dispatch,
8448
+ reloadAccounts
8449
+ ]);
8278
8450
  react.useEffect(() => {
8279
8451
  const isProcessing = state.creatingTransfer || state.transfer != null && ["CREATED", "SENDING", "SENT"].includes(state.transfer.status);
8280
8452
  if (!isProcessing) {
@@ -8525,6 +8697,42 @@ function useOneTapAutoResolveEffect(deps) {
8525
8697
  }
8526
8698
  }, [pendingOneTapSetupAction, reloadAccounts, oneTapLimitSavedDuringSetup]);
8527
8699
  }
8700
+
8701
+ // src/guestPreauthClaimWait.ts
8702
+ var GUEST_PREAUTH_SESSION_POLL_INTERVAL_MS = 1e3;
8703
+ var GUEST_PREAUTH_SESSION_POLL_TIMEOUT_MS = 12e4;
8704
+ async function waitForGuestPreauthAuthorizationSession(apiBaseUrl, sessionId, fetchSession, signal, options) {
8705
+ const intervalMs = GUEST_PREAUTH_SESSION_POLL_INTERVAL_MS;
8706
+ const timeoutMs = GUEST_PREAUTH_SESSION_POLL_TIMEOUT_MS;
8707
+ const deadline = Date.now() + timeoutMs;
8708
+ const sleepAbortable = (ms) => new Promise((resolve, reject) => {
8709
+ if (signal.aborted) {
8710
+ reject(new DOMException("Aborted", "AbortError"));
8711
+ return;
8712
+ }
8713
+ const t = setTimeout(() => {
8714
+ signal.removeEventListener("abort", onAbort);
8715
+ resolve();
8716
+ }, ms);
8717
+ const onAbort = () => {
8718
+ clearTimeout(t);
8719
+ signal.removeEventListener("abort", onAbort);
8720
+ reject(new DOMException("Aborted", "AbortError"));
8721
+ };
8722
+ signal.addEventListener("abort", onAbort, { once: true });
8723
+ });
8724
+ while (Date.now() < deadline) {
8725
+ if (signal.aborted) {
8726
+ throw new DOMException("Aborted", "AbortError");
8727
+ }
8728
+ const session = await fetchSession(apiBaseUrl, sessionId);
8729
+ if (session.status === "AUTHORIZED") return;
8730
+ await sleepAbortable(intervalMs);
8731
+ }
8732
+ throw new Error("Authorization session did not become AUTHORIZED in time.");
8733
+ }
8734
+
8735
+ // src/hooks/useGuestPreauthEffect.ts
8528
8736
  function useGuestPreauthEffect(deps) {
8529
8737
  const { state, dispatch, authenticated, apiBaseUrl, reloadAccounts } = deps;
8530
8738
  const { getAccessToken } = reactAuth.usePrivy();
@@ -8538,12 +8746,25 @@ function useGuestPreauthEffect(deps) {
8538
8746
  if (!authenticated) return;
8539
8747
  if (!state.guestSessionToken) return;
8540
8748
  if (settingOwnerRef.current) return;
8541
- const hasActive = state.accounts.some((a) => a.wallets.some((w) => w.status === "ACTIVE"));
8542
- if (!hasActive) return;
8543
8749
  settingOwnerRef.current = true;
8750
+ const abort = new AbortController();
8544
8751
  let cancelled = false;
8545
8752
  const setOwner = async () => {
8546
8753
  try {
8754
+ if (state.guestPreauthSessionId) {
8755
+ try {
8756
+ await waitForGuestPreauthAuthorizationSession(
8757
+ apiBaseUrl,
8758
+ state.guestPreauthSessionId,
8759
+ fetchAuthorizationSession,
8760
+ abort.signal
8761
+ );
8762
+ } catch (waitErr) {
8763
+ if (waitErr instanceof DOMException && waitErr.name === "AbortError") return;
8764
+ throw waitErr;
8765
+ }
8766
+ }
8767
+ if (cancelled) return;
8547
8768
  const token = await getAccessTokenRef.current();
8548
8769
  if (!token || cancelled) return;
8549
8770
  await setAccountOwner(apiBaseUrl, token, state.guestPreauthAccountId, state.guestSessionToken, {
@@ -8568,16 +8789,17 @@ function useGuestPreauthEffect(deps) {
8568
8789
  settingOwnerRef.current = false;
8569
8790
  }
8570
8791
  };
8571
- setOwner();
8792
+ void setOwner();
8572
8793
  return () => {
8573
8794
  cancelled = true;
8795
+ abort.abort();
8574
8796
  };
8575
8797
  }, [
8576
8798
  state.guestPreauthAccountId,
8799
+ state.guestPreauthSessionId,
8577
8800
  state.activeCredentialId,
8578
8801
  state.activePublicKey,
8579
8802
  state.guestSessionToken,
8580
- state.accounts,
8581
8803
  authenticated,
8582
8804
  apiBaseUrl,
8583
8805
  dispatch,
@@ -8618,6 +8840,9 @@ function useGuestPreauthPhaseSyncEffect(deps) {
8618
8840
  if (!state.guestPreauthorizing || !isDesktop) return;
8619
8841
  const pending = authExecutor.pendingSelectSource;
8620
8842
  if (pending) {
8843
+ if (state.phase.step === "token-picker") {
8844
+ return;
8845
+ }
8621
8846
  const intent = {
8622
8847
  step: "select-source",
8623
8848
  action: pending,
@@ -8631,6 +8856,10 @@ function useGuestPreauthPhaseSyncEffect(deps) {
8631
8856
  }
8632
8857
  if (state.phase.step === "select-source") {
8633
8858
  dispatch({ type: "SET_USER_INTENT", intent: { step: "one-tap-setup", action: null } });
8859
+ return;
8860
+ }
8861
+ if (state.phase.step === "token-picker") {
8862
+ dispatch({ type: "SET_USER_INTENT", intent: { step: "one-tap-setup", action: null } });
8634
8863
  }
8635
8864
  }, [
8636
8865
  state.guestPreauthorizing,
@@ -8640,6 +8869,38 @@ function useGuestPreauthPhaseSyncEffect(deps) {
8640
8869
  dispatch
8641
8870
  ]);
8642
8871
  }
8872
+ function useGuestPreauthWalletSetupEffect(deps) {
8873
+ const { state, dispatch, authExecutor, isDesktop } = deps;
8874
+ react.useEffect(() => {
8875
+ if (!isDesktop || !state.guestPreauthorizing || !state.guestPreauthSessionId) return;
8876
+ if (!state.guestPreauthAccountId) return;
8877
+ if (!authExecutor.executing || authExecutor.pendingSelectSource) return;
8878
+ if (state.verificationTarget) return;
8879
+ const p = state.phase;
8880
+ if (p.step === "wallet-setup" && p.mobile == null && p.guestDesktopExtension && p.accountId === state.guestPreauthAccountId) {
8881
+ return;
8882
+ }
8883
+ dispatch({
8884
+ type: "SET_USER_INTENT",
8885
+ intent: {
8886
+ step: "wallet-setup",
8887
+ mobile: null,
8888
+ accountId: state.guestPreauthAccountId,
8889
+ guestDesktopExtension: true
8890
+ }
8891
+ });
8892
+ }, [
8893
+ isDesktop,
8894
+ state.guestPreauthorizing,
8895
+ state.guestPreauthSessionId,
8896
+ state.guestPreauthAccountId,
8897
+ state.verificationTarget,
8898
+ state.phase,
8899
+ authExecutor.executing,
8900
+ authExecutor.pendingSelectSource,
8901
+ dispatch
8902
+ ]);
8903
+ }
8643
8904
  function BlinkPayment(props) {
8644
8905
  const resetKey = react.useRef(0);
8645
8906
  const handleBoundaryReset = react.useCallback(() => {
@@ -8724,7 +8985,13 @@ function BlinkPaymentInner({
8724
8985
  mobileFlowRefs,
8725
8986
  onComplete
8726
8987
  );
8727
- const sourceSelection = useSourceSelectionHandlers(dispatch, authExecutor);
8988
+ const sourceSelection = useSourceSelectionHandlers(dispatch, authExecutor, {
8989
+ guestPreauthSessionId: state.guestPreauthSessionId,
8990
+ guestPreauthAccountId: state.guestPreauthAccountId,
8991
+ isGuestFlow: state.isGuestFlow,
8992
+ guestPreauthorizing: state.guestPreauthorizing,
8993
+ isDesktop
8994
+ });
8728
8995
  const provider = useProviderHandlers({
8729
8996
  dispatch,
8730
8997
  getAccessToken,
@@ -8897,6 +9164,12 @@ function BlinkPaymentInner({
8897
9164
  dispatch,
8898
9165
  desktopGuestPreauth: isDesktop
8899
9166
  });
9167
+ useGuestPreauthWalletSetupEffect({
9168
+ state,
9169
+ dispatch,
9170
+ authExecutor,
9171
+ isDesktop
9172
+ });
8900
9173
  const handlers = react.useMemo(() => ({
8901
9174
  onSendLoginCode: auth.handleSendLoginCode,
8902
9175
  onVerifyLoginCode: auth.handleVerifyLoginCode,
@@ -8935,7 +9208,11 @@ function BlinkPaymentInner({
8935
9208
  onSelectGuestToken: guestTransfer.handleSelectGuestToken,
8936
9209
  onGuestBackFromTokenPicker: guestTransfer.handleGuestBackFromTokenPicker,
8937
9210
  onLogin: () => dispatch({ type: "REQUEST_LOGIN" }),
8938
- onPreauthorize: provider.handlePreauthorize
9211
+ onPreauthorize: provider.handlePreauthorize,
9212
+ onGuestSetupCompleteClose: () => {
9213
+ dispatch({ type: "GUEST_PREAUTH_SETUP_COMPLETE_DISMISSED" });
9214
+ onDismiss?.();
9215
+ }
8939
9216
  }), [
8940
9217
  auth,
8941
9218
  passkey,
@@ -8946,7 +9223,9 @@ function BlinkPaymentInner({
8946
9223
  oneTapSetup,
8947
9224
  guestTransfer,
8948
9225
  handleLogout,
8949
- handleNewPayment
9226
+ handleNewPayment,
9227
+ onDismiss,
9228
+ dispatch
8950
9229
  ]);
8951
9230
  return /* @__PURE__ */ jsxRuntime.jsx(
8952
9231
  StepRenderer,