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