@swype-org/react-sdk 0.1.266 → 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 +95 -58
- package/dist/index.cjs.map +1 -1
- package/dist/index.js +95 -58
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -8263,7 +8263,6 @@ function usePasskeyCheckEffect(deps) {
|
|
|
8263
8263
|
const existingTransfer = await fetchTransfer(apiBaseUrl, token, persisted.transferId);
|
|
8264
8264
|
if (cancelled) return;
|
|
8265
8265
|
if (existingTransfer.status === "COMPLETED") {
|
|
8266
|
-
clearMobileFlowState();
|
|
8267
8266
|
if (persisted.isGuestPreauth && persisted.guestSessionToken) {
|
|
8268
8267
|
let guestLookup = null;
|
|
8269
8268
|
try {
|
|
@@ -8272,19 +8271,32 @@ function usePasskeyCheckEffect(deps) {
|
|
|
8272
8271
|
persisted.guestSessionToken
|
|
8273
8272
|
);
|
|
8274
8273
|
} catch {
|
|
8275
|
-
|
|
8276
|
-
|
|
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
|
+
});
|
|
8277
8284
|
return;
|
|
8278
8285
|
}
|
|
8279
8286
|
if (guestLookup == null) {
|
|
8280
|
-
|
|
8281
|
-
|
|
8282
|
-
|
|
8283
|
-
|
|
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
|
|
8284
8296
|
});
|
|
8285
|
-
onCompleteRef.current?.(existingTransfer);
|
|
8286
8297
|
return;
|
|
8287
8298
|
}
|
|
8299
|
+
clearMobileFlowState();
|
|
8288
8300
|
dispatch({
|
|
8289
8301
|
type: "GUEST_PREAUTH_RESUME_WITH_TRANSFER",
|
|
8290
8302
|
transfer: existingTransfer,
|
|
@@ -8296,6 +8308,7 @@ function usePasskeyCheckEffect(deps) {
|
|
|
8296
8308
|
onCompleteRef.current?.(existingTransfer);
|
|
8297
8309
|
return;
|
|
8298
8310
|
}
|
|
8311
|
+
clearMobileFlowState();
|
|
8299
8312
|
dispatch({ type: "MOBILE_RESUME_SUCCESS", transfer: existingTransfer });
|
|
8300
8313
|
onCompleteRef.current?.(existingTransfer);
|
|
8301
8314
|
return;
|
|
@@ -8583,6 +8596,7 @@ function useProcessingEffect(deps) {
|
|
|
8583
8596
|
if (!state.transfer && (polling.transfer.status === "COMPLETED" || polling.transfer.status === "FAILED")) {
|
|
8584
8597
|
return;
|
|
8585
8598
|
}
|
|
8599
|
+
if (state.isGuestFlow) return;
|
|
8586
8600
|
if (polling.transfer.status === "COMPLETED") {
|
|
8587
8601
|
clearMobileFlowState();
|
|
8588
8602
|
dispatch({ type: "TRANSFER_COMPLETED", transfer: polling.transfer });
|
|
@@ -8597,6 +8611,7 @@ function useProcessingEffect(deps) {
|
|
|
8597
8611
|
state.transfer,
|
|
8598
8612
|
state.loginRequested,
|
|
8599
8613
|
state.verificationTarget,
|
|
8614
|
+
state.isGuestFlow,
|
|
8600
8615
|
onComplete,
|
|
8601
8616
|
dispatch,
|
|
8602
8617
|
reloadAccounts
|
|
@@ -8680,7 +8695,7 @@ function useMobilePollingEffect(deps) {
|
|
|
8680
8695
|
if (!state.mobileFlow || !mobileSetupFlowRef.current) return;
|
|
8681
8696
|
if (!setupAccountIdRef.current) return;
|
|
8682
8697
|
if (!state.guestPreauthSessionId || !state.isGuestFlow) return;
|
|
8683
|
-
const guestToken = state.guestSessionToken;
|
|
8698
|
+
const guestToken = state.guestSessionToken ?? loadMobileFlowState()?.guestSessionToken ?? null;
|
|
8684
8699
|
const preauthAccountId = state.guestPreauthAccountId;
|
|
8685
8700
|
const preauthSessionId = state.guestPreauthSessionId;
|
|
8686
8701
|
let cancelled = false;
|
|
@@ -8900,63 +8915,85 @@ function guestPreauthRestoreKey(guestToken) {
|
|
|
8900
8915
|
function useGuestPreauthMobileRestoreEffect(deps) {
|
|
8901
8916
|
const { dispatch, apiBaseUrl, privyReady, mobileSetupFlowRef, setupAccountIdRef } = deps;
|
|
8902
8917
|
const completedRef = useRef(false);
|
|
8918
|
+
const pollingCleanupRef = useRef(null);
|
|
8903
8919
|
useEffect(() => {
|
|
8904
8920
|
if (!privyReady) return;
|
|
8905
|
-
const
|
|
8906
|
-
if (!persisted?.isGuestPreauth || !persisted.guestSessionToken) {
|
|
8907
|
-
return;
|
|
8908
|
-
}
|
|
8909
|
-
const guestToken = persisted.guestSessionToken;
|
|
8910
|
-
const key = guestPreauthRestoreKey(guestToken);
|
|
8911
|
-
if (guestPreauthRestoreAttemptedKeys.has(key)) return;
|
|
8912
|
-
guestPreauthRestoreAttemptedKeys.add(key);
|
|
8913
|
-
if (completedRef.current) return;
|
|
8914
|
-
let cancelled = false;
|
|
8915
|
-
const POLL_INTERVAL_MS = 3e3;
|
|
8916
|
-
const handleAccountFound = async (guestLookup) => {
|
|
8921
|
+
const tryStart = () => {
|
|
8917
8922
|
if (completedRef.current) return;
|
|
8918
|
-
|
|
8919
|
-
|
|
8920
|
-
|
|
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 () => {
|
|
8932
|
-
try {
|
|
8933
|
-
if (cancelled) return;
|
|
8934
|
-
const guestLookup = await fetchGuestAccount(apiBaseUrl, guestToken);
|
|
8935
|
-
if (cancelled) return;
|
|
8936
|
-
if (guestLookup != null) {
|
|
8937
|
-
await handleAccountFound(guestLookup);
|
|
8938
|
-
}
|
|
8939
|
-
} catch {
|
|
8923
|
+
const persisted = loadMobileFlowState();
|
|
8924
|
+
if (!persisted?.isGuestPreauth || !persisted.guestSessionToken) {
|
|
8925
|
+
return;
|
|
8940
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;
|
|
8944
|
+
dispatch({
|
|
8945
|
+
type: "GUEST_PREAUTH_DETECTED",
|
|
8946
|
+
accountId: guestLookup.accountId,
|
|
8947
|
+
sessionId: persisted.sessionId ?? void 0
|
|
8948
|
+
});
|
|
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 {
|
|
8961
|
+
}
|
|
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
|
+
};
|
|
8941
8983
|
};
|
|
8942
|
-
|
|
8943
|
-
|
|
8944
|
-
const handleVisibility = () => {
|
|
8945
|
-
if (document.visibilityState === "visible" && !cancelled) void pollGuestAccount();
|
|
8984
|
+
const onOuterVisibility = () => {
|
|
8985
|
+
if (document.visibilityState === "visible") tryStart();
|
|
8946
8986
|
};
|
|
8947
|
-
const
|
|
8948
|
-
if (e.persisted
|
|
8987
|
+
const onOuterPageShow = (e) => {
|
|
8988
|
+
if (e.persisted) tryStart();
|
|
8949
8989
|
};
|
|
8950
|
-
|
|
8951
|
-
|
|
8990
|
+
tryStart();
|
|
8991
|
+
document.addEventListener("visibilitychange", onOuterVisibility);
|
|
8992
|
+
window.addEventListener("pageshow", onOuterPageShow);
|
|
8952
8993
|
return () => {
|
|
8953
|
-
|
|
8954
|
-
window.
|
|
8955
|
-
|
|
8956
|
-
window.removeEventListener("pageshow", handlePageShow);
|
|
8957
|
-
if (!completedRef.current) {
|
|
8958
|
-
guestPreauthRestoreAttemptedKeys.delete(key);
|
|
8959
|
-
}
|
|
8994
|
+
document.removeEventListener("visibilitychange", onOuterVisibility);
|
|
8995
|
+
window.removeEventListener("pageshow", onOuterPageShow);
|
|
8996
|
+
pollingCleanupRef.current?.();
|
|
8960
8997
|
};
|
|
8961
8998
|
}, [privyReady, apiBaseUrl, dispatch, mobileSetupFlowRef, setupAccountIdRef]);
|
|
8962
8999
|
}
|