@trustware/sdk-staging 1.1.12-staging.7 → 1.1.12-staging.8

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/widget.mjs CHANGED
@@ -571,7 +571,7 @@ var init_constants = __esm({
571
571
  "src/constants.ts"() {
572
572
  "use strict";
573
573
  SDK_NAME = "@trustware/sdk";
574
- SDK_VERSION = "1.1.12-staging.7";
574
+ SDK_VERSION = "1.1.12-staging.8";
575
575
  API_ROOT = "https://bv-staging-api.trustware.io";
576
576
  GTM_ID = "GTM-TZDGNCXB";
577
577
  API_PREFIX = "/api";
@@ -8911,12 +8911,32 @@ function mapWalletTokens(balances, chains, tokens) {
8911
8911
  if (!foundToken && balanceRow.category === "native") {
8912
8912
  const nativeAddress = canonicalTokenAddressForChain(
8913
8913
  chain,
8914
- getNativeTokenAddress2(chain.type),
8914
+ getNativeTokenAddress2(normalizeChainType2(chain)),
8915
8915
  tokens
8916
8916
  );
8917
8917
  const nativeKey = `${normalizeChainKey2(balanceRow.chain_id)}:${nativeAddress}`;
8918
8918
  foundToken = tokensByCanonicalKey.get(nativeKey);
8919
8919
  }
8920
+ if (!foundToken && balanceRow.category === "native") {
8921
+ const native = chain.nativeCurrency;
8922
+ const symbol = native?.symbol?.trim();
8923
+ if (symbol) {
8924
+ return [
8925
+ {
8926
+ ...balanceRow,
8927
+ symbol,
8928
+ decimals: native?.decimals ?? balanceRow.decimals ?? 18,
8929
+ name: native?.name?.trim() || symbol,
8930
+ iconUrl: chain.chainIconURI || "",
8931
+ chainId: balanceRow.chain_id,
8932
+ usdPrice: void 0,
8933
+ address: getNativeTokenAddress2(normalizeChainType2(chain)),
8934
+ chainIconURI: chain.chainIconURI || "",
8935
+ chainData: chain
8936
+ }
8937
+ ];
8938
+ }
8939
+ }
8920
8940
  if (!foundToken?.name || !foundToken.symbol || !foundToken.address) {
8921
8941
  return [];
8922
8942
  }
@@ -34157,6 +34177,33 @@ var init_useSwapExecution = __esm({
34157
34177
  }
34158
34178
  });
34159
34179
 
34180
+ // src/modes/swap/walletBalance.ts
34181
+ function compareKey(address, chainType) {
34182
+ if (chainType) return normalizeAddress2(address, chainType);
34183
+ return HEX_ADDRESS.test(address.trim()) ? address.toLowerCase() : address.trim();
34184
+ }
34185
+ function findWalletBalanceRow(rows, token, chainId, chainType) {
34186
+ const rawAddress = token?.address;
34187
+ if (!rawAddress || !rows?.length) return void 0;
34188
+ const wantAddress = compareKey(rawAddress, chainType);
34189
+ if (!wantAddress) return void 0;
34190
+ const wantChain = chainId == null ? "" : String(chainId).trim().toLowerCase();
34191
+ return rows.find((row) => {
34192
+ if (!row?.address) return false;
34193
+ if (compareKey(row.address, chainType) !== wantAddress) return false;
34194
+ if (!wantChain) return true;
34195
+ return String(row.chainId ?? "").trim().toLowerCase() === wantChain;
34196
+ });
34197
+ }
34198
+ var HEX_ADDRESS;
34199
+ var init_walletBalance = __esm({
34200
+ "src/modes/swap/walletBalance.ts"() {
34201
+ "use strict";
34202
+ init_chainHelpers();
34203
+ HEX_ADDRESS = /^0x[0-9a-f]+$/i;
34204
+ }
34205
+ });
34206
+
34160
34207
  // src/core/forex.ts
34161
34208
  async function fetchForexRates(base2 = "USD") {
34162
34209
  let r;
@@ -36318,14 +36365,19 @@ function SwapMode({
36318
36365
  route
36319
36366
  ]);
36320
36367
  const fromBalance = useMemo29(() => {
36321
- const walletToken = fromToken;
36322
- if (!walletToken || !("balance" in walletToken)) return null;
36323
- const raw = walletToken.balance;
36368
+ if (!fromToken) return null;
36369
+ const row = findWalletBalanceRow(
36370
+ yourWalletTokens,
36371
+ fromToken,
36372
+ fromChain?.chainId,
36373
+ normalizeChainType2(fromChain)
36374
+ );
36375
+ const raw = row?.balance ?? fromToken.balance;
36324
36376
  if (!raw) return null;
36325
- const decimals = fromToken?.decimals ?? 18;
36377
+ const decimals = row?.decimals ?? fromToken?.decimals ?? 18;
36326
36378
  const n = Number(rawToDecimal(raw, decimals));
36327
36379
  return Number.isFinite(n) ? n : null;
36328
- }, [fromToken]);
36380
+ }, [fromToken, fromChain, yourWalletTokens]);
36329
36381
  const balanceUsd = fromBalance !== null && hasFromUsdPrice ? fromBalance * fromTokenPriceUSD : null;
36330
36382
  const estimatedToAmount = useMemo29(() => {
36331
36383
  if (tokenSellNum <= 0 || !hasFromUsdPrice || !hasToUsdPrice) return null;
@@ -40088,6 +40140,7 @@ var init_SwapMode = __esm({
40088
40140
  init_useSwapRoute();
40089
40141
  init_useSwapExecution();
40090
40142
  init_routeValue();
40143
+ init_walletBalance();
40091
40144
  init_useForex();
40092
40145
  init_SwapTokenSelect();
40093
40146
  init_currency();