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