@swype-org/react-sdk 0.1.227 → 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",
@@ -1964,7 +1977,8 @@ function createInitialState(config) {
1964
1977
  guestSessionToken: null,
1965
1978
  guestPreauthAccountId: null,
1966
1979
  activePublicKey: null,
1967
- userIntent: null
1980
+ userIntent: null,
1981
+ loginRequested: false
1968
1982
  };
1969
1983
  }
1970
1984
  function paymentReducer(state, action) {
@@ -1974,7 +1988,8 @@ function paymentReducer(state, action) {
1974
1988
  return {
1975
1989
  ...state,
1976
1990
  verificationTarget: action.target,
1977
- error: null
1991
+ error: null,
1992
+ loginRequested: false
1978
1993
  };
1979
1994
  case "BACK_TO_LOGIN":
1980
1995
  return {
@@ -2211,11 +2226,20 @@ function paymentReducer(state, action) {
2211
2226
  ...state,
2212
2227
  guestPreauthAccountId: null,
2213
2228
  activePublicKey: null,
2214
- error: null
2229
+ error: null,
2230
+ userIntent: "configure-one-tap"
2215
2231
  };
2216
2232
  // ── User intent & error ──────────────────────────────────────
2217
2233
  case "SET_USER_INTENT":
2218
2234
  return { ...state, userIntent: action.intent };
2235
+ case "REQUEST_LOGIN":
2236
+ return {
2237
+ ...state,
2238
+ loginRequested: true,
2239
+ transfer: null,
2240
+ isGuestFlow: false,
2241
+ creatingTransfer: false
2242
+ };
2219
2243
  case "SET_ERROR":
2220
2244
  return { ...state, error: action.error };
2221
2245
  // ── Lifecycle ────────────────────────────────────────────────
@@ -2235,7 +2259,8 @@ function paymentReducer(state, action) {
2235
2259
  guestSessionToken: null,
2236
2260
  guestPreauthAccountId: null,
2237
2261
  activePublicKey: null,
2238
- userIntent: null
2262
+ userIntent: null,
2263
+ loginRequested: false
2239
2264
  };
2240
2265
  case "LOGOUT":
2241
2266
  return {
@@ -2328,7 +2353,7 @@ function resolveScreen(state) {
2328
2353
  if (state.authenticated && !state.activeCredentialId && !state.passkeyConfigLoaded) {
2329
2354
  return "loading";
2330
2355
  }
2331
- if (!state.authenticated && !state.verificationTarget && !state.isGuestFlow && (state.isReturningUser || state.guestPreauthRedirect)) {
2356
+ if (!state.authenticated && !state.verificationTarget && !state.isGuestFlow && (state.isReturningUser || state.guestPreauthRedirect || state.loginRequested)) {
2332
2357
  return "login";
2333
2358
  }
2334
2359
  if (!state.authenticated && state.verificationTarget != null) {
@@ -5900,6 +5925,7 @@ function StepRenderer(props) {
5900
5925
  isDesktop,
5901
5926
  isReturningUser,
5902
5927
  guestPreauthRedirect: props.state.guestPreauthAccountId != null,
5928
+ loginRequested: props.state.loginRequested,
5903
5929
  userIntent: props.state.userIntent,
5904
5930
  selectedAccount: props.selectedAccount,
5905
5931
  guestSettingSender: props.guestSettingSender
@@ -6033,7 +6059,7 @@ function StepRendererContent({
6033
6059
  useDeeplink: !isDesktop,
6034
6060
  error: state.error || (!isDesktop ? pollingError : authExecutorError),
6035
6061
  onRetryStatus: !isDesktop ? handlers.onRetryMobileStatus : void 0,
6036
- onBack: !isDesktop ? () => handlers.onSetUserIntent(null) : void 0,
6062
+ onBack: !isDesktop ? handlers.onBackFromOpenWallet : void 0,
6037
6063
  onLogout: handlers.onLogout
6038
6064
  }
6039
6065
  );
@@ -7419,6 +7445,7 @@ function useGuestTransferHandlers(deps) {
7419
7445
  if (!isGuestFlow || !guestTransferId || !guestSessionToken || !selectedGuestTokenRef.current) return;
7420
7446
  if (executingBridgeRef.current) return;
7421
7447
  executingBridgeRef.current = true;
7448
+ dispatch({ type: "PAY_STARTED" });
7422
7449
  const execute = async () => {
7423
7450
  try {
7424
7451
  let signPayload = null;
@@ -7515,6 +7542,7 @@ function useGuestTransferHandlers(deps) {
7515
7542
  onError?.(displayMsg);
7516
7543
  } finally {
7517
7544
  executingBridgeRef.current = false;
7545
+ dispatch({ type: "PAY_ENDED" });
7518
7546
  }
7519
7547
  };
7520
7548
  execute();
@@ -8231,21 +8259,40 @@ function usePaymentEffects(deps) {
8231
8259
  if (state.guestPreauthAccountId) return;
8232
8260
  if (!state.transfer || state.transfer.status !== "COMPLETED") return;
8233
8261
  let cancelled = false;
8234
- const checkPreauth = async () => {
8262
+ const ensureGuestAccount = async () => {
8235
8263
  try {
8236
- const result = await fetchGuestPreauthAccount(apiBaseUrl, state.guestSessionToken);
8264
+ let result = await fetchGuestAccount(apiBaseUrl, state.guestSessionToken);
8237
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
+ }
8238
8277
  if (result && !result.hasPasskey) {
8239
8278
  dispatch({ type: "GUEST_PREAUTH_DETECTED", accountId: result.accountId });
8240
8279
  }
8241
8280
  } catch {
8242
8281
  }
8243
8282
  };
8244
- checkPreauth();
8283
+ ensureGuestAccount();
8245
8284
  return () => {
8246
8285
  cancelled = true;
8247
8286
  };
8248
- }, [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
+ ]);
8249
8296
  const settingOwnerRef = react.useRef(false);
8250
8297
  react.useEffect(() => {
8251
8298
  if (!state.guestPreauthAccountId) return;
@@ -8519,6 +8566,7 @@ function BlinkPaymentInner({
8519
8566
  onIncreaseLimit: provider.handleIncreaseLimit,
8520
8567
  onConfirmSign: transfer.handleConfirmSign,
8521
8568
  onRetryMobileStatus: mobileFlow.handleRetryMobileStatus,
8569
+ onBackFromOpenWallet: () => dispatch({ type: "CLEAR_MOBILE_STATE" }),
8522
8570
  onLogout: handleLogout,
8523
8571
  onNewPayment: handleNewPayment,
8524
8572
  onSetUserIntent: (intent) => dispatch({ type: "SET_USER_INTENT", intent }),
@@ -8535,8 +8583,8 @@ function BlinkPaymentInner({
8535
8583
  onSelectAuthorizedToken: provider.handleSelectAuthorizedToken,
8536
8584
  onAuthorizeToken: provider.handleAuthorizeToken,
8537
8585
  onSelectGuestToken: guestTransfer.handleSelectGuestToken,
8538
- onLogin: () => dispatch({ type: "SET_USER_INTENT", intent: null }),
8539
- onPreauthorize: () => dispatch({ type: "SET_USER_INTENT", intent: null })
8586
+ onLogin: () => dispatch({ type: "REQUEST_LOGIN" }),
8587
+ onPreauthorize: () => dispatch({ type: "REQUEST_LOGIN" })
8540
8588
  }), [
8541
8589
  auth,
8542
8590
  passkey,