@trustware/sdk-staging 1.1.10-staging.0 → 1.1.11-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 (38) hide show
  1. package/README.md +54 -21
  2. package/dist/constants.cjs +1 -1
  3. package/dist/constants.mjs +1 -1
  4. package/dist/{core-BPLiD1UG.d.ts → core-B1WCJfDI.d.ts} +15 -2
  5. package/dist/{core-B7Ez-5-r.d.cts → core-CeNTuqPz.d.cts} +15 -2
  6. package/dist/core.cjs +365 -279
  7. package/dist/core.cjs.map +1 -1
  8. package/dist/core.d.cts +2 -2
  9. package/dist/core.d.ts +2 -2
  10. package/dist/core.mjs +363 -278
  11. package/dist/core.mjs.map +1 -1
  12. package/dist/index.cjs +375 -170
  13. package/dist/index.cjs.map +1 -1
  14. package/dist/index.d.cts +11 -5
  15. package/dist/index.d.ts +11 -5
  16. package/dist/index.mjs +373 -169
  17. package/dist/index.mjs.map +1 -1
  18. package/dist/{manager-B6NNV-E_.d.ts → manager-Bw8b1wSD.d.ts} +136 -21
  19. package/dist/{manager-BwjyFjjz.d.cts → manager-DNGk1YkR.d.cts} +136 -21
  20. package/dist/{metadata-BiTMMvlY.d.ts → metadata-C__KMeuz.d.ts} +1 -1
  21. package/dist/{metadata-HCflXcsF.d.cts → metadata-Dk4R8_-T.d.cts} +1 -1
  22. package/dist/smart-account.cjs +49 -44
  23. package/dist/smart-account.cjs.map +1 -1
  24. package/dist/smart-account.d.cts +17 -12
  25. package/dist/smart-account.d.ts +17 -12
  26. package/dist/smart-account.mjs +49 -44
  27. package/dist/smart-account.mjs.map +1 -1
  28. package/dist/wallet.cjs +54 -39
  29. package/dist/wallet.cjs.map +1 -1
  30. package/dist/wallet.d.cts +3 -3
  31. package/dist/wallet.d.ts +3 -3
  32. package/dist/wallet.mjs +54 -39
  33. package/dist/wallet.mjs.map +1 -1
  34. package/dist/widget.cjs +369 -170
  35. package/dist/widget.cjs.map +1 -1
  36. package/dist/widget.mjs +369 -169
  37. package/dist/widget.mjs.map +1 -1
  38. package/package.json +73 -5
package/dist/wallet.d.cts CHANGED
@@ -1,6 +1,6 @@
1
- import { S as SolanaProviderLike, W as WalletMeta, D as DetectedWallet, a as WalletId, b as SolanaWalletInterface } from './manager-BwjyFjjz.cjs';
2
- export { c as WagmiBridge, d as WagmiConnector, e as WalletSnapshot, u as useWalletConnectConnect, f as useWalletExternalDisconnect, g as useWalletInfo, h as useWireDetectionIntoManager, w as walletManager } from './manager-BwjyFjjz.cjs';
3
- export { P as POPULAR_ORDER, W as WALLETS, a as autoDetectWallet, b as buildDetectedWalletFromProvider, c as connectDetectedWallet, d as createWalletConnectEntry, t as toWalletInterfaceFromDetected, u as useEIP1193, e as useIsMobile, f as useWagmi, g as useWalletDetection } from './metadata-HCflXcsF.cjs';
1
+ import { S as SolanaProviderLike, W as WalletMeta, D as DetectedWallet, a as WalletId, b as SolanaWalletInterface } from './manager-DNGk1YkR.cjs';
2
+ export { c as WagmiBridge, d as WagmiConnector, e as WalletSnapshot, u as useWalletConnectConnect, f as useWalletExternalDisconnect, g as useWalletInfo, h as useWireDetectionIntoManager, w as walletManager } from './manager-DNGk1YkR.cjs';
3
+ export { P as POPULAR_ORDER, W as WALLETS, a as autoDetectWallet, b as buildDetectedWalletFromProvider, c as connectDetectedWallet, d as createWalletConnectEntry, t as toWalletInterfaceFromDetected, u as useEIP1193, e as useIsMobile, f as useWagmi, g as useWalletDetection } from './metadata-Dk4R8_-T.cjs';
4
4
  import './blockchain-BxAFzp0s.cjs';
5
5
 
