@swype-org/react-sdk 0.1.260 → 0.1.261

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
@@ -2439,13 +2439,37 @@ function applyAction(state, action) {
2439
2439
  selectedProviderId: action.providerId ?? state.selectedProviderId,
2440
2440
  error: action.error ?? null
2441
2441
  };
2442
- case "MOBILE_RESUME_SUCCESS":
2442
+ case "MOBILE_RESUME_SUCCESS": {
2443
+ const guestResume = action.guestCheckoutResume;
2443
2444
  return {
2444
2445
  ...state,
2445
2446
  transfer: action.transfer,
2446
2447
  error: null,
2447
2448
  mobileFlow: false,
2448
- deeplinkUri: null
2449
+ deeplinkUri: null,
2450
+ ...guestResume ? {
2451
+ isGuestFlow: true,
2452
+ guestSessionToken: guestResume.guestSessionToken,
2453
+ guestTransferId: action.transfer.id
2454
+ } : {}
2455
+ };
2456
+ }
2457
+ case "GUEST_PREAUTH_RESUME_WITH_TRANSFER":
2458
+ return {
2459
+ ...state,
2460
+ transfer: action.transfer,
2461
+ error: null,
2462
+ mobileFlow: false,
2463
+ deeplinkUri: null,
2464
+ isGuestFlow: true,
2465
+ guestSessionToken: action.guestSessionToken,
2466
+ guestTransferId: action.transfer.id,
2467
+ guestPreauthAccountId: action.guestPreauthAccountId,
2468
+ guestPreauthSessionId: action.guestPreauthSessionId ?? state.guestPreauthSessionId,
2469
+ selectedProviderId: action.selectedProviderId,
2470
+ selectedAccountId: action.guestPreauthAccountId,
2471
+ selectedWalletId: null,
2472
+ selectedTokenSymbol: null
2449
2473
  };
2450
2474
  case "MOBILE_RESUME_FAILED":
