@swype-org/react-sdk 0.1.272 → 0.1.277

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.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":
@@ -7196,7 +7260,7 @@ function useSourceSelectionHandlers(dispatch, authExecutor, options) {
7196
7260
  initializedSelectSourceActionRef
7197
7261
  };
7198
7262
  }
7199
- function useMobileFlowHandlers(dispatch, polling, reloadAccounts, pollingTransferIdRef, stateTransfer, refs, onComplete) {
7263
+ function useMobileFlowHandlers(dispatch, polling, reloadAccounts, pollingTransferIdRef, stateTransfer, refs, guestCheckout, onComplete) {
7200
7264
  const {
7201
7265
  mobileSetupFlowRef,
7202
7266
  handlingMobileReturnRef,
@@ -7207,6 +7271,10 @@ function useMobileFlowHandlers(dispatch, polling, reloadAccounts, pollingTransfe
7207
7271
  onCompleteRef.current = onComplete;
7208
7272
  const guestPollingActiveRef = useRef(false);
7209
7273
  const guestPollingCleanupRef = useRef(null);
7274
+ const guestTransferIdRef = useRef(guestCheckout.guestTransferId);
7275
+ guestTransferIdRef.current = guestCheckout.guestTransferId;
7276
+ const guestSessionTokenRef = useRef(guestCheckout.guestSessionToken);
7277
+ guestSessionTokenRef.current = guestCheckout.guestSessionToken;
7210
7278
  const startGuestPolling = useCallback((transferId, guestSessionToken) => {
7211
7279
  if (guestPollingActiveRef.current) return;
7212
7280
  guestPollingActiveRef.current = true;
@@ -7222,14 +7290,12 @@ function useMobileFlowHandlers(dispatch, polling, reloadAccounts, pollingTransfe
7222
7290
  cancelled = true;
7223
7291
  guestPollingActiveRef.current = false;
7224
7292
  guestPollingCleanupRef.current = null;
7225
- clearMobileFlowState();
7226
7293
  dispatch({ type: "GUEST_TRANSFER_COMPLETED", transfer, guestSessionToken });
7227
7294
  onCompleteRef.current?.(transfer);
7228
7295
  } else if (transfer.status === "FAILED") {
7229
7296
  cancelled = true;
7230
7297
  guestPollingActiveRef.current = false;
7231
7298
  guestPollingCleanupRef.current = null;
7232
- clearMobileFlowState();
7233
7299
  dispatch({ type: "TRANSFER_FAILED", transfer, error: "Transfer failed." });
7234
7300
  }
7235
7301
  } catch {
@@ -7246,20 +7312,26 @@ function useMobileFlowHandlers(dispatch, polling, reloadAccounts, pollingTransfe
7246
7312
  guestPollingCleanupRef.current = cleanup;
7247
7313
  }, [apiBaseUrl, dispatch]);
7248
7314
  useEffect(() => {
7249
- const persisted = loadMobileFlowState();
7250
- if (persisted?.isGuestCheckout && persisted.transferId && persisted.guestSessionToken) {
7251
- startGuestPolling(persisted.transferId, persisted.guestSessionToken);
7315
+ if (guestCheckout.mobileFlow && guestCheckout.isGuestFlow && guestCheckout.guestTransferId && guestCheckout.guestSessionToken) {
7316
+ startGuestPolling(guestCheckout.guestTransferId, guestCheckout.guestSessionToken);
7252
7317
  }
7253
7318
  return () => {
7254
7319
  guestPollingCleanupRef.current?.();
7255
7320
  };
7256
- }, [startGuestPolling]);
7321
+ }, [
7322
+ guestCheckout.mobileFlow,
7323
+ guestCheckout.isGuestFlow,
7324
+ guestCheckout.guestTransferId,
7325
+ guestCheckout.guestSessionToken,
7326
+ startGuestPolling
7327
+ ]);
7257
7328
  useEffect(() => {
7258
7329
  const tryStartPolling = () => {
7259
7330
  if (guestPollingActiveRef.current) return;
7260
- const persisted = loadMobileFlowState();
7261
- if (persisted?.isGuestCheckout && persisted.transferId && persisted.guestSessionToken) {
7262
- startGuestPolling(persisted.transferId, persisted.guestSessionToken);
7331
+ const transferId = guestTransferIdRef.current;
7332
+ const token = guestSessionTokenRef.current;
7333
+ if (transferId && token) {
7334
+ startGuestPolling(transferId, token);
7263
7335
  }
7264
7336
  };
7265
7337
  const handleVisibility = () => {
@@ -7403,16 +7475,13 @@ function useProviderHandlers(deps) {
7403
7475
  dispatch({ type: "PAY_ERROR", error: "This wallet is not available on mobile." });
7404
7476
  return;
7405
7477
  }
7406
- persistMobileFlowState({
7407
- transferId: result.id,
7408
- guestSessionToken: result.guestSessionToken,
7409
- isGuestCheckout: true,
7478
+ triggerDeeplink(result.uri);
7479
+ dispatch({
7480
+ type: "MOBILE_DEEPLINK_READY",
7410
7481
  deeplinkUri: result.uri,
7411
- providerId,
7412
- isSetup: false
7482
+ guestTransferId: result.id,
7483
+ guestSessionToken: result.guestSessionToken
7413
7484
  });
7414
- triggerDeeplink(result.uri);
7415
- dispatch({ type: "MOBILE_DEEPLINK_READY", deeplinkUri: result.uri });
7416
7485
  } else {
7417
7486
  const account = getAccount(wagmiConfig2);
7418
7487
  if (!account.isConnected) {
@@ -7748,6 +7817,14 @@ function useProviderHandlers(deps) {
7748
7817
  useWalletConnector: useWalletConnectorProp,
7749
7818
  userAgent: typeof navigator === "undefined" ? void 0 : navigator.userAgent
7750
7819
  });
7820
+ console.info("[blink-sdk] handlePreauthorize", {
7821
+ isMobile,
7822
+ useWalletConnectorProp,
7823
+ hasGuestSessionToken: !!guestSessionToken,
7824
+ selectedProviderId,
7825
+ guestTransferId,
7826
+ userAgent: typeof navigator === "undefined" ? null : navigator.userAgent
7827
+ });
7751
7828
  const providerName = providers.find((p) => p.id === selectedProviderId)?.name ?? "Wallet";
7752
7829
  if (!isMobile) {
7753
7830
  dispatch({ type: "GUEST_PREAUTH_BEGIN" });
@@ -8169,7 +8246,8 @@ function usePasskeyCheckEffect(deps) {
8169
8246
  setupAccountIdRef,
8170
8247
  reauthSessionIdRef,
8171
8248
  reauthTokenRef,
8172
- pollingTransferIdRef
8249
+ pollingTransferIdRef,
8250
+ startGuestAccountPolling
8173
8251
  } = deps;
8174
8252
  const { getAccessToken } = usePrivy();
8175
8253
  const onCompleteRef = useRef(deps.onComplete);
@@ -8192,8 +8270,23 @@ function usePasskeyCheckEffect(deps) {
8192
8270
  dispatch({ type: "SET_ERROR", error: null });
8193
8271
  setAuthInput("");
8194
8272
  setOtpCode("");
8273
+ const startGuestAccountPollingRef = startGuestAccountPolling;
8195
8274
  const restoreState = async (credId, token) => {
8196
8275
  const persisted = loadMobileFlowState();
8276
+ if (persisted?.isGuestPreauth && persisted.guestSessionToken && persisted.sessionId) {
8277
+ mobileSetupFlowRef.current = true;
8278
+ if (persisted.accountId) {
8279
+ setupAccountIdRef.current = persisted.accountId;
8280
+ dispatch({
8281
+ type: "GUEST_PREAUTH_DETECTED",
8282
+ accountId: persisted.accountId,
8283
+ sessionId: persisted.sessionId
8284
+ });
8285
+ }
8286
+ dispatch({ type: "MOBILE_DEEPLINK_READY", deeplinkUri: persisted.deeplinkUri });
8287
+ startGuestAccountPollingRef(persisted.guestSessionToken, persisted.sessionId);
8288
+ return;
8289
+ }
8197
8290
  let accts = [];
8198
8291
  try {
8199
8292
  accts = await fetchAccounts(apiBaseUrl, token, credId);
@@ -8842,10 +8935,24 @@ function useGuestPreauthMobileRestoreEffect(deps) {
8842
8935
  } = deps;
8843
8936
  const startedRef = useRef(false);
8844
8937
  useEffect(() => {
8845
- if (!privyReady) return;
8846
- const tryStart = () => {
8847
- if (startedRef.current) return;
8938
+ if (!privyReady) {
8939
+ console.info("[blink-sdk] guestPreauthMobileRestore: skipping, privyReady=false");
8940
+ return;
8941
+ }
8942
+ const tryStart = (trigger) => {
8943
+ if (startedRef.current) {
8944
+ console.info("[blink-sdk] guestPreauthMobileRestore.tryStart: already started", { trigger });
8945
+ return;
8946
+ }
8848
8947
  const persisted = loadMobileFlowState();
8948
+ console.info("[blink-sdk] guestPreauthMobileRestore.tryStart", {
8949
+ trigger,
8950
+ hasPersistedState: !!persisted,
8951
+ isGuestPreauth: persisted?.isGuestPreauth ?? false,
8952
+ hasGuestSessionToken: !!persisted?.guestSessionToken,
8953
+ hasSessionId: !!persisted?.sessionId,
8954
+ accountId: persisted?.accountId ?? null
8955
+ });
8849
8956
  if (!persisted?.isGuestPreauth || !persisted.guestSessionToken || !persisted.sessionId) {
8850
8957
  return;
8851
8958
  }
@@ -8865,15 +8972,28 @@ function useGuestPreauthMobileRestoreEffect(deps) {
8865
8972
  type: "MOBILE_DEEPLINK_READY",
8866
8973
  deeplinkUri: persisted.deeplinkUri
8867
8974
  });
8975
+ console.info("[blink-sdk] guestPreauthMobileRestore: starting guest account polling", {
8976
+ trigger,
8977
+ sessionId: persisted.sessionId
8978
+ });
8868
8979
  startGuestAccountPolling(persisted.guestSessionToken, persisted.sessionId);
8869
8980
  };
8870
8981
  const onVisibility = () => {
8871
- if (document.visibilityState === "visible") tryStart();
8982
+ console.info("[blink-sdk] guestPreauthMobileRestore: visibilitychange fired", {
8983
+ visibilityState: document.visibilityState,
8984
+ startedRef: startedRef.current
8985
+ });
8986
+ if (document.visibilityState === "visible") tryStart("visibilitychange");
8872
8987
  };
8873
- const onPageShow = () => {
8874
- if (document.visibilityState === "visible") tryStart();
8988
+ const onPageShow = (e) => {
8989
+ console.info("[blink-sdk] guestPreauthMobileRestore: pageshow fired", {
8990
+ persisted: e.persisted,
8991
+ visibilityState: document.visibilityState,
8992
+ startedRef: startedRef.current
8993
+ });
8994
+ if (document.visibilityState === "visible") tryStart("pageshow");
8875
8995
  };
8876
- tryStart();
8996
+ tryStart("initial");
8877
8997
  document.addEventListener("visibilitychange", onVisibility);
8878
8998
  window.addEventListener("pageshow", onPageShow);
8879
8999
  return () => {
@@ -9151,6 +9271,10 @@ function useGuestAccountPolling(intervalMs = 3e3) {
9151
9271
  const apiBaseUrlRef = useRef(apiBaseUrl);
9152
9272
  apiBaseUrlRef.current = apiBaseUrl;
9153
9273
  const stopPolling = useCallback(() => {
9274
+ console.info("[blink-sdk] useGuestAccountPolling.stopPolling called", {
9275
+ hadInterval: !!intervalRef.current,
9276
+ hadToken: !!guestTokenRef.current
9277
+ });
9154
9278
  if (intervalRef.current) {
9155
9279
  clearInterval(intervalRef.current);
9156
9280
  intervalRef.current = null;
@@ -9162,25 +9286,51 @@ function useGuestAccountPolling(intervalMs = 3e3) {
9162
9286
  const poll = useCallback(async () => {
9163
9287
  const token = guestTokenRef.current;
9164
9288
  const sessionId = sessionIdRef.current;
9165
- if (!token || !sessionId) return;
9289
+ if (!token || !sessionId) {
9290
+ console.info("[blink-sdk] useGuestAccountPolling.poll skipped (no token or sessionId)", {
9291
+ hasToken: !!token,
9292
+ hasSessionId: !!sessionId
9293
+ });
9294
+ return;
9295
+ }
9296
+ console.info("[blink-sdk] useGuestAccountPolling.poll executing", {
9297
+ apiBaseUrl: apiBaseUrlRef.current,
9298
+ tokenPrefix: token.slice(0, 8),
9299
+ sessionId
9300
+ });
9166
9301
  try {
9167
9302
  const lookup = await fetchGuestAccount(apiBaseUrlRef.current, token);
9168
9303
  if (!guestTokenRef.current) return;
9169
- if (lookup == null) return;
9304
+ if (lookup == null) {
9305
+ console.info("[blink-sdk] useGuestAccountPolling.poll: account not found yet");
9306
+ return;
9307
+ }
9308
+ console.info("[blink-sdk] useGuestAccountPolling.poll: account found, checking session");
9170
9309
  try {
9171
9310
  const session = await fetchAuthorizationSession(apiBaseUrlRef.current, sessionId);
9172
9311
  if (!guestTokenRef.current) return;
9173
- if (session.status !== "AUTHORIZED") return;
9174
- } catch {
9312
+ if (session.status !== "AUTHORIZED") {
9313
+ console.info("[blink-sdk] useGuestAccountPolling.poll: session not AUTHORIZED yet", session.status);
9314
+ return;
9315
+ }
9316
+ } catch (err) {
9317
+ console.info("[blink-sdk] useGuestAccountPolling.poll: session fetch failed", err);
9175
9318
  return;
9176
9319
  }
9320
+ console.info("[blink-sdk] useGuestAccountPolling.poll: COMPLETE \u2014 account + AUTHORIZED");
9177
9321
  setGuestAccount(lookup);
9178
9322
  stopPolling();
9179
- } catch {
9323
+ } catch (err) {
9324
+ console.info("[blink-sdk] useGuestAccountPolling.poll: fetch error, will retry", err);
9180
9325
  }
9181
9326
  }, [stopPolling]);
9182
9327
  const startPolling = useCallback(
9183
9328
  (guestToken, sessionId) => {
9329
+ console.info("[blink-sdk] useGuestAccountPolling.startPolling called", {
9330
+ tokenPrefix: guestToken.slice(0, 8),
9331
+ sessionId,
9332
+ intervalMs
9333
+ });
9184
9334
  stopPolling();
9185
9335
  guestTokenRef.current = guestToken;
9186
9336
  sessionIdRef.current = sessionId;
@@ -9193,11 +9343,22 @@ function useGuestAccountPolling(intervalMs = 3e3) {
9193
9343
  );
9194
9344
  useEffect(() => {
9195
9345
  const handleVisibility = () => {
9346
+ console.info("[blink-sdk] useGuestAccountPolling: visibilitychange fired", {
9347
+ visibilityState: document.visibilityState,
9348
+ hasToken: !!guestTokenRef.current,
9349
+ hasSessionId: !!sessionIdRef.current
9350
+ });
9196
9351
  if (document.visibilityState === "visible" && guestTokenRef.current) {
9197
9352
  void poll();
9198
9353
  }
9199
9354
  };
9200
- const handlePageShow = () => {
9355
+ const handlePageShow = (e) => {
9356
+ console.info("[blink-sdk] useGuestAccountPolling: pageshow fired", {
9357
+ persisted: e.persisted,
9358
+ visibilityState: document.visibilityState,
9359
+ hasToken: !!guestTokenRef.current,
9360
+ hasSessionId: !!sessionIdRef.current
9361
+ });
9201
9362
  if (document.visibilityState === "visible" && guestTokenRef.current) {
9202
9363
  void poll();
9203
9364
  }
@@ -9293,6 +9454,12 @@ function BlinkPaymentInner({
9293
9454
  transfer.pollingTransferIdRef,
9294
9455
  state.transfer,
9295
9456
  mobileFlowRefs,
9457
+ {
9458
+ mobileFlow: state.mobileFlow,
9459
+ isGuestFlow: state.isGuestFlow,
9460
+ guestTransferId: state.guestTransferId,
9461
+ guestSessionToken: state.guestSessionToken
9462
+ },
9296
9463
  onComplete
9297
9464
  );
9298
9465
  const sourceSelection = useSourceSelectionHandlers(dispatch, authExecutor, {
@@ -9398,9 +9565,22 @@ function BlinkPaymentInner({
9398
9565
  startGuestAccountPolling: guestAccountPolling.startPolling
9399
9566
  });
9400
9567
  useEffect(() => {
9568
+ console.info("[blink-sdk] guestPreauthCompletion effect", {
9569
+ hasGuestAccount: !!guestAccountPolling.guestAccount,
9570
+ guestAccountId: guestAccountPolling.guestAccount?.accountId ?? null,
9571
+ currentPreauthAccountId: state.guestPreauthAccountId,
9572
+ currentPhase: state.phase.step,
9573
+ mobileFlow: state.mobileFlow,
9574
+ loginRequested: state.loginRequested
9575
+ });
9401
9576
  if (!guestAccountPolling.guestAccount) return;
9402
9577
  const acct = guestAccountPolling.guestAccount;
9403
- if (acct.accountId !== state.guestPreauthAccountId) {
9578
+ const needsDetect = acct.accountId !== state.guestPreauthAccountId;
9579
+ console.info("[blink-sdk] guestPreauthCompletion: dispatching REQUEST_LOGIN + MOBILE_SETUP_COMPLETE", {
9580
+ accountId: acct.accountId,
9581
+ dispatchingGuestPreauthDetected: needsDetect
9582
+ });
9583
+ if (needsDetect) {
9404
9584
  dispatch({
9405
9585
  type: "GUEST_PREAUTH_DETECTED",
9406
9586
  accountId: acct.accountId,
@@ -9442,7 +9622,8 @@ function BlinkPaymentInner({
9442
9622
  reauthTokenRef: mobileFlowRefs.reauthTokenRef,
9443
9623
  pollingTransferIdRef: transfer.pollingTransferIdRef,
9444
9624
  handleAuthorizedMobileReturn: mobileFlow.handleAuthorizedMobileReturn,
9445
- onComplete
9625
+ onComplete,
9626
+ startGuestAccountPolling: guestAccountPolling.startPolling
9446
9627
  });
9447
9628
  useDataLoadEffect({
9448
9629
  state,