@swype-org/react-sdk 0.1.266 → 0.1.268

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
@@ -8263,7 +8263,6 @@ function usePasskeyCheckEffect(deps) {
8263
8263
  const existingTransfer = await fetchTransfer(apiBaseUrl, token, persisted.transferId);
8264
8264
  if (cancelled) return;
8265
8265
  if (existingTransfer.status === "COMPLETED") {
8266
- clearMobileFlowState();
8267
8266
  if (persisted.isGuestPreauth && persisted.guestSessionToken) {
8268
8267
  let guestLookup = null;
8269
8268
  try {
@@ -8272,19 +8271,32 @@ function usePasskeyCheckEffect(deps) {
8272
8271
  persisted.guestSessionToken
8273
8272
  );
8274
8273
  } catch {
8275
- dispatch({ type: "MOBILE_RESUME_SUCCESS", transfer: existingTransfer });
8276
- onCompleteRef.current?.(existingTransfer);
8274
+ persistMobileFlowState({
8275
+ deeplinkUri: persisted.deeplinkUri,
8276
+ providerId: persisted.providerId ?? null,
8277
+ isSetup: persisted.isSetup ?? true,
8278
+ guestSessionToken: persisted.guestSessionToken,
8279
+ transferId: persisted.transferId,
8280
+ isGuestPreauth: true,
8281
+ accountId: persisted.accountId,
8282
+ sessionId: persisted.sessionId
8283
+ });
8277
8284
  return;
8278
8285
  }
8279
8286
  if (guestLookup == null) {
8280
- dispatch({
8281
- type: "MOBILE_RESUME_SUCCESS",
8282
- transfer: existingTransfer,
8283
- guestCheckoutResume: { guestSessionToken: persisted.guestSessionToken }
8287
+ persistMobileFlowState({
8288
+ deeplinkUri: persisted.deeplinkUri,
8289
+ providerId: persisted.providerId ?? null,
8290
+ isSetup: persisted.isSetup ?? true,
8291
+ guestSessionToken: persisted.guestSessionToken,
8292
+ transferId: persisted.transferId,
8293
+ isGuestPreauth: true,
8294
+ accountId: persisted.accountId,
8295
+ sessionId: persisted.sessionId
8284
8296
  });
8285
- onCompleteRef.current?.(existingTransfer);
8286
8297
  return;
8287
8298
  }
8299
+ clearMobileFlowState();
8288
8300
  dispatch({
8289
8301
  type: "GUEST_PREAUTH_RESUME_WITH_TRANSFER",
8290
8302
  transfer: existingTransfer,
@@ -8296,6 +8308,7 @@ function usePasskeyCheckEffect(deps) {
8296
8308
  onCompleteRef.current?.(existingTransfer);
8297
8309
  return;
8298
8310
  }
8311
+ clearMobileFlowState();
8299
8312
  dispatch({ type: "MOBILE_RESUME_SUCCESS", transfer: existingTransfer });
8300
8313
  onCompleteRef.current?.(existingTransfer);
8301
8314
  return;
@@ -8583,6 +8596,7 @@ function useProcessingEffect(deps) {
8583
8596
  if (!state.transfer && (polling.transfer.status === "COMPLETED" || polling.transfer.status === "FAILED")) {
8584
8597
  return;
8585
8598
  }
8599
+ if (state.isGuestFlow) return;
8586
8600
  if (polling.transfer.status === "COMPLETED") {
8587
8601
  clearMobileFlowState();
8588
8602
  dispatch({ type: "TRANSFER_COMPLETED", transfer: polling.transfer });
@@ -8597,6 +8611,7 @@ function useProcessingEffect(deps) {
8597
8611
  state.transfer,
8598
8612
  state.loginRequested,
8599
8613
  state.verificationTarget,
8614
+ state.isGuestFlow,
8600
8615
  onComplete,
8601
8616
  dispatch,
8602
8617
  reloadAccounts
@@ -8680,7 +8695,7 @@ function useMobilePollingEffect(deps) {
8680
8695
  if (!state.mobileFlow || !mobileSetupFlowRef.current) return;
8681
8696
  if (!setupAccountIdRef.current) return;
8682
8697
  if (!state.guestPreauthSessionId || !state.isGuestFlow) return;
8683
- const guestToken = state.guestSessionToken;
8698
+ const guestToken = state.guestSessionToken ?? loadMobileFlowState()?.guestSessionToken ?? null;
8684
8699
  const preauthAccountId = state.guestPreauthAccountId;
8685
8700
  const preauthSessionId = state.guestPreauthSessionId;
8686
8701
  let cancelled = false;
@@ -8689,7 +8704,6 @@ function useMobilePollingEffect(deps) {
8689
8704
  const finishMobileAndDispatch = async () => {
8690
8705
  mobileSetupFlowRef.current = false;
8691
8706
  setupAccountIdRef.current = null;
8692
- clearMobileFlowState();
8693
8707
  try {
8694
8708
  await reloadAccounts();
8695
8709
  } catch {
@@ -8700,6 +8714,7 @@ function useMobilePollingEffect(deps) {
8700
8714
  completedGuestPreauth = true;
8701
8715
  cancelled = true;
8702
8716
  await finishMobileAndDispatch();
8717
+ clearMobileFlowState();
8703
8718
  dispatch({ type: "MOBILE_SETUP_COMPLETE" });
8704
8719
  };
8705
8720
  const completeGuestPreauthWithAccount = async (guestLookup) => {
@@ -8727,6 +8742,18 @@ function useMobilePollingEffect(deps) {
8727
8742
  const guestLookup = await fetchGuestAccount(apiBaseUrl, guestToken);
8728
8743
  if (cancelled) return;
8729
8744
  if (guestLookup != null) {
8745
+ if (preauthSessionId) {
8746
+ try {
8747
+ const session = await fetchAuthorizationSession(
8748
+ apiBaseUrl,
8749
+ preauthSessionId
8750
+ );
8751
+ if (cancelled) return;
8752
+ if (session.status !== "AUTHORIZED") return;
8753
+ } catch {
8754
+ return;
8755
+ }
8756
+ }
8730
8757
  await completeGuestPreauthWithAccount(guestLookup);
8731
8758
  }
8732
8759
  } catch {
@@ -8900,63 +8927,97 @@ function guestPreauthRestoreKey(guestToken) {
8900
8927
  function useGuestPreauthMobileRestoreEffect(deps) {
8901
8928
  const { dispatch, apiBaseUrl, privyReady, mobileSetupFlowRef, setupAccountIdRef } = deps;
8902
8929
  const completedRef = useRef(false);
8930
+ const pollingCleanupRef = useRef(null);
8903
8931
  useEffect(() => {
8904
8932
  if (!privyReady) return;
8905
- const persisted = loadMobileFlowState();
8906
- if (!persisted?.isGuestPreauth || !persisted.guestSessionToken) {
8907
- return;
8908
- }
8909
- const guestToken = persisted.guestSessionToken;
8910
- const key = guestPreauthRestoreKey(guestToken);
8911
- if (guestPreauthRestoreAttemptedKeys.has(key)) return;
8912
- guestPreauthRestoreAttemptedKeys.add(key);
8913
- if (completedRef.current) return;
8914
- let cancelled = false;
8915
- const POLL_INTERVAL_MS = 3e3;
8916
- const handleAccountFound = async (guestLookup) => {
8933
+ const tryStart = () => {
8917
8934
  if (completedRef.current) return;
8918
- completedRef.current = true;
8919
- cancelled = true;
8920
- clearMobileFlowState();
8921
- mobileSetupFlowRef.current = false;
8922
- setupAccountIdRef.current = null;
8923
- dispatch({
8924
- type: "GUEST_PREAUTH_DETECTED",
8925
- accountId: guestLookup.accountId,
8926
- sessionId: persisted.sessionId ?? void 0
8927
- });
8928
- dispatch({ type: "REQUEST_LOGIN" });
8929
- dispatch({ type: "MOBILE_SETUP_COMPLETE" });
8930
- };
8931
- const pollGuestAccount = async () => {
8932
- try {
8933
- if (cancelled) return;
8934
- const guestLookup = await fetchGuestAccount(apiBaseUrl, guestToken);
8935
- if (cancelled) return;
8936
- if (guestLookup != null) {
8937
- await handleAccountFound(guestLookup);
8938
- }
8939
- } catch {
8935
+ const persisted = loadMobileFlowState();
8936
+ if (!persisted?.isGuestPreauth || !persisted.guestSessionToken) {
8937
+ return;
8940
8938
  }
8939
+ const guestToken = persisted.guestSessionToken;
8940
+ const key = guestPreauthRestoreKey(guestToken);
8941
+ if (guestPreauthRestoreAttemptedKeys.has(key)) return;
8942
+ guestPreauthRestoreAttemptedKeys.add(key);
8943
+ let cancelled = false;
8944
+ const POLL_INTERVAL_MS = 3e3;
8945
+ mobileSetupFlowRef.current = true;
8946
+ if (persisted.accountId) {
8947
+ setupAccountIdRef.current = persisted.accountId;
8948
+ }
8949
+ const handleAccountFound = async (guestLookup) => {
8950
+ if (completedRef.current) return;
8951
+ completedRef.current = true;
8952
+ cancelled = true;
8953
+ clearMobileFlowState();
8954
+ mobileSetupFlowRef.current = false;
8955
+ setupAccountIdRef.current = null;
8956
+ dispatch({
8957
+ type: "GUEST_PREAUTH_DETECTED",
8958
+ accountId: guestLookup.accountId,
8959
+ sessionId: persisted.sessionId ?? void 0
8960
+ });
8961
+ dispatch({ type: "REQUEST_LOGIN" });
8962
+ dispatch({ type: "MOBILE_SETUP_COMPLETE" });
8963
+ };
8964
+ const pollGuestAccount = async () => {
8965
+ try {
8966
+ if (cancelled) return;
8967
+ const guestLookup = await fetchGuestAccount(apiBaseUrl, guestToken);
8968
+ if (cancelled) return;
8969
+ if (guestLookup != null) {
8970
+ if (persisted.sessionId) {
8971
+ try {
8972
+ const session = await fetchAuthorizationSession(
8973
+ apiBaseUrl,
8974
+ persisted.sessionId
8975
+ );
8976
+ if (cancelled) return;
8977
+ if (session.status !== "AUTHORIZED") return;
8978
+ } catch {
8979
+ return;
8980
+ }
8981
+ }
8982
+ await handleAccountFound(guestLookup);
8983
+ }
8984
+ } catch {
8985
+ }
8986
+ };
8987
+ pollGuestAccount();
8988
+ const intervalId = window.setInterval(pollGuestAccount, POLL_INTERVAL_MS);
8989
+ const handlePollVisibility = () => {
8990
+ if (document.visibilityState === "visible" && !cancelled) void pollGuestAccount();
8991
+ };
8992
+ const handlePollPageShow = (e) => {
8993
+ if (e.persisted && !cancelled) void pollGuestAccount();
8994
+ };
8995
+ document.addEventListener("visibilitychange", handlePollVisibility);
8996
+ window.addEventListener("pageshow", handlePollPageShow);
8997
+ pollingCleanupRef.current = () => {
8998
+ cancelled = true;
8999
+ window.clearInterval(intervalId);
9000
+ document.removeEventListener("visibilitychange", handlePollVisibility);
9001
+ window.removeEventListener("pageshow", handlePollPageShow);
9002
+ if (!completedRef.current) {
9003
+ guestPreauthRestoreAttemptedKeys.delete(key);
9004
+ }
9005
+ pollingCleanupRef.current = null;
9006
+ };
8941
9007
  };
8942
- pollGuestAccount();
8943
- const intervalId = window.setInterval(pollGuestAccount, POLL_INTERVAL_MS);
8944
- const handleVisibility = () => {
8945
- if (document.visibilityState === "visible" && !cancelled) void pollGuestAccount();
9008
+ const onOuterVisibility = () => {
9009
+ if (document.visibilityState === "visible") tryStart();
8946
9010
  };
8947
- const handlePageShow = (e) => {
8948
- if (e.persisted && !cancelled) void pollGuestAccount();
9011
+ const onOuterPageShow = (e) => {
9012
+ if (e.persisted) tryStart();
8949
9013
  };
8950
- document.addEventListener("visibilitychange", handleVisibility);
8951
- window.addEventListener("pageshow", handlePageShow);
9014
+ tryStart();
9015
+ document.addEventListener("visibilitychange", onOuterVisibility);
9016
+ window.addEventListener("pageshow", onOuterPageShow);
8952
9017
  return () => {
8953
- cancelled = true;
8954
- window.clearInterval(intervalId);
8955
- document.removeEventListener("visibilitychange", handleVisibility);
8956
- window.removeEventListener("pageshow", handlePageShow);
8957
- if (!completedRef.current) {
8958
- guestPreauthRestoreAttemptedKeys.delete(key);
8959
- }
9018
+ document.removeEventListener("visibilitychange", onOuterVisibility);
9019
+ window.removeEventListener("pageshow", onOuterPageShow);
9020
+ pollingCleanupRef.current?.();
8960
9021
  };
8961
9022
  }, [privyReady, apiBaseUrl, dispatch, mobileSetupFlowRef, setupAccountIdRef]);
8962
9023
  }