@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.d.cts CHANGED
@@ -453,8 +453,7 @@ declare function fetchGuestPreauthAccount(apiBaseUrl: string, guestToken: string
453
453
  hasPasskey: boolean;
454
454
  walletAddress: string | null;
455
455
  } | null>;
456
- declare function claimAccount(apiBaseUrl: string, accessToken: string, accountId: string, body: {
457
- guestToken: string;
456
+ declare function setAccountOwner(apiBaseUrl: string, accessToken: string, accountId: string, guestSessionToken: string, body: {
458
457
  credentialId: string;
459
458
  publicKey: string;
460
459
  }): Promise<{
@@ -468,7 +467,6 @@ type api_CreateGuestTransferParams = CreateGuestTransferParams;
468
467
  type api_CreateTransferParams = CreateTransferParams;
469
468
  type api_GuestBalanceOption = GuestBalanceOption;
470
469
  type api_GuestTransferResult = GuestTransferResult;
471
- declare const api_claimAccount: typeof claimAccount;
472
470
  declare const api_createAccount: typeof createAccount;
473
471
  declare const api_createAccountAuthorizationSession: typeof createAccountAuthorizationSession;
474
472
  declare const api_createGuestTransfer: typeof createGuestTransfer;
@@ -488,13 +486,14 @@ declare const api_getTransferByGuestToken: typeof getTransferByGuestToken;
488
486
  declare const api_registerPasskey: typeof registerPasskey;
489
487
  declare const api_reportActionCompletion: typeof reportActionCompletion;
490
488
  declare const api_reportPasskeyActivity: typeof reportPasskeyActivity;
489
+ declare const api_setAccountOwner: typeof setAccountOwner;
491
490
  declare const api_setTransferSender: typeof setTransferSender;
492
491
  declare const api_signGuestTransfer: typeof signGuestTransfer;
493
492
  declare const api_signTransfer: typeof signTransfer;
494
493
  declare const api_updateUserConfig: typeof updateUserConfig;
495
494
  declare const api_updateUserConfigBySession: typeof updateUserConfigBySession;
496
495
  declare namespace api {
497
- export { type api_CreateAccountParams as CreateAccountParams, type api_CreateGuestTransferParams as CreateGuestTransferParams, type api_CreateTransferParams as CreateTransferParams, type api_GuestBalanceOption as GuestBalanceOption, type api_GuestTransferResult as GuestTransferResult, api_claimAccount as claimAccount, api_createAccount as createAccount, api_createAccountAuthorizationSession as createAccountAuthorizationSession, api_createGuestTransfer as createGuestTransfer, api_createTransfer as createTransfer, api_fetchAccount as fetchAccount, api_fetchAccounts as fetchAccounts, api_fetchAuthorizationSession as fetchAuthorizationSession, api_fetchChains as fetchChains, api_fetchGuestPreauthAccount as fetchGuestPreauthAccount, api_fetchGuestTransferBalances as fetchGuestTransferBalances, api_fetchMerchantPublicKey as fetchMerchantPublicKey, api_fetchProviders as fetchProviders, api_fetchTransfer as fetchTransfer, api_fetchUserConfig as fetchUserConfig, api_getGuestTransfer as getGuestTransfer, api_getTransferByGuestToken as getTransferByGuestToken, api_registerPasskey as registerPasskey, api_reportActionCompletion as reportActionCompletion, api_reportPasskeyActivity as reportPasskeyActivity, api_setTransferSender as setTransferSender, api_signGuestTransfer as signGuestTransfer, api_signTransfer as signTransfer, api_updateUserConfig as updateUserConfig, api_updateUserConfigBySession as updateUserConfigBySession };
496
+ export { type api_CreateAccountParams as CreateAccountParams, type api_CreateGuestTransferParams as CreateGuestTransferParams, type api_CreateTransferParams as CreateTransferParams, type api_GuestBalanceOption as GuestBalanceOption, type api_GuestTransferResult as GuestTransferResult, api_createAccount as createAccount, api_createAccountAuthorizationSession as createAccountAuthorizationSession, api_createGuestTransfer as createGuestTransfer, api_createTransfer as createTransfer, api_fetchAccount as fetchAccount, api_fetchAccounts as fetchAccounts, api_fetchAuthorizationSession as fetchAuthorizationSession, api_fetchChains as fetchChains, api_fetchGuestPreauthAccount as fetchGuestPreauthAccount, api_fetchGuestTransferBalances as fetchGuestTransferBalances, api_fetchMerchantPublicKey as fetchMerchantPublicKey, api_fetchProviders as fetchProviders, api_fetchTransfer as fetchTransfer, api_fetchUserConfig as fetchUserConfig, api_getGuestTransfer as getGuestTransfer, api_getTransferByGuestToken as getTransferByGuestToken, api_registerPasskey as registerPasskey, api_reportActionCompletion as reportActionCompletion, api_reportPasskeyActivity as reportPasskeyActivity, api_setAccountOwner as setAccountOwner, api_setTransferSender as setTransferSender, api_signGuestTransfer as signGuestTransfer, api_signTransfer as signTransfer, api_updateUserConfig as updateUserConfig, api_updateUserConfigBySession as updateUserConfigBySession };
498
497
  }
499
498
 
500
499
  interface BlinkPaymentProps {
package/dist/index.d.ts CHANGED
@@ -453,8 +453,7 @@ declare function fetchGuestPreauthAccount(apiBaseUrl: string, guestToken: string
453
453
  hasPasskey: boolean;
454
454
  walletAddress: string | null;
455
455
  } | null>;
456
- declare function claimAccount(apiBaseUrl: string, accessToken: string, accountId: string, body: {
457
- guestToken: string;
456
+ declare function setAccountOwner(apiBaseUrl: string, accessToken: string, accountId: string, guestSessionToken: string, body: {
458
457
  credentialId: string;
459
458
  publicKey: string;
460
459
  }): Promise<{
@@ -468,7 +467,6 @@ type api_CreateGuestTransferParams = CreateGuestTransferParams;
468
467
  type api_CreateTransferParams = CreateTransferParams;
469
468
  type api_GuestBalanceOption = GuestBalanceOption;
470
469
  type api_GuestTransferResult = GuestTransferResult;
471
- declare const api_claimAccount: typeof claimAccount;
472
470
  declare const api_createAccount: typeof createAccount;
473
471
  declare const api_createAccountAuthorizationSession: typeof createAccountAuthorizationSession;
474
472
  declare const api_createGuestTransfer: typeof createGuestTransfer;
@@ -488,13 +486,14 @@ declare const api_getTransferByGuestToken: typeof getTransferByGuestToken;
488
486
  declare const api_registerPasskey: typeof registerPasskey;
489
487
  declare const api_reportActionCompletion: typeof reportActionCompletion;
490
488
  declare const api_reportPasskeyActivity: typeof reportPasskeyActivity;
489
+ declare const api_setAccountOwner: typeof setAccountOwner;
491
490
  declare const api_setTransferSender: typeof setTransferSender;
492
491
  declare const api_signGuestTransfer: typeof signGuestTransfer;
493
492
  declare const api_signTransfer: typeof signTransfer;
494
493
  declare const api_updateUserConfig: typeof updateUserConfig;
495
494
  declare const api_updateUserConfigBySession: typeof updateUserConfigBySession;
496
495
  declare namespace api {
497
- export { type api_CreateAccountParams as CreateAccountParams, type api_CreateGuestTransferParams as CreateGuestTransferParams, type api_CreateTransferParams as CreateTransferParams, type api_GuestBalanceOption as GuestBalanceOption, type api_GuestTransferResult as GuestTransferResult, api_claimAccount as claimAccount, api_createAccount as createAccount, api_createAccountAuthorizationSession as createAccountAuthorizationSession, api_createGuestTransfer as createGuestTransfer, api_createTransfer as createTransfer, api_fetchAccount as fetchAccount, api_fetchAccounts as fetchAccounts, api_fetchAuthorizationSession as fetchAuthorizationSession, api_fetchChains as fetchChains, api_fetchGuestPreauthAccount as fetchGuestPreauthAccount, api_fetchGuestTransferBalances as fetchGuestTransferBalances, api_fetchMerchantPublicKey as fetchMerchantPublicKey, api_fetchProviders as fetchProviders, api_fetchTransfer as fetchTransfer, api_fetchUserConfig as fetchUserConfig, api_getGuestTransfer as getGuestTransfer, api_getTransferByGuestToken as getTransferByGuestToken, api_registerPasskey as registerPasskey, api_reportActionCompletion as reportActionCompletion, api_reportPasskeyActivity as reportPasskeyActivity, api_setTransferSender as setTransferSender, api_signGuestTransfer as signGuestTransfer, api_signTransfer as signTransfer, api_updateUserConfig as updateUserConfig, api_updateUserConfigBySession as updateUserConfigBySession };
496
+ export { type api_CreateAccountParams as CreateAccountParams, type api_CreateGuestTransferParams as CreateGuestTransferParams, type api_CreateTransferParams as CreateTransferParams, type api_GuestBalanceOption as GuestBalanceOption, type api_GuestTransferResult as GuestTransferResult, api_createAccount as createAccount, api_createAccountAuthorizationSession as createAccountAuthorizationSession, api_createGuestTransfer as createGuestTransfer, api_createTransfer as createTransfer, api_fetchAccount as fetchAccount, api_fetchAccounts as fetchAccounts, api_fetchAuthorizationSession as fetchAuthorizationSession, api_fetchChains as fetchChains, api_fetchGuestPreauthAccount as fetchGuestPreauthAccount, api_fetchGuestTransferBalances as fetchGuestTransferBalances, api_fetchMerchantPublicKey as fetchMerchantPublicKey, api_fetchProviders as fetchProviders, api_fetchTransfer as fetchTransfer, api_fetchUserConfig as fetchUserConfig, api_getGuestTransfer as getGuestTransfer, api_getTransferByGuestToken as getTransferByGuestToken, api_registerPasskey as registerPasskey, api_reportActionCompletion as reportActionCompletion, api_reportPasskeyActivity as reportPasskeyActivity, api_setAccountOwner as setAccountOwner, api_setTransferSender as setTransferSender, api_signGuestTransfer as signGuestTransfer, api_signTransfer as signTransfer, api_updateUserConfig as updateUserConfig, api_updateUserConfigBySession as updateUserConfigBySession };
498
497
  }
499
498
 
500
499
  interface BlinkPaymentProps {
package/dist/index.js CHANGED
@@ -456,7 +456,6 @@ async function waitForTransactionReceipt(config, parameters) {
456
456
  // src/api.ts
457
457
  var api_exports = {};
458
458
  __export(api_exports, {
459
- claimAccount: () => claimAccount,
460
459
  createAccount: () => createAccount,
461
460
  createAccountAuthorizationSession: () => createAccountAuthorizationSession,
462
461
  createGuestTransfer: () => createGuestTransfer,
@@ -476,6 +475,7 @@ __export(api_exports, {
476
475
  registerPasskey: () => registerPasskey,
477
476
  reportActionCompletion: () => reportActionCompletion,
478
477
  reportPasskeyActivity: () => reportPasskeyActivity,
478
+ setAccountOwner: () => setAccountOwner,
479
479
  setTransferSender: () => setTransferSender,
480
480
  signGuestTransfer: () => signGuestTransfer,
481
481
  signTransfer: () => signTransfer,
@@ -773,12 +773,13 @@ async function fetchGuestPreauthAccount(apiBaseUrl, guestToken) {
773
773
  if (!res.ok) await throwApiError(res);
774
774
  return await res.json();
775
775
  }
776
- async function claimAccount(apiBaseUrl, accessToken, accountId, body) {
777
- const res = await fetch(`${apiBaseUrl}/v1/accounts/${accountId}/claim`, {
778
- method: "POST",
776
+ async function setAccountOwner(apiBaseUrl, accessToken, accountId, guestSessionToken, body) {
777
+ const res = await fetch(`${apiBaseUrl}/v1/accounts/${accountId}/owner`, {
778
+ method: "PUT",
779
779
  headers: {
780
780
  "Content-Type": "application/json",
781
- "Authorization": `Bearer ${accessToken}`
781
+ "Authorization": `Bearer ${accessToken}`,
782
+ "x-guest-session-token": guestSessionToken
782
783
  },
783
784
  body: JSON.stringify(body)
784
785
  });
@@ -2214,7 +2215,7 @@ function paymentReducer(state, action) {
2214
2215
  guestPreauthAccountId: action.accountId,
2215
2216
  step: "login"
2216
2217
  };
2217
- case "GUEST_PREAUTH_CLAIMED":
2218
+ case "ACCOUNT_OWNER_SET":
2218
2219
  return {
2219
2220
  ...state,
2220
2221
  guestPreauthAccountId: null,
@@ -6817,13 +6818,10 @@ function useMobileFlowHandlers(dispatch, polling, reloadAccounts, pollingTransfe
6817
6818
  const onCompleteRef = useRef(onComplete);
6818
6819
  onCompleteRef.current = onComplete;
6819
6820
  const guestPollingActiveRef = useRef(false);
6820
- useEffect(() => {
6821
- const persisted = loadMobileFlowState();
6822
- if (!persisted?.isGuestCheckout || !persisted.transferId || !persisted.guestSessionToken) return;
6821
+ const guestPollingCleanupRef = useRef(null);
6822
+ const startGuestPolling = useCallback((transferId, guestSessionToken) => {
6823
6823
  if (guestPollingActiveRef.current) return;
6824
6824
  guestPollingActiveRef.current = true;
6825
- const transferId = persisted.transferId;
6826
- const guestSessionToken = persisted.guestSessionToken;
6827
6825
  let cancelled = false;
6828
6826
  const POLL_INTERVAL_MS = 3e3;
6829
6827
  dispatch({ type: "NAVIGATE", step: "processing" });
@@ -6835,12 +6833,14 @@ function useMobileFlowHandlers(dispatch, polling, reloadAccounts, pollingTransfe
6835
6833
  if (transfer.status === "COMPLETED") {
6836
6834
  cancelled = true;
6837
6835
  guestPollingActiveRef.current = false;
6836
+ guestPollingCleanupRef.current = null;
6838
6837
  clearMobileFlowState();
6839
6838
  dispatch({ type: "GUEST_TRANSFER_COMPLETED", transfer, guestSessionToken });
6840
6839
  onCompleteRef.current?.(transfer);
6841
6840
  } else if (transfer.status === "FAILED") {
6842
6841
  cancelled = true;
6843
6842
  guestPollingActiveRef.current = false;
6843
+ guestPollingCleanupRef.current = null;
6844
6844
  clearMobileFlowState();
6845
6845
  dispatch({ type: "TRANSFER_FAILED", transfer, error: "Transfer failed." });
6846
6846
  }
@@ -6849,26 +6849,44 @@ function useMobileFlowHandlers(dispatch, polling, reloadAccounts, pollingTransfe
6849
6849
  };
6850
6850
  poll();
6851
6851
  const intervalId = window.setInterval(poll, POLL_INTERVAL_MS);
6852
- const handleVisibility = () => {
6853
- if (document.visibilityState === "visible" && !cancelled) {
6854
- poll();
6852
+ const cleanup = () => {
6853
+ cancelled = true;
6854
+ guestPollingActiveRef.current = false;
6855
+ guestPollingCleanupRef.current = null;
6856
+ window.clearInterval(intervalId);
6857
+ };
6858
+ guestPollingCleanupRef.current = cleanup;
6859
+ }, [apiBaseUrl, dispatch]);
6860
+ useEffect(() => {
6861
+ const persisted = loadMobileFlowState();
6862
+ if (persisted?.isGuestCheckout && persisted.transferId && persisted.guestSessionToken) {
6863
+ startGuestPolling(persisted.transferId, persisted.guestSessionToken);
6864
+ }
6865
+ return () => {
6866
+ guestPollingCleanupRef.current?.();
6867
+ };
6868
+ }, [startGuestPolling]);
6869
+ useEffect(() => {
6870
+ const tryStartPolling = () => {
6871
+ if (guestPollingActiveRef.current) return;
6872
+ const persisted = loadMobileFlowState();
6873
+ if (persisted?.isGuestCheckout && persisted.transferId && persisted.guestSessionToken) {
6874
+ startGuestPolling(persisted.transferId, persisted.guestSessionToken);
6855
6875
  }
6856
6876
  };
6877
+ const handleVisibility = () => {
6878
+ if (document.visibilityState === "visible") tryStartPolling();
6879
+ };
6857
6880
  const handlePageShow = (e) => {
6858
- if (e.persisted && !cancelled) {
6859
- poll();
6860
- }
6881
+ if (e.persisted) tryStartPolling();
6861
6882
  };
6862
6883
  document.addEventListener("visibilitychange", handleVisibility);
6863
6884
  window.addEventListener("pageshow", handlePageShow);
6864
6885
  return () => {
6865
- cancelled = true;
6866
- guestPollingActiveRef.current = false;
6867
- window.clearInterval(intervalId);
6868
6886
  document.removeEventListener("visibilitychange", handleVisibility);
6869
6887
  window.removeEventListener("pageshow", handlePageShow);
6870
6888
  };
6871
- }, [apiBaseUrl, dispatch]);
6889
+ }, [startGuestPolling]);
6872
6890
  const handleAuthorizedMobileReturn = useCallback(async (authorizedTransfer, isSetup) => {
6873
6891
  if (handlingMobileReturnRef.current) return;
6874
6892
  handlingMobileReturnRef.current = true;
@@ -8324,22 +8342,21 @@ function usePaymentEffects(deps) {
8324
8342
  cancelled = true;
8325
8343
  };
8326
8344
  }, [state.step, state.guestSessionToken, state.guestPreauthAccountId, apiBaseUrl, dispatch]);
8327
- const claimingRef = useRef(false);
8345
+ const settingOwnerRef = useRef(false);
8328
8346
  useEffect(() => {
8329
8347
  if (!state.guestPreauthAccountId) return;
8330
8348
  if (!state.activeCredentialId) return;
8331
8349
  if (!state.activePublicKey) return;
8332
8350
  if (!authenticated) return;
8333
8351
  if (!state.guestSessionToken) return;
8334
- if (claimingRef.current) return;
8335
- claimingRef.current = true;
8352
+ if (settingOwnerRef.current) return;
8353
+ settingOwnerRef.current = true;
8336
8354
  let cancelled = false;
8337
- const claimPreauth = async () => {
8355
+ const setOwner = async () => {
8338
8356
  try {
8339
8357
  const token = await getAccessTokenRef.current();
8340
8358
  if (!token || cancelled) return;
8341
- await claimAccount(apiBaseUrl, token, state.guestPreauthAccountId, {
8342
- guestToken: state.guestSessionToken,
8359
+ await setAccountOwner(apiBaseUrl, token, state.guestPreauthAccountId, state.guestSessionToken, {
8343
8360
  credentialId: state.activeCredentialId,
8344
8361
  publicKey: state.activePublicKey
8345
8362
  });
@@ -8349,19 +8366,19 @@ function usePaymentEffects(deps) {
8349
8366
  } catch {
8350
8367
  }
8351
8368
  if (cancelled) return;
8352
- dispatch({ type: "GUEST_PREAUTH_CLAIMED" });
8369
+ dispatch({ type: "ACCOUNT_OWNER_SET" });
8353
8370
  } catch (err) {
8354
8371
  if (cancelled) return;
8355
8372
  captureException(err);
8356
8373
  dispatch({
8357
8374
  type: "SET_ERROR",
8358
- error: err instanceof Error ? err.message : "Failed to claim account"
8375
+ error: err instanceof Error ? err.message : "Failed to set account owner"
8359
8376
  });
8360
8377
  } finally {
8361
- claimingRef.current = false;
8378
+ settingOwnerRef.current = false;
8362
8379
  }
8363
8380
  };
8364
- claimPreauth();
8381
+ setOwner();
8365
8382
  return () => {
8366
8383
  cancelled = true;
8367
8384
  };