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