@swype-org/react-sdk 0.1.225 → 0.1.226

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
@@ -6821,13 +6821,10 @@ function useMobileFlowHandlers(dispatch, polling, reloadAccounts, pollingTransfe
6821
6821
  const onCompleteRef = react.useRef(onComplete);
6822
6822
  onCompleteRef.current = onComplete;
6823
6823
  const guestPollingActiveRef = react.useRef(false);
6824
- react.useEffect(() => {
6825
- const persisted = loadMobileFlowState();
6826
- if (!persisted?.isGuestCheckout || !persisted.transferId || !persisted.guestSessionToken) return;
6824
+ const guestPollingCleanupRef = react.useRef(null);
6825
+ const startGuestPolling = react.useCallback((transferId, guestSessionToken) => {
6827
6826
  if (guestPollingActiveRef.current) return;
6828
6827
  guestPollingActiveRef.current = true;
6829
- const transferId = persisted.transferId;
6830
- const guestSessionToken = persisted.guestSessionToken;
6831
6828
  let cancelled = false;
6832
6829
  const POLL_INTERVAL_MS = 3e3;
6833
6830
  dispatch({ type: "NAVIGATE", step: "processing" });
@@ -6839,12 +6836,14 @@ function useMobileFlowHandlers(dispatch, polling, reloadAccounts, pollingTransfe
6839
6836
  if (transfer.status === "COMPLETED") {
6840
6837
  cancelled = true;
6841
6838
  guestPollingActiveRef.current = false;
6839
+ guestPollingCleanupRef.current = null;
6842
6840
  clearMobileFlowState();
6843
6841
  dispatch({ type: "GUEST_TRANSFER_COMPLETED", transfer, guestSessionToken });
6844
6842
  onCompleteRef.current?.(transfer);
6845
6843
  } else if (transfer.status === "FAILED") {
6846
6844
  cancelled = true;
6847
6845
  guestPollingActiveRef.current = false;
6846
+ guestPollingCleanupRef.current = null;
6848
6847
  clearMobileFlowState();
6849
6848
  dispatch({ type: "TRANSFER_FAILED", transfer, error: "Transfer failed." });
6850
6849
  }
@@ -6853,26 +6852,44 @@ function useMobileFlowHandlers(dispatch, polling, reloadAccounts, pollingTransfe
6853
6852
  };
6854
6853
  poll();
6855
6854
  const intervalId = window.setInterval(poll, POLL_INTERVAL_MS);
6856
- const handleVisibility = () => {
6857
- if (document.visibilityState === "visible" && !cancelled) {
6858
- poll();
6855
+ const cleanup = () => {
6856
+ cancelled = true;
6857
+ guestPollingActiveRef.current = false;
6858
+ guestPollingCleanupRef.current = null;
6859
+ window.clearInterval(intervalId);
6860
+ };
6861
+ guestPollingCleanupRef.current = cleanup;
6862
+ }, [apiBaseUrl, dispatch]);
6863
+ react.useEffect(() => {
6864
+ const persisted = loadMobileFlowState();
6865
+ if (persisted?.isGuestCheckout && persisted.transferId && persisted.guestSessionToken) {
6866
+ startGuestPolling(persisted.transferId, persisted.guestSessionToken);
6867
+ }
6868
+ return () => {
6869
+ guestPollingCleanupRef.current?.();
6870
+ };
6871
+ }, [startGuestPolling]);
6872
+ react.useEffect(() => {
6873
+ const tryStartPolling = () => {
6874
+ if (guestPollingActiveRef.current) return;
6875
+ const persisted = loadMobileFlowState();
6876
+ if (persisted?.isGuestCheckout && persisted.transferId && persisted.guestSessionToken) {
6877
+ startGuestPolling(persisted.transferId, persisted.guestSessionToken);
6859
6878
  }
6860
6879
  };
6880
+ const handleVisibility = () => {
6881
+ if (document.visibilityState === "visible") tryStartPolling();
6882
+ };
6861
6883
  const handlePageShow = (e) => {
6862
- if (e.persisted && !cancelled) {
6863
- poll();
6864
- }
6884
+ if (e.persisted) tryStartPolling();
6865
6885
  };
6866
6886
  document.addEventListener("visibilitychange", handleVisibility);
6867
6887
  window.addEventListener("pageshow", handlePageShow);
6868
6888
  return () => {
6869
- cancelled = true;
6870
- guestPollingActiveRef.current = false;
6871
- window.clearInterval(intervalId);
6872
6889
  document.removeEventListener("visibilitychange", handleVisibility);
6873
6890
  window.removeEventListener("pageshow", handlePageShow);
6874
6891
  };
6875
- }, [apiBaseUrl, dispatch]);
6892
+ }, [startGuestPolling]);
6876
6893
  const handleAuthorizedMobileReturn = react.useCallback(async (authorizedTransfer, isSetup) => {
6877
6894
  if (handlingMobileReturnRef.current) return;
6878
6895
  handlingMobileReturnRef.current = true;