@swype-org/react-sdk 0.1.262 → 0.1.264

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
@@ -8681,14 +8681,13 @@ function useMobilePollingEffect(deps) {
8681
8681
  if (!state.mobileFlow || !mobileSetupFlowRef.current) return;
8682
8682
  if (!setupAccountIdRef.current) return;
8683
8683
  if (!state.guestPreauthSessionId || !state.isGuestFlow) return;
8684
- const sessionId = state.guestPreauthSessionId;
8684
+ const guestToken = state.guestSessionToken;
8685
+ const preauthAccountId = state.guestPreauthAccountId;
8686
+ const preauthSessionId = state.guestPreauthSessionId;
8685
8687
  let cancelled = false;
8686
8688
  let completedGuestPreauth = false;
8687
8689
  const POLL_INTERVAL_MS = 3e3;
8688
- const completeGuestPreauthSetup = async () => {
8689
- if (completedGuestPreauth) return;
8690
- completedGuestPreauth = true;
8691
- cancelled = true;
8690
+ const finishMobileAndDispatch = async () => {
8692
8691
  mobileSetupFlowRef.current = false;
8693
8692
  setupAccountIdRef.current = null;
8694
8693
  clearMobileFlowState();
@@ -8696,24 +8695,19 @@ function useMobilePollingEffect(deps) {
8696
8695
  await reloadAccounts();
8697
8696
  } catch {
8698
8697
  }
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
- }
8698
+ };
8699
+ const completeGuestPreauthWithoutToken = async () => {
8700
+ if (completedGuestPreauth) return;
8701
+ completedGuestPreauth = true;
8702
+ cancelled = true;
8703
+ await finishMobileAndDispatch();
8704
+ dispatch({ type: "MOBILE_SETUP_COMPLETE" });
8705
+ };
8706
+ const completeGuestPreauthWithAccount = async (guestLookup) => {
8707
+ if (completedGuestPreauth) return;
8708
+ completedGuestPreauth = true;
8709
+ cancelled = true;
8710
+ await finishMobileAndDispatch();
8717
8711
  if (guestLookup.accountId !== preauthAccountId) {
8718
8712
  dispatch({
8719
8713
  type: "GUEST_PREAUTH_DETECTED",
@@ -8726,24 +8720,28 @@ function useMobilePollingEffect(deps) {
8726
8720
  }
8727
8721
  dispatch({ type: "MOBILE_SETUP_COMPLETE" });
8728
8722
  };
8729
- const pollGuestPreauthSession = async () => {
8723
+ const pollGuestAccount = async () => {
8730
8724
  try {
8731
8725
  if (cancelled) return;
8732
- const session = await fetchAuthorizationSession(apiBaseUrl, sessionId);
8726
+ if (!guestToken) {
8727
+ await completeGuestPreauthWithoutToken();
8728
+ return;
8729
+ }
8730
+ const guestLookup = await fetchGuestAccount(apiBaseUrl, guestToken);
8733
8731
  if (cancelled) return;
8734
- if (session.status === "AUTHORIZED") {
8735
- await completeGuestPreauthSetup();
8732
+ if (guestLookup != null) {
8733
+ await completeGuestPreauthWithAccount(guestLookup);
8736
8734
  }
8737
8735
  } catch {
8738
8736
  }
8739
8737
  };
8740
- pollGuestPreauthSession();
8741
- const intervalId = window.setInterval(pollGuestPreauthSession, POLL_INTERVAL_MS);
8738
+ pollGuestAccount();
8739
+ const intervalId = window.setInterval(pollGuestAccount, POLL_INTERVAL_MS);
8742
8740
  const handleVisibility = () => {
8743
- if (document.visibilityState === "visible" && !cancelled) void pollGuestPreauthSession();
8741
+ if (document.visibilityState === "visible" && !cancelled) void pollGuestAccount();
8744
8742
  };
8745
8743
  const handlePageShow = (e) => {
8746
- if (e.persisted && !cancelled) void pollGuestPreauthSession();
8744
+ if (e.persisted && !cancelled) void pollGuestAccount();
8747
8745
  };
8748
8746
  document.addEventListener("visibilitychange", handleVisibility);
8749
8747
  window.addEventListener("pageshow", handlePageShow);