@trustware/sdk-staging 1.1.11-staging.2 → 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 (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 +60 -21
  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 +60 -21
  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 +14 -4
  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 +14 -4
  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 +60 -21
  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 +60 -21
  42. package/dist/widget.mjs.map +1 -1
  43. package/package.json +2 -1
@@ -47,10 +47,34 @@ type TokenPageResult = {
47
47
  data: TokenDef[];
48
48
  pageInfo: TokenPageInfo;
49
49
  };
50
+ /**
51
+ * Terminal state of an address balance scan.
52
+ *
53
+ * `partial` is the one field a caller cannot reconstruct from the chunks: the
54
+ * backend scans every configured chain and reports `partial: true` when any of
55
+ * them failed, so "no balance on chain X" and "we could not reach chain X" look
56
+ * identical in the rows themselves. Rendering an empty wallet off a partial
57
+ * scan is the failure this exists to prevent.
58
+ */
59
+ type BalanceStreamSummary = {
60
+ address: string;
61
+ partial: boolean;
62
+ /** Chains that reported a result — equal to `total` on a complete scan. */
63
+ completed: number;
64
+ total: number;
65
+ /** Server-side scan duration. Absent on the buffered path, which does not report it. */
66
+ elapsedMs?: number;
67
+ };
50
68
  type BalanceStreamOptions = {
51
69
  stream?: boolean;
52
70
  signal?: AbortSignal;
53
71
  strict?: boolean;
72
+ /**
73
+ * Called once per scan with its terminal state, on the streamed and buffered
74
+ * paths alike — including when a stream fails and falls back — so a consumer
75
+ * can trust `partial` without knowing which path served it.
76
+ */
77
+ onSummary?: (summary: BalanceStreamSummary) => void;
54
78
  };
55
79
  type GetBalancesOptions = {
56
80
  /** Bypass the in-memory balance cache and re-fetch fresh data from the network. */
@@ -111,4 +135,4 @@ type TokenWithBalance = TokenDef & {
111
135
  balance?: bigint;
112
136
  };
113
137
 
114
- export type { BalanceRow as B, ChainDef as C, GetBalancesOptions as G, NativeCurrency as N, TokenDef as T, WalletAddressBalanceWrapper as W, BalanceStreamOptions as a, ChainMeta as b, ChainType as c, TokenMeta as d, TokenPageInfo as e, TokenPageOptions as f, TokenPageResult as g, TokenType as h, TokenWithBalance as i };
138
+ export type { BalanceRow as B, ChainDef as C, GetBalancesOptions as G, NativeCurrency as N, TokenDef as T, WalletAddressBalanceWrapper as W, BalanceStreamOptions as a, BalanceStreamSummary as b, ChainMeta as c, ChainType as d, TokenMeta as e, TokenPageInfo as f, TokenPageOptions as g, TokenPageResult as h, TokenType as i, TokenWithBalance as j };
@@ -47,10 +47,34 @@ type TokenPageResult = {
47
47
  data: TokenDef[];
48
48
  pageInfo: TokenPageInfo;
49
49
  };
50
+ /**
51
+ * Terminal state of an address balance scan.
52
+ *
53
+ * `partial` is the one field a caller cannot reconstruct from the chunks: the
54
+ * backend scans every configured chain and reports `partial: true` when any of
55
+ * them failed, so "no balance on chain X" and "we could not reach chain X" look
56
+ * identical in the rows themselves. Rendering an empty wallet off a partial
57
+ * scan is the failure this exists to prevent.
58
+ */
59
+ type BalanceStreamSummary = {
60
+ address: string;
61
+ partial: boolean;
62
+ /** Chains that reported a result — equal to `total` on a complete scan. */
63
+ completed: number;
64
+ total: number;
65
+ /** Server-side scan duration. Absent on the buffered path, which does not report it. */
66
+ elapsedMs?: number;
67
+ };
50
68
  type BalanceStreamOptions = {
51
69
  stream?: boolean;
52
70
  signal?: AbortSignal;
53
71
  strict?: boolean;
72
+ /**
73
+ * Called once per scan with its terminal state, on the streamed and buffered
74
+ * paths alike — including when a stream fails and falls back — so a consumer
75
+ * can trust `partial` without knowing which path served it.
76
+ */
77
+ onSummary?: (summary: BalanceStreamSummary) => void;
54
78
  };
55
79
  type GetBalancesOptions = {
56
80
  /** Bypass the in-memory balance cache and re-fetch fresh data from the network. */
@@ -111,4 +135,4 @@ type TokenWithBalance = TokenDef & {
111
135
  balance?: bigint;
112
136
  };
113
137
 
114
- export type { BalanceRow as B, ChainDef as C, GetBalancesOptions as G, NativeCurrency as N, TokenDef as T, WalletAddressBalanceWrapper as W, BalanceStreamOptions as a, ChainMeta as b, ChainType as c, TokenMeta as d, TokenPageInfo as e, TokenPageOptions as f, TokenPageResult as g, TokenType as h, TokenWithBalance as i };
138
+ export type { BalanceRow as B, ChainDef as C, GetBalancesOptions as G, NativeCurrency as N, TokenDef as T, WalletAddressBalanceWrapper as W, BalanceStreamOptions as a, BalanceStreamSummary as b, ChainMeta as c, ChainType as d, TokenMeta as e, TokenPageInfo as f, TokenPageOptions as g, TokenPageResult as h, TokenType as i, TokenWithBalance as j };
@@ -30,7 +30,7 @@ __export(constants_exports, {
30
30
  });
31
31
  module.exports = __toCommonJS(constants_exports);
32
32
  var SDK_NAME = "@trustware/sdk";
33
- var SDK_VERSION = "1.1.11-staging.2";
33
+ var SDK_VERSION = "1.1.12-staging.1";
34
34
  var API_ROOT = "https://bv-staging-api.trustware.io";
35
35
  var GTM_ID = "GTM-TZDGNCXB";
36
36
  var API_PREFIX = "/api";
@@ -1,6 +1,6 @@
1
1
  // src/constants.ts
2
2
  var SDK_NAME = "@trustware/sdk";
3
- var SDK_VERSION = "1.1.11-staging.2";
3
+ var SDK_VERSION = "1.1.12-staging.1";
4
4
  var API_ROOT = "https://bv-staging-api.trustware.io";
5
5
  var GTM_ID = "GTM-TZDGNCXB";
6
6
  var API_PREFIX = "/api";
@@ -1,6 +1,6 @@
1
- import { n as BuildRouteResult, k as Transaction, T as TrustwareConfigOptions, i as WalletInterFaceAPI, A as ResolvedTrustwareConfig, X as TrustwareTheme, a2 as WalletIdentity, w as walletManager, Z as WalletAddressResolution, aa as buildRoute, ab as buildDepositAddress, ac as submitReceipt, ad as submitStepReceipt, ae as getStatus, af as pollStatus } from './manager-Bw8b1wSD.js';
2
- import { C as ChainDef, c as ChainType, G as GetBalancesOptions, B as BalanceRow, a as BalanceStreamOptions, W as WalletAddressBalanceWrapper } from './blockchain-BxAFzp0s.js';
3
- import { T as Token } from './types-BJY9r-mz.js';
1
+ import { n as BuildRouteResult, k as Transaction, T as TrustwareConfigOptions, i as WalletInterFaceAPI, A as ResolvedTrustwareConfig, X as TrustwareTheme, a2 as WalletIdentity, w as walletManager, Z as WalletAddressResolution, aa as buildRoute, ab as buildDepositAddress, ac as submitReceipt, ad as submitStepReceipt, ae as getStatus, af as pollStatus } from './manager-D8nQsod2.js';
2
+ import { C as ChainDef, d as ChainType, G as GetBalancesOptions, B as BalanceRow, a as BalanceStreamOptions, W as WalletAddressBalanceWrapper } from './blockchain-DmCPxnxr.js';
3
+ import { T as Token } from './types-CMmx0S4U.js';
4
4
 
5
5
  type AddressValidationResult = {
6
6
  isValid: boolean;
@@ -1,6 +1,6 @@
1
- import { n as BuildRouteResult, k as Transaction, T as TrustwareConfigOptions, i as WalletInterFaceAPI, A as ResolvedTrustwareConfig, X as TrustwareTheme, a2 as WalletIdentity, w as walletManager, Z as WalletAddressResolution, aa as buildRoute, ab as buildDepositAddress, ac as submitReceipt, ad as submitStepReceipt, ae as getStatus, af as pollStatus } from './manager-DNGk1YkR.cjs';
2
- import { C as ChainDef, c as ChainType, G as GetBalancesOptions, B as BalanceRow, a as BalanceStreamOptions, W as WalletAddressBalanceWrapper } from './blockchain-BxAFzp0s.cjs';
3
- import { T as Token } from './types-DX3HtFcn.cjs';
1
+ import { n as BuildRouteResult, k as Transaction, T as TrustwareConfigOptions, i as WalletInterFaceAPI, A as ResolvedTrustwareConfig, X as TrustwareTheme, a2 as WalletIdentity, w as walletManager, Z as WalletAddressResolution, aa as buildRoute, ab as buildDepositAddress, ac as submitReceipt, ad as submitStepReceipt, ae as getStatus, af as pollStatus } from './manager-BZ8gyHGT.cjs';
2
+ import { C as ChainDef, d as ChainType, G as GetBalancesOptions, B as BalanceRow, a as BalanceStreamOptions, W as WalletAddressBalanceWrapper } from './blockchain-DmCPxnxr.cjs';
3
+ import { T as Token } from './types-DEUb5IZA.cjs';
4
4
 
5
5
  type AddressValidationResult = {
6
6
  isValid: boolean;
package/dist/core.cjs CHANGED
@@ -57,7 +57,17 @@ var init_config = __esm({
57
57
  RATE_LIMIT_WAIT_BUDGET_MS = 1e4;
58
58
  DEFAULT_FEATURE_FLAGS = {
59
59
  tokensPagination: true,
60
- balanceStreaming: false,
60
+ // On by default: an address scan covers every configured chain and takes
61
+ // seconds end to end, so streaming turns one long wait into a wallet that
62
+ // fills in as results land — first chunk in ~200ms against a ~2.3s buffered
63
+ // response, measured on a live backend.
64
+ //
65
+ // Safe to default because the path degrades on its own: a backend with
66
+ // BALANCE_STREAM_ENABLED off refuses the stream, and the SDK falls back to
67
+ // the buffered endpoint (emitting balance_stream_fallback), as does any
68
+ // runtime whose fetch has no readable body — React Native, most notably.
69
+ // The cost of defaulting ahead of a backend is one refused request per scan.
70
+ balanceStreaming: true,
61
71
  shouldAllowGA4: true,
62
72
  swapMode: false,
63
73
  swapDefaultDestToken: null,
@@ -73,7 +83,7 @@ var init_constants = __esm({
73
83
  "src/constants.ts"() {
74
84
  "use strict";
75
85
  SDK_NAME = "@trustware/sdk";
76
- SDK_VERSION = "1.1.11-staging.2";
86
+ SDK_VERSION = "1.1.12-staging.1";
77
87
  API_ROOT = "https://bv-staging-api.trustware.io";
78
88
  API_PREFIX = "/api";
79
89
  WALLETCONNECT_PROJECT_ID = "72ea74c400f5111d43aea638d7d83a24";
@@ -116,7 +126,7 @@ async function assertOK(r) {
116
126
  throw new Error(`HTTP ${r.status}: ${msg}`);
117
127
  }
118
128
  async function validateSdkAccess() {
119
- const r = await fetch(`${apiBase()}/sdk/validate`, {
129
+ const r = await fetch(`${apiBase()}/v1/sdk/validate`, {
120
130
  method: "GET",
121
131
  headers: jsonHeaders()
122
132
  });
@@ -1799,6 +1809,16 @@ function mergeBalanceWrappers(current, incoming) {
1799
1809
  }
1800
1810
  return Array.from(merged.values());
1801
1811
  }
1812
+ function toSummary(frame, address) {
1813
+ const total = toNumberOrUndefined(frame.total) ?? 0;
1814
+ return {
1815
+ address: toStringOrUndefined(frame.address) ?? address,
1816
+ partial: Boolean(frame.partial),
1817
+ completed: toNumberOrUndefined(frame.completed) ?? 0,
1818
+ total,
1819
+ elapsedMs: toNumberOrUndefined(frame.elapsed)
1820
+ };
1821
+ }
1802
1822
  async function parseStreamingBalances(response, address, options = {}) {
1803
1823
  if (!response.body) {
1804
1824
  throw new Error("balances stream: empty response body");
@@ -1819,7 +1839,12 @@ async function parseStreamingBalances(response, address, options = {}) {
1819
1839
  if (!trimmed) continue;
1820
1840
  try {
1821
1841
  const parsed = JSON.parse(trimmed);
1822
- if (!parsed.chain_id) continue;
1842
+ if (!parsed.chain_id) {
1843
+ if (parsed.type === "summary") {
1844
+ options.onSummary?.(toSummary(parsed, address));
1845
+ }
1846
+ continue;
1847
+ }
1823
1848
  const chunk = normalizeStreamChunk(parsed);
1824
1849
  emitBalanceStreamChunk(address, chunk.length);
1825
1850
  yield chunk;
@@ -1838,6 +1863,8 @@ async function parseStreamingBalances(response, address, options = {}) {
1838
1863
  const chunk = normalizeStreamChunk(parsed);
1839
1864
  emitBalanceStreamChunk(address, chunk.length);
1840
1865
  yield chunk;
1866
+ } else if (parsed.type === "summary") {
1867
+ options.onSummary?.(toSummary(parsed, address));
1841
1868
  }
1842
1869
  } catch (error) {
1843
1870
  if (options.strict) {
@@ -1892,7 +1919,7 @@ async function getBalancesByAddress(address, opts) {
1892
1919
  }
1893
1920
  return merged;
1894
1921
  }
1895
- const url = `${apiBase()}/data/balances/${address}`;
1922
+ const url = `${apiBase()}/v1/data/balances/${address}`;
1896
1923
  const r = await rateLimitedFetch(url, {
1897
1924
  method: "GET",
1898
1925
  credentials: "omit",
@@ -1900,14 +1927,27 @@ async function getBalancesByAddress(address, opts) {
1900
1927
  });
1901
1928
  if (!r.ok) throw new Error(`balances: HTTP ${r.status}`);
1902
1929
  const j = await r.json();
1903
- return Array.isArray(j) ? j : j.results ?? [];
1930
+ const results = Array.isArray(j) ? j : j.results ?? [];
1931
+ if (opts?.onSummary) {
1932
+ const completed = results.length;
1933
+ opts.onSummary({
1934
+ address,
1935
+ partial: Array.isArray(j) ? false : Boolean(j.partial),
1936
+ completed,
1937
+ total: completed
1938
+ });
1939
+ }
1940
+ return results;
1941
+ }
1942
+ function bufferedOptions(opts) {
1943
+ return { ...opts, stream: false };
1904
1944
  }
1905
1945
  async function* getBalancesByAddressStream(address, opts = {}) {
1906
1946
  if (!TrustwareConfigStore.get().features.balanceStreaming) {
1907
- yield await getBalancesByAddress(address);
1947
+ yield await getBalancesByAddress(address, bufferedOptions(opts));
1908
1948
  return;
1909
1949
  }
1910
- const url = `${apiBase()}/data/balances/${address}?stream=1`;
1950
+ const url = `${apiBase()}/v1/data/balances/${address}?stream=1`;
1911
1951
  try {
1912
1952
  const response = await rateLimitedFetch(url, {
1913
1953
  method: "GET",
@@ -1923,7 +1963,14 @@ async function* getBalancesByAddressStream(address, opts = {}) {
1923
1963
  const contentType = response.headers.get("content-type") ?? "";
1924
1964
  if (contentType.includes("application/json")) {
1925
1965
  const payload = await response.json();
1926
- yield Array.isArray(payload) ? payload : payload.results ?? [];
1966
+ const results = Array.isArray(payload) ? payload : payload.results ?? [];
1967
+ opts.onSummary?.({
1968
+ address,
1969
+ partial: Array.isArray(payload) ? false : Boolean(payload.partial),
1970
+ completed: results.length,
1971
+ total: results.length
1972
+ });
1973
+ yield results;
1927
1974
  return;
1928
1975
  }
1929
1976
  const stream = await parseStreamingBalances(response, address, opts);
@@ -1932,7 +1979,7 @@ async function* getBalancesByAddressStream(address, opts = {}) {
1932
1979
  }
1933
1980
  } catch (error) {
1934
1981
  emitBalanceStreamFallback(address, error);
1935
- yield await getBalancesByAddress(address);
1982
+ yield await getBalancesByAddress(address, bufferedOptions(opts));
1936
1983
  }
1937
1984
  }
1938
1985
  async function ensureRegistry() {