@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.cjs
CHANGED
|
@@ -8266,7 +8266,6 @@ function usePasskeyCheckEffect(deps) {
|
|
|
8266
8266
|
const existingTransfer = await fetchTransfer(apiBaseUrl, token, persisted.transferId);
|
|
8267
8267
|
if (cancelled) return;
|
|
8268
8268
|
if (existingTransfer.status === "COMPLETED") {
|
|
8269
|
-
clearMobileFlowState();
|
|
8270
8269
|
if (persisted.isGuestPreauth && persisted.guestSessionToken) {
|
|
8271
8270
|
let guestLookup = null;
|
|
8272
8271
|
try {
|
|
@@ -8275,19 +8274,32 @@ function usePasskeyCheckEffect(deps) {
|
|
|
8275
8274
|
persisted.guestSessionToken
|
|
8276
8275
|
);
|
|
8277
8276
|
} catch {
|
|
8278
|
-
|
|
8279
|
-
|
|
8277
|
+
persistMobileFlowState({
|
|
8278
|
+
deeplinkUri: persisted.deeplinkUri,
|
|
8279
|
+
providerId: persisted.providerId ?? null,
|
|
8280
|
+
isSetup: persisted.isSetup ?? true,
|
|
8281
|
+
guestSessionToken: persisted.guestSessionToken,
|
|
8282
|
+
transferId: persisted.transferId,
|
|
8283
|
+
isGuestPreauth: true,
|
|
8284
|
+
accountId: persisted.accountId,
|
|
8285
|
+
sessionId: persisted.sessionId
|
|
8286
|
+
});
|
|
8280
8287
|
return;
|
|
8281
8288
|
}
|
|
8282
8289
|
if (guestLookup == null) {
|
|
8283
|
-
|
|
8284
|
-
|
|
8285
|
-
|
|
8286
|
-
|
|
8290
|
+
persistMobileFlowState({
|
|
8291
|
+
deeplinkUri: persisted.deeplinkUri,
|
|
8292
|
+
providerId: persisted.providerId ?? null,
|
|
8293
|
+
isSetup: persisted.isSetup ?? true,
|
|
8294
|
+
guestSessionToken: persisted.guestSessionToken,
|
|
8295
|
+
transferId: persisted.transferId,
|
|
8296
|
+
isGuestPreauth: true,
|
|
8297
|
+
accountId: persisted.accountId,
|
|
8298
|
+
sessionId: persisted.sessionId
|
|
8287
8299
|
});
|
|
8288
|
-
onCompleteRef.current?.(existingTransfer);
|
|
8289
8300
|
return;
|
|
8290
8301
|
}
|
|
8302
|
+
clearMobileFlowState();
|
|
8291
8303
|
dispatch({
|
|
8292
8304
|
type: "GUEST_PREAUTH_RESUME_WITH_TRANSFER",
|
|
8293
8305
|
transfer: existingTransfer,
|
|
@@ -8299,6 +8311,7 @@ function usePasskeyCheckEffect(deps) {
|
|
|
8299
8311
|
onCompleteRef.current?.(existingTransfer);
|
|
8300
8312
|
return;
|
|
8301
8313
|
}
|
|
8314
|
+
clearMobileFlowState();
|
|
8302
8315
|
dispatch({ type: "MOBILE_RESUME_SUCCESS", transfer: existingTransfer });
|
|
8303
8316
|
onCompleteRef.current?.(existingTransfer);
|
|
8304
8317
|
return;
|
|
@@ -8586,6 +8599,7 @@ function useProcessingEffect(deps) {
|
|
|
8586
8599
|
if (!state.transfer && (polling.transfer.status === "COMPLETED" || polling.transfer.status === "FAILED")) {
|
|
8587
8600
|
return;
|
|
8588
8601
|
}
|
|
8602
|
+
if (state.isGuestFlow) return;
|
|
8589
8603
|
if (polling.transfer.status === "COMPLETED") {
|
|
8590
8604
|
clearMobileFlowState();
|
|
8591
8605
|
dispatch({ type: "TRANSFER_COMPLETED", transfer: polling.transfer });
|
|
@@ -8600,6 +8614,7 @@ function useProcessingEffect(deps) {
|
|
|
8600
8614
|
state.transfer,
|
|
8601
8615
|
state.loginRequested,
|
|
8602
8616
|
state.verificationTarget,
|
|
8617
|
+
state.isGuestFlow,
|
|
8603
8618
|
onComplete,
|
|
8604
8619
|
dispatch,
|
|
8605
8620
|
reloadAccounts
|
|
@@ -8683,7 +8698,7 @@ function useMobilePollingEffect(deps) {
|
|
|
8683
8698
|
if (!state.mobileFlow || !mobileSetupFlowRef.current) return;
|
|
8684
8699
|
if (!setupAccountIdRef.current) return;
|
|
8685
8700
|
if (!state.guestPreauthSessionId || !state.isGuestFlow) return;
|
|
8686
|
-
const guestToken = state.guestSessionToken;
|
|
8701
|
+
const guestToken = state.guestSessionToken ?? loadMobileFlowState()?.guestSessionToken ?? null;
|
|
8687
8702
|
const preauthAccountId = state.guestPreauthAccountId;
|
|
8688
8703
|
const preauthSessionId = state.guestPreauthSessionId;
|
|
8689
8704
|
let cancelled = false;
|
|
@@ -8903,63 +8918,85 @@ function guestPreauthRestoreKey(guestToken) {
|
|
|
8903
8918
|
function useGuestPreauthMobileRestoreEffect(deps) {
|
|
8904
8919
|
const { dispatch, apiBaseUrl, privyReady, mobileSetupFlowRef, setupAccountIdRef } = deps;
|
|
8905
8920
|
const completedRef = react.useRef(false);
|
|
8921
|
+
const pollingCleanupRef = react.useRef(null);
|
|
8906
8922
|
react.useEffect(() => {
|
|
8907
8923
|
if (!privyReady) return;
|
|
8908
|
-
const
|
|
8909
|
-
if (!persisted?.isGuestPreauth || !persisted.guestSessionToken) {
|
|
8910
|
-
return;
|
|
8911
|
-
}
|
|
8912
|
-
const guestToken = persisted.guestSessionToken;
|
|
8913
|
-
const key = guestPreauthRestoreKey(guestToken);
|
|
8914
|
-
if (guestPreauthRestoreAttemptedKeys.has(key)) return;
|
|
8915
|
-
guestPreauthRestoreAttemptedKeys.add(key);
|
|
8916
|
-
if (completedRef.current) return;
|
|
8917
|
-
let cancelled = false;
|
|
8918
|
-
const POLL_INTERVAL_MS = 3e3;
|
|
8919
|
-
const handleAccountFound = async (guestLookup) => {
|
|
8924
|
+
const tryStart = () => {
|
|
8920
8925
|
if (completedRef.current) return;
|
|
8921
|
-
|
|
8922
|
-
|
|
8923
|
-
|
|
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 () => {
|
|
8935
|
-
try {
|
|
8936
|
-
if (cancelled) return;
|
|
8937
|
-
const guestLookup = await fetchGuestAccount(apiBaseUrl, guestToken);
|
|
8938
|
-
if (cancelled) return;
|
|
8939
|
-
if (guestLookup != null) {
|
|
8940
|
-
await handleAccountFound(guestLookup);
|
|
8941
|
-
}
|
|
8942
|
-
} catch {
|
|
8926
|
+
const persisted = loadMobileFlowState();
|
|
8927
|
+
if (!persisted?.isGuestPreauth || !persisted.guestSessionToken) {
|
|
8928
|
+
return;
|
|
8943
8929
|
}
|
|
8930
|
+
const guestToken = persisted.guestSessionToken;
|
|
8931
|
+
const key = guestPreauthRestoreKey(guestToken);
|
|
8932
|
+
if (guestPreauthRestoreAttemptedKeys.has(key)) return;
|
|
8933
|
+
guestPreauthRestoreAttemptedKeys.add(key);
|
|
8934
|
+
let cancelled = false;
|
|
8935
|
+
const POLL_INTERVAL_MS = 3e3;
|
|
8936
|
+
mobileSetupFlowRef.current = true;
|
|
8937
|
+
if (persisted.accountId) {
|
|
8938
|
+
setupAccountIdRef.current = persisted.accountId;
|
|
8939
|
+
}
|
|
8940
|
+
const handleAccountFound = async (guestLookup) => {
|
|
8941
|
+
if (completedRef.current) return;
|
|
8942
|
+
completedRef.current = true;
|
|
8943
|
+
cancelled = true;
|
|
8944
|
+
clearMobileFlowState();
|
|
8945
|
+
mobileSetupFlowRef.current = false;
|
|
8946
|
+
setupAccountIdRef.current = null;
|
|
8947
|
+
dispatch({
|
|
8948
|
+
type: "GUEST_PREAUTH_DETECTED",
|
|
8949
|
+
accountId: guestLookup.accountId,
|
|
8950
|
+
sessionId: persisted.sessionId ?? void 0
|
|
8951
|
+
});
|
|
8952
|
+
dispatch({ type: "REQUEST_LOGIN" });
|
|
8953
|
+
dispatch({ type: "MOBILE_SETUP_COMPLETE" });
|
|
8954
|
+
};
|
|
8955
|
+
const pollGuestAccount = async () => {
|
|
8956
|
+
try {
|
|
8957
|
+
if (cancelled) return;
|
|
8958
|
+
const guestLookup = await fetchGuestAccount(apiBaseUrl, guestToken);
|
|
8959
|
+
if (cancelled) return;
|
|
8960
|
+
if (guestLookup != null) {
|
|
8961
|
+
await handleAccountFound(guestLookup);
|
|
8962
|
+
}
|
|
8963
|
+
} catch {
|
|
8964
|
+
}
|
|
8965
|
+
};
|
|
8966
|
+
pollGuestAccount();
|
|
8967
|
+
const intervalId = window.setInterval(pollGuestAccount, POLL_INTERVAL_MS);
|
|
8968
|
+
const handlePollVisibility = () => {
|
|
8969
|
+
if (document.visibilityState === "visible" && !cancelled) void pollGuestAccount();
|
|
8970
|
+
};
|
|
8971
|
+
const handlePollPageShow = (e) => {
|
|
8972
|
+
if (e.persisted && !cancelled) void pollGuestAccount();
|
|
8973
|
+
};
|
|
8974
|
+
document.addEventListener("visibilitychange", handlePollVisibility);
|
|
8975
|
+
window.addEventListener("pageshow", handlePollPageShow);
|
|
8976
|
+
pollingCleanupRef.current = () => {
|
|
8977
|
+
cancelled = true;
|
|
8978
|
+
window.clearInterval(intervalId);
|
|
8979
|
+
document.removeEventListener("visibilitychange", handlePollVisibility);
|
|
8980
|
+
window.removeEventListener("pageshow", handlePollPageShow);
|
|
8981
|
+
if (!completedRef.current) {
|
|
8982
|
+
guestPreauthRestoreAttemptedKeys.delete(key);
|
|
8983
|
+
}
|
|
8984
|
+
pollingCleanupRef.current = null;
|
|
8985
|
+
};
|
|
8944
8986
|
};
|
|
8945
|
-
|
|
8946
|
-
|
|
8947
|
-
const handleVisibility = () => {
|
|
8948
|
-
if (document.visibilityState === "visible" && !cancelled) void pollGuestAccount();
|
|
8987
|
+
const onOuterVisibility = () => {
|
|
8988
|
+
if (document.visibilityState === "visible") tryStart();
|
|
8949
8989
|
};
|
|
8950
|
-
const
|
|
8951
|
-
if (e.persisted
|
|
8990
|
+
const onOuterPageShow = (e) => {
|
|
8991
|
+
if (e.persisted) tryStart();
|
|
8952
8992
|
};
|
|
8953
|
-
|
|
8954
|
-
|
|
8993
|
+
tryStart();
|
|
8994
|
+
document.addEventListener("visibilitychange", onOuterVisibility);
|
|
8995
|
+
window.addEventListener("pageshow", onOuterPageShow);
|
|
8955
8996
|
return () => {
|
|
8956
|
-
|
|
8957
|
-
window.
|
|
8958
|
-
|
|
8959
|
-
window.removeEventListener("pageshow", handlePageShow);
|
|
8960
|
-
if (!completedRef.current) {
|
|
8961
|
-
guestPreauthRestoreAttemptedKeys.delete(key);
|
|
8962
|
-
}
|
|
8997
|
+
document.removeEventListener("visibilitychange", onOuterVisibility);
|
|
8998
|
+
window.removeEventListener("pageshow", onOuterPageShow);
|
|
8999
|
+
pollingCleanupRef.current?.();
|
|
8963
9000
|
};
|
|
8964
9001
|
}, [privyReady, apiBaseUrl, dispatch, mobileSetupFlowRef, setupAccountIdRef]);
|
|
8965
9002
|
}
|