@rash2x/bridge-widget 0.6.99 → 0.7.0

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.
@@ -2210,6 +2210,31 @@ function resolveTokenOnChainFromMatrix$1(assetMatrix, assetSymbol, chainKey) {
2210
2210
  const DEFAULT_SLIPPAGE_BPS = 50;
2211
2211
  const lower = (s2) => (s2 ?? "").toLowerCase();
2212
2212
  const normSym = (s2) => (s2 ?? "").toUpperCase().replace(/₮/g, "T").replace(/[^A-Z0-9]/g, "");
2213
+ const isPositivePrice = (v2) => typeof v2 === "number" && Number.isFinite(v2) && v2 > 0;
2214
+ const NATIVE_SYMBOL_ALIASES = {
2215
+ ETH: ["WETH"],
2216
+ BNB: ["WBNB"],
2217
+ AVAX: ["WAVAX"],
2218
+ TRX: ["WTRX"],
2219
+ MATIC: ["WMATIC", "POL", "WPOL"],
2220
+ POL: ["MATIC", "WMATIC", "WPOL"]
2221
+ };
2222
+ function nativeSymbolCandidates(symbol) {
2223
+ const out = /* @__PURE__ */ new Set([symbol]);
2224
+ if (symbol.startsWith("W") && symbol.length > 1) {
2225
+ out.add(symbol.slice(1));
2226
+ } else {
2227
+ out.add(`W${symbol}`);
2228
+ }
2229
+ for (const alias of NATIVE_SYMBOL_ALIASES[symbol] ?? []) {
2230
+ out.add(alias);
2231
+ }
2232
+ return out;
2233
+ }
2234
+ function pickBestPricedToken(tokens) {
2235
+ if (!tokens.length) return void 0;
2236
+ return tokens.find((t2) => isPositivePrice(t2.price?.usd)) ?? tokens[0];
2237
+ }
2213
2238
  function tonNorm(addr) {
2214
2239
  if (!addr) return null;
2215
2240
  try {
@@ -2257,14 +2282,25 @@ function findNativeMeta(tokens, chain2) {
2257
2282
  if (!sym) {
2258
2283
  return { decimals: nativeDecimals, priceUsd: void 0 };
2259
2284
  }
2260
- const sameChain = tokens?.find(
2261
- (t2) => t2.chainKey === chain2.chainKey && normSym(t2.symbol) === sym
2262
- ) ?? void 0;
2263
- if (sameChain)
2264
- return { decimals: sameChain.decimals, priceUsd: sameChain.price?.usd };
2265
- const anyChain = tokens?.find((t2) => normSym(t2.symbol) === sym);
2266
- if (anyChain)
2267
- return { decimals: anyChain.decimals, priceUsd: anyChain.price?.usd };
2285
+ const symbols = nativeSymbolCandidates(sym);
2286
+ const sameChainMatches = tokens?.filter(
2287
+ (t2) => t2.chainKey === chain2.chainKey && symbols.has(normSym(t2.symbol))
2288
+ ) ?? [];
2289
+ const sameChain = pickBestPricedToken(sameChainMatches);
2290
+ if (sameChain) {
2291
+ return {
2292
+ decimals: sameChain.decimals,
2293
+ priceUsd: isPositivePrice(sameChain.price?.usd) ? sameChain.price?.usd : void 0
2294
+ };
2295
+ }
2296
+ const anyChainMatches = tokens?.filter((t2) => symbols.has(normSym(t2.symbol))) ?? [];
2297
+ const anyChain = pickBestPricedToken(anyChainMatches);
2298
+ if (anyChain) {
2299
+ return {
2300
+ decimals: anyChain.decimals,
2301
+ priceUsd: isPositivePrice(anyChain.price?.usd) ? anyChain.price?.usd : void 0
2302
+ };
2303
+ }
2268
2304
  return { decimals: nativeDecimals, priceUsd: void 0 };
2269
2305
  }
2270
2306
  function lookupTokenMeta(tokens, chains, chainKey, tokenAddr) {
@@ -2279,7 +2315,13 @@ function lookupTokenMeta(tokens, chains, chainKey, tokenAddr) {
2279
2315
  }
2280
2316
  return lower(t2.address) === lower(tokenAddr);
2281
2317
  }) ?? void 0;
2282
- if (hit) return { decimals: hit.decimals, priceUsd: hit.price?.usd };
2318
+ if (hit) {
2319
+ const hitPriceUsd = isPositivePrice(hit.price?.usd) ? hit.price?.usd : void 0;
2320
+ if (hitPriceUsd !== void 0 || !isNativeAddrEqual(chain2, tokenAddr)) {
2321
+ return { decimals: hit.decimals, priceUsd: hitPriceUsd };
2322
+ }
2323
+ return findNativeMeta(tokens, chain2);
2324
+ }
2283
2325
  if (isNativeAddrEqual(chain2, tokenAddr)) {
2284
2326
  return findNativeMeta(tokens, chain2);
2285
2327
  }
@@ -2342,7 +2384,12 @@ function computeFeeBreakdownUsd(quote, srcToken, tokens, chains) {
2342
2384
  let messageFeeUsd = 0;
2343
2385
  const messageFees = quote.fees.filter((f4) => f4.type === "message");
2344
2386
  for (const f4 of messageFees) {
2345
- const { decimals, priceUsd } = lookupTokenMeta(tokens, chains, f4.chainKey, f4.token);
2387
+ const { decimals, priceUsd } = lookupTokenMeta(
2388
+ tokens,
2389
+ chains,
2390
+ f4.chainKey,
2391
+ f4.token
2392
+ );
2346
2393
  const human = fromLD(f4.amount || "0", decimals);
2347
2394
  messageFeeUsd += human * (priceUsd ?? 0);
2348
2395
  }
@@ -2374,7 +2421,9 @@ async function addNetworkFeesToQuote(quote, chainRegistry, chains) {
2374
2421
  if (!strategy) continue;
2375
2422
  const chain2 = chains.find((c2) => c2.chainKey === chainKey);
2376
2423
  if (!chain2) continue;
2377
- const stepsForChain = quote.steps.filter((step) => step.chainKey === chainKey);
2424
+ const stepsForChain = quote.steps.filter(
2425
+ (step) => step.chainKey === chainKey
2426
+ );
2378
2427
  if (!stepsForChain.length) continue;
2379
2428
  try {
2380
2429
  const networkFeeHuman = await strategy.estimateNetworkFee(stepsForChain);
@@ -2391,7 +2440,10 @@ async function addNetworkFeesToQuote(quote, chainRegistry, chains) {
2391
2440
  });
2392
2441
  }
2393
2442
  } catch (error) {
2394
- console.warn(`Failed to estimate network fee for chain ${chainKey}:`, error);
2443
+ console.warn(
2444
+ `Failed to estimate network fee for chain ${chainKey}:`,
2445
+ error
2446
+ );
2395
2447
  }
2396
2448
  }
2397
2449
  return {
@@ -2865,7 +2917,7 @@ const TokenSymbol = ({
2865
2917
  };
2866
2918
  function useFeeBreakdown() {
2867
2919
  const { quote } = useBridgeQuoteStore();
2868
- const { tokens, selectedAssetSymbol, assetMatrix } = useTokensStore();
2920
+ const { tokens, allTokens, selectedAssetSymbol, assetMatrix } = useTokensStore();
2869
2921
  const { fromChain, chains } = useChainsStore();
2870
2922
  return useMemo(() => {
2871
2923
  const srcToken = resolveTokenOnChainFromMatrix$1(
@@ -2873,8 +2925,8 @@ function useFeeBreakdown() {
2873
2925
  selectedAssetSymbol,
2874
2926
  fromChain?.chainKey
2875
2927
  );
2876
- return computeFeeBreakdownUsd(quote, srcToken, tokens, chains);
2877
- }, [quote, tokens, chains, selectedAssetSymbol, assetMatrix, fromChain]);
2928
+ return computeFeeBreakdownUsd(quote, srcToken, allTokens ?? tokens, chains);
2929
+ }, [quote, allTokens, tokens, chains, selectedAssetSymbol, assetMatrix, fromChain]);
2878
2930
  }
2879
2931
  function useBridgeExternalData(options) {
2880
2932
  const selectedAssetSymbol = useTokensStore(
@@ -2882,6 +2934,7 @@ function useBridgeExternalData(options) {
2882
2934
  );
2883
2935
  const assetMatrix = useTokensStore((state2) => state2.assetMatrix);
2884
2936
  const tokens = useTokensStore((state2) => state2.tokens);
2937
+ const allTokens = useTokensStore((state2) => state2.allTokens);
2885
2938
  const fromChain = useChainsStore((state2) => state2.fromChain);
2886
2939
  const toChain = useChainsStore((state2) => state2.toChain);
2887
2940
  const chains = useChainsStore((state2) => state2.chains);
@@ -2896,7 +2949,7 @@ function useBridgeExternalData(options) {
2896
2949
  dstChain: toChain,
2897
2950
  assetMatrix,
2898
2951
  chains,
2899
- tokens,
2952
+ tokens: allTokens ?? tokens,
2900
2953
  quote,
2901
2954
  slippageBps
2902
2955
  }),
@@ -2907,6 +2960,7 @@ function useBridgeExternalData(options) {
2907
2960
  toChain,
2908
2961
  assetMatrix,
2909
2962
  chains,
2963
+ allTokens,
2910
2964
  tokens,
2911
2965
  quote,
2912
2966
  slippageBps
@@ -25734,7 +25788,7 @@ class WalletConnectModal {
25734
25788
  }
25735
25789
  async initUi() {
25736
25790
  if (typeof window !== "undefined") {
25737
- await import("./index-ZGjXGtUd.js");
25791
+ await import("./index-CbOaxQWE.js");
25738
25792
  const modal = document.createElement("wcm-modal");
25739
25793
  document.body.insertAdjacentElement("beforeend", modal);
25740
25794
  OptionsCtrl.setIsUiLoaded(true);
@@ -26582,4 +26636,4 @@ export {
26582
26636
  calculateMinReceived as y,
26583
26637
  getQuoteDetails as z
26584
26638
  };
26585
- //# sourceMappingURL=index-d47EGpyZ.js.map
26639
+ //# sourceMappingURL=index-D_iIDai5.js.map