@swype-org/react-sdk 0.1.224 → 0.1.226

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 CHANGED
@@ -459,7 +459,6 @@ async function waitForTransactionReceipt(config, parameters) {
459
459
  // src/api.ts
460
460
  var api_exports = {};
461
461
  __export(api_exports, {
462
- claimAccount: () => claimAccount,
463
462
  createAccount: () => createAccount,
464
463
  createAccountAuthorizationSession: () => createAccountAuthorizationSession,
465
464
  createGuestTransfer: () => createGuestTransfer,
@@ -479,6 +478,7 @@ __export(api_exports, {
479
478
  registerPasskey: () => registerPasskey,
480
479
  reportActionCompletion: () => reportActionCompletion,
481
480
  reportPasskeyActivity: () => reportPasskeyActivity,
481
+ setAccountOwner: () => setAccountOwner,
482
482
  setTransferSender: () => setTransferSender,
483
483
  signGuestTransfer: () => signGuestTransfer,
484
484
  signTransfer: () => signTransfer,
@@ -776,12 +776,13 @@ async function fetchGuestPreauthAccount(apiBaseUrl, guestToken) {
776
776
  if (!res.ok) await throwApiError(res);
777
777
  return await res.json();
778
778
  }
779
- async function claimAccount(apiBaseUrl, accessToken, accountId, body) {
780
- const res = await fetch(`${apiBaseUrl}/v1/accounts/${accountId}/claim`, {
781
- method: "POST",
779
+ async function setAccountOwner(apiBaseUrl, accessToken, accountId, guestSessionToken, body) {
780
+ const res = await fetch(`${apiBaseUrl}/v1/accounts/${accountId}/owner`, {
781
+ method: "PUT",
782
782
  headers: {
783
783
  "Content-Type": "application/json",
784
- "Authorization": `Bearer ${accessToken}`
784
+ "Authorization": `Bearer ${accessToken}`,
785
+ "x-guest-session-token": guestSessionToken
785
786
  },
786
787
  body: JSON.stringify(body)
787
788
  });
@@ -2217,7 +2218,7 @@ function paymentReducer(state, action) {
2217
2218
  guestPreauthAccountId: action.accountId,
2218
2219
  step: "login"
2219
2220
  };
2220
- case "GUEST_PREAUTH_CLAIMED":
2221
+ case "ACCOUNT_OWNER_SET":
2221
2222
  return {
2222
2223
  ...state,
2223
2224
  guestPreauthAccountId: null,
@@ -6820,13 +6821,10 @@ function useMobileFlowHandlers(dispatch, polling, reloadAccounts, pollingTransfe
6820
6821
  const onCompleteRef = react.useRef(onComplete);
6821
6822
  onCompleteRef.current = onComplete;
6822
6823
  const guestPollingActiveRef = react.useRef(false);
6823
- react.useEffect(() => {
6824
- const persisted = loadMobileFlowState();
6825
- if (!persisted?.isGuestCheckout || !persisted.transferId || !persisted.guestSessionToken) return;
6824
+ const guestPollingCleanupRef = react.useRef(null);
6825
+ const startGuestPolling = react.useCallback((transferId, guestSessionToken) => {
6826
6826
  if (guestPollingActiveRef.current) return;
6827
6827
  guestPollingActiveRef.current = true;
6828
- const transferId = persisted.transferId;
6829
- const guestSessionToken = persisted.guestSessionToken;
6830
6828
  let cancelled = false;
6831
6829
  const POLL_INTERVAL_MS = 3e3;
6832
6830
  dispatch({ type: "NAVIGATE", step: "processing" });
@@ -6838,12 +6836,14 @@ function useMobileFlowHandlers(dispatch, polling, reloadAccounts, pollingTransfe
6838
6836
  if (transfer.status === "COMPLETED") {
6839
6837
  cancelled = true;
6840
6838
  guestPollingActiveRef.current = false;
6839
+ guestPollingCleanupRef.current = null;
6841
6840
  clearMobileFlowState();
6842
6841
  dispatch({ type: "GUEST_TRANSFER_COMPLETED", transfer, guestSessionToken });
6843
6842
  onCompleteRef.current?.(transfer);
6844
6843
  } else if (transfer.status === "FAILED") {
6845
6844
  cancelled = true;
6846
6845
  guestPollingActiveRef.current = false;
6846
+ guestPollingCleanupRef.current = null;
6847
6847
  clearMobileFlowState();
6848
6848
  dispatch({ type: "TRANSFER_FAILED", transfer, error: "Transfer failed." });
6849
6849
  }
@@ -6852,26 +6852,44 @@ function useMobileFlowHandlers(dispatch, polling, reloadAccounts, pollingTransfe
6852
6852
  };
6853
6853
  poll();
6854
6854
  const intervalId = window.setInterval(poll, POLL_INTERVAL_MS);
6855
- const handleVisibility = () => {
6856
- if (document.visibilityState === "visible" && !cancelled) {
6857
- poll();
6855
+ const cleanup = () => {
6856
+ cancelled = true;
6857
+ guestPollingActiveRef.current = false;
6858
+ guestPollingCleanupRef.current = null;
6859
+ window.clearInterval(intervalId);
6860
+ };
6861
+ guestPollingCleanupRef.current = cleanup;
6862
+ }, [apiBaseUrl, dispatch]);
6863
+ react.useEffect(() => {
6864
+ const persisted = loadMobileFlowState();
6865
+ if (persisted?.isGuestCheckout && persisted.transferId && persisted.guestSessionToken) {
6866
+ startGuestPolling(persisted.transferId, persisted.guestSessionToken);
6867
+ }
6868
+ return () => {
6869
+ guestPollingCleanupRef.current?.();
6870
+ };
6871
+ }, [startGuestPolling]);
6872
+ react.useEffect(() => {
6873
+ const tryStartPolling = () => {
6874
+ if (guestPollingActiveRef.current) return;
6875
+ const persisted = loadMobileFlowState();
6876
+ if (persisted?.isGuestCheckout && persisted.transferId && persisted.guestSessionToken) {
6877
+ startGuestPolling(persisted.transferId, persisted.guestSessionToken);
6858
6878
  }
6859
6879
  };
6880
+ const handleVisibility = () => {
6881
+ if (document.visibilityState === "visible") tryStartPolling();
6882
+ };
6860
6883
  const handlePageShow = (e) => {
6861
- if (e.persisted && !cancelled) {
6862
- poll();
6863
- }
6884
+ if (e.persisted) tryStartPolling();
6864
6885
  };
6865
6886
  document.addEventListener("visibilitychange", handleVisibility);
6866
6887
  window.addEventListener("pageshow", handlePageShow);
6867
6888
  return () => {
6868
- cancelled = true;
6869
- guestPollingActiveRef.current = false;
6870
- window.clearInterval(intervalId);
6871
6889
  document.removeEventListener("visibilitychange", handleVisibility);
6872
6890
  window.removeEventListener("pageshow", handlePageShow);
6873
6891
  };
6874
- }, [apiBaseUrl, dispatch]);
6892
+ }, [startGuestPolling]);
6875
6893
  const handleAuthorizedMobileReturn = react.useCallback(async (authorizedTransfer, isSetup) => {
6876
6894
  if (handlingMobileReturnRef.current) return;
6877
6895
  handlingMobileReturnRef.current = true;
@@ -8327,22 +8345,21 @@ function usePaymentEffects(deps) {
8327
8345
  cancelled = true;
8328
8346
  };
8329
8347
  }, [state.step, state.guestSessionToken, state.guestPreauthAccountId, apiBaseUrl, dispatch]);
8330
- const claimingRef = react.useRef(false);
8348
+ const settingOwnerRef = react.useRef(false);
8331
8349
  react.useEffect(() => {
8332
8350
  if (!state.guestPreauthAccountId) return;
8333
8351
  if (!state.activeCredentialId) return;
8334
8352
  if (!state.activePublicKey) return;
8335
8353
  if (!authenticated) return;
8336
8354
  if (!state.guestSessionToken) return;
8337
- if (claimingRef.current) return;
8338
- claimingRef.current = true;
8355
+ if (settingOwnerRef.current) return;
8356
+ settingOwnerRef.current = true;
8339
8357
  let cancelled = false;
8340
- const claimPreauth = async () => {
8358
+ const setOwner = async () => {
8341
8359
  try {
8342
8360
  const token = await getAccessTokenRef.current();
8343
8361
  if (!token || cancelled) return;
8344
- await claimAccount(apiBaseUrl, token, state.guestPreauthAccountId, {
8345
- guestToken: state.guestSessionToken,
8362
+ await setAccountOwner(apiBaseUrl, token, state.guestPreauthAccountId, state.guestSessionToken, {
8346
8363
  credentialId: state.activeCredentialId,
8347
8364
  publicKey: state.activePublicKey
8348
8365
  });
@@ -8352,19 +8369,19 @@ function usePaymentEffects(deps) {
8352
8369
  } catch {
8353
8370
  }
8354
8371
  if (cancelled) return;
8355
- dispatch({ type: "GUEST_PREAUTH_CLAIMED" });
8372
+ dispatch({ type: "ACCOUNT_OWNER_SET" });
8356
8373
  } catch (err) {
8357
8374
  if (cancelled) return;
8358
8375
  captureException(err);
8359
8376
  dispatch({
8360
8377
  type: "SET_ERROR",
8361
- error: err instanceof Error ? err.message : "Failed to claim account"
8378
+ error: err instanceof Error ? err.message : "Failed to set account owner"
8362
8379
  });
8363
8380
  } finally {
8364
- claimingRef.current = false;
8381
+ settingOwnerRef.current = false;
8365
8382
  }
8366
8383
  };
8367
- claimPreauth();
8384
+ setOwner();
8368
8385
  return () => {
8369
8386
  cancelled = true;
8370
8387
  };