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

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 (44) hide show
  1. package/README.md +54 -21
  2. package/dist/{blockchain-BxAFzp0s.d.cts → blockchain-DmCPxnxr.d.cts} +25 -1
  3. package/dist/{blockchain-BxAFzp0s.d.ts → blockchain-DmCPxnxr.d.ts} +25 -1
  4. package/dist/constants.cjs +1 -1
  5. package/dist/constants.mjs +1 -1
  6. package/dist/{core-BgYLe9Q7.d.ts → core-B4YDGtJT.d.ts} +3 -3
  7. package/dist/{core-fLSt4qD2.d.cts → core-Ck7dinYj.d.cts} +3 -3
  8. package/dist/core.cjs +141 -52
  9. package/dist/core.cjs.map +1 -1
  10. package/dist/core.d.cts +4 -4
  11. package/dist/core.d.ts +4 -4
  12. package/dist/core.mjs +139 -51
  13. package/dist/core.mjs.map +1 -1
  14. package/dist/index.cjs +166 -75
  15. package/dist/index.cjs.map +1 -1
  16. package/dist/index.d.cts +14 -8
  17. package/dist/index.d.ts +14 -8
  18. package/dist/index.mjs +164 -75
  19. package/dist/index.mjs.map +1 -1
  20. package/dist/{manager-DT8enQbE.d.cts → manager-BZ8gyHGT.d.cts} +90 -23
  21. package/dist/{manager-BY3NHAks.d.ts → manager-D8nQsod2.d.ts} +90 -23
  22. package/dist/{metadata-DyxUcKHk.d.cts → metadata-B23D0oO9.d.cts} +1 -1
  23. package/dist/{metadata-BPvFYMlc.d.ts → metadata-BOjEF7oo.d.ts} +1 -1
  24. package/dist/smart-account.cjs +62 -47
  25. package/dist/smart-account.cjs.map +1 -1
  26. package/dist/smart-account.d.cts +6 -0
  27. package/dist/smart-account.d.ts +6 -0
  28. package/dist/smart-account.mjs +62 -47
  29. package/dist/smart-account.mjs.map +1 -1
  30. package/dist/{types-BJY9r-mz.d.ts → types-CMmx0S4U.d.ts} +1 -1
  31. package/dist/{types-DX3HtFcn.d.cts → types-DEUb5IZA.d.cts} +1 -1
  32. package/dist/wallet.cjs +51 -40
  33. package/dist/wallet.cjs.map +1 -1
  34. package/dist/wallet.d.cts +4 -4
  35. package/dist/wallet.d.ts +4 -4
  36. package/dist/wallet.mjs +51 -40
  37. package/dist/wallet.mjs.map +1 -1
  38. package/dist/widget.cjs +160 -75
  39. package/dist/widget.cjs.map +1 -1
  40. package/dist/widget.d.cts +2 -2
  41. package/dist/widget.d.ts +2 -2
  42. package/dist/widget.mjs +160 -75
  43. package/dist/widget.mjs.map +1 -1
  44. package/package.json +74 -5
@@ -1,4 +1,4 @@
1
- import { C as ChainDef } from './blockchain-BxAFzp0s.js';
1
+ import { C as ChainDef } from './blockchain-DmCPxnxr.js';
2
2
 
