@swype-org/react-sdk 0.1.264 → 0.1.267
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 +107 -91
- package/dist/index.cjs.map +1 -1
- package/dist/index.js +107 -91
- 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
|
|
@@ -8262,7 +8263,6 @@ function usePasskeyCheckEffect(deps) {
|
|
|
8262
8263
|
const existingTransfer = await fetchTransfer(apiBaseUrl, token, persisted.transferId);
|
|
8263
8264
|
if (cancelled) return;
|
|
8264
8265
|
if (existingTransfer.status === "COMPLETED") {
|
|
8265
|
-
clearMobileFlowState();
|
|
8266
8266
|
if (persisted.isGuestPreauth && persisted.guestSessionToken) {
|
|
8267
8267
|
let guestLookup = null;
|
|
8268
8268
|
try {
|
|
@@ -8271,19 +8271,32 @@ function usePasskeyCheckEffect(deps) {
|
|
|
8271
8271
|
persisted.guestSessionToken
|
|
8272
8272
|
);
|
|
8273
8273
|
} catch {
|
|
8274
|
-
|
|
8275
|
-
|
|
8274
|
+
persistMobileFlowState({
|
|
8275
|
+
deeplinkUri: persisted.deeplinkUri,
|
|
8276
|
+
providerId: persisted.providerId ?? null,
|
|
8277
|
+
isSetup: persisted.isSetup ?? true,
|
|
8278
|
+
guestSessionToken: persisted.guestSessionToken,
|
|
8279
|
+
transferId: persisted.transferId,
|
|
8280
|
+
isGuestPreauth: true,
|
|
8281
|
+
accountId: persisted.accountId,
|
|
8282
|
+
sessionId: persisted.sessionId
|
|
8283
|
+
});
|
|
8276
8284
|
return;
|
|
8277
8285
|
}
|
|
8278
8286
|
if (guestLookup == null) {
|
|
8279
|
-
|
|
8280
|
-
|
|
8281
|
-
|
|
8282
|
-
|
|
8287
|
+
persistMobileFlowState({
|
|
8288
|
+
deeplinkUri: persisted.deeplinkUri,
|
|
8289
|
+
providerId: persisted.providerId ?? null,
|
|
8290
|
+
isSetup: persisted.isSetup ?? true,
|
|
8291
|
+
guestSessionToken: persisted.guestSessionToken,
|
|
8292
|
+
transferId: persisted.transferId,
|
|
8293
|
+
isGuestPreauth: true,
|
|
8294
|
+
accountId: persisted.accountId,
|
|
8295
|
+
sessionId: persisted.sessionId
|
|
8283
8296
|
});
|
|
8284
|
-
onCompleteRef.current?.(existingTransfer);
|
|
8285
8297
|
return;
|
|
8286
8298
|
}
|
|
8299
|
+
clearMobileFlowState();
|
|
8287
8300
|
dispatch({
|
|
8288
8301
|
type: "GUEST_PREAUTH_RESUME_WITH_TRANSFER",
|
|
8289
8302
|
transfer: existingTransfer,
|
|
@@ -8295,6 +8308,7 @@ function usePasskeyCheckEffect(deps) {
|
|
|
8295
8308
|
onCompleteRef.current?.(existingTransfer);
|
|
8296
8309
|
return;
|
|
8297
8310
|
}
|
|
8311
|
+
clearMobileFlowState();
|
|
8298
8312
|
dispatch({ type: "MOBILE_RESUME_SUCCESS", transfer: existingTransfer });
|
|
8299
8313
|
onCompleteRef.current?.(existingTransfer);
|
|
8300
8314
|
return;
|
|
@@ -8582,6 +8596,7 @@ function useProcessingEffect(deps) {
|
|
|
8582
8596
|
if (!state.transfer && (polling.transfer.status === "COMPLETED" || polling.transfer.status === "FAILED")) {
|
|
8583
8597
|
return;
|
|
8584
8598
|
}
|
|
8599
|
+
if (state.isGuestFlow) return;
|
|
8585
8600
|
if (polling.transfer.status === "COMPLETED") {
|
|
8586
8601
|
clearMobileFlowState();
|
|
8587
8602
|
dispatch({ type: "TRANSFER_COMPLETED", transfer: polling.transfer });
|
|
@@ -8596,6 +8611,7 @@ function useProcessingEffect(deps) {
|
|
|
8596
8611
|
state.transfer,
|
|
8597
8612
|
state.loginRequested,
|
|
8598
8613
|
state.verificationTarget,
|
|
8614
|
+
state.isGuestFlow,
|
|
8599
8615
|
onComplete,
|
|
8600
8616
|
dispatch,
|
|
8601
8617
|
reloadAccounts
|
|
@@ -8650,11 +8666,9 @@ function useMobilePollingEffect(deps) {
|
|
|
8650
8666
|
reloadAccounts,
|
|
8651
8667
|
apiBaseUrl
|
|
8652
8668
|
} = deps;
|
|
8653
|
-
const { getAccessToken
|
|
8669
|
+
const { getAccessToken } = usePrivy();
|
|
8654
8670
|
const getAccessTokenRef = useRef(getAccessToken);
|
|
8655
8671
|
getAccessTokenRef.current = getAccessToken;
|
|
8656
|
-
const privyAuthenticatedRef = useRef(privyAuthenticated);
|
|
8657
|
-
privyAuthenticatedRef.current = privyAuthenticated;
|
|
8658
8672
|
const handleAuthorizedMobileReturnRef = useRef(deps.handleAuthorizedMobileReturn);
|
|
8659
8673
|
handleAuthorizedMobileReturnRef.current = deps.handleAuthorizedMobileReturn;
|
|
8660
8674
|
useEffect(() => {
|
|
@@ -8681,7 +8695,7 @@ function useMobilePollingEffect(deps) {
|
|
|
8681
8695
|
if (!state.mobileFlow || !mobileSetupFlowRef.current) return;
|
|
8682
8696
|
if (!setupAccountIdRef.current) return;
|
|
8683
8697
|
if (!state.guestPreauthSessionId || !state.isGuestFlow) return;
|
|
8684
|
-
const guestToken = state.guestSessionToken;
|
|
8698
|
+
const guestToken = state.guestSessionToken ?? loadMobileFlowState()?.guestSessionToken ?? null;
|
|
8685
8699
|
const preauthAccountId = state.guestPreauthAccountId;
|
|
8686
8700
|
const preauthSessionId = state.guestPreauthSessionId;
|
|
8687
8701
|
let cancelled = false;
|
|
@@ -8715,9 +8729,7 @@ function useMobilePollingEffect(deps) {
|
|
|
8715
8729
|
sessionId: preauthSessionId ?? void 0
|
|
8716
8730
|
});
|
|
8717
8731
|
}
|
|
8718
|
-
|
|
8719
|
-
dispatch({ type: "REQUEST_LOGIN" });
|
|
8720
|
-
}
|
|
8732
|
+
dispatch({ type: "REQUEST_LOGIN" });
|
|
8721
8733
|
dispatch({ type: "MOBILE_SETUP_COMPLETE" });
|
|
8722
8734
|
};
|
|
8723
8735
|
const pollGuestAccount = async () => {
|
|
@@ -8897,88 +8909,93 @@ function useMobilePollingEffect(deps) {
|
|
|
8897
8909
|
]);
|
|
8898
8910
|
}
|
|
8899
8911
|
var guestPreauthRestoreAttemptedKeys = /* @__PURE__ */ new Set();
|
|
8900
|
-
function guestPreauthRestoreKey(
|
|
8901
|
-
return
|
|
8912
|
+
function guestPreauthRestoreKey(guestToken) {
|
|
8913
|
+
return guestToken;
|
|
8902
8914
|
}
|
|
8903
8915
|
function useGuestPreauthMobileRestoreEffect(deps) {
|
|
8904
|
-
const {
|
|
8905
|
-
|
|
8906
|
-
|
|
8907
|
-
privyReady,
|
|
8908
|
-
authenticated,
|
|
8909
|
-
mobileSetupFlowRef,
|
|
8910
|
-
setupAccountIdRef
|
|
8911
|
-
} = deps;
|
|
8916
|
+
const { dispatch, apiBaseUrl, privyReady, mobileSetupFlowRef, setupAccountIdRef } = deps;
|
|
8917
|
+
const completedRef = useRef(false);
|
|
8918
|
+
const pollingCleanupRef = useRef(null);
|
|
8912
8919
|
useEffect(() => {
|
|
8913
|
-
if (!privyReady
|
|
8914
|
-
const
|
|
8915
|
-
|
|
8916
|
-
|
|
8917
|
-
|
|
8918
|
-
|
|
8919
|
-
|
|
8920
|
-
|
|
8921
|
-
|
|
8922
|
-
|
|
8923
|
-
|
|
8924
|
-
|
|
8925
|
-
|
|
8926
|
-
|
|
8927
|
-
|
|
8928
|
-
|
|
8929
|
-
|
|
8930
|
-
|
|
8931
|
-
if (
|
|
8932
|
-
|
|
8933
|
-
|
|
8934
|
-
|
|
8935
|
-
|
|
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;
|
|
8920
|
+
if (!privyReady) return;
|
|
8921
|
+
const tryStart = () => {
|
|
8922
|
+
if (completedRef.current) return;
|
|
8923
|
+
const persisted = loadMobileFlowState();
|
|
8924
|
+
if (!persisted?.isGuestPreauth || !persisted.guestSessionToken) {
|
|
8925
|
+
return;
|
|
8926
|
+
}
|
|
8927
|
+
const guestToken = persisted.guestSessionToken;
|
|
8928
|
+
const key = guestPreauthRestoreKey(guestToken);
|
|
8929
|
+
if (guestPreauthRestoreAttemptedKeys.has(key)) return;
|
|
8930
|
+
guestPreauthRestoreAttemptedKeys.add(key);
|
|
8931
|
+
let cancelled = false;
|
|
8932
|
+
const POLL_INTERVAL_MS = 3e3;
|
|
8933
|
+
mobileSetupFlowRef.current = true;
|
|
8934
|
+
if (persisted.accountId) {
|
|
8935
|
+
setupAccountIdRef.current = persisted.accountId;
|
|
8936
|
+
}
|
|
8937
|
+
const handleAccountFound = async (guestLookup) => {
|
|
8938
|
+
if (completedRef.current) return;
|
|
8939
|
+
completedRef.current = true;
|
|
8940
|
+
cancelled = true;
|
|
8941
|
+
clearMobileFlowState();
|
|
8942
|
+
mobileSetupFlowRef.current = false;
|
|
8943
|
+
setupAccountIdRef.current = null;
|
|
8957
8944
|
dispatch({
|
|
8958
|
-
type: "
|
|
8959
|
-
|
|
8960
|
-
|
|
8961
|
-
guestPreauthAccountId,
|
|
8962
|
-
guestPreauthSessionId: persisted.sessionId,
|
|
8963
|
-
selectedProviderId: persisted.providerId,
|
|
8964
|
-
deeplinkUri: persisted.deeplinkUri,
|
|
8965
|
-
mobileOpen
|
|
8945
|
+
type: "GUEST_PREAUTH_DETECTED",
|
|
8946
|
+
accountId: guestLookup.accountId,
|
|
8947
|
+
sessionId: persisted.sessionId ?? void 0
|
|
8966
8948
|
});
|
|
8967
|
-
|
|
8968
|
-
|
|
8969
|
-
|
|
8970
|
-
|
|
8971
|
-
|
|
8949
|
+
dispatch({ type: "REQUEST_LOGIN" });
|
|
8950
|
+
dispatch({ type: "MOBILE_SETUP_COMPLETE" });
|
|
8951
|
+
};
|
|
8952
|
+
const pollGuestAccount = async () => {
|
|
8953
|
+
try {
|
|
8954
|
+
if (cancelled) return;
|
|
8955
|
+
const guestLookup = await fetchGuestAccount(apiBaseUrl, guestToken);
|
|
8956
|
+
if (cancelled) return;
|
|
8957
|
+
if (guestLookup != null) {
|
|
8958
|
+
await handleAccountFound(guestLookup);
|
|
8959
|
+
}
|
|
8960
|
+
} catch {
|
|
8972
8961
|
}
|
|
8973
|
-
}
|
|
8974
|
-
|
|
8975
|
-
|
|
8976
|
-
|
|
8977
|
-
|
|
8962
|
+
};
|
|
8963
|
+
pollGuestAccount();
|
|
8964
|
+
const intervalId = window.setInterval(pollGuestAccount, POLL_INTERVAL_MS);
|
|
8965
|
+
const handlePollVisibility = () => {
|
|
8966
|
+
if (document.visibilityState === "visible" && !cancelled) void pollGuestAccount();
|
|
8967
|
+
};
|
|
8968
|
+
const handlePollPageShow = (e) => {
|
|
8969
|
+
if (e.persisted && !cancelled) void pollGuestAccount();
|
|
8970
|
+
};
|
|
8971
|
+
document.addEventListener("visibilitychange", handlePollVisibility);
|
|
8972
|
+
window.addEventListener("pageshow", handlePollPageShow);
|
|
8973
|
+
pollingCleanupRef.current = () => {
|
|
8974
|
+
cancelled = true;
|
|
8975
|
+
window.clearInterval(intervalId);
|
|
8976
|
+
document.removeEventListener("visibilitychange", handlePollVisibility);
|
|
8977
|
+
window.removeEventListener("pageshow", handlePollPageShow);
|
|
8978
|
+
if (!completedRef.current) {
|
|
8979
|
+
guestPreauthRestoreAttemptedKeys.delete(key);
|
|
8980
|
+
}
|
|
8981
|
+
pollingCleanupRef.current = null;
|
|
8982
|
+
};
|
|
8983
|
+
};
|
|
8984
|
+
const onOuterVisibility = () => {
|
|
8985
|
+
if (document.visibilityState === "visible") tryStart();
|
|
8986
|
+
};
|
|
8987
|
+
const onOuterPageShow = (e) => {
|
|
8988
|
+
if (e.persisted) tryStart();
|
|
8989
|
+
};
|
|
8990
|
+
tryStart();
|
|
8991
|
+
document.addEventListener("visibilitychange", onOuterVisibility);
|
|
8992
|
+
window.addEventListener("pageshow", onOuterPageShow);
|
|
8978
8993
|
return () => {
|
|
8979
|
-
|
|
8994
|
+
document.removeEventListener("visibilitychange", onOuterVisibility);
|
|
8995
|
+
window.removeEventListener("pageshow", onOuterPageShow);
|
|
8996
|
+
pollingCleanupRef.current?.();
|
|
8980
8997
|
};
|
|
8981
|
-
}, [privyReady,
|
|
8998
|
+
}, [privyReady, apiBaseUrl, dispatch, mobileSetupFlowRef, setupAccountIdRef]);
|
|
8982
8999
|
}
|
|
8983
9000
|
function useSelectSourceEffect(deps) {
|
|
8984
9001
|
const {
|
|
@@ -9421,7 +9438,6 @@ function BlinkPaymentInner({
|
|
|
9421
9438
|
dispatch,
|
|
9422
9439
|
apiBaseUrl,
|
|
9423
9440
|
privyReady: state.privyReady,
|
|
9424
|
-
authenticated,
|
|
9425
9441
|
mobileSetupFlowRef: mobileFlowRefs.mobileSetupFlowRef,
|
|
9426
9442
|
setupAccountIdRef: mobileFlowRefs.setupAccountIdRef
|
|
9427
9443
|
});
|