@swype-org/react-sdk 0.1.232 → 0.1.241

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,14 +2004,29 @@ 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
+ case "otp-verify":
2015
+ case "passkey-create":
2016
+ case "passkey-verify":
2017
+ case "data-loading":
2018
+ return true;
2019
+ case "wallet-setup":
2020
+ return phase.mobile == null;
2021
+ default:
2022
+ return false;
2023
+ }
2024
+ }
2007
2025
  function resolvePhase(state) {
2008
2026
  const p = state.phase;
2009
- if (p.step === "select-source" && state.transfer?.status === "COMPLETED" && state.guestPreauthorizing) {
2027
+ if (state.transfer?.status === "COMPLETED" && state.guestPreauthorizing && isGuestPreauthCompletedTransferPinPhase(p)) {
2010
2028
  return p;
2011
2029
  }
2012
- if (state.transfer?.status === "COMPLETED" && state.guestPreauthorizing) {
2013
- return { step: "processing", transfer: state.transfer };
2014
- }
2015
2030
  if (state.transfer?.status === "COMPLETED") {
2016
2031
  return { step: "completed", transfer: state.transfer };
2017
2032
  }
@@ -2021,10 +2036,9 @@ function resolvePhase(state) {
2021
2036
  if (state.creatingTransfer || isTransferInFlight(state.transfer)) {
2022
2037
  return { step: "processing", transfer: state.transfer };
2023
2038
  }
2024
- if (p.step === "token-picker" || p.step === "one-tap-setup" || p.step === "select-source" || p.step === "confirm-sign" || p.step === "guest-token-picker") {
2039
+ 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
2040
  return p;
2026
2041
  }
2027
- if (p.step === "wallet-setup") return p;
2028
2042
  if (state.mobileFlow && state.deeplinkUri) {
2029
2043
  return {
2030
2044
  step: "wallet-setup",
@@ -2032,7 +2046,19 @@ function resolvePhase(state) {
2032
2046
  accountId: null
2033
2047
  };
2034
2048
  }
2035
- if (!state.activeCredentialId && !state.passkeyConfigLoaded) {
2049
+ if (p.step === "wallet-setup" && p.mobile == null) {
2050
+ return p;
2051
+ }
2052
+ if (state.isGuestFlow && state.selectedProviderId != null && !state.transfer) {
2053
+ return { step: "guest-token-picker" };
2054
+ }
2055
+ if (p.step === "wallet-picker" && !state.creatingTransfer && !(state.mobileFlow && state.deeplinkUri)) {
2056
+ return p;
2057
+ }
2058
+ if (!state.privyReady) {
2059
+ return { step: "initializing" };
2060
+ }
2061
+ if (state.privyAuthenticated && !state.activeCredentialId && !state.passkeyConfigLoaded) {
2036
2062
  return { step: "initializing" };
2037
2063
  }
2038
2064
  if (state.verificationTarget) {
@@ -2050,9 +2076,6 @@ function resolvePhase(state) {
2050
2076
  if (state.loadingData && state.activeCredentialId && hasActiveWallet(state.accounts)) {
2051
2077
  return { step: "data-loading" };
2052
2078
  }
2053
- if (state.isGuestFlow && state.selectedProviderId != null && !state.transfer) {
2054
- return { step: "guest-token-picker" };
2055
- }
2056
2079
  if (state.activeCredentialId && !hasActiveWallet(state.accounts) && !state.mobileFlow) {
2057
2080
  return { step: "wallet-picker", reason: "link" };
2058
2081
  }
@@ -2109,7 +2132,9 @@ function createInitialState(config) {
2109
2132
  guestPreauthSessionId: null,
2110
2133
  activePublicKey: null,
2111
2134
  loginRequested: false,
2112
- guestPreauthorizing: false
2135
+ guestPreauthorizing: false,
2136
+ privyReady: false,
2137
+ privyAuthenticated: false
2113
2138
  };
2114
2139
  }
2115
2140
  function paymentReducer(state, action) {
@@ -2339,6 +2364,17 @@ function applyAction(state, action) {
2339
2364
  selectedWalletId: null,
2340
2365
  selectedTokenSymbol: null
2341
2366
  };
2367
+ case "GUEST_BACK_FROM_TOKEN_PICKER":
2368
+ return {
2369
+ ...state,
2370
+ selectedProviderId: null,
2371
+ guestTransferId: null,
2372
+ guestSessionToken: null,
2373
+ selectedAccountId: null,
2374
+ selectedWalletId: null,
2375
+ selectedTokenSymbol: null,
2376
+ error: null
2377
+ };
2342
2378
  case "GUEST_TRANSFER_COMPLETED":
2343
2379
  return {
2344
2380
  ...state,
@@ -2352,7 +2388,10 @@ function applyAction(state, action) {
2352
2388
  return {
2353
2389
  ...state,
2354
2390
  guestPreauthAccountId: action.accountId,
2355
- guestPreauthSessionId: action.sessionId ?? state.guestPreauthSessionId
2391
+ guestPreauthSessionId: action.sessionId ?? state.guestPreauthSessionId,
2392
+ selectedAccountId: action.accountId,
2393
+ selectedWalletId: null,
2394
+ selectedTokenSymbol: null
2356
2395
  };
2357
2396
  case "GUEST_PREAUTH_BEGIN":
2358
2397
  return { ...state, guestPreauthorizing: true, error: null };
@@ -2410,7 +2449,15 @@ function applyAction(state, action) {
2410
2449
  depositAmount: action.depositAmount,
2411
2450
  passkeyPopupNeeded: state.passkeyPopupNeeded,
2412
2451
  activeCredentialId: null
2413
- })
2452
+ }),
2453
+ privyReady: action.privyReady,
2454
+ privyAuthenticated: false
2455
+ };
2456
+ case "SYNC_PRIVY_SESSION":
2457
+ return {
2458
+ ...state,
2459
+ privyReady: action.ready,
2460
+ privyAuthenticated: action.authenticated
2414
2461
  };
2415
2462
  case "SYNC_AMOUNT":
2416
2463
  return { ...state, amount: action.amount };
@@ -2478,7 +2525,6 @@ function screenForPhase(phase) {
2478
2525
  case "wallet-setup":
2479
2526
  return phase.mobile ? "open-wallet" : "setup-status";
2480
2527
  case "select-source":
2481
- if (phase.skipOneTapLimit) return "select-source";
2482
2528
  return phase.isDesktop ? "setup" : "select-source";
2483
2529
  case "one-tap-setup":
2484
2530
  return "setup";
@@ -6014,7 +6060,8 @@ function StepRendererContent({
6014
6060
  pollingError,
6015
6061
  authExecutorError,
6016
6062
  transferSigningSigning,
6017
- transferSigningError
6063
+ transferSigningError,
6064
+ pendingSelectSource
6018
6065
  } = remote;
6019
6066
  const {
6020
6067
  pendingConnections,
@@ -6214,6 +6261,26 @@ function StepRendererContent({
6214
6261
  }
6215
6262
  case "token-picker": {
6216
6263
  if (!selectedAccount) {
6264
+ if (pendingSelectSource && selectSourceChoices.length > 0) {
6265
+ return /* @__PURE__ */ jsxRuntime.jsx(
6266
+ SelectSourceScreen,
6267
+ {
6268
+ choices: selectSourceChoices,
6269
+ selectedChainName: selectSourceChainName,
6270
+ selectedTokenSymbol: selectSourceTokenSymbol,
6271
+ recommended: selectSourceRecommended,
6272
+ onChainChange: handlers.onSelectSourceChainChange,
6273
+ onTokenChange: handlers.onSetSelectSourceTokenSymbol,
6274
+ onConfirm: handlers.onConfirmSelectSource,
6275
+ onBack: () => handlers.onSetPhase({
6276
+ step: "select-source",
6277
+ action: pendingSelectSource,
6278
+ isDesktop
6279
+ }),
6280
+ onLogout: handlers.onLogout
6281
+ }
6282
+ );
6283
+ }
6217
6284
  return /* @__PURE__ */ jsxRuntime.jsx(BlinkLoadingScreen, {});
6218
6285
  }
6219
6286
  return /* @__PURE__ */ jsxRuntime.jsx(
@@ -6241,7 +6308,7 @@ function StepRendererContent({
6241
6308
  depositAmount: depositAmount ?? void 0,
6242
6309
  error: state.error,
6243
6310
  onSelect: handlers.onSelectGuestToken,
6244
- onBack: () => handlers.onSetPhase({ step: "wallet-picker", reason: "guest-entry" })
6311
+ onBack: handlers.onGuestBackFromTokenPicker
6245
6312
  }
6246
6313
  );
6247
6314
  case "processing": {
@@ -6523,9 +6590,18 @@ function usePasskeyHandlers(dispatch, apiBaseUrl, accounts, knownCredentialIds,
6523
6590
  const { user, getAccessToken } = reactAuth.usePrivy();
6524
6591
  const checkingPasskeyRef = react.useRef(false);
6525
6592
  const activateExistingCredential = react.useCallback(async (credentialId) => {
6526
- dispatch({ type: "PASSKEY_ACTIVATED", credentialId });
6527
- window.localStorage.setItem(ACTIVE_CREDENTIAL_STORAGE_KEY, credentialId);
6528
6593
  const token = await getAccessToken();
6594
+ let publicKey;
6595
+ if (token) {
6596
+ try {
6597
+ const { config } = await fetchUserConfig(apiBaseUrl, token);
6598
+ const allPasskeys = config.passkeys ?? (config.passkey ? [config.passkey] : []);
6599
+ publicKey = allPasskeys.find((p) => p.credentialId === credentialId)?.publicKey;
6600
+ } catch {
6601
+ }
6602
+ }
6603
+ dispatch({ type: "PASSKEY_ACTIVATED", credentialId, publicKey });
6604
+ window.localStorage.setItem(ACTIVE_CREDENTIAL_STORAGE_KEY, credentialId);
6529
6605
  if (token) {
6530
6606
  reportPasskeyActivity(apiBaseUrl, token, credentialId).catch(() => {
6531
6607
  });
@@ -6598,9 +6674,13 @@ function usePasskeyHandlers(dispatch, apiBaseUrl, accounts, knownCredentialIds,
6598
6674
  authToken: token ?? void 0,
6599
6675
  apiBaseUrl
6600
6676
  });
6601
- const { credentialId } = await createPasskeyViaPopup(popupOptions);
6602
- dispatch({ type: "PASSKEY_ACTIVATED", credentialId });
6677
+ const { credentialId, publicKey } = await createPasskeyViaPopup(popupOptions);
6678
+ dispatch({ type: "PASSKEY_ACTIVATED", credentialId, publicKey });
6603
6679
  localStorage.setItem(ACTIVE_CREDENTIAL_STORAGE_KEY, credentialId);
6680
+ if (token) {
6681
+ reportPasskeyActivity(apiBaseUrl, token, credentialId).catch(() => {
6682
+ });
6683
+ }
6604
6684
  } catch (err) {
6605
6685
  captureException(err);
6606
6686
  dispatch({
@@ -6616,19 +6696,25 @@ function usePasskeyHandlers(dispatch, apiBaseUrl, accounts, knownCredentialIds,
6616
6696
  dispatch({ type: "SET_ERROR", error: null });
6617
6697
  try {
6618
6698
  const token = await getAccessToken();
6699
+ if (!token) throw new Error("Not authenticated");
6619
6700
  const matched = await findDevicePasskeyViaPopup({
6620
6701
  credentialIds: knownCredentialIds,
6621
6702
  rpId: resolvePasskeyRpId(),
6622
- authToken: token ?? void 0,
6703
+ authToken: token,
6623
6704
  apiBaseUrl
6624
6705
  });
6625
6706
  if (matched) {
6626
- dispatch({ type: "PASSKEY_ACTIVATED", credentialId: matched });
6627
- window.localStorage.setItem(ACTIVE_CREDENTIAL_STORAGE_KEY, matched);
6628
- if (token) {
6629
- reportPasskeyActivity(apiBaseUrl, token, matched).catch(() => {
6630
- });
6707
+ let publicKey;
6708
+ try {
6709
+ const { config } = await fetchUserConfig(apiBaseUrl, token);
6710
+ const allPasskeys = config.passkeys ?? (config.passkey ? [config.passkey] : []);
6711
+ publicKey = allPasskeys.find((p) => p.credentialId === matched)?.publicKey;
6712
+ } catch {
6631
6713
  }
6714
+ dispatch({ type: "PASSKEY_ACTIVATED", credentialId: matched, publicKey });
6715
+ window.localStorage.setItem(ACTIVE_CREDENTIAL_STORAGE_KEY, matched);
6716
+ reportPasskeyActivity(apiBaseUrl, token, matched).catch(() => {
6717
+ });
6632
6718
  } else {
6633
6719
  dispatch({
6634
6720
  type: "SET_ERROR",
@@ -6792,15 +6878,15 @@ function useTransferHandlers(deps) {
6792
6878
  pollingTransferIdRef
6793
6879
  };
6794
6880
  }
6795
- function useSourceSelectionHandlers(dispatch, authExecutor) {
6881
+ function useSourceSelectionHandlers(dispatch, authExecutor, options) {
6796
6882
  const [selectSourceChainName, setSelectSourceChainName] = react.useState("");
6797
6883
  const [selectSourceTokenSymbol, setSelectSourceTokenSymbol] = react.useState("");
6798
6884
  const initializedSelectSourceActionRef = react.useRef(null);
6799
6885
  const pendingSelectSourceAction = authExecutor.pendingSelectSource;
6800
6886
  const selectSourceChoices = react.useMemo(() => {
6801
6887
  if (!pendingSelectSourceAction) return [];
6802
- const options = pendingSelectSourceAction.metadata?.options ?? [];
6803
- return buildSelectSourceChoices(options);
6888
+ const options2 = pendingSelectSourceAction.metadata?.options ?? [];
6889
+ return buildSelectSourceChoices(options2);
6804
6890
  }, [pendingSelectSourceAction]);
6805
6891
  const selectSourceRecommended = react.useMemo(() => {
6806
6892
  if (!pendingSelectSourceAction) return null;
@@ -6808,16 +6894,16 @@ function useSourceSelectionHandlers(dispatch, authExecutor) {
6808
6894
  }, [pendingSelectSourceAction]);
6809
6895
  const selectSourceAvailableBalance = react.useMemo(() => {
6810
6896
  if (!pendingSelectSourceAction) return 0;
6811
- const options = pendingSelectSourceAction.metadata?.options ?? [];
6897
+ const options2 = pendingSelectSourceAction.metadata?.options ?? [];
6812
6898
  const recommended = selectSourceRecommended;
6813
6899
  if (recommended) {
6814
- const match = options.find(
6900
+ const match = options2.find(
6815
6901
  (opt) => opt.chainName === recommended.chainName && opt.tokenSymbol === recommended.tokenSymbol
6816
6902
  );
6817
6903
  if (match) return Number(match.rawBalance) / Math.pow(10, match.decimals);
6818
6904
  }
6819
6905
  let max = 0;
6820
- for (const opt of options) {
6906
+ for (const opt of options2) {
6821
6907
  const bal = Number(opt.rawBalance) / Math.pow(10, opt.decimals);
6822
6908
  if (bal > max) max = bal;
6823
6909
  }
@@ -6841,7 +6927,17 @@ function useSourceSelectionHandlers(dispatch, authExecutor) {
6841
6927
  chainName: selectSourceChainName,
6842
6928
  tokenSymbol: selectSourceTokenSymbol
6843
6929
  });
6844
- }, [authExecutor, selectSourceChainName, selectSourceTokenSymbol]);
6930
+ if (options?.guestPreauthorizing && options?.isDesktop) {
6931
+ dispatch({ type: "REQUEST_LOGIN" });
6932
+ }
6933
+ }, [
6934
+ authExecutor,
6935
+ dispatch,
6936
+ options?.guestPreauthorizing,
6937
+ options?.isDesktop,
6938
+ selectSourceChainName,
6939
+ selectSourceTokenSymbol
6940
+ ]);
6845
6941
  return {
6846
6942
  selectSourceChainName,
6847
6943
  selectSourceTokenSymbol,
@@ -7677,11 +7773,15 @@ function useGuestTransferHandlers(deps) {
7677
7773
  };
7678
7774
  execute();
7679
7775
  }, [isGuestFlow, guestTransferId, guestSessionToken, settingSender, apiBaseUrl, wagmiConfig2, switchChainAsync, dispatch, onComplete, onError]);
7776
+ const handleGuestBackFromTokenPicker = react.useCallback(() => {
7777
+ dispatch({ type: "GUEST_BACK_FROM_TOKEN_PICKER" });
7778
+ }, [dispatch]);
7680
7779
  return {
7681
7780
  guestTokenEntries,
7682
7781
  loadingBalances,
7683
7782
  settingSender,
7684
- handleSelectGuestToken
7783
+ handleSelectGuestToken,
7784
+ handleGuestBackFromTokenPicker
7685
7785
  };
7686
7786
  }
7687
7787
  function useOneTapSetupHandlers(deps) {
@@ -7691,15 +7791,24 @@ function useOneTapSetupHandlers(deps) {
7691
7791
  apiBaseUrl,
7692
7792
  authExecutor,
7693
7793
  selectSourceChainName,
7694
- selectSourceTokenSymbol
7794
+ selectSourceTokenSymbol,
7795
+ authorizationSessionIdForGuest
7695
7796
  } = deps;
7696
7797
  const [savingOneTapLimit, setSavingOneTapLimit] = react.useState(false);
7697
7798
  const handleSetupOneTap = react.useCallback(async (limit) => {
7698
7799
  setSavingOneTapLimit(true);
7699
7800
  try {
7700
- const token = await getAccessToken();
7701
- if (!token) throw new Error("Not authenticated");
7702
- await updateUserConfig(apiBaseUrl, token, { defaultAllowance: limit });
7801
+ if (authorizationSessionIdForGuest) {
7802
+ await updateUserConfigBySession(
7803
+ apiBaseUrl,
7804
+ authorizationSessionIdForGuest,
7805
+ { defaultAllowance: limit }
7806
+ );
7807
+ } else {
7808
+ const token = await getAccessToken();
7809
+ if (!token) throw new Error("Not authenticated");
7810
+ await updateUserConfig(apiBaseUrl, token, { defaultAllowance: limit });
7811
+ }
7703
7812
  if (authExecutor.pendingSelectSource) {
7704
7813
  const action = authExecutor.pendingSelectSource;
7705
7814
  const recommended = action.metadata?.recommended;
@@ -7729,12 +7838,30 @@ function useOneTapSetupHandlers(deps) {
7729
7838
  } finally {
7730
7839
  setSavingOneTapLimit(false);
7731
7840
  }
7732
- }, [getAccessToken, apiBaseUrl, authExecutor, dispatch, selectSourceChainName, selectSourceTokenSymbol]);
7841
+ }, [
7842
+ getAccessToken,
7843
+ apiBaseUrl,
7844
+ authExecutor,
7845
+ dispatch,
7846
+ selectSourceChainName,
7847
+ selectSourceTokenSymbol,
7848
+ authorizationSessionIdForGuest
7849
+ ]);
7733
7850
  return {
7734
7851
  handleSetupOneTap,
7735
7852
  savingOneTapLimit
7736
7853
  };
7737
7854
  }
7855
+ function usePrivySessionSyncEffect(deps) {
7856
+ const { dispatch, ready, authenticated } = deps;
7857
+ react.useEffect(() => {
7858
+ dispatch({
7859
+ type: "SYNC_PRIVY_SESSION",
7860
+ ready,
7861
+ authenticated
7862
+ });
7863
+ }, [dispatch, ready, authenticated]);
7864
+ }
7738
7865
  function useOtpEffects(deps) {
7739
7866
  const {
7740
7867
  state,
@@ -7928,7 +8055,18 @@ function usePasskeyCheckEffect(deps) {
7928
8055
  if (token || cancelled) break;
7929
8056
  await new Promise((r) => setTimeout(r, 1e3));
7930
8057
  }
7931
- if (!token || cancelled) return;
8058
+ if (cancelled) return;
8059
+ if (!token) {
8060
+ dispatch({
8061
+ type: "PASSKEY_CONFIG_LOADED",
8062
+ knownIds: []
8063
+ });
8064
+ dispatch({
8065
+ type: "SET_ERROR",
8066
+ error: "Could not refresh your session. Try signing in again."
8067
+ });
8068
+ return;
8069
+ }
7932
8070
  const { config } = await fetchUserConfig(apiBaseUrl, token);
7933
8071
  if (cancelled) return;
7934
8072
  const allPasskeys = config.passkeys ?? (config.passkey ? [config.passkey] : []);
@@ -7939,6 +8077,10 @@ function usePasskeyCheckEffect(deps) {
7939
8077
  });
7940
8078
  if (allPasskeys.length === 0) return;
7941
8079
  if (activeCredentialId && allPasskeys.some((p) => p.credentialId === activeCredentialId)) {
8080
+ const pk = allPasskeys.find((p) => p.credentialId === activeCredentialId)?.publicKey;
8081
+ if (pk) {
8082
+ dispatch({ type: "PASSKEY_ACTIVATED", credentialId: activeCredentialId, publicKey: pk });
8083
+ }
7942
8084
  await restoreState(activeCredentialId, token);
7943
8085
  return;
7944
8086
  }
@@ -7957,13 +8099,22 @@ function usePasskeyCheckEffect(deps) {
7957
8099
  }
7958
8100
  if (cancelled) return;
7959
8101
  if (matched) {
7960
- dispatch({ type: "PASSKEY_ACTIVATED", credentialId: matched });
8102
+ const publicKey = allPasskeys.find((p) => p.credentialId === matched)?.publicKey;
8103
+ dispatch({ type: "PASSKEY_ACTIVATED", credentialId: matched, publicKey });
7961
8104
  window.localStorage.setItem(ACTIVE_CREDENTIAL_STORAGE_KEY, matched);
7962
8105
  reportPasskeyActivity(apiBaseUrl, token, matched).catch(() => {
7963
8106
  });
7964
8107
  await restoreState(matched, token);
7965
8108
  }
7966
- } catch {
8109
+ } catch (err) {
8110
+ dispatch({
8111
+ type: "PASSKEY_CONFIG_LOADED",
8112
+ knownIds: []
8113
+ });
8114
+ dispatch({
8115
+ type: "SET_ERROR",
8116
+ error: err instanceof Error ? err.message : "Unable to load passkey settings."
8117
+ });
7967
8118
  }
7968
8119
  };
7969
8120
  checkPasskey();
@@ -8513,22 +8664,25 @@ function useGuestPreauthPhaseSyncEffect(deps) {
8513
8664
  if (!state.guestPreauthorizing || !isDesktop) return;
8514
8665
  const pending = authExecutor.pendingSelectSource;
8515
8666
  if (pending) {
8667
+ if (state.phase.step === "token-picker") {
8668
+ return;
8669
+ }
8516
8670
  const intent = {
8517
8671
  step: "select-source",
8518
8672
  action: pending,
8519
- isDesktop,
8520
- skipOneTapLimit: true
8673
+ isDesktop
8521
8674
  };
8522
- if (state.phase.step === "select-source") {
8523
- const ph = state.phase;
8524
- if (ph.skipOneTapLimit && ph.action.id === pending.id) {
8525
- return;
8526
- }
8675
+ if (state.phase.step === "select-source" && state.phase.action.id === pending.id) {
8676
+ return;
8527
8677
  }
8528
8678
  dispatch({ type: "SET_USER_INTENT", intent });
8529
8679
  return;
8530
8680
  }
8531
- if (state.phase.step === "select-source" && state.phase.skipOneTapLimit === true) {
8681
+ if (state.phase.step === "select-source") {
8682
+ dispatch({ type: "SET_USER_INTENT", intent: { step: "one-tap-setup", action: null } });
8683
+ return;
8684
+ }
8685
+ if (state.phase.step === "token-picker") {
8532
8686
  dispatch({ type: "SET_USER_INTENT", intent: { step: "one-tap-setup", action: null } });
8533
8687
  }
8534
8688
  }, [
@@ -8539,6 +8693,42 @@ function useGuestPreauthPhaseSyncEffect(deps) {
8539
8693
  dispatch
8540
8694
  ]);
8541
8695
  }
8696
+ function useGuestPreauthWalletSetupEffect(deps) {
8697
+ const { state, dispatch, authExecutor, isDesktop, privyAuthenticated } = deps;
8698
+ react.useEffect(() => {
8699
+ if (!isDesktop || !state.guestPreauthorizing || !state.guestPreauthSessionId) return;
8700
+ if (!authExecutor.executing || authExecutor.pendingSelectSource) return;
8701
+ if (!privyAuthenticated || !state.activeCredentialId) return;
8702
+ if (state.verificationTarget) return;
8703
+ if (state.loginRequested) return;
8704
+ const p = state.phase;
8705
+ if (p.step === "wallet-setup" && p.mobile == null) {
8706
+ const id = state.guestPreauthAccountId;
8707
+ if (id != null && p.accountId === id) return;
8708
+ }
8709
+ dispatch({
8710
+ type: "SET_USER_INTENT",
8711
+ intent: {
8712
+ step: "wallet-setup",
8713
+ mobile: null,
8714
+ accountId: state.guestPreauthAccountId
8715
+ }
8716
+ });
8717
+ }, [
8718
+ isDesktop,
8719
+ state.guestPreauthorizing,
8720
+ state.guestPreauthSessionId,
8721
+ state.guestPreauthAccountId,
8722
+ state.activeCredentialId,
8723
+ state.verificationTarget,
8724
+ state.loginRequested,
8725
+ state.phase,
8726
+ authExecutor.executing,
8727
+ authExecutor.pendingSelectSource,
8728
+ dispatch,
8729
+ privyAuthenticated
8730
+ ]);
8731
+ }
8542
8732
  function BlinkPayment(props) {
8543
8733
  const resetKey = react.useRef(0);
8544
8734
  const handleBoundaryReset = react.useCallback(() => {
@@ -8623,7 +8813,10 @@ function BlinkPaymentInner({
8623
8813
  mobileFlowRefs,
8624
8814
  onComplete
8625
8815
  );
8626
- const sourceSelection = useSourceSelectionHandlers(dispatch, authExecutor);
8816
+ const sourceSelection = useSourceSelectionHandlers(dispatch, authExecutor, {
8817
+ guestPreauthorizing: state.guestPreauthorizing,
8818
+ isDesktop
8819
+ });
8627
8820
  const provider = useProviderHandlers({
8628
8821
  dispatch,
8629
8822
  getAccessToken,
@@ -8657,7 +8850,8 @@ function BlinkPaymentInner({
8657
8850
  apiBaseUrl,
8658
8851
  authExecutor,
8659
8852
  selectSourceChainName: sourceSelection.selectSourceChainName,
8660
- selectSourceTokenSymbol: sourceSelection.selectSourceTokenSymbol
8853
+ selectSourceTokenSymbol: sourceSelection.selectSourceTokenSymbol,
8854
+ authorizationSessionIdForGuest: state.guestPreauthSessionId
8661
8855
  });
8662
8856
  const guestTransfer = useGuestTransferHandlers({
8663
8857
  dispatch,
@@ -8690,13 +8884,14 @@ function BlinkPaymentInner({
8690
8884
  passkey.checkingPasskeyRef.current = false;
8691
8885
  auth.setAuthInput("");
8692
8886
  auth.setOtpCode("");
8693
- dispatch({ type: "LOGOUT", depositAmount });
8694
- }, [logout, polling, depositAmount, auth, passkey]);
8887
+ dispatch({ type: "LOGOUT", depositAmount, privyReady: ready });
8888
+ }, [logout, polling, depositAmount, auth, passkey, ready]);
8695
8889
  react.useEffect(() => {
8696
8890
  if (depositAmount != null) {
8697
8891
  dispatch({ type: "SYNC_AMOUNT", amount: depositAmount.toString() });
8698
8892
  }
8699
8893
  }, [depositAmount, dispatch]);
8894
+ usePrivySessionSyncEffect({ dispatch, ready, authenticated });
8700
8895
  useOtpEffects({
8701
8896
  state,
8702
8897
  dispatch,
@@ -8794,6 +8989,13 @@ function BlinkPaymentInner({
8794
8989
  dispatch,
8795
8990
  desktopGuestPreauth: isDesktop
8796
8991
  });
8992
+ useGuestPreauthWalletSetupEffect({
8993
+ state,
8994
+ dispatch,
8995
+ authExecutor,
8996
+ isDesktop,
8997
+ privyAuthenticated: authenticated
8998
+ });
8797
8999
  const handlers = react.useMemo(() => ({
8798
9000
  onSendLoginCode: auth.handleSendLoginCode,
8799
9001
  onVerifyLoginCode: auth.handleVerifyLoginCode,
@@ -8830,6 +9032,7 @@ function BlinkPaymentInner({
8830
9032
  onSelectAuthorizedToken: provider.handleSelectAuthorizedToken,
8831
9033
  onAuthorizeToken: provider.handleAuthorizeToken,
8832
9034
  onSelectGuestToken: guestTransfer.handleSelectGuestToken,
9035
+ onGuestBackFromTokenPicker: guestTransfer.handleGuestBackFromTokenPicker,
8833
9036
  onLogin: () => dispatch({ type: "REQUEST_LOGIN" }),
8834
9037
  onPreauthorize: provider.handlePreauthorize
8835
9038
  }), [