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