@swype-org/react-sdk 0.1.260 → 0.1.262

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(() => {
@@ -8604,16 +8662,25 @@ function useMobilePollingEffect(deps) {
8604
8662
  handlingMobileReturnRef.current = false;
8605
8663
  return;
8606
8664
  }
8665
+ if (state.isGuestFlow && state.guestPreauthSessionId != null && mobileSetupFlowRef.current) {
8666
+ return;
8667
+ }
8607
8668
  if (handlingMobileReturnRef.current) return;
8608
8669
  const polledTransfer = polling.transfer;
8609
8670
  if (!polledTransfer || polledTransfer.status !== "AUTHORIZED") return;
8610
8671
  void handleAuthorizedMobileReturnRef.current(polledTransfer, mobileSetupFlowRef.current);
8611
- }, [state.mobileFlow, polling.transfer, handlingMobileReturnRef, mobileSetupFlowRef]);
8672
+ }, [
8673
+ state.mobileFlow,
8674
+ state.isGuestFlow,
8675
+ state.guestPreauthSessionId,
8676
+ polling.transfer,
8677
+ handlingMobileReturnRef,
8678
+ mobileSetupFlowRef
8679
+ ]);
8612
8680
  useEffect(() => {
8613
8681
  if (!state.mobileFlow || !mobileSetupFlowRef.current) return;
8614
8682
  if (!setupAccountIdRef.current) return;
8615
8683
  if (!state.guestPreauthSessionId || !state.isGuestFlow) return;
8616
- if (state.activeCredentialId) return;
8617
8684
  const sessionId = state.guestPreauthSessionId;
8618
8685
  let cancelled = false;
8619
8686
  let completedGuestPreauth = false;
@@ -8629,6 +8696,34 @@ function useMobilePollingEffect(deps) {
8629
8696
  await reloadAccounts();
8630
8697
  } catch {
8631
8698
  }
8699
+ const guestToken = state.guestSessionToken;
8700
+ const preauthAccountId = state.guestPreauthAccountId;
8701
+ const preauthSessionId = state.guestPreauthSessionId;
8702
+ if (!guestToken) {
8703
+ dispatch({ type: "MOBILE_SETUP_COMPLETE" });
8704
+ return;
8705
+ }
8706
+ let guestLookup = null;
8707
+ try {
8708
+ guestLookup = await fetchGuestAccount(apiBaseUrl, guestToken);
8709
+ } catch {
8710
+ dispatch({ type: "MOBILE_SETUP_COMPLETE" });
8711
+ return;
8712
+ }
8713
+ if (guestLookup == null) {
8714
+ dispatch({ type: "MOBILE_SETUP_COMPLETE" });
8715
+ return;
8716
+ }
8717
+ if (guestLookup.accountId !== preauthAccountId) {
8718
+ dispatch({
8719
+ type: "GUEST_PREAUTH_DETECTED",
8720
+ accountId: guestLookup.accountId,
8721
+ sessionId: preauthSessionId ?? void 0
8722
+ });
8723
+ }
8724
+ if (!privyAuthenticatedRef.current) {
8725
+ dispatch({ type: "REQUEST_LOGIN" });
8726
+ }
8632
8727
  dispatch({ type: "MOBILE_SETUP_COMPLETE" });
8633
8728
  };
8634
8729
  const pollGuestPreauthSession = async () => {
@@ -8660,9 +8755,10 @@ function useMobilePollingEffect(deps) {
8660
8755
  };
8661
8756
  }, [
8662
8757
  state.mobileFlow,
8663
- state.activeCredentialId,
8664
8758
  state.guestPreauthSessionId,
8665
8759
  state.isGuestFlow,
8760
+ state.guestSessionToken,
8761
+ state.guestPreauthAccountId,
8666
8762
  apiBaseUrl,
8667
8763
  reloadAccounts,
8668
8764
  dispatch,
@@ -8671,6 +8767,7 @@ function useMobilePollingEffect(deps) {
8671
8767
  ]);
8672
8768
  useEffect(() => {
8673
8769
  if (!state.mobileFlow || !mobileSetupFlowRef.current) return;
8770
+ if (state.isGuestFlow && state.guestPreauthSessionId != null) return;
8674
8771
  if (!state.activeCredentialId || !setupAccountIdRef.current) return;
8675
8772
  const accountId = setupAccountIdRef.current;
8676
8773
  const credentialId = state.activeCredentialId;
@@ -8759,6 +8856,8 @@ function useMobilePollingEffect(deps) {
8759
8856
  };
8760
8857
  }, [
8761
8858
  state.mobileFlow,
8859
+ state.isGuestFlow,
8860
+ state.guestPreauthSessionId,
8762
8861
  state.activeCredentialId,
8763
8862
  apiBaseUrl,
8764
8863
  reloadAccounts,
@@ -8830,11 +8929,38 @@ function useGuestPreauthMobileRestoreEffect(deps) {
8830
8929
  ]);
8831
8930
  if (cancelled) return;
8832
8931
  const mobileOpen = session.status !== "AUTHORIZED";
8932
+ let guestLookup = null;
8933
+ if (!mobileOpen) {
8934
+ try {
8935
+ guestLookup = await fetchGuestAccount(
8936
+ apiBaseUrl,
8937
+ persisted.guestSessionToken
8938
+ );
8939
+ } catch {
8940
+ dispatch({
8941
+ type: "MOBILE_RESUME_SUCCESS",
8942
+ transfer,
8943
+ guestCheckoutResume: { guestSessionToken: persisted.guestSessionToken }
8944
+ });
8945
+ clearMobileFlowState();
8946
+ return;
8947
+ }
8948
+ if (guestLookup == null) {
8949
+ dispatch({
8950
+ type: "MOBILE_RESUME_SUCCESS",
8951
+ transfer,
8952
+ guestCheckoutResume: { guestSessionToken: persisted.guestSessionToken }
8953
+ });
8954
+ clearMobileFlowState();
8955
+ return;
8956
+ }
8957
+ }
8958
+ const guestPreauthAccountId = !mobileOpen && guestLookup != null ? guestLookup.accountId : persisted.accountId;
8833
8959
  dispatch({
8834
8960
  type: "RESTORE_GUEST_PREAUTH_MOBILE",
8835
8961
  transfer,
8836
8962
  guestSessionToken: persisted.guestSessionToken,
8837
- guestPreauthAccountId: persisted.accountId,
8963
+ guestPreauthAccountId,
8838
8964
  guestPreauthSessionId: persisted.sessionId,
8839
8965
  selectedProviderId: persisted.providerId,
8840
8966
  deeplinkUri: persisted.deeplinkUri,
@@ -8842,7 +8968,7 @@ function useGuestPreauthMobileRestoreEffect(deps) {
8842
8968
  });
8843
8969
  if (mobileOpen) {
8844
8970
  mobileSetupFlowRef.current = true;
8845
- setupAccountIdRef.current = persisted.accountId;
8971
+ setupAccountIdRef.current = persisted.accountId ?? null;
8846
8972
  } else {
8847
8973
  clearMobileFlowState();
8848
8974
  }