@swype-org/react-sdk 0.1.272 → 0.1.280
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 +280 -38
- package/dist/index.cjs.map +1 -1
- package/dist/index.js +280 -38
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -1853,6 +1853,17 @@ function effectiveMinTransferAmountUsd(depositAmount) {
|
|
|
1853
1853
|
}
|
|
1854
1854
|
function persistMobileFlowState(data) {
|
|
1855
1855
|
try {
|
|
1856
|
+
console.info("[blink-sdk] persistMobileFlowState", {
|
|
1857
|
+
isGuestPreauth: data.isGuestPreauth ?? false,
|
|
1858
|
+
isGuestCheckout: data.isGuestCheckout ?? false,
|
|
1859
|
+
isReauthorization: data.isReauthorization ?? false,
|
|
1860
|
+
isSetup: data.isSetup,
|
|
1861
|
+
hasGuestSessionToken: !!data.guestSessionToken,
|
|
1862
|
+
hasSessionId: !!data.sessionId,
|
|
1863
|
+
hasAccountId: !!data.accountId,
|
|
1864
|
+
hasTransferId: !!data.transferId,
|
|
1865
|
+
caller: new Error().stack?.split("\n")[2]?.trim()
|
|
1866
|
+
});
|
|
1856
1867
|
sessionStorage.setItem(MOBILE_FLOW_STORAGE_KEY, JSON.stringify(data));
|
|
1857
1868
|
} catch {
|
|
1858
1869
|
}
|
|
@@ -1868,6 +1879,10 @@ function loadMobileFlowState() {
|
|
|
1868
1879
|
}
|
|
1869
1880
|
function clearMobileFlowState() {
|
|
1870
1881
|
try {
|
|
1882
|
+
console.info("[blink-sdk] clearMobileFlowState", {
|
|
1883
|
+
hadState: sessionStorage.getItem(MOBILE_FLOW_STORAGE_KEY) != null,
|
|
1884
|
+
caller: new Error().stack?.split("\n")[2]?.trim()
|
|
1885
|
+
});
|
|
1871
1886
|
sessionStorage.removeItem(MOBILE_FLOW_STORAGE_KEY);
|
|
1872
1887
|
} catch {
|
|
1873
1888
|
}
|
|
@@ -2193,6 +2208,25 @@ function resolvePhase(state) {
|
|
|
2193
2208
|
} else {
|
|
2194
2209
|
nextPhase = { step: "wallet-picker", reason: "entry" };
|
|
2195
2210
|
}
|
|
2211
|
+
if (state.guestPreauthSessionId != null) {
|
|
2212
|
+
console.info("[blink-sdk] resolvePhase (guest preauth context)", {
|
|
2213
|
+
resolvedStep: nextPhase.step,
|
|
2214
|
+
currentStep: currentPhase.step,
|
|
2215
|
+
branchGuestPostPayLogin,
|
|
2216
|
+
branchMobileWalletSetup,
|
|
2217
|
+
branchLoginRequested,
|
|
2218
|
+
branchCompleted,
|
|
2219
|
+
branchKeepGuestPreauthPin,
|
|
2220
|
+
branchGuestSetupComplete,
|
|
2221
|
+
transferStatus: state.transfer?.status ?? null,
|
|
2222
|
+
mobileFlow: state.mobileFlow,
|
|
2223
|
+
deeplinkUri: state.deeplinkUri != null,
|
|
2224
|
+
loginRequested: state.loginRequested,
|
|
2225
|
+
guestPreauthorizing: state.guestPreauthorizing,
|
|
2226
|
+
privyAuthenticated: state.privyAuthenticated,
|
|
2227
|
+
isGuestFlow: state.isGuestFlow
|
|
2228
|
+
});
|
|
2229
|
+
}
|
|
2196
2230
|
return nextPhase;
|
|
2197
2231
|
}
|
|
2198
2232
|
|
|
@@ -2260,6 +2294,30 @@ function paymentReducer(state, action) {
|
|
|
2260
2294
|
loginRequested: next.loginRequested
|
|
2261
2295
|
});
|
|
2262
2296
|
}
|
|
2297
|
+
if (action.type === "REQUEST_LOGIN") {
|
|
2298
|
+
console.info("[blink-sdk] reducer REQUEST_LOGIN", {
|
|
2299
|
+
resolvedPhase: phase.step,
|
|
2300
|
+
mobileFlow: next.mobileFlow,
|
|
2301
|
+
loginRequested: next.loginRequested,
|
|
2302
|
+
guestPreauthSessionId: next.guestPreauthSessionId,
|
|
2303
|
+
guestPreauthAccountId: next.guestPreauthAccountId,
|
|
2304
|
+
transferStatus: next.transfer?.status ?? null,
|
|
2305
|
+
isGuestFlow: next.isGuestFlow,
|
|
2306
|
+
privyReady: next.privyReady,
|
|
2307
|
+
privyAuthenticated: next.privyAuthenticated
|
|
2308
|
+
});
|
|
2309
|
+
}
|
|
2310
|
+
if (action.type === "MOBILE_SETUP_COMPLETE") {
|
|
2311
|
+
console.info("[blink-sdk] reducer MOBILE_SETUP_COMPLETE", {
|
|
2312
|
+
resolvedPhase: phase.step,
|
|
2313
|
+
mobileFlow: next.mobileFlow,
|
|
2314
|
+
deeplinkUri: next.deeplinkUri,
|
|
2315
|
+
loginRequested: next.loginRequested,
|
|
2316
|
+
guestPreauthSessionId: next.guestPreauthSessionId,
|
|
2317
|
+
transferStatus: next.transfer?.status ?? null,
|
|
2318
|
+
isGuestFlow: next.isGuestFlow
|
|
2319
|
+
});
|
|
2320
|
+
}
|
|
2263
2321
|
return { ...next, phase };
|
|
2264
2322
|
}
|
|
2265
2323
|
function applyAction(state, action) {
|
|
@@ -2410,7 +2468,12 @@ function applyAction(state, action) {
|
|
|
2410
2468
|
return {
|
|
2411
2469
|
...state,
|
|
2412
2470
|
mobileFlow: true,
|
|
2413
|
-
deeplinkUri: action.deeplinkUri
|
|
2471
|
+
deeplinkUri: action.deeplinkUri,
|
|
2472
|
+
...action.guestTransferId != null && {
|
|
2473
|
+
guestTransferId: action.guestTransferId,
|
|
2474
|
+
guestSessionToken: action.guestSessionToken ?? null,
|
|
2475
|
+
isGuestFlow: true
|
|
2476
|
+
}
|
|
2414
2477
|
};
|
|
2415
2478
|
case "MOBILE_SETUP_COMPLETE":
|
|
2416
2479
|
return {
|
|
@@ -2528,6 +2591,7 @@ function applyAction(state, action) {
|
|
|
2528
2591
|
mobileFlow: false,
|
|
2529
2592
|
deeplinkUri: null,
|
|
2530
2593
|
isGuestFlow: true,
|
|
2594
|
+
guestTransferId: null,
|
|
2531
2595
|
guestSessionToken: action.guestSessionToken ?? state.guestSessionToken
|
|
2532
2596
|
};
|
|
2533
2597
|
case "GUEST_PREAUTH_DETECTED":
|
|
@@ -6277,6 +6341,7 @@ function StepRendererContent({
|
|
|
6277
6341
|
const {
|
|
6278
6342
|
pollingTransfer,
|
|
6279
6343
|
pollingError,
|
|
6344
|
+
guestAccountPollingError,
|
|
6280
6345
|
authExecutorError,
|
|
6281
6346
|
transferSigningSigning,
|
|
6282
6347
|
transferSigningError,
|
|
@@ -6392,7 +6457,7 @@ function StepRendererContent({
|
|
|
6392
6457
|
deeplinkUri: state.deeplinkUri ?? "",
|
|
6393
6458
|
loading: !isDesktop ? state.creatingTransfer || !state.deeplinkUri : state.creatingTransfer,
|
|
6394
6459
|
useDeeplink: !isDesktop,
|
|
6395
|
-
error: state.error || (!isDesktop ? pollingError : authExecutorError),
|
|
6460
|
+
error: state.error || guestAccountPollingError || (!isDesktop ? pollingError : authExecutorError),
|
|
6396
6461
|
onRetryStatus: !isDesktop ? handlers.onRetryMobileStatus : void 0,
|
|
6397
6462
|
onBack: !isDesktop ? handlers.onBackFromOpenWallet : void 0,
|
|
6398
6463
|
onLogout: handlers.onLogout
|
|
@@ -7196,7 +7261,7 @@ function useSourceSelectionHandlers(dispatch, authExecutor, options) {
|
|
|
7196
7261
|
initializedSelectSourceActionRef
|
|
7197
7262
|
};
|
|
7198
7263
|
}
|
|
7199
|
-
function useMobileFlowHandlers(dispatch, polling, reloadAccounts, pollingTransferIdRef, stateTransfer, refs, onComplete) {
|
|
7264
|
+
function useMobileFlowHandlers(dispatch, polling, reloadAccounts, pollingTransferIdRef, stateTransfer, refs, guestCheckout, onComplete) {
|
|
7200
7265
|
const {
|
|
7201
7266
|
mobileSetupFlowRef,
|
|
7202
7267
|
handlingMobileReturnRef,
|
|
@@ -7207,6 +7272,10 @@ function useMobileFlowHandlers(dispatch, polling, reloadAccounts, pollingTransfe
|
|
|
7207
7272
|
onCompleteRef.current = onComplete;
|
|
7208
7273
|
const guestPollingActiveRef = useRef(false);
|
|
7209
7274
|
const guestPollingCleanupRef = useRef(null);
|
|
7275
|
+
const guestTransferIdRef = useRef(guestCheckout.guestTransferId);
|
|
7276
|
+
guestTransferIdRef.current = guestCheckout.guestTransferId;
|
|
7277
|
+
const guestSessionTokenRef = useRef(guestCheckout.guestSessionToken);
|
|
7278
|
+
guestSessionTokenRef.current = guestCheckout.guestSessionToken;
|
|
7210
7279
|
const startGuestPolling = useCallback((transferId, guestSessionToken) => {
|
|
7211
7280
|
if (guestPollingActiveRef.current) return;
|
|
7212
7281
|
guestPollingActiveRef.current = true;
|
|
@@ -7222,14 +7291,12 @@ function useMobileFlowHandlers(dispatch, polling, reloadAccounts, pollingTransfe
|
|
|
7222
7291
|
cancelled = true;
|
|
7223
7292
|
guestPollingActiveRef.current = false;
|
|
7224
7293
|
guestPollingCleanupRef.current = null;
|
|
7225
|
-
clearMobileFlowState();
|
|
7226
7294
|
dispatch({ type: "GUEST_TRANSFER_COMPLETED", transfer, guestSessionToken });
|
|
7227
7295
|
onCompleteRef.current?.(transfer);
|
|
7228
7296
|
} else if (transfer.status === "FAILED") {
|
|
7229
7297
|
cancelled = true;
|
|
7230
7298
|
guestPollingActiveRef.current = false;
|
|
7231
7299
|
guestPollingCleanupRef.current = null;
|
|
7232
|
-
clearMobileFlowState();
|
|
7233
7300
|
dispatch({ type: "TRANSFER_FAILED", transfer, error: "Transfer failed." });
|
|
7234
7301
|
}
|
|
7235
7302
|
} catch {
|
|
@@ -7246,20 +7313,26 @@ function useMobileFlowHandlers(dispatch, polling, reloadAccounts, pollingTransfe
|
|
|
7246
7313
|
guestPollingCleanupRef.current = cleanup;
|
|
7247
7314
|
}, [apiBaseUrl, dispatch]);
|
|
7248
7315
|
useEffect(() => {
|
|
7249
|
-
|
|
7250
|
-
|
|
7251
|
-
startGuestPolling(persisted.transferId, persisted.guestSessionToken);
|
|
7316
|
+
if (guestCheckout.mobileFlow && guestCheckout.isGuestFlow && guestCheckout.guestTransferId && guestCheckout.guestSessionToken) {
|
|
7317
|
+
startGuestPolling(guestCheckout.guestTransferId, guestCheckout.guestSessionToken);
|
|
7252
7318
|
}
|
|
7253
7319
|
return () => {
|
|
7254
7320
|
guestPollingCleanupRef.current?.();
|
|
7255
7321
|
};
|
|
7256
|
-
}, [
|
|
7322
|
+
}, [
|
|
7323
|
+
guestCheckout.mobileFlow,
|
|
7324
|
+
guestCheckout.isGuestFlow,
|
|
7325
|
+
guestCheckout.guestTransferId,
|
|
7326
|
+
guestCheckout.guestSessionToken,
|
|
7327
|
+
startGuestPolling
|
|
7328
|
+
]);
|
|
7257
7329
|
useEffect(() => {
|
|
7258
7330
|
const tryStartPolling = () => {
|
|
7259
7331
|
if (guestPollingActiveRef.current) return;
|
|
7260
|
-
const
|
|
7261
|
-
|
|
7262
|
-
|
|
7332
|
+
const transferId = guestTransferIdRef.current;
|
|
7333
|
+
const token = guestSessionTokenRef.current;
|
|
7334
|
+
if (transferId && token) {
|
|
7335
|
+
startGuestPolling(transferId, token);
|
|
7263
7336
|
}
|
|
7264
7337
|
};
|
|
7265
7338
|
const handleVisibility = () => {
|
|
@@ -7403,16 +7476,13 @@ function useProviderHandlers(deps) {
|
|
|
7403
7476
|
dispatch({ type: "PAY_ERROR", error: "This wallet is not available on mobile." });
|
|
7404
7477
|
return;
|
|
7405
7478
|
}
|
|
7406
|
-
|
|
7407
|
-
|
|
7408
|
-
|
|
7409
|
-
isGuestCheckout: true,
|
|
7479
|
+
triggerDeeplink(result.uri);
|
|
7480
|
+
dispatch({
|
|
7481
|
+
type: "MOBILE_DEEPLINK_READY",
|
|
7410
7482
|
deeplinkUri: result.uri,
|
|
7411
|
-
|
|
7412
|
-
|
|
7483
|
+
guestTransferId: result.id,
|
|
7484
|
+
guestSessionToken: result.guestSessionToken
|
|
7413
7485
|
});
|
|
7414
|
-
triggerDeeplink(result.uri);
|
|
7415
|
-
dispatch({ type: "MOBILE_DEEPLINK_READY", deeplinkUri: result.uri });
|
|
7416
7486
|
} else {
|
|
7417
7487
|
const account = getAccount(wagmiConfig2);
|
|
7418
7488
|
if (!account.isConnected) {
|
|
@@ -7748,6 +7818,14 @@ function useProviderHandlers(deps) {
|
|
|
7748
7818
|
useWalletConnector: useWalletConnectorProp,
|
|
7749
7819
|
userAgent: typeof navigator === "undefined" ? void 0 : navigator.userAgent
|
|
7750
7820
|
});
|
|
7821
|
+
console.info("[blink-sdk] handlePreauthorize", {
|
|
7822
|
+
isMobile,
|
|
7823
|
+
useWalletConnectorProp,
|
|
7824
|
+
hasGuestSessionToken: !!guestSessionToken,
|
|
7825
|
+
selectedProviderId,
|
|
7826
|
+
guestTransferId,
|
|
7827
|
+
userAgent: typeof navigator === "undefined" ? null : navigator.userAgent
|
|
7828
|
+
});
|
|
7751
7829
|
const providerName = providers.find((p) => p.id === selectedProviderId)?.name ?? "Wallet";
|
|
7752
7830
|
if (!isMobile) {
|
|
7753
7831
|
dispatch({ type: "GUEST_PREAUTH_BEGIN" });
|
|
@@ -8169,7 +8247,8 @@ function usePasskeyCheckEffect(deps) {
|
|
|
8169
8247
|
setupAccountIdRef,
|
|
8170
8248
|
reauthSessionIdRef,
|
|
8171
8249
|
reauthTokenRef,
|
|
8172
|
-
pollingTransferIdRef
|
|
8250
|
+
pollingTransferIdRef,
|
|
8251
|
+
startGuestAccountPolling
|
|
8173
8252
|
} = deps;
|
|
8174
8253
|
const { getAccessToken } = usePrivy();
|
|
8175
8254
|
const onCompleteRef = useRef(deps.onComplete);
|
|
@@ -8192,8 +8271,23 @@ function usePasskeyCheckEffect(deps) {
|
|
|
8192
8271
|
dispatch({ type: "SET_ERROR", error: null });
|
|
8193
8272
|
setAuthInput("");
|
|
8194
8273
|
setOtpCode("");
|
|
8274
|
+
const startGuestAccountPollingRef = startGuestAccountPolling;
|
|
8195
8275
|
const restoreState = async (credId, token) => {
|
|
8196
8276
|
const persisted = loadMobileFlowState();
|
|
8277
|
+
if (persisted?.isGuestPreauth && persisted.guestSessionToken && persisted.sessionId) {
|
|
8278
|
+
mobileSetupFlowRef.current = true;
|
|
8279
|
+
if (persisted.accountId) {
|
|
8280
|
+
setupAccountIdRef.current = persisted.accountId;
|
|
8281
|
+
dispatch({
|
|
8282
|
+
type: "GUEST_PREAUTH_DETECTED",
|
|
8283
|
+
accountId: persisted.accountId,
|
|
8284
|
+
sessionId: persisted.sessionId
|
|
8285
|
+
});
|
|
8286
|
+
}
|
|
8287
|
+
dispatch({ type: "MOBILE_DEEPLINK_READY", deeplinkUri: persisted.deeplinkUri });
|
|
8288
|
+
startGuestAccountPollingRef(persisted.guestSessionToken, persisted.sessionId);
|
|
8289
|
+
return;
|
|
8290
|
+
}
|
|
8197
8291
|
let accts = [];
|
|
8198
8292
|
try {
|
|
8199
8293
|
accts = await fetchAccounts(apiBaseUrl, token, credId);
|
|
@@ -8842,10 +8936,24 @@ function useGuestPreauthMobileRestoreEffect(deps) {
|
|
|
8842
8936
|
} = deps;
|
|
8843
8937
|
const startedRef = useRef(false);
|
|
8844
8938
|
useEffect(() => {
|
|
8845
|
-
if (!privyReady)
|
|
8846
|
-
|
|
8847
|
-
|
|
8939
|
+
if (!privyReady) {
|
|
8940
|
+
console.info("[blink-sdk] guestPreauthMobileRestore: skipping, privyReady=false");
|
|
8941
|
+
return;
|
|
8942
|
+
}
|
|
8943
|
+
const tryStart = (trigger) => {
|
|
8944
|
+
if (startedRef.current) {
|
|
8945
|
+
console.info("[blink-sdk] guestPreauthMobileRestore.tryStart: already started", { trigger });
|
|
8946
|
+
return;
|
|
8947
|
+
}
|
|
8848
8948
|
const persisted = loadMobileFlowState();
|
|
8949
|
+
console.info("[blink-sdk] guestPreauthMobileRestore.tryStart", {
|
|
8950
|
+
trigger,
|
|
8951
|
+
hasPersistedState: !!persisted,
|
|
8952
|
+
isGuestPreauth: persisted?.isGuestPreauth ?? false,
|
|
8953
|
+
hasGuestSessionToken: !!persisted?.guestSessionToken,
|
|
8954
|
+
hasSessionId: !!persisted?.sessionId,
|
|
8955
|
+
accountId: persisted?.accountId ?? null
|
|
8956
|
+
});
|
|
8849
8957
|
if (!persisted?.isGuestPreauth || !persisted.guestSessionToken || !persisted.sessionId) {
|
|
8850
8958
|
return;
|
|
8851
8959
|
}
|
|
@@ -8865,15 +8973,28 @@ function useGuestPreauthMobileRestoreEffect(deps) {
|
|
|
8865
8973
|
type: "MOBILE_DEEPLINK_READY",
|
|
8866
8974
|
deeplinkUri: persisted.deeplinkUri
|
|
8867
8975
|
});
|
|
8976
|
+
console.info("[blink-sdk] guestPreauthMobileRestore: starting guest account polling", {
|
|
8977
|
+
trigger,
|
|
8978
|
+
sessionId: persisted.sessionId
|
|
8979
|
+
});
|
|
8868
8980
|
startGuestAccountPolling(persisted.guestSessionToken, persisted.sessionId);
|
|
8869
8981
|
};
|
|
8870
8982
|
const onVisibility = () => {
|
|
8871
|
-
|
|
8983
|
+
console.info("[blink-sdk] guestPreauthMobileRestore: visibilitychange fired", {
|
|
8984
|
+
visibilityState: document.visibilityState,
|
|
8985
|
+
startedRef: startedRef.current
|
|
8986
|
+
});
|
|
8987
|
+
if (document.visibilityState === "visible") tryStart("visibilitychange");
|
|
8872
8988
|
};
|
|
8873
|
-
const onPageShow = () => {
|
|
8874
|
-
|
|
8989
|
+
const onPageShow = (e) => {
|
|
8990
|
+
console.info("[blink-sdk] guestPreauthMobileRestore: pageshow fired", {
|
|
8991
|
+
persisted: e.persisted,
|
|
8992
|
+
visibilityState: document.visibilityState,
|
|
8993
|
+
startedRef: startedRef.current
|
|
8994
|
+
});
|
|
8995
|
+
if (document.visibilityState === "visible") tryStart("pageshow");
|
|
8875
8996
|
};
|
|
8876
|
-
tryStart();
|
|
8997
|
+
tryStart("initial");
|
|
8877
8998
|
document.addEventListener("visibilitychange", onVisibility);
|
|
8878
8999
|
window.addEventListener("pageshow", onPageShow);
|
|
8879
9000
|
return () => {
|
|
@@ -9141,16 +9262,37 @@ function useGuestPreauthWalletSetupEffect(deps) {
|
|
|
9141
9262
|
dispatch
|
|
9142
9263
|
]);
|
|
9143
9264
|
}
|
|
9265
|
+
function useGuestAccountAutoPollingEffect(deps) {
|
|
9266
|
+
const {
|
|
9267
|
+
mobileFlow,
|
|
9268
|
+
isGuestFlow,
|
|
9269
|
+
guestSessionToken,
|
|
9270
|
+
isPolling,
|
|
9271
|
+
guestAccount,
|
|
9272
|
+
startPolling
|
|
9273
|
+
} = deps;
|
|
9274
|
+
useEffect(() => {
|
|
9275
|
+
if (!mobileFlow || !isGuestFlow || !guestSessionToken) return;
|
|
9276
|
+
if (isPolling || guestAccount) return;
|
|
9277
|
+
startPolling(guestSessionToken);
|
|
9278
|
+
}, [mobileFlow, isGuestFlow, guestSessionToken, isPolling, guestAccount, startPolling]);
|
|
9279
|
+
}
|
|
9144
9280
|
function useGuestAccountPolling(intervalMs = 3e3) {
|
|
9145
9281
|
const { apiBaseUrl } = useBlinkConfig();
|
|
9146
9282
|
const [guestAccount, setGuestAccount] = useState(null);
|
|
9147
9283
|
const [isPolling, setIsPolling] = useState(false);
|
|
9284
|
+
const [error, setError] = useState(null);
|
|
9285
|
+
const consecutiveFailuresRef = useRef(0);
|
|
9148
9286
|
const intervalRef = useRef(null);
|
|
9149
9287
|
const guestTokenRef = useRef(null);
|
|
9150
9288
|
const sessionIdRef = useRef(null);
|
|
9151
9289
|
const apiBaseUrlRef = useRef(apiBaseUrl);
|
|
9152
9290
|
apiBaseUrlRef.current = apiBaseUrl;
|
|
9153
9291
|
const stopPolling = useCallback(() => {
|
|
9292
|
+
console.info("[blink-sdk] useGuestAccountPolling.stopPolling called", {
|
|
9293
|
+
hadInterval: !!intervalRef.current,
|
|
9294
|
+
hadToken: !!guestTokenRef.current
|
|
9295
|
+
});
|
|
9154
9296
|
if (intervalRef.current) {
|
|
9155
9297
|
clearInterval(intervalRef.current);
|
|
9156
9298
|
intervalRef.current = null;
|
|
@@ -9162,29 +9304,70 @@ function useGuestAccountPolling(intervalMs = 3e3) {
|
|
|
9162
9304
|
const poll = useCallback(async () => {
|
|
9163
9305
|
const token = guestTokenRef.current;
|
|
9164
9306
|
const sessionId = sessionIdRef.current;
|
|
9165
|
-
if (!token
|
|
9307
|
+
if (!token) {
|
|
9308
|
+
console.info("[blink-sdk] useGuestAccountPolling.poll skipped (no token)");
|
|
9309
|
+
return;
|
|
9310
|
+
}
|
|
9311
|
+
console.info("[blink-sdk] useGuestAccountPolling.poll executing", {
|
|
9312
|
+
apiBaseUrl: apiBaseUrlRef.current,
|
|
9313
|
+
tokenPrefix: token.slice(0, 8),
|
|
9314
|
+
sessionId: sessionId ?? "(none \u2014 account-only mode)"
|
|
9315
|
+
});
|
|
9166
9316
|
try {
|
|
9167
9317
|
const lookup = await fetchGuestAccount(apiBaseUrlRef.current, token);
|
|
9168
9318
|
if (!guestTokenRef.current) return;
|
|
9169
|
-
|
|
9319
|
+
consecutiveFailuresRef.current = 0;
|
|
9320
|
+
setError(null);
|
|
9321
|
+
if (lookup == null) {
|
|
9322
|
+
console.info("[blink-sdk] useGuestAccountPolling.poll: account not found yet");
|
|
9323
|
+
return;
|
|
9324
|
+
}
|
|
9325
|
+
if (!sessionId) {
|
|
9326
|
+
console.info("[blink-sdk] useGuestAccountPolling.poll: COMPLETE \u2014 account found (no session check)");
|
|
9327
|
+
setGuestAccount(lookup);
|
|
9328
|
+
stopPolling();
|
|
9329
|
+
return;
|
|
9330
|
+
}
|
|
9331
|
+
console.info("[blink-sdk] useGuestAccountPolling.poll: account found, checking session");
|
|
9170
9332
|
try {
|
|
9171
9333
|
const session = await fetchAuthorizationSession(apiBaseUrlRef.current, sessionId);
|
|
9172
9334
|
if (!guestTokenRef.current) return;
|
|
9173
|
-
if (session.status !== "AUTHORIZED")
|
|
9174
|
-
|
|
9335
|
+
if (session.status !== "AUTHORIZED") {
|
|
9336
|
+
console.info("[blink-sdk] useGuestAccountPolling.poll: session not AUTHORIZED yet", session.status);
|
|
9337
|
+
return;
|
|
9338
|
+
}
|
|
9339
|
+
} catch (sessionErr) {
|
|
9340
|
+
consecutiveFailuresRef.current += 1;
|
|
9341
|
+
console.info("[blink-sdk] useGuestAccountPolling.poll: session fetch failed", sessionErr);
|
|
9342
|
+
if (consecutiveFailuresRef.current >= 3) {
|
|
9343
|
+
setError(sessionErr instanceof Error ? sessionErr.message : "Failed to check authorization status");
|
|
9344
|
+
}
|
|
9175
9345
|
return;
|
|
9176
9346
|
}
|
|
9347
|
+
console.info("[blink-sdk] useGuestAccountPolling.poll: COMPLETE \u2014 account + AUTHORIZED");
|
|
9177
9348
|
setGuestAccount(lookup);
|
|
9178
9349
|
stopPolling();
|
|
9179
|
-
} catch {
|
|
9350
|
+
} catch (err) {
|
|
9351
|
+
consecutiveFailuresRef.current += 1;
|
|
9352
|
+
console.info("[blink-sdk] useGuestAccountPolling.poll: fetch error, will retry", err);
|
|
9353
|
+
if (consecutiveFailuresRef.current >= 3) {
|
|
9354
|
+
setError(err instanceof Error ? err.message : "Failed to check account status");
|
|
9355
|
+
}
|
|
9180
9356
|
}
|
|
9181
9357
|
}, [stopPolling]);
|
|
9182
9358
|
const startPolling = useCallback(
|
|
9183
9359
|
(guestToken, sessionId) => {
|
|
9360
|
+
console.info("[blink-sdk] useGuestAccountPolling.startPolling called", {
|
|
9361
|
+
tokenPrefix: guestToken.slice(0, 8),
|
|
9362
|
+
sessionId: sessionId ?? "(none \u2014 account-only mode)",
|
|
9363
|
+
intervalMs
|
|
9364
|
+
});
|
|
9184
9365
|
stopPolling();
|
|
9185
9366
|
guestTokenRef.current = guestToken;
|
|
9186
|
-
sessionIdRef.current = sessionId;
|
|
9367
|
+
sessionIdRef.current = sessionId ?? null;
|
|
9187
9368
|
setGuestAccount(null);
|
|
9369
|
+
setError(null);
|
|
9370
|
+
consecutiveFailuresRef.current = 0;
|
|
9188
9371
|
setIsPolling(true);
|
|
9189
9372
|
poll();
|
|
9190
9373
|
intervalRef.current = setInterval(poll, intervalMs);
|
|
@@ -9193,11 +9376,22 @@ function useGuestAccountPolling(intervalMs = 3e3) {
|
|
|
9193
9376
|
);
|
|
9194
9377
|
useEffect(() => {
|
|
9195
9378
|
const handleVisibility = () => {
|
|
9379
|
+
console.info("[blink-sdk] useGuestAccountPolling: visibilitychange fired", {
|
|
9380
|
+
visibilityState: document.visibilityState,
|
|
9381
|
+
hasToken: !!guestTokenRef.current,
|
|
9382
|
+
hasSessionId: !!sessionIdRef.current
|
|
9383
|
+
});
|
|
9196
9384
|
if (document.visibilityState === "visible" && guestTokenRef.current) {
|
|
9197
9385
|
void poll();
|
|
9198
9386
|
}
|
|
9199
9387
|
};
|
|
9200
|
-
const handlePageShow = () => {
|
|
9388
|
+
const handlePageShow = (e) => {
|
|
9389
|
+
console.info("[blink-sdk] useGuestAccountPolling: pageshow fired", {
|
|
9390
|
+
persisted: e.persisted,
|
|
9391
|
+
visibilityState: document.visibilityState,
|
|
9392
|
+
hasToken: !!guestTokenRef.current,
|
|
9393
|
+
hasSessionId: !!sessionIdRef.current
|
|
9394
|
+
});
|
|
9201
9395
|
if (document.visibilityState === "visible" && guestTokenRef.current) {
|
|
9202
9396
|
void poll();
|
|
9203
9397
|
}
|
|
@@ -9210,7 +9404,7 @@ function useGuestAccountPolling(intervalMs = 3e3) {
|
|
|
9210
9404
|
};
|
|
9211
9405
|
}, [poll]);
|
|
9212
9406
|
useEffect(() => () => stopPolling(), [stopPolling]);
|
|
9213
|
-
return { guestAccount, isPolling, startPolling, stopPolling };
|
|
9407
|
+
return { guestAccount, error, isPolling, startPolling, stopPolling };
|
|
9214
9408
|
}
|
|
9215
9409
|
function BlinkPayment(props) {
|
|
9216
9410
|
const resetKey = useRef(0);
|
|
@@ -9293,6 +9487,12 @@ function BlinkPaymentInner({
|
|
|
9293
9487
|
transfer.pollingTransferIdRef,
|
|
9294
9488
|
state.transfer,
|
|
9295
9489
|
mobileFlowRefs,
|
|
9490
|
+
{
|
|
9491
|
+
mobileFlow: state.mobileFlow,
|
|
9492
|
+
isGuestFlow: state.isGuestFlow,
|
|
9493
|
+
guestTransferId: state.guestTransferId,
|
|
9494
|
+
guestSessionToken: state.guestSessionToken
|
|
9495
|
+
},
|
|
9296
9496
|
onComplete
|
|
9297
9497
|
);
|
|
9298
9498
|
const sourceSelection = useSourceSelectionHandlers(dispatch, authExecutor, {
|
|
@@ -9397,10 +9597,50 @@ function BlinkPaymentInner({
|
|
|
9397
9597
|
setupAccountIdRef: mobileFlowRefs.setupAccountIdRef,
|
|
9398
9598
|
startGuestAccountPolling: guestAccountPolling.startPolling
|
|
9399
9599
|
});
|
|
9600
|
+
useGuestAccountAutoPollingEffect({
|
|
9601
|
+
mobileFlow: state.mobileFlow,
|
|
9602
|
+
isGuestFlow: state.isGuestFlow,
|
|
9603
|
+
guestSessionToken: state.guestSessionToken,
|
|
9604
|
+
isPolling: guestAccountPolling.isPolling,
|
|
9605
|
+
guestAccount: guestAccountPolling.guestAccount,
|
|
9606
|
+
startPolling: guestAccountPolling.startPolling
|
|
9607
|
+
});
|
|
9608
|
+
const guestSessionTokenRef = useRef(state.guestSessionToken);
|
|
9609
|
+
guestSessionTokenRef.current = state.guestSessionToken;
|
|
9610
|
+
const guestPreauthSessionIdRef = useRef(state.guestPreauthSessionId);
|
|
9611
|
+
guestPreauthSessionIdRef.current = state.guestPreauthSessionId;
|
|
9612
|
+
useEffect(() => {
|
|
9613
|
+
const handleVisibility = () => {
|
|
9614
|
+
if (document.visibilityState !== "visible") return;
|
|
9615
|
+
const token = guestSessionTokenRef.current;
|
|
9616
|
+
const sessionId = guestPreauthSessionIdRef.current;
|
|
9617
|
+
if (!token) return;
|
|
9618
|
+
if (guestAccountPolling.isPolling || guestAccountPolling.guestAccount) return;
|
|
9619
|
+
console.info("[blink-sdk] warm-return: restarting guest account polling from React state", {
|
|
9620
|
+
sessionId: sessionId ?? "(none \u2014 account-only mode)"
|
|
9621
|
+
});
|
|
9622
|
+
guestAccountPolling.startPolling(token, sessionId ?? void 0);
|
|
9623
|
+
};
|
|
9624
|
+
document.addEventListener("visibilitychange", handleVisibility);
|
|
9625
|
+
return () => document.removeEventListener("visibilitychange", handleVisibility);
|
|
9626
|
+
}, [guestAccountPolling.isPolling, guestAccountPolling.guestAccount, guestAccountPolling.startPolling]);
|
|
9400
9627
|
useEffect(() => {
|
|
9628
|
+
console.info("[blink-sdk] guestPreauthCompletion effect", {
|
|
9629
|
+
hasGuestAccount: !!guestAccountPolling.guestAccount,
|
|
9630
|
+
guestAccountId: guestAccountPolling.guestAccount?.accountId ?? null,
|
|
9631
|
+
currentPreauthAccountId: state.guestPreauthAccountId,
|
|
9632
|
+
currentPhase: state.phase.step,
|
|
9633
|
+
mobileFlow: state.mobileFlow,
|
|
9634
|
+
loginRequested: state.loginRequested
|
|
9635
|
+
});
|
|
9401
9636
|
if (!guestAccountPolling.guestAccount) return;
|
|
9402
9637
|
const acct = guestAccountPolling.guestAccount;
|
|
9403
|
-
|
|
9638
|
+
const needsDetect = acct.accountId !== state.guestPreauthAccountId;
|
|
9639
|
+
console.info("[blink-sdk] guestPreauthCompletion: dispatching REQUEST_LOGIN + MOBILE_SETUP_COMPLETE", {
|
|
9640
|
+
accountId: acct.accountId,
|
|
9641
|
+
dispatchingGuestPreauthDetected: needsDetect
|
|
9642
|
+
});
|
|
9643
|
+
if (needsDetect) {
|
|
9404
9644
|
dispatch({
|
|
9405
9645
|
type: "GUEST_PREAUTH_DETECTED",
|
|
9406
9646
|
accountId: acct.accountId,
|
|
@@ -9442,7 +9682,8 @@ function BlinkPaymentInner({
|
|
|
9442
9682
|
reauthTokenRef: mobileFlowRefs.reauthTokenRef,
|
|
9443
9683
|
pollingTransferIdRef: transfer.pollingTransferIdRef,
|
|
9444
9684
|
handleAuthorizedMobileReturn: mobileFlow.handleAuthorizedMobileReturn,
|
|
9445
|
-
onComplete
|
|
9685
|
+
onComplete,
|
|
9686
|
+
startGuestAccountPolling: guestAccountPolling.startPolling
|
|
9446
9687
|
});
|
|
9447
9688
|
useDataLoadEffect({
|
|
9448
9689
|
state,
|
|
@@ -9589,6 +9830,7 @@ function BlinkPaymentInner({
|
|
|
9589
9830
|
remote: {
|
|
9590
9831
|
pollingTransfer: polling.transfer,
|
|
9591
9832
|
pollingError: polling.error,
|
|
9833
|
+
guestAccountPollingError: guestAccountPolling.error,
|
|
9592
9834
|
authExecutorError: authExecutor.error,
|
|
9593
9835
|
transferSigningSigning: transferSigning.signing,
|
|
9594
9836
|
transferSigningError: transferSigning.error,
|