@trustware/sdk-staging 1.1.11-staging.2 → 1.1.12-staging.2

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.
Files changed (43) hide show
  1. package/dist/{blockchain-BxAFzp0s.d.cts → blockchain-DmCPxnxr.d.cts} +25 -1
  2. package/dist/{blockchain-BxAFzp0s.d.ts → blockchain-DmCPxnxr.d.ts} +25 -1
  3. package/dist/constants.cjs +1 -1
  4. package/dist/constants.mjs +1 -1
  5. package/dist/{core-B1WCJfDI.d.ts → core-B4YDGtJT.d.ts} +3 -3
  6. package/dist/{core-CeNTuqPz.d.cts → core-Ck7dinYj.d.cts} +3 -3
  7. package/dist/core.cjs +57 -10
  8. package/dist/core.cjs.map +1 -1
  9. package/dist/core.d.cts +4 -4
  10. package/dist/core.d.ts +4 -4
  11. package/dist/core.mjs +57 -10
  12. package/dist/core.mjs.map +1 -1
  13. package/dist/index.cjs +124 -29
  14. package/dist/index.cjs.map +1 -1
  15. package/dist/index.d.cts +8 -8
  16. package/dist/index.d.ts +8 -8
  17. package/dist/index.mjs +124 -29
  18. package/dist/index.mjs.map +1 -1
  19. package/dist/{manager-DNGk1YkR.d.cts → manager-BZ8gyHGT.d.cts} +1 -1
  20. package/dist/{manager-Bw8b1wSD.d.ts → manager-D8nQsod2.d.ts} +1 -1
  21. package/dist/{metadata-Dk4R8_-T.d.cts → metadata-B23D0oO9.d.cts} +1 -1
  22. package/dist/{metadata-C__KMeuz.d.ts → metadata-BOjEF7oo.d.ts} +1 -1
  23. package/dist/smart-account.cjs +26 -5
  24. package/dist/smart-account.cjs.map +1 -1
  25. package/dist/smart-account.d.cts +1 -0
  26. package/dist/smart-account.d.ts +1 -0
  27. package/dist/smart-account.mjs +26 -5
  28. package/dist/smart-account.mjs.map +1 -1
  29. package/dist/{types-BJY9r-mz.d.ts → types-CMmx0S4U.d.ts} +1 -1
  30. package/dist/{types-DX3HtFcn.d.cts → types-DEUb5IZA.d.cts} +1 -1
  31. package/dist/wallet.cjs +12 -2
  32. package/dist/wallet.cjs.map +1 -1
  33. package/dist/wallet.d.cts +4 -4
  34. package/dist/wallet.d.ts +4 -4
  35. package/dist/wallet.mjs +12 -2
  36. package/dist/wallet.mjs.map +1 -1
  37. package/dist/widget.cjs +124 -29
  38. package/dist/widget.cjs.map +1 -1
  39. package/dist/widget.d.cts +2 -2
  40. package/dist/widget.d.ts +2 -2
  41. package/dist/widget.mjs +124 -29
  42. package/dist/widget.mjs.map +1 -1
  43. package/package.json +2 -1
