@swype-org/react-sdk 0.1.228 → 0.1.229

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
@@ -461,13 +461,14 @@ var api_exports = {};
461
461
  __export(api_exports, {
462
462
  createAccount: () => createAccount,
463
463
  createAccountAuthorizationSession: () => createAccountAuthorizationSession,
464
+ createGuestAccount: () => createGuestAccount,
464
465
  createGuestTransfer: () => createGuestTransfer,
465
466
  createTransfer: () => createTransfer,
466
467
  fetchAccount: () => fetchAccount,
467
468
  fetchAccounts: () => fetchAccounts,
468
469
  fetchAuthorizationSession: () => fetchAuthorizationSession,
469
470
  fetchChains: () => fetchChains,
470
- fetchGuestPreauthAccount: () => fetchGuestPreauthAccount,
471
+ fetchGuestAccount: () => fetchGuestAccount,
471
472
  fetchGuestTransferBalances: () => fetchGuestTransferBalances,
472
473
  fetchMerchantPublicKey: () => fetchMerchantPublicKey,
473
474
  fetchProviders: () => fetchProviders,
@@ -769,13 +770,25 @@ async function fetchGuestTransferBalances(apiBaseUrl, transferId, guestSessionTo
769
770
  const data = await res.json();
770
771
  return data.items;
771
772
  }
772
- async function fetchGuestPreauthAccount(apiBaseUrl, guestToken) {
773
+ async function fetchGuestAccount(apiBaseUrl, guestToken) {
773
774
  const params = new URLSearchParams({ guestToken });
774
- const res = await fetch(`${apiBaseUrl}/v1/guest-preauth?${params.toString()}`);
775
+ const res = await fetch(`${apiBaseUrl}/v1/accounts?${params.toString()}`);
775
776
  if (res.status === 404) return null;
776
777
  if (!res.ok) await throwApiError(res);
777
778
  return await res.json();
778
779
  }
780
+ async function createGuestAccount(apiBaseUrl, guestSessionToken, providerId, name) {
781
+ const res = await fetch(`${apiBaseUrl}/v1/accounts`, {
782
+ method: "POST",
783
+ headers: {
784
+ "Content-Type": "application/json",
785
+ "x-guest-session-token": guestSessionToken
786
+ },
787
+ body: JSON.stringify({ providerId, name })
788
+ });
789
+ if (!res.ok) await throwApiError(res);
790
+ return await res.json();
791
+ }
779
792
  async function setAccountOwner(apiBaseUrl, accessToken, accountId, guestSessionToken, body) {
780
793
  const res = await fetch(`${apiBaseUrl}/v1/accounts/${accountId}/owner`, {
781
794
  method: "PUT",
@@ -2213,7 +2226,8 @@ function paymentReducer(state, action) {
2213
2226
  ...state,
2214
2227
  guestPreauthAccountId: null,
2215
2228
  activePublicKey: null,
2216
- error: null
2229
+ error: null,
2230
+ userIntent: "configure-one-tap"
2217
2231
  };
2218
2232
  // ── User intent & error ──────────────────────────────────────
2219
2233
  case "SET_USER_INTENT":
@@ -8245,21 +8259,40 @@ function usePaymentEffects(deps) {
8245
8259
  if (state.guestPreauthAccountId) return;
8246
8260
  if (!state.transfer || state.transfer.status !== "COMPLETED") return;
8247
8261
  let cancelled = false;
8248
- const checkPreauth = async () => {
8262
+ const ensureGuestAccount = async () => {
8249
8263
  try {
8250
- const result = await fetchGuestPreauthAccount(apiBaseUrl, state.guestSessionToken);
8264
+ let result = await fetchGuestAccount(apiBaseUrl, state.guestSessionToken);
8251
8265
  if (cancelled) return;
8266
+ if (!result && state.selectedProviderId) {
8267
+ const providerName = state.providers.find((p) => p.id === state.selectedProviderId)?.name ?? "Wallet";
8268
+ const created = await createGuestAccount(
8269
+ apiBaseUrl,
8270
+ state.guestSessionToken,
8271
+ state.selectedProviderId,
8272
+ providerName
8273
+ );
8274
+ if (cancelled) return;
8275
+ result = { accountId: created.accountId, hasPasskey: false, walletAddress: null };
8276
+ }
8252
8277
  if (result && !result.hasPasskey) {
8253
8278
  dispatch({ type: "GUEST_PREAUTH_DETECTED", accountId: result.accountId });
8254
8279
  }
8255
8280
  } catch {
8256
8281
  }
8257
8282
  };
8258
- checkPreauth();
8283
+ ensureGuestAccount();
8259
8284
  return () => {
8260
8285
  cancelled = true;
8261
8286
  };
8262
- }, [state.transfer, state.guestSessionToken, state.guestPreauthAccountId, apiBaseUrl, dispatch]);
8287
+ }, [
8288
+ state.transfer,
8289
+ state.guestSessionToken,
8290
+ state.guestPreauthAccountId,
8291
+ state.selectedProviderId,
8292
+ state.providers,
8293
+ apiBaseUrl,
8294
+ dispatch
8295
+ ]);
8263
8296
  const settingOwnerRef = react.useRef(false);
8264
8297
  react.useEffect(() => {
8265
8298
  if (!state.guestPreauthAccountId) return;