6
6
  type SolanaEventHandlers = {
package/dist/wallet.d.ts CHANGED
@@ -1,6 +1,6 @@
1
- import { S as SolanaProviderLike, W as WalletMeta, D as DetectedWallet, a as WalletId, b as SolanaWalletInterface } from './manager-B6NNV-E_.js';
2
- export { c as WagmiBridge, d as WagmiConnector, e as WalletSnapshot, u as useWalletConnectConnect, f as useWalletExternalDisconnect, g as useWalletInfo, h as useWireDetectionIntoManager, w as walletManager } from './manager-B6NNV-E_.js';
3
- export { P as POPULAR_ORDER, W as WALLETS, a as autoDetectWallet, b as buildDetectedWalletFromProvider, c as connectDetectedWallet, d as createWalletConnectEntry, t as toWalletInterfaceFromDetected, u as useEIP1193, e as useIsMobile, f as useWagmi, g as useWalletDetection } from './metadata-BiTMMvlY.js';
1
+ import { S as SolanaProviderLike, W as WalletMeta, D as DetectedWallet, a as WalletId, b as SolanaWalletInterface } from './manager-Bw8b1wSD.js';
2
+ export { c as WagmiBridge, d as WagmiConnector, e as WalletSnapshot, u as useWalletConnectConnect, f as useWalletExternalDisconnect, g as useWalletInfo, h as useWireDetectionIntoManager, w as walletManager } from './manager-Bw8b1wSD.js';
3
+ export { P as POPULAR_ORDER, W as WALLETS, a as autoDetectWallet, b as buildDetectedWalletFromProvider, c as connectDetectedWallet, d as createWalletConnectEntry, t as toWalletInterfaceFromDetected, u as useEIP1193, e as useIsMobile, f as useWagmi, g as useWalletDetection } from './metadata-C__KMeuz.js';
4
4
  import './blockchain-BxAFzp0s.js';
5
5
 
6
6
  type SolanaEventHandlers = {
package/dist/wallet.mjs CHANGED
@@ -193,6 +193,20 @@ var init_eipWallets = __esm({
193
193
  "src/wallets/eipWallets.ts"() {
194
194
  "use strict";
195
195
  CHAIN_PARAMS = {
196
+ 1: {
197
+ chainIdHex: "0x1",
198
+ chainName: "Ethereum",
199
+ rpcUrls: ["https://eth.llamarpc.com"],
200
+ nativeCurrency: { name: "Ether", symbol: "ETH", decimals: 18 },
201
+ blockExplorerUrls: ["https://etherscan.io"]
202
+ },
203
+ 137: {
204
+ chainIdHex: "0x89",
205
+ chainName: "Polygon",
206
+ rpcUrls: ["https://polygon-rpc.com"],
207
+ nativeCurrency: { name: "POL", symbol: "POL", decimals: 18 },
208
+ blockExplorerUrls: ["https://polygonscan.com"]
209
+ },
196
210
  8453: {
197
211
  chainIdHex: "0x2105",
198
212
  chainName: "Base",
@@ -224,7 +238,7 @@ var init_constants = __esm({
224
238
  "src/constants.ts"() {
225
239
  "use strict";
226
240
  SDK_NAME = "@trustware/sdk";
227
- SDK_VERSION = "1.1.10-staging.0";
241
+ SDK_VERSION = "1.1.11-staging.2";
228
242
  API_ROOT = "https://bv-staging-api.trustware.io";
229
243
  API_PREFIX = "/api";
230
244
  WALLETCONNECT_PROJECT_ID = "72ea74c400f5111d43aea638d7d83a24";
@@ -247,16 +261,14 @@ var init_defaults = __esm({
247
261
  });
248
262
 
249
263
  // src/types/config.ts
250
- var DEFAULT_RETRY_CONFIG, DEFAULT_FEATURE_FLAGS;
264
+ var DEFAULT_RETRY_CONFIG, RATE_LIMIT_WAIT_BUDGET_MS, DEFAULT_FEATURE_FLAGS;
251
265
  var init_config = __esm({
252
266
  "src/types/config.ts"() {
253
267
  "use strict";
254
268
  DEFAULT_RETRY_CONFIG = {
255
- autoRetry: true,
256
- maxRetries: 3,
257
- baseDelayMs: 1e3,
258
269
  approachingThreshold: 5
259
270
  };
271
+ RATE_LIMIT_WAIT_BUDGET_MS = 1e4;
260
272
  DEFAULT_FEATURE_FLAGS = {
261
273
  tokensPagination: true,
262
274
  balanceStreaming: false,
@@ -3709,9 +3721,6 @@ function resolveConfig(input) {
3709
3721
  const theme = input.theme ?? "system";
3710
3722
  const messages = deepMerge(DEFAULT_MESSAGES, input.messages);
3711
3723
  const retry = {
3712
- autoRetry: input.retry?.autoRetry ?? DEFAULT_RETRY_CONFIG.autoRetry,
3713
- maxRetries: input.retry?.maxRetries ?? DEFAULT_RETRY_CONFIG.maxRetries,
3714
- baseDelayMs: input.retry?.baseDelayMs ?? DEFAULT_RETRY_CONFIG.baseDelayMs,
3715
3724
  approachingThreshold: input.retry?.approachingThreshold ?? DEFAULT_RETRY_CONFIG.approachingThreshold,
3716
3725
  onRateLimitInfo: input.retry?.onRateLimitInfo,
3717
3726
  onRateLimited: input.retry?.onRateLimited,
@@ -3812,50 +3821,54 @@ function notifyRateLimitCallbacks(info, isRateLimited, retryCount) {
3812
3821
  retry.onRateLimitApproaching(info, retry.approachingThreshold);
3813
3822
  }
3814
3823
  }
3815
- function calculateBackoffDelay(baseDelayMs, retryCount, retryAfter) {
3816
- if (retryAfter && retryAfter > 0) {
3817
- return retryAfter * 1e3;
3824
+ function serverDirectedWaitMs(info) {
3825
+ if (!info) return null;
3826
+ if (typeof info.retryAfter === "number" && info.retryAfter > 0) {
3827
+ return info.retryAfter * 1e3;
3818
3828
  }
3819
- return baseDelayMs * Math.pow(2, retryCount);
3829
+ if (typeof info.reset === "number" && info.reset > 0) {
3830
+ const untilReset = info.reset * 1e3 - Date.now();
3831
+ if (untilReset > 0) return untilReset;
3832
+ }
3833
+ return null;
3820
3834
  }
3821
3835
  function sleep(ms) {
3822
3836
  return new Promise((resolve) => setTimeout(resolve, ms));
3823
3837
  }
3824
- async function rateLimitedFetch(url, options = {}) {
3825
- const { skipRateLimit, ...fetchOptions } = options;
3826
- const cfg = TrustwareConfigStore.get();
3827
- if (!cfg.retry.autoRetry || skipRateLimit) {
3828
- return fetch(url, fetchOptions);
3829
- }
3830
- const { maxRetries, baseDelayMs } = cfg.retry;
3838
+ async function withRateLimitRetry(attempt) {
3839
+ let waitedMs = 0;
3831
3840
  let retryCount = 0;
3832
3841
  while (true) {
3833
- const response = await fetch(url, fetchOptions);
3842
+ const response = await attempt();
3834
3843
  const rateLimitInfo = parseRateLimitHeaders(response);
3835
- if (response.status === 429) {
3844
+ if (response.status !== 429) {
3836
3845
  if (rateLimitInfo) {
3837
- notifyRateLimitCallbacks(rateLimitInfo, true, retryCount);
3838
- }
3839
- if (retryCount >= maxRetries) {
3840
- throw new RateLimitError(
3841
- rateLimitInfo || { limit: 0, remaining: 0, reset: 0 },
3842
- true
3843
- );
3846
+ notifyRateLimitCallbacks(rateLimitInfo, false, 0);
3844
3847
  }
3845
- const delay = calculateBackoffDelay(
3846
- baseDelayMs,
3847
- retryCount,
3848
- rateLimitInfo?.retryAfter
3849
- );
3850
- await sleep(delay);
3851
- retryCount++;
3852
- continue;
3848
+ return response;
3853
3849
  }
3854
3850
  if (rateLimitInfo) {
3855
- notifyRateLimitCallbacks(rateLimitInfo, false, 0);
3851
+ notifyRateLimitCallbacks(rateLimitInfo, true, retryCount);
3852
+ }
3853
+ const waitMs = serverDirectedWaitMs(rateLimitInfo);
3854
+ const info = rateLimitInfo || { limit: 0, remaining: 0, reset: 0 };
3855
+ if (waitMs === null) {
3856
+ throw new RateLimitError(info, true);
3856
3857
  }
3857
- return response;
3858
+ if (waitedMs + waitMs > RATE_LIMIT_WAIT_BUDGET_MS) {
3859
+ throw new RateLimitError(info, false);
3860
+ }
3861
+ await sleep(waitMs);
3862
+ waitedMs += waitMs;
3863
+ retryCount++;
3864
+ }
3865
+ }
3866
+ async function rateLimitedFetch(url, options = {}) {
3867
+ const { skipRateLimit, ...fetchOptions } = options;
3868
+ if (skipRateLimit) {
3869
+ return fetch(url, fetchOptions);
3858
3870
  }
3871
+ return withRateLimitRetry(() => fetch(url, fetchOptions));
3859
3872
  }
3860
3873
  var RateLimitError;
3861
3874
  var init_http = __esm({
@@ -3863,9 +3876,11 @@ var init_http = __esm({
3863
3876
  "use strict";
3864
3877
  init_constants();
3865
3878
  init_config2();
3879
+ init_config();
3866
3880
  RateLimitError = class extends Error {
3867
3881
  constructor(info, retriesExhausted) {
3868
- 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.`;
3882
+ const seconds = info.retryAfter ?? (info.reset > 0 ? Math.max(0, Math.ceil((info.reset * 1e3 - Date.now()) / 1e3)) : null);
3883
+ const message = seconds === null ? "Rate limit exceeded. The server did not say when to retry." : `Rate limit exceeded. Try again in ${seconds} seconds.`;
3869
3884
  super(message);
3870
3885
  this.name = "RateLimitError";
3871
3886
  this.rateLimitInfo = info;