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