package/dist/index.cjs CHANGED
@@ -59,7 +59,17 @@ var init_config = __esm({
59
59
  RATE_LIMIT_WAIT_BUDGET_MS = 1e4;
60
60
  DEFAULT_FEATURE_FLAGS = {
61
61
  tokensPagination: true,
62
- balanceStreaming: false,
62
+ // On by default: an address scan covers every configured chain and takes
63
+ // seconds end to end, so streaming turns one long wait into a wallet that
64
+ // fills in as results land — first chunk in ~200ms against a ~2.3s buffered
65
+ // response, measured on a live backend.
66
+ //
67
+ // Safe to default because the path degrades on its own: a backend with
68
+ // BALANCE_STREAM_ENABLED off refuses the stream, and the SDK falls back to
69
+ // the buffered endpoint (emitting balance_stream_fallback), as does any
70
+ // runtime whose fetch has no readable body — React Native, most notably.
71
+ // The cost of defaulting ahead of a backend is one refused request per scan.
72
+ balanceStreaming: true,
63
73
  shouldAllowGA4: true,
64
74
  swapMode: false,
65
75
  swapDefaultDestToken: null,
@@ -504,7 +514,7 @@ var init_constants = __esm({
504
514
  "src/constants.ts"() {
505
515
  "use strict";
506
516
  SDK_NAME = "@trustware/sdk";
507
- SDK_VERSION = "1.1.11-staging.2";
517
+ SDK_VERSION = "1.1.12-staging.2";
508
518
  API_ROOT = "https://bv-staging-api.trustware.io";
509
519
  GTM_ID = "GTM-TZDGNCXB";
510
520
  API_PREFIX = "/api";
@@ -552,7 +562,7 @@ function isNotFoundError(err) {
552
562
  return err instanceof Error && err.message.startsWith("HTTP 404");
553
563
  }
554
564
  async function validateSdkAccess() {
555
- const r = await fetch(`${apiBase()}/sdk/validate`, {
565
+ const r = await fetch(`${apiBase()}/v1/sdk/validate`, {
556
566
  method: "GET",
557
567
  headers: jsonHeaders()
558
568
  });
@@ -5107,6 +5117,16 @@ function mergeBalanceWrappers(current, incoming) {
5107
5117
  }
5108
5118
  return Array.from(merged.values());
5109
5119
  }
5120
+ function toSummary(frame, address) {
5121
+ const total = toNumberOrUndefined(frame.total) ?? 0;
5122
+ return {
5123
+ address: toStringOrUndefined(frame.address) ?? address,
5124
+ partial: Boolean(frame.partial),
5125
+ completed: toNumberOrUndefined(frame.completed) ?? 0,
5126
+ total,
5127
+ elapsedMs: toNumberOrUndefined(frame.elapsed)
5128
+ };
5129
+ }
5110
5130
  async function parseStreamingBalances(response, address, options = {}) {
5111
5131
  if (!response.body) {
5112
5132
  throw new Error("balances stream: empty response body");
@@ -5127,7 +5147,12 @@ async function parseStreamingBalances(response, address, options = {}) {
5127
5147
  if (!trimmed) continue;
5128
5148
  try {
5129
5149
  const parsed = JSON.parse(trimmed);
5130
- if (!parsed.chain_id) continue;
5150
+ if (!parsed.chain_id) {
5151
+ if (parsed.type === "summary") {
5152
+ options.onSummary?.(toSummary(parsed, address));
5153
+ }
5154
+ continue;
5155
+ }
5131
5156
  const chunk = normalizeStreamChunk(parsed);
5132
5157
  emitBalanceStreamChunk(address, chunk.length);
5133
5158
  yield chunk;
@@ -5146,6 +5171,8 @@ async function parseStreamingBalances(response, address, options = {}) {
5146
5171
  const chunk = normalizeStreamChunk(parsed);
5147
5172
  emitBalanceStreamChunk(address, chunk.length);
5148
5173
  yield chunk;
5174
+ } else if (parsed.type === "summary") {
5175
+ options.onSummary?.(toSummary(parsed, address));
5149
5176
  }
5150
5177
  } catch (error) {
5151
5178
  if (options.strict) {
@@ -5200,7 +5227,7 @@ async function getBalancesByAddress(address, opts) {
5200
5227
  }
5201
5228
  return merged;
5202
5229
  }
5203
- const url = `${apiBase()}/data/balances/${address}`;
5230
+ const url = `${apiBase()}/v1/data/balances/${address}`;
5204
5231
  const r = await rateLimitedFetch(url, {
5205
5232
  method: "GET",
5206
5233
  credentials: "omit",
@@ -5208,14 +5235,27 @@ async function getBalancesByAddress(address, opts) {
5208
5235
  });
5209
5236
  if (!r.ok) throw new Error(`balances: HTTP ${r.status}`);
5210
5237
  const j = await r.json();
5211
- return Array.isArray(j) ? j : j.results ?? [];
5238
+ const results = Array.isArray(j) ? j : j.results ?? [];
5239
+ if (opts?.onSummary) {
5240
+ const completed = results.length;
5241
+ opts.onSummary({
5242
+ address,
5243
+ partial: Array.isArray(j) ? false : Boolean(j.partial),
5244
+ completed,
5245
+ total: completed
5246
+ });
5247
+ }
5248
+ return results;
5249
+ }
5250
+ function bufferedOptions(opts) {
5251
+ return { ...opts, stream: false };
5212
5252
  }
5213
5253
  async function* getBalancesByAddressStream(address, opts = {}) {
5214
5254
  if (!TrustwareConfigStore.get().features.balanceStreaming) {
5215
- yield await getBalancesByAddress(address);
5255
+ yield await getBalancesByAddress(address, bufferedOptions(opts));
5216
5256
  return;
5217
5257
  }
5218
- const url = `${apiBase()}/data/balances/${address}?stream=1`;
5258
+ const url = `${apiBase()}/v1/data/balances/${address}?stream=1`;
5219
5259
  try {
5220
5260
  const response = await rateLimitedFetch(url, {
5221
5261
  method: "GET",
@@ -5231,7 +5271,14 @@ async function* getBalancesByAddressStream(address, opts = {}) {
5231
5271
  const contentType = response.headers.get("content-type") ?? "";
5232
5272
  if (contentType.includes("application/json")) {
5233
5273
  const payload = await response.json();
5234
- yield Array.isArray(payload) ? payload : payload.results ?? [];
5274
+ const results = Array.isArray(payload) ? payload : payload.results ?? [];
5275
+ opts.onSummary?.({
5276
+ address,
5277
+ partial: Array.isArray(payload) ? false : Boolean(payload.partial),
5278
+ completed: results.length,
5279
+ total: results.length
5280
+ });
5281
+ yield results;
5235
5282
  return;
5236
5283
  }
5237
5284
  const stream = await parseStreamingBalances(response, address, opts);
@@ -5240,7 +5287,7 @@ async function* getBalancesByAddressStream(address, opts = {}) {
5240
5287
  }
5241
5288
  } catch (error) {
5242
5289
  emitBalanceStreamFallback(address, error);
5243
- yield await getBalancesByAddress(address);
5290
+ yield await getBalancesByAddress(address, bufferedOptions(opts));
5244
5291
  }
5245
5292
  }
5246
5293
  async function ensureRegistry() {
@@ -8288,15 +8335,7 @@ function useTrustwareConfig() {
8288
8335
  // Shared with the resolver rather than restated, so this placeholder
8289
8336
  // can't drift from the real defaults.
8290
8337
  retry: { ...DEFAULT_RETRY_CONFIG },
8291
- features: {
8292
- tokensPagination: true,
8293
- balanceStreaming: false,
8294
- shouldAllowGA4: true,
8295
- swapMode: false,
8296
- swapDefaultDestToken: null,
8297
- swapLockDestToken: false,
8298
- swapAllowedDestTokens: null
8299
- }
8338
+ features: { ...DEFAULT_FEATURE_FLAGS }
8300
8339
  };
8301
8340
  }
8302
8341
  });
@@ -20617,7 +20656,7 @@ var VERSION;
20617
20656
  var init_version = __esm({
20618
20657
  "node_modules/@aa-sdk/core/dist/esm/version.js"() {
20619
20658
  "use strict";
20620
- VERSION = "4.88.4";
20659
+ VERSION = "4.88.5";
20621
20660
  }
20622
20661
  });
20623
20662
 
@@ -29136,7 +29175,7 @@ var VERSION2;
29136
29175
  var init_version2 = __esm({
29137
29176
  "node_modules/@account-kit/infra/dist/esm/version.js"() {
29138
29177
  "use strict";
29139
- VERSION2 = "4.88.4";
29178
+ VERSION2 = "4.88.5";
29140
29179
  }
29141
29180
  });
29142
29181
 
@@ -31843,7 +31882,18 @@ async function sendRouteAsUserOperation(params) {
31843
31882
  );
31844
31883
  }
31845
31884
  console.debug("[send] UserOp included", { userOpHash, txHash });
31846
- await submitReceipt(intentId, txHash, getSponsorshipRequestId(), eoaAddress);
31885
+ try {
31886
+ void submitReceipt(
31887
+ intentId,
31888
+ txHash,
31889
+ getSponsorshipRequestId(),
31890
+ eoaAddress
31891
+ ).catch((err) => {
31892
+ console.debug("[send] receipt submission failed (non-fatal)", err);
31893
+ });
31894
+ } catch (err) {
31895
+ console.debug("[send] receipt submission failed (non-fatal)", err);
31896
+ }
31847
31897
  return { userOpHash, txHash, intentId };
31848
31898
  }
31849
31899
  var NATIVE_ADDRS;
@@ -34067,10 +34117,6 @@ function useSwapExecution(fromChain) {
34067
34117
  numericChainId,
34068
34118
  { approvalsEnsured: ownsApprovals }
34069
34119
  );
34070
- try {
34071
- await submitReceipt(routeResult.intentId, hash);
34072
- } catch {
34073
- }
34074
34120
  setState((p) => ({
34075
34121
  ...p,
34076
34122
  isSubmitting: false,
@@ -34079,6 +34125,8 @@ function useSwapExecution(fromChain) {
34079
34125
  txStatus: "processing"
34080
34126
  }));
34081
34127
  startPolling(routeResult.intentId, onSuccess, onError);
34128
+ void submitReceipt(routeResult.intentId, hash).catch(() => {
34129
+ });
34082
34130
  } catch (err) {
34083
34131
  const msg = mapTxError(err);
34084
34132
  setState((p) => ({
@@ -36514,6 +36562,7 @@ function SwapMode({
36514
36562
  }, [route.loading]);
36515
36563
  (0, import_react50.useEffect)(() => {
36516
36564
  if (!route.data) return;
36565
+ if (stage !== "home" && stage !== "review") return;
36517
36566
  const id = setInterval(() => {
36518
36567
  const ts = quoteTimestampRef.current;
36519
36568
  if (ts === null) return;
@@ -36525,7 +36574,11 @@ function SwapMode({
36525
36574
  }
36526
36575
  }, 1e3);
36527
36576
  return () => clearInterval(id);
36528
- }, [route.data]);
36577
+ }, [route.data, stage]);
36578
+ const handleRetryQuote = (0, import_react50.useCallback)(() => {
36579
+ if (!latestFetchParamsRef.current) return;
36580
+ void fetchRef.current(latestFetchParamsRef.current);
36581
+ }, []);
36529
36582
  (0, import_react50.useEffect)(() => {
36530
36583
  if (stage !== "review") return;
36531
36584
  if (!route.data || !walletAddress) return;
@@ -38054,6 +38107,10 @@ function SwapMode({
38054
38107
  txStatus: execution.txStatus,
38055
38108
  isSubmitting: execution.isSubmitting,
38056
38109
  isGasSponsored,
38110
+ hasQuote: !!route.data,
38111
+ isQuoteRefreshing: route.loading,
38112
+ quoteError: route.error,
38113
+ onRetryQuote: handleRetryQuote,
38057
38114
  onExecute: () => void handleExecute()
38058
38115
  }
38059
38116
  )
@@ -39390,10 +39447,15 @@ function SwapActionArea({
39390
39447
  txStatus,
39391
39448
  isSubmitting,
39392
39449
  isGasSponsored,
39450
+ hasQuote,
39451
+ isQuoteRefreshing,
39452
+ quoteError,
39453
+ onRetryQuote,
39393
39454
  onExecute
39394
39455
  }) {
39395
39456
  const needsApproval = allowanceStatus === "needed" && !isGasSponsored;
39396
39457
  const isChecking = allowanceStatus === "checking";
39458
+ const quoteUnavailable = !hasQuote && !isQuoteRefreshing && !isSubmitting && txStatus === "idle";
39397
39459
  let label;
39398
39460
  if (isChecking) {
39399
39461
  label = "Checking approval...";
@@ -39401,12 +39463,14 @@ function SwapActionArea({
39401
39463
  label = `Approving ${fromTokenSymbol}...`;
39402
39464
  } else if (isSubmitting) {
39403
39465
  label = "Confirm in wallet...";
39466
+ } else if (isQuoteRefreshing) {
39467
+ label = "Refreshing quote...";
39404
39468
  } else if (needsApproval) {
39405
39469
  label = `Approve ${fromTokenSymbol}`;
39406
39470
  } else {
39407
39471
  label = "Swap";
39408
39472
  }
39409
- const isDisabled = isSubmitting || isChecking;
39473
+ const isDisabled = isSubmitting || isChecking || isQuoteRefreshing || !hasQuote;
39410
39474
  return /* @__PURE__ */ (0, import_jsx_runtime59.jsxs)("div", { style: { marginTop: spacing[6] }, children: [
39411
39475
  isGasSponsored && !isSubmitting && /* @__PURE__ */ (0, import_jsx_runtime59.jsxs)(
39412
39476
  "div",
@@ -39446,7 +39510,38 @@ function SwapActionArea({
39446
39510
  ]
39447
39511
  }
39448
39512
  ),
39449
- /* @__PURE__ */ (0, import_jsx_runtime59.jsx)(
39513
+ quoteUnavailable ? /* @__PURE__ */ (0, import_jsx_runtime59.jsxs)(import_jsx_runtime59.Fragment, { children: [
39514
+ /* @__PURE__ */ (0, import_jsx_runtime59.jsx)(
39515
+ "p",
39516
+ {
39517
+ style: {
39518
+ fontSize: fontSize.xs,
39519
+ color: colors.destructive,
39520
+ textAlign: "center",
39521
+ marginBottom: spacing[3]
39522
+ },
39523
+ children: quoteError ?? "This quote expired."
39524
+ }
39525
+ ),
39526
+ /* @__PURE__ */ (0, import_jsx_runtime59.jsx)(
39527
+ "button",
39528
+ {
39529
+ onClick: onRetryQuote,
39530
+ style: {
39531
+ width: "100%",
39532
+ height: "3.5rem",
39533
+ borderRadius: "1.5rem",
39534
+ backgroundColor: colors.primary,
39535
+ color: colors.primaryForeground,
39536
+ fontSize: fontSize.base,
39537
+ fontWeight: fontWeight.semibold,
39538
+ border: 0,
39539
+ cursor: "pointer"
39540
+ },
39541
+ children: "Get a new quote"
39542
+ }
39543
+ )
39544
+ ] }) : /* @__PURE__ */ (0, import_jsx_runtime59.jsx)(
39450
39545
  "button",
39451
39546
  {
39452
39547
  onClick: onExecute,