2451
2475
  return {
@@ -8239,6 +8263,38 @@ function usePasskeyCheckEffect(deps) {
8239
8263
  if (cancelled) return;
8240
8264
  if (existingTransfer.status === "COMPLETED") {
8241
8265
  clearMobileFlowState();
8266
+ if (persisted.isGuestPreauth && persisted.guestSessionToken) {
8267
+ let guestLookup = null;
8268
+ try {
8269
+ guestLookup = await fetchGuestAccount(
8270
+ apiBaseUrl,
8271
+ persisted.guestSessionToken
8272
+ );
8273
+ } catch {
8274
+ dispatch({ type: "MOBILE_RESUME_SUCCESS", transfer: existingTransfer });
8275
+ onCompleteRef.current?.(existingTransfer);
8276
+ return;
8277
+ }
8278
+ if (guestLookup == null) {
8279
+ dispatch({
8280
+ type: "MOBILE_RESUME_SUCCESS",
8281
+ transfer: existingTransfer,
8282
+ guestCheckoutResume: { guestSessionToken: persisted.guestSessionToken }
8283
+ });
8284
+ onCompleteRef.current?.(existingTransfer);
8285
+ return;
8286
+ }
8287
+ dispatch({
8288
+ type: "GUEST_PREAUTH_RESUME_WITH_TRANSFER",
8289
+ transfer: existingTransfer,
8290
+ guestSessionToken: persisted.guestSessionToken,
8291
+ guestPreauthAccountId: guestLookup.accountId,
8292
+ guestPreauthSessionId: persisted.sessionId ?? null,
8293
+ selectedProviderId: persisted.providerId
8294
+ });
8295
+ onCompleteRef.current?.(existingTransfer);
8296
+ return;
8297
+ }
8242
8298
  dispatch({ type: "MOBILE_RESUME_SUCCESS", transfer: existingTransfer });
8243
8299
  onCompleteRef.current?.(existingTransfer);
8244
8300
  return;
@@ -8594,9 +8650,11 @@ function useMobilePollingEffect(deps) {
8594
8650
  reloadAccounts,
8595
8651
  apiBaseUrl
8596
8652
  } = deps;
8597
- const { getAccessToken } = usePrivy();
8653
+ const { getAccessToken, authenticated: privyAuthenticated } = usePrivy();
8598
8654
  const getAccessTokenRef = useRef(getAccessToken);
8599
8655
  getAccessTokenRef.current = getAccessToken;
8656
+ const privyAuthenticatedRef = useRef(privyAuthenticated);
8657
+ privyAuthenticatedRef.current = privyAuthenticated;
8600
8658
  const handleAuthorizedMobileReturnRef = useRef(deps.handleAuthorizedMobileReturn);
8601
8659
  handleAuthorizedMobileReturnRef.current = deps.handleAuthorizedMobileReturn;
8602
8660
  useEffect(() => {
@@ -8629,6 +8687,34 @@ function useMobilePollingEffect(deps) {
8629
8687
  await reloadAccounts();
8630
8688
  } catch {
8631
8689
  }
8690
+ const guestToken = state.guestSessionToken;
8691
+ const preauthAccountId = state.guestPreauthAccountId;
8692
+ const preauthSessionId = state.guestPreauthSessionId;
8693
+ if (!guestToken) {
8694
+ dispatch({ type: "MOBILE_SETUP_COMPLETE" });
8695
+ return;
8696
+ }
8697
+ let guestLookup = null;
8698
+ try {
8699
+ guestLookup = await fetchGuestAccount(apiBaseUrl, guestToken);
8700
+ } catch {
8701
+ dispatch({ type: "MOBILE_SETUP_COMPLETE" });
8702
+ return;
8703
+ }
8704
+ if (guestLookup == null) {
8705
+ dispatch({ type: "MOBILE_SETUP_COMPLETE" });
8706
+ return;
8707
+ }
8708
+ if (guestLookup.accountId !== preauthAccountId) {
8709
+ dispatch({
8710
+ type: "GUEST_PREAUTH_DETECTED",
8711
+ accountId: guestLookup.accountId,
8712
+ sessionId: preauthSessionId ?? void 0
8713
+ });
8714
+ }
8715
+ if (!privyAuthenticatedRef.current) {
8716
+ dispatch({ type: "REQUEST_LOGIN" });
8717
+ }
8632
8718
  dispatch({ type: "MOBILE_SETUP_COMPLETE" });
8633
8719
  };
8634
8720
  const pollGuestPreauthSession = async () => {
@@ -8663,6 +8749,8 @@ function useMobilePollingEffect(deps) {
8663
8749
  state.activeCredentialId,
8664
8750
  state.guestPreauthSessionId,
8665
8751
  state.isGuestFlow,
8752
+ state.guestSessionToken,
8753
+ state.guestPreauthAccountId,
8666
8754
  apiBaseUrl,
8667
8755
  reloadAccounts,
8668
8756
  dispatch,
@@ -8830,11 +8918,38 @@ function useGuestPreauthMobileRestoreEffect(deps) {
8830
8918
  ]);
8831
8919
  if (cancelled) return;
8832
8920
  const mobileOpen = session.status !== "AUTHORIZED";
8921
+ let guestLookup = null;
8922
+ if (!mobileOpen) {
8923
+ try {
8924
+ guestLookup = await fetchGuestAccount(
8925
+ apiBaseUrl,
8926
+ persisted.guestSessionToken
8927
+ );
8928
+ } catch {
8929
+ dispatch({
8930
+ type: "MOBILE_RESUME_SUCCESS",
8931
+ transfer,
8932
+ guestCheckoutResume: { guestSessionToken: persisted.guestSessionToken }
8933
+ });
8934
+ clearMobileFlowState();
8935
+ return;
8936
+ }
8937
+ if (guestLookup == null) {
8938
+ dispatch({
8939
+ type: "MOBILE_RESUME_SUCCESS",
8940
+ transfer,
8941
+ guestCheckoutResume: { guestSessionToken: persisted.guestSessionToken }
8942
+ });
8943
+ clearMobileFlowState();
8944
+ return;
8945
+ }
8946
+ }
8947
+ const guestPreauthAccountId = !mobileOpen && guestLookup != null ? guestLookup.accountId : persisted.accountId;
8833
8948
  dispatch({
8834
8949
  type: "RESTORE_GUEST_PREAUTH_MOBILE",
8835
8950
  transfer,
8836
8951
  guestSessionToken: persisted.guestSessionToken,
8837
- guestPreauthAccountId: persisted.accountId,
8952
+ guestPreauthAccountId,
8838
8953
  guestPreauthSessionId: persisted.sessionId,
8839
8954
  selectedProviderId: persisted.providerId,
8840
8955
  deeplinkUri: persisted.deeplinkUri,
@@ -8842,7 +8957,7 @@ function useGuestPreauthMobileRestoreEffect(deps) {
8842
8957
  });
8843
8958
  if (mobileOpen) {
8844
8959
  mobileSetupFlowRef.current = true;
8845
- setupAccountIdRef.current = persisted.accountId;
8960
+ setupAccountIdRef.current = persisted.accountId ?? null;
8846
8961
  } else {
8847
8962
  clearMobileFlowState();
8848
8963
  }