@swype-org/react-sdk 0.1.271 → 0.1.272
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 +124 -177
- package/dist/index.cjs.map +1 -1
- package/dist/index.js +124 -177
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -7339,7 +7339,8 @@ function useProviderHandlers(deps) {
|
|
|
7339
7339
|
destination,
|
|
7340
7340
|
guestSessionToken,
|
|
7341
7341
|
guestTransferId,
|
|
7342
|
-
selectedProviderId
|
|
7342
|
+
selectedProviderId,
|
|
7343
|
+
startGuestAccountPolling
|
|
7343
7344
|
} = deps;
|
|
7344
7345
|
const wagmiConfig2 = useConfig();
|
|
7345
7346
|
const { connectAsync, connectors } = useConnect();
|
|
@@ -7779,6 +7780,7 @@ function useProviderHandlers(deps) {
|
|
|
7779
7780
|
triggerDeeplink(created.sessionUri);
|
|
7780
7781
|
dispatch({ type: "MOBILE_DEEPLINK_READY", deeplinkUri: created.sessionUri });
|
|
7781
7782
|
}
|
|
7783
|
+
startGuestAccountPolling(guestSessionToken, session.id);
|
|
7782
7784
|
dispatch({
|
|
7783
7785
|
type: "GUEST_PREAUTH_DETECTED",
|
|
7784
7786
|
accountId: created.accountId,
|
|
@@ -7806,7 +7808,8 @@ function useProviderHandlers(deps) {
|
|
|
7806
7808
|
useWalletConnectorProp,
|
|
7807
7809
|
mobileSetupFlowRef,
|
|
7808
7810
|
handlingMobileReturnRef,
|
|
7809
|
-
setupAccountIdRef
|
|
7811
|
+
setupAccountIdRef,
|
|
7812
|
+
startGuestAccountPolling
|
|
7810
7813
|
]);
|
|
7811
7814
|
return {
|
|
7812
7815
|
handlePrepareProvider,
|
|
@@ -8691,100 +8694,6 @@ function useMobilePollingEffect(deps) {
|
|
|
8691
8694
|
handlingMobileReturnRef,
|
|
8692
8695
|
mobileSetupFlowRef
|
|
8693
8696
|
]);
|
|
8694
|
-
useEffect(() => {
|
|
8695
|
-
if (!state.mobileFlow || !state.isGuestFlow || !state.guestPreauthSessionId || !state.guestPreauthAccountId) {
|
|
8696
|
-
return;
|
|
8697
|
-
}
|
|
8698
|
-
const guestToken = state.guestSessionToken ?? loadMobileFlowState()?.guestSessionToken ?? null;
|
|
8699
|
-
const preauthAccountId = state.guestPreauthAccountId;
|
|
8700
|
-
const preauthSessionId = state.guestPreauthSessionId;
|
|
8701
|
-
let cancelled = false;
|
|
8702
|
-
let completedGuestPreauth = false;
|
|
8703
|
-
const POLL_INTERVAL_MS = 3e3;
|
|
8704
|
-
const finishMobileAndDispatch = async () => {
|
|
8705
|
-
mobileSetupFlowRef.current = false;
|
|
8706
|
-
setupAccountIdRef.current = null;
|
|
8707
|
-
try {
|
|
8708
|
-
await reloadAccounts();
|
|
8709
|
-
} catch {
|
|
8710
|
-
}
|
|
8711
|
-
};
|
|
8712
|
-
const completeGuestPreauthWithoutToken = async () => {
|
|
8713
|
-
if (completedGuestPreauth) return;
|
|
8714
|
-
completedGuestPreauth = true;
|
|
8715
|
-
cancelled = true;
|
|
8716
|
-
await finishMobileAndDispatch();
|
|
8717
|
-
clearMobileFlowState();
|
|
8718
|
-
dispatch({ type: "MOBILE_SETUP_COMPLETE" });
|
|
8719
|
-
};
|
|
8720
|
-
const completeGuestPreauthWithAccount = async (guestLookup) => {
|
|
8721
|
-
if (completedGuestPreauth) return;
|
|
8722
|
-
completedGuestPreauth = true;
|
|
8723
|
-
cancelled = true;
|
|
8724
|
-
await finishMobileAndDispatch();
|
|
8725
|
-
if (guestLookup.accountId !== preauthAccountId) {
|
|
8726
|
-
dispatch({
|
|
8727
|
-
type: "GUEST_PREAUTH_DETECTED",
|
|
8728
|
-
accountId: guestLookup.accountId,
|
|
8729
|
-
sessionId: preauthSessionId ?? void 0
|
|
8730
|
-
});
|
|
8731
|
-
}
|
|
8732
|
-
dispatch({ type: "REQUEST_LOGIN" });
|
|
8733
|
-
dispatch({ type: "MOBILE_SETUP_COMPLETE" });
|
|
8734
|
-
};
|
|
8735
|
-
const pollGuestAccount = async () => {
|
|
8736
|
-
try {
|
|
8737
|
-
if (cancelled) return;
|
|
8738
|
-
if (!guestToken) {
|
|
8739
|
-
await completeGuestPreauthWithoutToken();
|
|
8740
|
-
return;
|
|
8741
|
-
}
|
|
8742
|
-
const guestLookup = await fetchGuestAccount(apiBaseUrl, guestToken);
|
|
8743
|
-
if (cancelled) return;
|
|
8744
|
-
if (guestLookup != null) {
|
|
8745
|
-
if (preauthSessionId) {
|
|
8746
|
-
try {
|
|
8747
|
-
const session = await fetchAuthorizationSession(
|
|
8748
|
-
apiBaseUrl,
|
|
8749
|
-
preauthSessionId
|
|
8750
|
-
);
|
|
8751
|
-
if (cancelled) return;
|
|
8752
|
-
if (session.status !== "AUTHORIZED") return;
|
|
8753
|
-
} catch {
|
|
8754
|
-
return;
|
|
8755
|
-
}
|
|
8756
|
-
}
|
|
8757
|
-
await completeGuestPreauthWithAccount(guestLookup);
|
|
8758
|
-
}
|
|
8759
|
-
} catch {
|
|
8760
|
-
}
|
|
8761
|
-
};
|
|
8762
|
-
pollGuestAccount();
|
|
8763
|
-
const intervalId = window.setInterval(pollGuestAccount, POLL_INTERVAL_MS);
|
|
8764
|
-
const handleVisibility = () => {
|
|
8765
|
-
if (document.visibilityState === "visible" && !cancelled) void pollGuestAccount();
|
|
8766
|
-
};
|
|
8767
|
-
const handlePageShow = () => {
|
|
8768
|
-
if (document.visibilityState === "visible" && !cancelled) void pollGuestAccount();
|
|
8769
|
-
};
|
|
8770
|
-
document.addEventListener("visibilitychange", handleVisibility);
|
|
8771
|
-
window.addEventListener("pageshow", handlePageShow);
|
|
8772
|
-
return () => {
|
|
8773
|
-
cancelled = true;
|
|
8774
|
-
window.clearInterval(intervalId);
|
|
8775
|
-
document.removeEventListener("visibilitychange", handleVisibility);
|
|
8776
|
-
window.removeEventListener("pageshow", handlePageShow);
|
|
8777
|
-
};
|
|
8778
|
-
}, [
|
|
8779
|
-
state.mobileFlow,
|
|
8780
|
-
state.guestPreauthSessionId,
|
|
8781
|
-
state.isGuestFlow,
|
|
8782
|
-
state.guestSessionToken,
|
|
8783
|
-
state.guestPreauthAccountId,
|
|
8784
|
-
apiBaseUrl,
|
|
8785
|
-
reloadAccounts,
|
|
8786
|
-
dispatch
|
|
8787
|
-
]);
|
|
8788
8697
|
useEffect(() => {
|
|
8789
8698
|
if (!state.mobileFlow || !mobileSetupFlowRef.current) return;
|
|
8790
8699
|
if (state.isGuestFlow && state.guestPreauthSessionId != null) return;
|
|
@@ -8923,106 +8832,55 @@ function useMobilePollingEffect(deps) {
|
|
|
8923
8832
|
pollingTransferIdRef
|
|
8924
8833
|
]);
|
|
8925
8834
|
}
|
|
8926
|
-
var guestPreauthRestoreAttemptedKeys = /* @__PURE__ */ new Set();
|
|
8927
|
-
function guestPreauthRestoreKey(guestToken) {
|
|
8928
|
-
return guestToken;
|
|
8929
|
-
}
|
|
8930
8835
|
function useGuestPreauthMobileRestoreEffect(deps) {
|
|
8931
|
-
const {
|
|
8932
|
-
|
|
8933
|
-
|
|
8836
|
+
const {
|
|
8837
|
+
dispatch,
|
|
8838
|
+
privyReady,
|
|
8839
|
+
mobileSetupFlowRef,
|
|
8840
|
+
setupAccountIdRef,
|
|
8841
|
+
startGuestAccountPolling
|
|
8842
|
+
} = deps;
|
|
8843
|
+
const startedRef = useRef(false);
|
|
8934
8844
|
useEffect(() => {
|
|
8935
8845
|
if (!privyReady) return;
|
|
8936
8846
|
const tryStart = () => {
|
|
8937
|
-
if (
|
|
8847
|
+
if (startedRef.current) return;
|
|
8938
8848
|
const persisted = loadMobileFlowState();
|
|
8939
|
-
if (!persisted?.isGuestPreauth || !persisted.guestSessionToken) {
|
|
8849
|
+
if (!persisted?.isGuestPreauth || !persisted.guestSessionToken || !persisted.sessionId) {
|
|
8940
8850
|
return;
|
|
8941
8851
|
}
|
|
8942
|
-
|
|
8943
|
-
const key = guestPreauthRestoreKey(guestToken);
|
|
8944
|
-
if (guestPreauthRestoreAttemptedKeys.has(key)) return;
|
|
8945
|
-
guestPreauthRestoreAttemptedKeys.add(key);
|
|
8946
|
-
let cancelled = false;
|
|
8947
|
-
const POLL_INTERVAL_MS = 3e3;
|
|
8852
|
+
startedRef.current = true;
|
|
8948
8853
|
mobileSetupFlowRef.current = true;
|
|
8949
8854
|
if (persisted.accountId) {
|
|
8950
8855
|
setupAccountIdRef.current = persisted.accountId;
|
|
8951
8856
|
}
|
|
8952
|
-
|
|
8953
|
-
if (completedRef.current) return;
|
|
8954
|
-
completedRef.current = true;
|
|
8955
|
-
cancelled = true;
|
|
8956
|
-
clearMobileFlowState();
|
|
8957
|
-
mobileSetupFlowRef.current = false;
|
|
8958
|
-
setupAccountIdRef.current = null;
|
|
8857
|
+
if (persisted.accountId) {
|
|
8959
8858
|
dispatch({
|
|
8960
8859
|
type: "GUEST_PREAUTH_DETECTED",
|
|
8961
|
-
accountId:
|
|
8962
|
-
sessionId: persisted.sessionId
|
|
8860
|
+
accountId: persisted.accountId,
|
|
8861
|
+
sessionId: persisted.sessionId
|
|
8963
8862
|
});
|
|
8964
|
-
|
|
8965
|
-
|
|
8966
|
-
|
|
8967
|
-
|
|
8968
|
-
|
|
8969
|
-
|
|
8970
|
-
const guestLookup = await fetchGuestAccount(apiBaseUrl, guestToken);
|
|
8971
|
-
if (cancelled) return;
|
|
8972
|
-
if (guestLookup != null) {
|
|
8973
|
-
if (persisted.sessionId) {
|
|
8974
|
-
try {
|
|
8975
|
-
const session = await fetchAuthorizationSession(
|
|
8976
|
-
apiBaseUrl,
|
|
8977
|
-
persisted.sessionId
|
|
8978
|
-
);
|
|
8979
|
-
if (cancelled) return;
|
|
8980
|
-
if (session.status !== "AUTHORIZED") return;
|
|
8981
|
-
} catch {
|
|
8982
|
-
return;
|
|
8983
|
-
}
|
|
8984
|
-
}
|
|
8985
|
-
await handleAccountFound(guestLookup);
|
|
8986
|
-
}
|
|
8987
|
-
} catch {
|
|
8988
|
-
}
|
|
8989
|
-
};
|
|
8990
|
-
pollGuestAccount();
|
|
8991
|
-
const intervalId = window.setInterval(pollGuestAccount, POLL_INTERVAL_MS);
|
|
8992
|
-
const handlePollVisibility = () => {
|
|
8993
|
-
if (document.visibilityState === "visible" && !cancelled) void pollGuestAccount();
|
|
8994
|
-
};
|
|
8995
|
-
const handlePollPageShow = () => {
|
|
8996
|
-
if (document.visibilityState === "visible" && !cancelled) void pollGuestAccount();
|
|
8997
|
-
};
|
|
8998
|
-
document.addEventListener("visibilitychange", handlePollVisibility);
|
|
8999
|
-
window.addEventListener("pageshow", handlePollPageShow);
|
|
9000
|
-
pollingCleanupRef.current = () => {
|
|
9001
|
-
cancelled = true;
|
|
9002
|
-
window.clearInterval(intervalId);
|
|
9003
|
-
document.removeEventListener("visibilitychange", handlePollVisibility);
|
|
9004
|
-
window.removeEventListener("pageshow", handlePollPageShow);
|
|
9005
|
-
if (!completedRef.current) {
|
|
9006
|
-
guestPreauthRestoreAttemptedKeys.delete(key);
|
|
9007
|
-
}
|
|
9008
|
-
pollingCleanupRef.current = null;
|
|
9009
|
-
};
|
|
8863
|
+
}
|
|
8864
|
+
dispatch({
|
|
8865
|
+
type: "MOBILE_DEEPLINK_READY",
|
|
8866
|
+
deeplinkUri: persisted.deeplinkUri
|
|
8867
|
+
});
|
|
8868
|
+
startGuestAccountPolling(persisted.guestSessionToken, persisted.sessionId);
|
|
9010
8869
|
};
|
|
9011
|
-
const
|
|
8870
|
+
const onVisibility = () => {
|
|
9012
8871
|
if (document.visibilityState === "visible") tryStart();
|
|
9013
8872
|
};
|
|
9014
|
-
const
|
|
8873
|
+
const onPageShow = () => {
|
|
9015
8874
|
if (document.visibilityState === "visible") tryStart();
|
|
9016
8875
|
};
|
|
9017
8876
|
tryStart();
|
|
9018
|
-
document.addEventListener("visibilitychange",
|
|
9019
|
-
window.addEventListener("pageshow",
|
|
8877
|
+
document.addEventListener("visibilitychange", onVisibility);
|
|
8878
|
+
window.addEventListener("pageshow", onPageShow);
|
|
9020
8879
|
return () => {
|
|
9021
|
-
document.removeEventListener("visibilitychange",
|
|
9022
|
-
window.removeEventListener("pageshow",
|
|
9023
|
-
pollingCleanupRef.current?.();
|
|
8880
|
+
document.removeEventListener("visibilitychange", onVisibility);
|
|
8881
|
+
window.removeEventListener("pageshow", onPageShow);
|
|
9024
8882
|
};
|
|
9025
|
-
}, [privyReady,
|
|
8883
|
+
}, [privyReady, dispatch, mobileSetupFlowRef, setupAccountIdRef, startGuestAccountPolling]);
|
|
9026
8884
|
}
|
|
9027
8885
|
function useSelectSourceEffect(deps) {
|
|
9028
8886
|
const {
|
|
@@ -9283,6 +9141,77 @@ function useGuestPreauthWalletSetupEffect(deps) {
|
|
|
9283
9141
|
dispatch
|
|
9284
9142
|
]);
|
|
9285
9143
|
}
|
|
9144
|
+
function useGuestAccountPolling(intervalMs = 3e3) {
|
|
9145
|
+
const { apiBaseUrl } = useBlinkConfig();
|
|
9146
|
+
const [guestAccount, setGuestAccount] = useState(null);
|
|
9147
|
+
const [isPolling, setIsPolling] = useState(false);
|
|
9148
|
+
const intervalRef = useRef(null);
|
|
9149
|
+
const guestTokenRef = useRef(null);
|
|
9150
|
+
const sessionIdRef = useRef(null);
|
|
9151
|
+
const apiBaseUrlRef = useRef(apiBaseUrl);
|
|
9152
|
+
apiBaseUrlRef.current = apiBaseUrl;
|
|
9153
|
+
const stopPolling = useCallback(() => {
|
|
9154
|
+
if (intervalRef.current) {
|
|
9155
|
+
clearInterval(intervalRef.current);
|
|
9156
|
+
intervalRef.current = null;
|
|
9157
|
+
}
|
|
9158
|
+
guestTokenRef.current = null;
|
|
9159
|
+
sessionIdRef.current = null;
|
|
9160
|
+
setIsPolling(false);
|
|
9161
|
+
}, []);
|
|
9162
|
+
const poll = useCallback(async () => {
|
|
9163
|
+
const token = guestTokenRef.current;
|
|
9164
|
+
const sessionId = sessionIdRef.current;
|
|
9165
|
+
if (!token || !sessionId) return;
|
|
9166
|
+
try {
|
|
9167
|
+
const lookup = await fetchGuestAccount(apiBaseUrlRef.current, token);
|
|
9168
|
+
if (!guestTokenRef.current) return;
|
|
9169
|
+
if (lookup == null) return;
|
|
9170
|
+
try {
|
|
9171
|
+
const session = await fetchAuthorizationSession(apiBaseUrlRef.current, sessionId);
|
|
9172
|
+
if (!guestTokenRef.current) return;
|
|
9173
|
+
if (session.status !== "AUTHORIZED") return;
|
|
9174
|
+
} catch {
|
|
9175
|
+
return;
|
|
9176
|
+
}
|
|
9177
|
+
setGuestAccount(lookup);
|
|
9178
|
+
stopPolling();
|
|
9179
|
+
} catch {
|
|
9180
|
+
}
|
|
9181
|
+
}, [stopPolling]);
|
|
9182
|
+
const startPolling = useCallback(
|
|
9183
|
+
(guestToken, sessionId) => {
|
|
9184
|
+
stopPolling();
|
|
9185
|
+
guestTokenRef.current = guestToken;
|
|
9186
|
+
sessionIdRef.current = sessionId;
|
|
9187
|
+
setGuestAccount(null);
|
|
9188
|
+
setIsPolling(true);
|
|
9189
|
+
poll();
|
|
9190
|
+
intervalRef.current = setInterval(poll, intervalMs);
|
|
9191
|
+
},
|
|
9192
|
+
[poll, intervalMs, stopPolling]
|
|
9193
|
+
);
|
|
9194
|
+
useEffect(() => {
|
|
9195
|
+
const handleVisibility = () => {
|
|
9196
|
+
if (document.visibilityState === "visible" && guestTokenRef.current) {
|
|
9197
|
+
void poll();
|
|
9198
|
+
}
|
|
9199
|
+
};
|
|
9200
|
+
const handlePageShow = () => {
|
|
9201
|
+
if (document.visibilityState === "visible" && guestTokenRef.current) {
|
|
9202
|
+
void poll();
|
|
9203
|
+
}
|
|
9204
|
+
};
|
|
9205
|
+
document.addEventListener("visibilitychange", handleVisibility);
|
|
9206
|
+
window.addEventListener("pageshow", handlePageShow);
|
|
9207
|
+
return () => {
|
|
9208
|
+
document.removeEventListener("visibilitychange", handleVisibility);
|
|
9209
|
+
window.removeEventListener("pageshow", handlePageShow);
|
|
9210
|
+
};
|
|
9211
|
+
}, [poll]);
|
|
9212
|
+
useEffect(() => () => stopPolling(), [stopPolling]);
|
|
9213
|
+
return { guestAccount, isPolling, startPolling, stopPolling };
|
|
9214
|
+
}
|
|
9286
9215
|
function BlinkPayment(props) {
|
|
9287
9216
|
const resetKey = useRef(0);
|
|
9288
9217
|
const handleBoundaryReset = useCallback(() => {
|
|
@@ -9319,6 +9248,7 @@ function BlinkPaymentInner({
|
|
|
9319
9248
|
);
|
|
9320
9249
|
const authExecutor = useAuthorizationExecutor();
|
|
9321
9250
|
const polling = useTransferPolling();
|
|
9251
|
+
const guestAccountPolling = useGuestAccountPolling();
|
|
9322
9252
|
const transferSigning = useTransferSigning();
|
|
9323
9253
|
const mobileFlowRefs = {
|
|
9324
9254
|
mobileSetupFlowRef: useRef(false),
|
|
@@ -9398,7 +9328,8 @@ function BlinkPaymentInner({
|
|
|
9398
9328
|
destination,
|
|
9399
9329
|
guestSessionToken: state.guestSessionToken,
|
|
9400
9330
|
guestTransferId: state.guestTransferId,
|
|
9401
|
-
selectedProviderId: state.selectedProviderId
|
|
9331
|
+
selectedProviderId: state.selectedProviderId,
|
|
9332
|
+
startGuestAccountPolling: guestAccountPolling.startPolling
|
|
9402
9333
|
});
|
|
9403
9334
|
const guestPostPayPreauth = useMemo(
|
|
9404
9335
|
() => !!state.guestPreauthSessionId && state.isGuestFlow || state.guestPreauthorizing && isDesktop,
|
|
@@ -9461,11 +9392,27 @@ function BlinkPaymentInner({
|
|
|
9461
9392
|
usePrivySessionSyncEffect({ dispatch, ready, authenticated });
|
|
9462
9393
|
useGuestPreauthMobileRestoreEffect({
|
|
9463
9394
|
dispatch,
|
|
9464
|
-
apiBaseUrl,
|
|
9465
9395
|
privyReady: state.privyReady,
|
|
9466
9396
|
mobileSetupFlowRef: mobileFlowRefs.mobileSetupFlowRef,
|
|
9467
|
-
setupAccountIdRef: mobileFlowRefs.setupAccountIdRef
|
|
9397
|
+
setupAccountIdRef: mobileFlowRefs.setupAccountIdRef,
|
|
9398
|
+
startGuestAccountPolling: guestAccountPolling.startPolling
|
|
9468
9399
|
});
|
|
9400
|
+
useEffect(() => {
|
|
9401
|
+
if (!guestAccountPolling.guestAccount) return;
|
|
9402
|
+
const acct = guestAccountPolling.guestAccount;
|
|
9403
|
+
if (acct.accountId !== state.guestPreauthAccountId) {
|
|
9404
|
+
dispatch({
|
|
9405
|
+
type: "GUEST_PREAUTH_DETECTED",
|
|
9406
|
+
accountId: acct.accountId,
|
|
9407
|
+
sessionId: state.guestPreauthSessionId ?? void 0
|
|
9408
|
+
});
|
|
9409
|
+
}
|
|
9410
|
+
mobileFlowRefs.mobileSetupFlowRef.current = false;
|
|
9411
|
+
mobileFlowRefs.setupAccountIdRef.current = null;
|
|
9412
|
+
clearMobileFlowState();
|
|
9413
|
+
dispatch({ type: "REQUEST_LOGIN" });
|
|
9414
|
+
dispatch({ type: "MOBILE_SETUP_COMPLETE" });
|
|
9415
|
+
}, [guestAccountPolling.guestAccount]);
|
|
9469
9416
|
useOtpEffects({
|
|
9470
9417
|
state,
|
|
9471
9418
|
dispatch,
|