3
3
  interface YourTokenData {
4
4
  chainIconURI: string;
@@ -1,4 +1,4 @@
1
- import { C as ChainDef } from './blockchain-BxAFzp0s.cjs';
1
+ import { C as ChainDef } from './blockchain-DmCPxnxr.cjs';
2
2
 
3
3
  interface YourTokenData {
4
4
  chainIconURI: string;
package/dist/wallet.cjs CHANGED
@@ -264,7 +264,7 @@ var init_constants = __esm({
264
264
  "src/constants.ts"() {
265
265
  "use strict";
266
266
  SDK_NAME = "@trustware/sdk";
267
- SDK_VERSION = "1.1.11-staging.1";
267
+ SDK_VERSION = "1.1.12-staging.1";
268
268
  API_ROOT = "https://bv-staging-api.trustware.io";
269
269
  API_PREFIX = "/api";
270
270
  WALLETCONNECT_PROJECT_ID = "72ea74c400f5111d43aea638d7d83a24";
@@ -287,19 +287,27 @@ var init_defaults = __esm({
287
287
  });
288
288
 
289
289
  // src/types/config.ts
290
- var DEFAULT_RETRY_CONFIG, DEFAULT_FEATURE_FLAGS;
290
+ var DEFAULT_RETRY_CONFIG, RATE_LIMIT_WAIT_BUDGET_MS, DEFAULT_FEATURE_FLAGS;
291
291
  var init_config = __esm({
292
292
  "src/types/config.ts"() {
293
293
  "use strict";
294
294
  DEFAULT_RETRY_CONFIG = {
295
- autoRetry: true,
296
- maxRetries: 3,
297
- baseDelayMs: 1e3,
298
295
  approachingThreshold: 5
299
296
  };
297
+ RATE_LIMIT_WAIT_BUDGET_MS = 1e4;
300
298
  DEFAULT_FEATURE_FLAGS = {
301
299
  tokensPagination: true,
302
- balanceStreaming: false,
300
+ // On by default: an address scan covers every configured chain and takes
301
+ // seconds end to end, so streaming turns one long wait into a wallet that
302
+ // fills in as results land — first chunk in ~200ms against a ~2.3s buffered
303
+ // response, measured on a live backend.
304
+ //
305
+ // Safe to default because the path degrades on its own: a backend with
306
+ // BALANCE_STREAM_ENABLED off refuses the stream, and the SDK falls back to
307
+ // the buffered endpoint (emitting balance_stream_fallback), as does any
308
+ // runtime whose fetch has no readable body — React Native, most notably.
309
+ // The cost of defaulting ahead of a backend is one refused request per scan.
310
+ balanceStreaming: true,
303
311
  shouldAllowGA4: true,
304
312
  swapMode: false,
305
313
  swapDefaultDestToken: null,
@@ -3749,9 +3757,6 @@ function resolveConfig(input) {
3749
3757
  const theme = input.theme ?? "system";
3750
3758
  const messages = deepMerge(DEFAULT_MESSAGES, input.messages);
3751
3759
  const retry = {
3752
- autoRetry: input.retry?.autoRetry ?? DEFAULT_RETRY_CONFIG.autoRetry,
3753
- maxRetries: input.retry?.maxRetries ?? DEFAULT_RETRY_CONFIG.maxRetries,
3754
- baseDelayMs: input.retry?.baseDelayMs ?? DEFAULT_RETRY_CONFIG.baseDelayMs,
3755
3760
  approachingThreshold: input.retry?.approachingThreshold ?? DEFAULT_RETRY_CONFIG.approachingThreshold,
3756
3761
  onRateLimitInfo: input.retry?.onRateLimitInfo,
3757
3762
  onRateLimited: input.retry?.onRateLimited,
@@ -3852,50 +3857,54 @@ function notifyRateLimitCallbacks(info, isRateLimited, retryCount) {
3852
3857
  retry.onRateLimitApproaching(info, retry.approachingThreshold);
3853
3858
  }
3854
3859
  }
3855
- function calculateBackoffDelay(baseDelayMs, retryCount, retryAfter) {
3856
- if (retryAfter && retryAfter > 0) {
3857
- return retryAfter * 1e3;
3860
+ function serverDirectedWaitMs(info) {
3861
+ if (!info) return null;
3862
+ if (typeof info.retryAfter === "number" && info.retryAfter > 0) {
3863
+ return info.retryAfter * 1e3;
3858
3864
  }
3859
- return baseDelayMs * Math.pow(2, retryCount);
3865
+ if (typeof info.reset === "number" && info.reset > 0) {
3866
+ const untilReset = info.reset * 1e3 - Date.now();
3867
+ if (untilReset > 0) return untilReset;
3868
+ }
3869
+ return null;
3860
3870
  }
3861
3871
  function sleep(ms) {
3862
3872
  return new Promise((resolve) => setTimeout(resolve, ms));
3863
3873
  }
3864
- async function rateLimitedFetch(url, options = {}) {
3865
- const { skipRateLimit, ...fetchOptions } = options;
3866
- const cfg = TrustwareConfigStore.get();
3867
- if (!cfg.retry.autoRetry || skipRateLimit) {
3868
- return fetch(url, fetchOptions);
3869
- }
3870
- const { maxRetries, baseDelayMs } = cfg.retry;
3874
+ async function withRateLimitRetry(attempt) {
3875
+ let waitedMs = 0;
3871
3876
  let retryCount = 0;
3872
3877
  while (true) {
3873
- const response = await fetch(url, fetchOptions);
3878
+ const response = await attempt();
3874
3879
  const rateLimitInfo = parseRateLimitHeaders(response);
3875
- if (response.status === 429) {
3880
+ if (response.status !== 429) {
3876
3881
  if (rateLimitInfo) {
3877
- notifyRateLimitCallbacks(rateLimitInfo, true, retryCount);
3878
- }
3879
- if (retryCount >= maxRetries) {
3880
- throw new RateLimitError(
3881
- rateLimitInfo || { limit: 0, remaining: 0, reset: 0 },
3882
- true
3883
- );
3882
+ notifyRateLimitCallbacks(rateLimitInfo, false, 0);
3884
3883
  }
3885
- const delay = calculateBackoffDelay(
3886
- baseDelayMs,
3887
- retryCount,
3888
- rateLimitInfo?.retryAfter
3889
- );
3890
- await sleep(delay);
3891
- retryCount++;
3892
- continue;
3884
+ return response;
3893
3885
  }
3894
3886
  if (rateLimitInfo) {
3895
- notifyRateLimitCallbacks(rateLimitInfo, false, 0);
3887
+ notifyRateLimitCallbacks(rateLimitInfo, true, retryCount);
3896
3888
  }
3897
- return response;
3889
+ const waitMs = serverDirectedWaitMs(rateLimitInfo);
3890
+ const info = rateLimitInfo || { limit: 0, remaining: 0, reset: 0 };
3891
+ if (waitMs === null) {
3892
+ throw new RateLimitError(info, true);
3893
+ }
3894
+ if (waitedMs + waitMs > RATE_LIMIT_WAIT_BUDGET_MS) {
3895
+ throw new RateLimitError(info, false);
3896
+ }
3897
+ await sleep(waitMs);
3898
+ waitedMs += waitMs;
3899
+ retryCount++;
3900
+ }
3901
+ }
3902
+ async function rateLimitedFetch(url, options = {}) {
3903
+ const { skipRateLimit, ...fetchOptions } = options;
3904
+ if (skipRateLimit) {
3905
+ return fetch(url, fetchOptions);
3898
3906
  }
3907
+ return withRateLimitRetry(() => fetch(url, fetchOptions));
3899
3908
  }
3900
3909
  var RateLimitError;
3901
3910
  var init_http = __esm({
@@ -3903,9 +3912,11 @@ var init_http = __esm({
3903
3912
  "use strict";
3904
3913
  init_constants();
3905
3914
  init_config2();
3915
+ init_config();
3906
3916
  RateLimitError = class extends Error {
3907
3917
  constructor(info, retriesExhausted) {
3908
- const message = retriesExhausted ? `Rate limit exceeded after max retries. Try again in ${info.retryAfter ?? Math.ceil((info.reset * 1e3 - Date.now()) / 1e3)} seconds.` : `Rate limit exceeded. Try again in ${info.retryAfter} seconds.`;
3918
+ const seconds = info.retryAfter ?? (info.reset > 0 ? Math.max(0, Math.ceil((info.reset * 1e3 - Date.now()) / 1e3)) : null);
3919
+ const message = seconds === null ? "Rate limit exceeded. The server did not say when to retry." : `Rate limit exceeded. Try again in ${seconds} seconds.`;
3909
3920
  super(message);
3910
3921
  this.name = "RateLimitError";
3911
3922
  this.rateLimitInfo = info;