@swype-org/react-sdk 0.1.264 → 0.1.266
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 +53 -74
- package/dist/index.cjs.map +1 -1
- package/dist/index.js +53 -74
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -2415,7 +2415,8 @@ function applyAction(state, action) {
|
|
|
2415
2415
|
case "MOBILE_SETUP_COMPLETE":
|
|
2416
2416
|
return {
|
|
2417
2417
|
...state,
|
|
2418
|
-
|
|
2418
|
+
// Do not use `??`: explicit `null` must clear the transfer (guest preauth → login / claim).
|
|
2419
|
+
transfer: action.transfer !== void 0 ? action.transfer : state.transfer,
|
|
2419
2420
|
error: null,
|
|
2420
2421
|
mobileFlow: false,
|
|
2421
2422
|
deeplinkUri: null
|
|
@@ -8650,11 +8651,9 @@ function useMobilePollingEffect(deps) {
|
|
|
8650
8651
|
reloadAccounts,
|
|
8651
8652
|
apiBaseUrl
|
|
8652
8653
|
} = deps;
|
|
8653
|
-
const { getAccessToken
|
|
8654
|
+
const { getAccessToken } = usePrivy();
|
|
8654
8655
|
const getAccessTokenRef = useRef(getAccessToken);
|
|
8655
8656
|
getAccessTokenRef.current = getAccessToken;
|
|
8656
|
-
const privyAuthenticatedRef = useRef(privyAuthenticated);
|
|
8657
|
-
privyAuthenticatedRef.current = privyAuthenticated;
|
|
8658
8657
|
const handleAuthorizedMobileReturnRef = useRef(deps.handleAuthorizedMobileReturn);
|
|
8659
8658
|
handleAuthorizedMobileReturnRef.current = deps.handleAuthorizedMobileReturn;
|
|
8660
8659
|
useEffect(() => {
|
|
@@ -8715,9 +8714,7 @@ function useMobilePollingEffect(deps) {
|
|
|
8715
8714
|
sessionId: preauthSessionId ?? void 0
|
|
8716
8715
|
});
|
|
8717
8716
|
}
|
|
8718
|
-
|
|
8719
|
-
dispatch({ type: "REQUEST_LOGIN" });
|
|
8720
|
-
}
|
|
8717
|
+
dispatch({ type: "REQUEST_LOGIN" });
|
|
8721
8718
|
dispatch({ type: "MOBILE_SETUP_COMPLETE" });
|
|
8722
8719
|
};
|
|
8723
8720
|
const pollGuestAccount = async () => {
|
|
@@ -8897,88 +8894,71 @@ function useMobilePollingEffect(deps) {
|
|
|
8897
8894
|
]);
|
|
8898
8895
|
}
|
|
8899
8896
|
var guestPreauthRestoreAttemptedKeys = /* @__PURE__ */ new Set();
|
|
8900
|
-
function guestPreauthRestoreKey(
|
|
8901
|
-
return
|
|
8897
|
+
function guestPreauthRestoreKey(guestToken) {
|
|
8898
|
+
return guestToken;
|
|
8902
8899
|
}
|
|
8903
8900
|
function useGuestPreauthMobileRestoreEffect(deps) {
|
|
8904
|
-
const {
|
|
8905
|
-
|
|
8906
|
-
apiBaseUrl,
|
|
8907
|
-
privyReady,
|
|
8908
|
-
authenticated,
|
|
8909
|
-
mobileSetupFlowRef,
|
|
8910
|
-
setupAccountIdRef
|
|
8911
|
-
} = deps;
|
|
8901
|
+
const { dispatch, apiBaseUrl, privyReady, mobileSetupFlowRef, setupAccountIdRef } = deps;
|
|
8902
|
+
const completedRef = useRef(false);
|
|
8912
8903
|
useEffect(() => {
|
|
8913
|
-
if (!privyReady
|
|
8904
|
+
if (!privyReady) return;
|
|
8914
8905
|
const persisted = loadMobileFlowState();
|
|
8915
|
-
if (!persisted?.isGuestPreauth || !persisted.
|
|
8906
|
+
if (!persisted?.isGuestPreauth || !persisted.guestSessionToken) {
|
|
8916
8907
|
return;
|
|
8917
8908
|
}
|
|
8918
|
-
const
|
|
8909
|
+
const guestToken = persisted.guestSessionToken;
|
|
8910
|
+
const key = guestPreauthRestoreKey(guestToken);
|
|
8919
8911
|
if (guestPreauthRestoreAttemptedKeys.has(key)) return;
|
|
8920
8912
|
guestPreauthRestoreAttemptedKeys.add(key);
|
|
8913
|
+
if (completedRef.current) return;
|
|
8921
8914
|
let cancelled = false;
|
|
8922
|
-
|
|
8915
|
+
const POLL_INTERVAL_MS = 3e3;
|
|
8916
|
+
const handleAccountFound = async (guestLookup) => {
|
|
8917
|
+
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 () => {
|
|
8923
8932
|
try {
|
|
8924
|
-
const [transfer, session] = await Promise.all([
|
|
8925
|
-
getGuestTransfer(apiBaseUrl, persisted.transferId, persisted.guestSessionToken),
|
|
8926
|
-
fetchAuthorizationSession(apiBaseUrl, persisted.sessionId)
|
|
8927
|
-
]);
|
|
8928
8933
|
if (cancelled) return;
|
|
8929
|
-
const
|
|
8930
|
-
|
|
8931
|
-
if (
|
|
8932
|
-
|
|
8933
|
-
guestLookup = await fetchGuestAccount(
|
|
8934
|
-
apiBaseUrl,
|
|
8935
|
-
persisted.guestSessionToken
|
|
8936
|
-
);
|
|
8937
|
-
} catch {
|
|
8938
|
-
dispatch({
|
|
8939
|
-
type: "MOBILE_RESUME_SUCCESS",
|
|
8940
|
-
transfer,
|
|
8941
|
-
guestCheckoutResume: { guestSessionToken: persisted.guestSessionToken }
|
|
8942
|
-
});
|
|
8943
|
-
clearMobileFlowState();
|
|
8944
|
-
return;
|
|
8945
|
-
}
|
|
8946
|
-
if (guestLookup == null) {
|
|
8947
|
-
dispatch({
|
|
8948
|
-
type: "MOBILE_RESUME_SUCCESS",
|
|
8949
|
-
transfer,
|
|
8950
|
-
guestCheckoutResume: { guestSessionToken: persisted.guestSessionToken }
|
|
8951
|
-
});
|
|
8952
|
-
clearMobileFlowState();
|
|
8953
|
-
return;
|
|
8954
|
-
}
|
|
8955
|
-
}
|
|
8956
|
-
const guestPreauthAccountId = !mobileOpen && guestLookup != null ? guestLookup.accountId : persisted.accountId;
|
|
8957
|
-
dispatch({
|
|
8958
|
-
type: "RESTORE_GUEST_PREAUTH_MOBILE",
|
|
8959
|
-
transfer,
|
|
8960
|
-
guestSessionToken: persisted.guestSessionToken,
|
|
8961
|
-
guestPreauthAccountId,
|
|
8962
|
-
guestPreauthSessionId: persisted.sessionId,
|
|
8963
|
-
selectedProviderId: persisted.providerId,
|
|
8964
|
-
deeplinkUri: persisted.deeplinkUri,
|
|
8965
|
-
mobileOpen
|
|
8966
|
-
});
|
|
8967
|
-
if (mobileOpen) {
|
|
8968
|
-
mobileSetupFlowRef.current = true;
|
|
8969
|
-
setupAccountIdRef.current = persisted.accountId ?? null;
|
|
8970
|
-
} else {
|
|
8971
|
-
clearMobileFlowState();
|
|
8934
|
+
const guestLookup = await fetchGuestAccount(apiBaseUrl, guestToken);
|
|
8935
|
+
if (cancelled) return;
|
|
8936
|
+
if (guestLookup != null) {
|
|
8937
|
+
await handleAccountFound(guestLookup);
|
|
8972
8938
|
}
|
|
8973
|
-
} catch
|
|
8974
|
-
guestPreauthRestoreAttemptedKeys.delete(key);
|
|
8975
|
-
captureException(err);
|
|
8939
|
+
} catch {
|
|
8976
8940
|
}
|
|
8977
|
-
}
|
|
8941
|
+
};
|
|
8942
|
+
pollGuestAccount();
|
|
8943
|
+
const intervalId = window.setInterval(pollGuestAccount, POLL_INTERVAL_MS);
|
|
8944
|
+
const handleVisibility = () => {
|
|
8945
|
+
if (document.visibilityState === "visible" && !cancelled) void pollGuestAccount();
|
|
8946
|
+
};
|
|
8947
|
+
const handlePageShow = (e) => {
|
|
8948
|
+
if (e.persisted && !cancelled) void pollGuestAccount();
|
|
8949
|
+
};
|
|
8950
|
+
document.addEventListener("visibilitychange", handleVisibility);
|
|
8951
|
+
window.addEventListener("pageshow", handlePageShow);
|
|
8978
8952
|
return () => {
|
|
8979
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
|
+
}
|
|
8980
8960
|
};
|
|
8981
|
-
}, [privyReady,
|
|
8961
|
+
}, [privyReady, apiBaseUrl, dispatch, mobileSetupFlowRef, setupAccountIdRef]);
|
|
8982
8962
|
}
|
|
8983
8963
|
function useSelectSourceEffect(deps) {
|
|
8984
8964
|
const {
|
|
@@ -9421,7 +9401,6 @@ function BlinkPaymentInner({
|
|
|
9421
9401
|
dispatch,
|
|
9422
9402
|
apiBaseUrl,
|
|
9423
9403
|
privyReady: state.privyReady,
|
|
9424
|
-
authenticated,
|
|
9425
9404
|
mobileSetupFlowRef: mobileFlowRefs.mobileSetupFlowRef,
|
|
9426
9405
|
setupAccountIdRef: mobileFlowRefs.setupAccountIdRef
|
|
9427
9406
|
});
|