@rash2x/bridge-widget 0.6.99 → 0.7.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.
@@ -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
  }
@@ -2337,26 +2379,58 @@ function getRouteDisplayName(route) {
2337
2379
  return route.split(/[/\-_]/).map((part) => part.charAt(0).toUpperCase() + part.slice(1)).join(" ");
2338
2380
  }
2339
2381
  function computeFeeBreakdownUsd(quote, srcToken, tokens, chains) {
2340
- const empty = { messageFeeUsd: 0, bridgeFeeUsd: 0, totalFeeUsd: 0 };
2382
+ const empty = {
2383
+ messageFeeAmount: 0,
2384
+ messageFeeSymbol: "",
2385
+ messageFeeUsd: 0,
2386
+ bridgeFeeAmount: 0,
2387
+ bridgeFeeSymbol: "",
2388
+ bridgeFeeUsd: 0,
2389
+ totalFeeUsd: 0
2390
+ };
2341
2391
  if (!quote || !srcToken) return empty;
2342
2392
  let messageFeeUsd = 0;
2393
+ let messageFeeAmount = 0;
2394
+ let messageFeeSymbol = "";
2343
2395
  const messageFees = quote.fees.filter((f4) => f4.type === "message");
2344
2396
  for (const f4 of messageFees) {
2345
- const { decimals, priceUsd } = lookupTokenMeta(tokens, chains, f4.chainKey, f4.token);
2397
+ const { decimals, priceUsd } = lookupTokenMeta(
2398
+ tokens,
2399
+ chains,
2400
+ f4.chainKey,
2401
+ f4.token
2402
+ );
2346
2403
  const human = fromLD(f4.amount || "0", decimals);
2404
+ messageFeeAmount += human;
2347
2405
  messageFeeUsd += human * (priceUsd ?? 0);
2406
+ if (!messageFeeSymbol) {
2407
+ const chain2 = chains?.find((c2) => c2.chainKey === f4.chainKey);
2408
+ const token = tokens?.find(
2409
+ (t2) => t2.chainKey === f4.chainKey && t2.address.toLowerCase() === f4.token.toLowerCase()
2410
+ );
2411
+ messageFeeSymbol = token?.symbol?.toUpperCase() ?? chain2?.nativeCurrency?.symbol?.toUpperCase() ?? "";
2412
+ }
2348
2413
  }
2414
+ let bridgeFeeAmount = 0;
2349
2415
  let bridgeFeeUsd = 0;
2350
- if (srcToken.price?.usd) {
2351
- const srcHuman = fromLD(quote.srcAmount, srcToken.decimals);
2352
- const dstHuman = fromLD(quote.dstAmount, srcToken.decimals);
2353
- const diff = srcHuman - dstHuman;
2354
- if (diff > 0) {
2355
- bridgeFeeUsd = diff * srcToken.price.usd;
2356
- }
2416
+ const bridgeFeeSymbol = srcToken.symbol?.toUpperCase() ?? "";
2417
+ const srcHuman = fromLD(quote.srcAmount, srcToken.decimals);
2418
+ const dstHuman = fromLD(quote.dstAmount, srcToken.decimals);
2419
+ const diff = srcHuman - dstHuman;
2420
+ if (diff > 0) {
2421
+ bridgeFeeAmount = diff;
2422
+ bridgeFeeUsd = (srcToken.price?.usd ?? 0) * diff;
2357
2423
  }
2358
2424
  const totalFeeUsd = messageFeeUsd + bridgeFeeUsd;
2359
- return { messageFeeUsd, bridgeFeeUsd, totalFeeUsd };
2425
+ return {
2426
+ messageFeeAmount,
2427
+ messageFeeSymbol,
2428
+ messageFeeUsd,
2429
+ bridgeFeeAmount,
2430
+ bridgeFeeSymbol,
2431
+ bridgeFeeUsd,
2432
+ totalFeeUsd
2433
+ };
2360
2434
  }
2361
2435
  async function addNetworkFeesToQuote(quote, chainRegistry, chains) {
2362
2436
  if (!quote || !chains) {
@@ -2374,7 +2448,9 @@ async function addNetworkFeesToQuote(quote, chainRegistry, chains) {
2374
2448
  if (!strategy) continue;
2375
2449
  const chain2 = chains.find((c2) => c2.chainKey === chainKey);
2376
2450
  if (!chain2) continue;
2377
- const stepsForChain = quote.steps.filter((step) => step.chainKey === chainKey);
2451
+ const stepsForChain = quote.steps.filter(
2452
+ (step) => step.chainKey === chainKey
2453
+ );
2378
2454
  if (!stepsForChain.length) continue;
2379
2455
  try {
2380
2456
  const networkFeeHuman = await strategy.estimateNetworkFee(stepsForChain);
@@ -2391,7 +2467,10 @@ async function addNetworkFeesToQuote(quote, chainRegistry, chains) {
2391
2467
  });
2392
2468
  }
2393
2469
  } catch (error) {
2394
- console.warn(`Failed to estimate network fee for chain ${chainKey}:`, error);
2470
+ console.warn(
2471
+ `Failed to estimate network fee for chain ${chainKey}:`,
2472
+ error
2473
+ );
2395
2474
  }
2396
2475
  }
2397
2476
  return {
@@ -2865,7 +2944,7 @@ const TokenSymbol = ({
2865
2944
  };
2866
2945
  function useFeeBreakdown() {
2867
2946
  const { quote } = useBridgeQuoteStore();
2868
- const { tokens, selectedAssetSymbol, assetMatrix } = useTokensStore();
2947
+ const { tokens, allTokens, selectedAssetSymbol, assetMatrix } = useTokensStore();
2869
2948
  const { fromChain, chains } = useChainsStore();
2870
2949
  return useMemo(() => {
2871
2950
  const srcToken = resolveTokenOnChainFromMatrix$1(
@@ -2873,8 +2952,8 @@ function useFeeBreakdown() {
2873
2952
  selectedAssetSymbol,
2874
2953
  fromChain?.chainKey
2875
2954
  );
2876
- return computeFeeBreakdownUsd(quote, srcToken, tokens, chains);
2877
- }, [quote, tokens, chains, selectedAssetSymbol, assetMatrix, fromChain]);
2955
+ return computeFeeBreakdownUsd(quote, srcToken, allTokens ?? tokens, chains);
2956
+ }, [quote, allTokens, tokens, chains, selectedAssetSymbol, assetMatrix, fromChain]);
2878
2957
  }
2879
2958
  function useBridgeExternalData(options) {
2880
2959
  const selectedAssetSymbol = useTokensStore(
@@ -2882,6 +2961,7 @@ function useBridgeExternalData(options) {
2882
2961
  );
2883
2962
  const assetMatrix = useTokensStore((state2) => state2.assetMatrix);
2884
2963
  const tokens = useTokensStore((state2) => state2.tokens);
2964
+ const allTokens = useTokensStore((state2) => state2.allTokens);
2885
2965
  const fromChain = useChainsStore((state2) => state2.fromChain);
2886
2966
  const toChain = useChainsStore((state2) => state2.toChain);
2887
2967
  const chains = useChainsStore((state2) => state2.chains);
@@ -2896,7 +2976,7 @@ function useBridgeExternalData(options) {
2896
2976
  dstChain: toChain,
2897
2977
  assetMatrix,
2898
2978
  chains,
2899
- tokens,
2979
+ tokens: allTokens ?? tokens,
2900
2980
  quote,
2901
2981
  slippageBps
2902
2982
  }),
@@ -2907,6 +2987,7 @@ function useBridgeExternalData(options) {
2907
2987
  toChain,
2908
2988
  assetMatrix,
2909
2989
  chains,
2990
+ allTokens,
2910
2991
  tokens,
2911
2992
  quote,
2912
2993
  slippageBps
@@ -3023,6 +3104,8 @@ const Details = () => {
3023
3104
  1,
3024
3105
  Math.round(bridgeData.quoteDetails?.etaSeconds / 60)
3025
3106
  )}m` : "—";
3107
+ const messageFeeDisplay = !quote ? "—" : fees.messageFeeAmount > 0 ? `${truncateToDecimals(fees.messageFeeAmount, 6)} ${fees.messageFeeSymbol}` : "—";
3108
+ const bridgeFeeDisplay = !quote ? "—" : fees.bridgeFeeAmount > 0 ? `${truncateToDecimals(fees.bridgeFeeAmount, 6)} ${fees.bridgeFeeSymbol}` : "—";
3026
3109
  const totalFeeDisplay = !quote ? "—" : formatUsd(fees.totalFeeUsd);
3027
3110
  const currentSlippageText = !quote ? "—" : formatPercentage(slippageBps);
3028
3111
  const routeText = getRouteDisplayName(quote?.route);
@@ -3064,6 +3147,24 @@ const Details = () => {
3064
3147
  value: currentSlippageText
3065
3148
  }
3066
3149
  ),
3150
+ /* @__PURE__ */ jsx(
3151
+ DetailsRow,
3152
+ {
3153
+ label: t2("transaction.messageFee"),
3154
+ tooltip: t2("transaction.messageFeeTooltip"),
3155
+ value: messageFeeDisplay,
3156
+ isLoading
3157
+ }
3158
+ ),
3159
+ /* @__PURE__ */ jsx(
3160
+ DetailsRow,
3161
+ {
3162
+ label: t2("transaction.bridgeFee"),
3163
+ tooltip: t2("transaction.bridgeFeeTooltip"),
3164
+ value: bridgeFeeDisplay,
3165
+ isLoading
3166
+ }
3167
+ ),
3067
3168
  /* @__PURE__ */ jsx(
3068
3169
  DetailsRow,
3069
3170
  {
@@ -25734,7 +25835,7 @@ class WalletConnectModal {
25734
25835
  }
25735
25836
  async initUi() {
25736
25837
  if (typeof window !== "undefined") {
25737
- await import("./index-ZGjXGtUd.js");
25838
+ await import("./index-Fzl5CHpO.js");
25738
25839
  const modal = document.createElement("wcm-modal");
25739
25840
  document.body.insertAdjacentElement("beforeend", modal);
25740
25841
  OptionsCtrl.setIsUiLoaded(true);
@@ -26582,4 +26683,4 @@ export {
26582
26683
  calculateMinReceived as y,
26583
26684
  getQuoteDetails as z
26584
26685
  };
26585
- //# sourceMappingURL=index-d47EGpyZ.js.map
26686
+ //# sourceMappingURL=index-DMIMGpk_.js.map