@swype-org/react-sdk 0.1.262 → 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 +82 -105
- package/dist/index.cjs.map +1 -1
- package/dist/index.js +82 -105
- 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(() => {
|
|
@@ -8684,14 +8683,13 @@ function useMobilePollingEffect(deps) {
|
|
|
8684
8683
|
if (!state.mobileFlow || !mobileSetupFlowRef.current) return;
|
|
8685
8684
|
if (!setupAccountIdRef.current) return;
|
|
8686
8685
|
if (!state.guestPreauthSessionId || !state.isGuestFlow) return;
|
|
8687
|
-
const
|
|
8686
|
+
const guestToken = state.guestSessionToken;
|
|
8687
|
+
const preauthAccountId = state.guestPreauthAccountId;
|
|
8688
|
+
const preauthSessionId = state.guestPreauthSessionId;
|
|
8688
8689
|
let cancelled = false;
|
|
8689
8690
|
let completedGuestPreauth = false;
|
|
8690
8691
|
const POLL_INTERVAL_MS = 3e3;
|
|
8691
|
-
const
|
|
8692
|
-
if (completedGuestPreauth) return;
|
|
8693
|
-
completedGuestPreauth = true;
|
|
8694
|
-
cancelled = true;
|
|
8692
|
+
const finishMobileAndDispatch = async () => {
|
|
8695
8693
|
mobileSetupFlowRef.current = false;
|
|
8696
8694
|
setupAccountIdRef.current = null;
|
|
8697
8695
|
clearMobileFlowState();
|
|
@@ -8699,24 +8697,19 @@ function useMobilePollingEffect(deps) {
|
|
|
8699
8697
|
await reloadAccounts();
|
|
8700
8698
|
} catch {
|
|
8701
8699
|
}
|
|
8702
|
-
|
|
8703
|
-
|
|
8704
|
-
|
|
8705
|
-
|
|
8706
|
-
|
|
8707
|
-
|
|
8708
|
-
}
|
|
8709
|
-
|
|
8710
|
-
|
|
8711
|
-
|
|
8712
|
-
|
|
8713
|
-
|
|
8714
|
-
|
|
8715
|
-
}
|
|
8716
|
-
if (guestLookup == null) {
|
|
8717
|
-
dispatch({ type: "MOBILE_SETUP_COMPLETE" });
|
|
8718
|
-
return;
|
|
8719
|
-
}
|
|
8700
|
+
};
|
|
8701
|
+
const completeGuestPreauthWithoutToken = async () => {
|
|
8702
|
+
if (completedGuestPreauth) return;
|
|
8703
|
+
completedGuestPreauth = true;
|
|
8704
|
+
cancelled = true;
|
|
8705
|
+
await finishMobileAndDispatch();
|
|
8706
|
+
dispatch({ type: "MOBILE_SETUP_COMPLETE" });
|
|
8707
|
+
};
|
|
8708
|
+
const completeGuestPreauthWithAccount = async (guestLookup) => {
|
|
8709
|
+
if (completedGuestPreauth) return;
|
|
8710
|
+
completedGuestPreauth = true;
|
|
8711
|
+
cancelled = true;
|
|
8712
|
+
await finishMobileAndDispatch();
|
|
8720
8713
|
if (guestLookup.accountId !== preauthAccountId) {
|
|
8721
8714
|
dispatch({
|
|
8722
8715
|
type: "GUEST_PREAUTH_DETECTED",
|
|
@@ -8724,29 +8717,31 @@ function useMobilePollingEffect(deps) {
|
|
|
8724
8717
|
sessionId: preauthSessionId ?? void 0
|
|
8725
8718
|
});
|
|
8726
8719
|
}
|
|
8727
|
-
|
|
8728
|
-
dispatch({ type: "REQUEST_LOGIN" });
|
|
8729
|
-
}
|
|
8720
|
+
dispatch({ type: "REQUEST_LOGIN" });
|
|
8730
8721
|
dispatch({ type: "MOBILE_SETUP_COMPLETE" });
|
|
8731
8722
|
};
|
|
8732
|
-
const
|
|
8723
|
+
const pollGuestAccount = async () => {
|
|
8733
8724
|
try {
|
|
8734
8725
|
if (cancelled) return;
|
|
8735
|
-
|
|
8726
|
+
if (!guestToken) {
|
|
8727
|
+
await completeGuestPreauthWithoutToken();
|
|
8728
|
+
return;
|
|
8729
|
+
}
|
|
8730
|
+
const guestLookup = await fetchGuestAccount(apiBaseUrl, guestToken);
|
|
8736
8731
|
if (cancelled) return;
|
|
8737
|
-
if (
|
|
8738
|
-
await
|
|
8732
|
+
if (guestLookup != null) {
|
|
8733
|
+
await completeGuestPreauthWithAccount(guestLookup);
|
|
8739
8734
|
}
|
|
8740
8735
|
} catch {
|
|
8741
8736
|
}
|
|
8742
8737
|
};
|
|
8743
|
-
|
|
8744
|
-
const intervalId = window.setInterval(
|
|
8738
|
+
pollGuestAccount();
|
|
8739
|
+
const intervalId = window.setInterval(pollGuestAccount, POLL_INTERVAL_MS);
|
|
8745
8740
|
const handleVisibility = () => {
|
|
8746
|
-
if (document.visibilityState === "visible" && !cancelled) void
|
|
8741
|
+
if (document.visibilityState === "visible" && !cancelled) void pollGuestAccount();
|
|
8747
8742
|
};
|
|
8748
8743
|
const handlePageShow = (e) => {
|
|
8749
|
-
if (e.persisted && !cancelled) void
|
|
8744
|
+
if (e.persisted && !cancelled) void pollGuestAccount();
|
|
8750
8745
|
};
|
|
8751
8746
|
document.addEventListener("visibilitychange", handleVisibility);
|
|
8752
8747
|
window.addEventListener("pageshow", handlePageShow);
|
|
@@ -8902,88 +8897,71 @@ function useMobilePollingEffect(deps) {
|
|
|
8902
8897
|
]);
|
|
8903
8898
|
}
|
|
8904
8899
|
var guestPreauthRestoreAttemptedKeys = /* @__PURE__ */ new Set();
|
|
8905
|
-
function guestPreauthRestoreKey(
|
|
8906
|
-
return
|
|
8900
|
+
function guestPreauthRestoreKey(guestToken) {
|
|
8901
|
+
return guestToken;
|
|
8907
8902
|
}
|
|
8908
8903
|
function useGuestPreauthMobileRestoreEffect(deps) {
|
|
8909
|
-
const {
|
|
8910
|
-
|
|
8911
|
-
apiBaseUrl,
|
|
8912
|
-
privyReady,
|
|
8913
|
-
authenticated,
|
|
8914
|
-
mobileSetupFlowRef,
|
|
8915
|
-
setupAccountIdRef
|
|
8916
|
-
} = deps;
|
|
8904
|
+
const { dispatch, apiBaseUrl, privyReady, mobileSetupFlowRef, setupAccountIdRef } = deps;
|
|
8905
|
+
const completedRef = react.useRef(false);
|
|
8917
8906
|
react.useEffect(() => {
|
|
8918
|
-
if (!privyReady
|
|
8907
|
+
if (!privyReady) return;
|
|
8919
8908
|
const persisted = loadMobileFlowState();
|
|
8920
|
-
if (!persisted?.isGuestPreauth || !persisted.
|
|
8909
|
+
if (!persisted?.isGuestPreauth || !persisted.guestSessionToken) {
|
|
8921
8910
|
return;
|
|
8922
8911
|
}
|
|
8923
|
-
const
|
|
8912
|
+
const guestToken = persisted.guestSessionToken;
|
|
8913
|
+
const key = guestPreauthRestoreKey(guestToken);
|
|
8924
8914
|
if (guestPreauthRestoreAttemptedKeys.has(key)) return;
|
|
8925
8915
|
guestPreauthRestoreAttemptedKeys.add(key);
|
|
8916
|
+
if (completedRef.current) return;
|
|
8926
8917
|
let cancelled = false;
|
|
8927
|
-
|
|
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 () => {
|
|
8928
8935
|
try {
|
|
8929
|
-
const [transfer, session] = await Promise.all([
|
|
8930
|
-
getGuestTransfer(apiBaseUrl, persisted.transferId, persisted.guestSessionToken),
|
|
8931
|
-
fetchAuthorizationSession(apiBaseUrl, persisted.sessionId)
|
|
8932
|
-
]);
|
|
8933
8936
|
if (cancelled) return;
|
|
8934
|
-
const
|
|
8935
|
-
|
|
8936
|
-
if (
|
|
8937
|
-
|
|
8938
|
-
guestLookup = await fetchGuestAccount(
|
|
8939
|
-
apiBaseUrl,
|
|
8940
|
-
persisted.guestSessionToken
|
|
8941
|
-
);
|
|
8942
|
-
} catch {
|
|
8943
|
-
dispatch({
|
|
8944
|
-
type: "MOBILE_RESUME_SUCCESS",
|
|
8945
|
-
transfer,
|
|
8946
|
-
guestCheckoutResume: { guestSessionToken: persisted.guestSessionToken }
|
|
8947
|
-
});
|
|
8948
|
-
clearMobileFlowState();
|
|
8949
|
-
return;
|
|
8950
|
-
}
|
|
8951
|
-
if (guestLookup == null) {
|
|
8952
|
-
dispatch({
|
|
8953
|
-
type: "MOBILE_RESUME_SUCCESS",
|
|
8954
|
-
transfer,
|
|
8955
|
-
guestCheckoutResume: { guestSessionToken: persisted.guestSessionToken }
|
|
8956
|
-
});
|
|
8957
|
-
clearMobileFlowState();
|
|
8958
|
-
return;
|
|
8959
|
-
}
|
|
8960
|
-
}
|
|
8961
|
-
const guestPreauthAccountId = !mobileOpen && guestLookup != null ? guestLookup.accountId : persisted.accountId;
|
|
8962
|
-
dispatch({
|
|
8963
|
-
type: "RESTORE_GUEST_PREAUTH_MOBILE",
|
|
8964
|
-
transfer,
|
|
8965
|
-
guestSessionToken: persisted.guestSessionToken,
|
|
8966
|
-
guestPreauthAccountId,
|
|
8967
|
-
guestPreauthSessionId: persisted.sessionId,
|
|
8968
|
-
selectedProviderId: persisted.providerId,
|
|
8969
|
-
deeplinkUri: persisted.deeplinkUri,
|
|
8970
|
-
mobileOpen
|
|
8971
|
-
});
|
|
8972
|
-
if (mobileOpen) {
|
|
8973
|
-
mobileSetupFlowRef.current = true;
|
|
8974
|
-
setupAccountIdRef.current = persisted.accountId ?? null;
|
|
8975
|
-
} else {
|
|
8976
|
-
clearMobileFlowState();
|
|
8937
|
+
const guestLookup = await fetchGuestAccount(apiBaseUrl, guestToken);
|
|
8938
|
+
if (cancelled) return;
|
|
8939
|
+
if (guestLookup != null) {
|
|
8940
|
+
await handleAccountFound(guestLookup);
|
|
8977
8941
|
}
|
|
8978
|
-
} catch
|
|
8979
|
-
guestPreauthRestoreAttemptedKeys.delete(key);
|
|
8980
|
-
captureException(err);
|
|
8942
|
+
} catch {
|
|
8981
8943
|
}
|
|
8982
|
-
}
|
|
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);
|
|
8983
8955
|
return () => {
|
|
8984
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
|
+
}
|
|
8985
8963
|
};
|
|
8986
|
-
}, [privyReady,
|
|
8964
|
+
}, [privyReady, apiBaseUrl, dispatch, mobileSetupFlowRef, setupAccountIdRef]);
|
|
8987
8965
|
}
|
|
8988
8966
|
function useSelectSourceEffect(deps) {
|
|
8989
8967
|
const {
|
|
@@ -9426,7 +9404,6 @@ function BlinkPaymentInner({
|
|
|
9426
9404
|
dispatch,
|
|
9427
9405
|
apiBaseUrl,
|
|
9428
9406
|
privyReady: state.privyReady,
|
|
9429
|
-
authenticated,
|
|
9430
9407
|
mobileSetupFlowRef: mobileFlowRefs.mobileSetupFlowRef,
|
|
9431
9408
|
setupAccountIdRef: mobileFlowRefs.setupAccountIdRef
|
|
9432
9409
|
});
|