@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.
@@ -2211,6 +2211,31 @@ function resolveTokenOnChainFromMatrix$1(assetMatrix, assetSymbol, chainKey) {
2211
2211
  const DEFAULT_SLIPPAGE_BPS = 50;
2212
2212
  const lower = (s2) => (s2 ?? "").toLowerCase();
2213
2213
  const normSym = (s2) => (s2 ?? "").toUpperCase().replace(/₮/g, "T").replace(/[^A-Z0-9]/g, "");
2214
+ const isPositivePrice = (v2) => typeof v2 === "number" && Number.isFinite(v2) && v2 > 0;
2215
+ const NATIVE_SYMBOL_ALIASES = {
2216
+ ETH: ["WETH"],
2217
+ BNB: ["WBNB"],
2218
+ AVAX: ["WAVAX"],
2219
+ TRX: ["WTRX"],
2220
+ MATIC: ["WMATIC", "POL", "WPOL"],
2221
+ POL: ["MATIC", "WMATIC", "WPOL"]
2222
+ };
2223
+ function nativeSymbolCandidates(symbol) {
2224
+ const out = /* @__PURE__ */ new Set([symbol]);
2225
+ if (symbol.startsWith("W") && symbol.length > 1) {
2226
+ out.add(symbol.slice(1));
2227
+ } else {
2228
+ out.add(`W${symbol}`);
2229
+ }
2230
+ for (const alias of NATIVE_SYMBOL_ALIASES[symbol] ?? []) {
2231
+ out.add(alias);
2232
+ }
2233
+ return out;
2234
+ }
2235
+ function pickBestPricedToken(tokens) {
2236
+ if (!tokens.length) return void 0;
2237
+ return tokens.find((t2) => isPositivePrice(t2.price?.usd)) ?? tokens[0];
2238
+ }
2214
2239
  function tonNorm(addr) {
2215
2240
  if (!addr) return null;
2216
2241
  try {
@@ -2258,14 +2283,25 @@ function findNativeMeta(tokens, chain2) {
2258
2283
  if (!sym) {
2259
2284
  return { decimals: nativeDecimals, priceUsd: void 0 };
2260
2285
  }
2261
- const sameChain = tokens?.find(
2262
- (t2) => t2.chainKey === chain2.chainKey && normSym(t2.symbol) === sym
2263
- ) ?? void 0;
2264
- if (sameChain)
2265
- return { decimals: sameChain.decimals, priceUsd: sameChain.price?.usd };
2266
- const anyChain = tokens?.find((t2) => normSym(t2.symbol) === sym);
2267
- if (anyChain)
2268
- return { decimals: anyChain.decimals, priceUsd: anyChain.price?.usd };
2286
+ const symbols = nativeSymbolCandidates(sym);
2287
+ const sameChainMatches = tokens?.filter(
2288
+ (t2) => t2.chainKey === chain2.chainKey && symbols.has(normSym(t2.symbol))
2289
+ ) ?? [];
2290
+ const sameChain = pickBestPricedToken(sameChainMatches);
2291
+ if (sameChain) {
2292
+ return {
2293
+ decimals: sameChain.decimals,
2294
+ priceUsd: isPositivePrice(sameChain.price?.usd) ? sameChain.price?.usd : void 0
2295
+ };
2296
+ }
2297
+ const anyChainMatches = tokens?.filter((t2) => symbols.has(normSym(t2.symbol))) ?? [];
2298
+ const anyChain = pickBestPricedToken(anyChainMatches);
2299
+ if (anyChain) {
2300
+ return {
2301
+ decimals: anyChain.decimals,
2302
+ priceUsd: isPositivePrice(anyChain.price?.usd) ? anyChain.price?.usd : void 0
2303
+ };
2304
+ }
2269
2305
  return { decimals: nativeDecimals, priceUsd: void 0 };
2270
2306
  }
2271
2307
  function lookupTokenMeta(tokens, chains, chainKey, tokenAddr) {
@@ -2280,7 +2316,13 @@ function lookupTokenMeta(tokens, chains, chainKey, tokenAddr) {
2280
2316
  }
2281
2317
  return lower(t2.address) === lower(tokenAddr);
2282
2318
  }) ?? void 0;
2283
- if (hit) return { decimals: hit.decimals, priceUsd: hit.price?.usd };
2319
+ if (hit) {
2320
+ const hitPriceUsd = isPositivePrice(hit.price?.usd) ? hit.price?.usd : void 0;
2321
+ if (hitPriceUsd !== void 0 || !isNativeAddrEqual(chain2, tokenAddr)) {
2322
+ return { decimals: hit.decimals, priceUsd: hitPriceUsd };
2323
+ }
2324
+ return findNativeMeta(tokens, chain2);
2325
+ }
2284
2326
  if (isNativeAddrEqual(chain2, tokenAddr)) {
2285
2327
  return findNativeMeta(tokens, chain2);
2286
2328
  }
@@ -2338,26 +2380,58 @@ function getRouteDisplayName(route) {
2338
2380
  return route.split(/[/\-_]/).map((part) => part.charAt(0).toUpperCase() + part.slice(1)).join(" ");
2339
2381
  }
2340
2382
  function computeFeeBreakdownUsd(quote, srcToken, tokens, chains) {
2341
- const empty = { messageFeeUsd: 0, bridgeFeeUsd: 0, totalFeeUsd: 0 };
2383
+ const empty = {
2384
+ messageFeeAmount: 0,
2385
+ messageFeeSymbol: "",
2386
+ messageFeeUsd: 0,
2387
+ bridgeFeeAmount: 0,
2388
+ bridgeFeeSymbol: "",
2389
+ bridgeFeeUsd: 0,
2390
+ totalFeeUsd: 0
2391
+ };
2342
2392
  if (!quote || !srcToken) return empty;
2343
2393
  let messageFeeUsd = 0;
2394
+ let messageFeeAmount = 0;
2395
+ let messageFeeSymbol = "";
2344
2396
  const messageFees = quote.fees.filter((f4) => f4.type === "message");
2345
2397
  for (const f4 of messageFees) {
2346
- const { decimals, priceUsd } = lookupTokenMeta(tokens, chains, f4.chainKey, f4.token);
2398
+ const { decimals, priceUsd } = lookupTokenMeta(
2399
+ tokens,
2400
+ chains,
2401
+ f4.chainKey,
2402
+ f4.token
2403
+ );
2347
2404
  const human = fromLD(f4.amount || "0", decimals);
2405
+ messageFeeAmount += human;
2348
2406
  messageFeeUsd += human * (priceUsd ?? 0);
2407
+ if (!messageFeeSymbol) {
2408
+ const chain2 = chains?.find((c2) => c2.chainKey === f4.chainKey);
2409
+ const token = tokens?.find(
2410
+ (t2) => t2.chainKey === f4.chainKey && t2.address.toLowerCase() === f4.token.toLowerCase()
2411
+ );
2412
+ messageFeeSymbol = token?.symbol?.toUpperCase() ?? chain2?.nativeCurrency?.symbol?.toUpperCase() ?? "";
2413
+ }
2349
2414
  }
2415
+ let bridgeFeeAmount = 0;
2350
2416
  let bridgeFeeUsd = 0;
2351
- if (srcToken.price?.usd) {
2352
- const srcHuman = fromLD(quote.srcAmount, srcToken.decimals);
2353
- const dstHuman = fromLD(quote.dstAmount, srcToken.decimals);
2354
- const diff = srcHuman - dstHuman;
2355
- if (diff > 0) {
2356
- bridgeFeeUsd = diff * srcToken.price.usd;
2357
- }
2417
+ const bridgeFeeSymbol = srcToken.symbol?.toUpperCase() ?? "";
2418
+ const srcHuman = fromLD(quote.srcAmount, srcToken.decimals);
2419
+ const dstHuman = fromLD(quote.dstAmount, srcToken.decimals);
2420
+ const diff = srcHuman - dstHuman;
2421
+ if (diff > 0) {
2422
+ bridgeFeeAmount = diff;
2423
+ bridgeFeeUsd = (srcToken.price?.usd ?? 0) * diff;
2358
2424
  }
2359
2425
  const totalFeeUsd = messageFeeUsd + bridgeFeeUsd;
2360
- return { messageFeeUsd, bridgeFeeUsd, totalFeeUsd };
2426
+ return {
2427
+ messageFeeAmount,
2428
+ messageFeeSymbol,
2429
+ messageFeeUsd,
2430
+ bridgeFeeAmount,
2431
+ bridgeFeeSymbol,
2432
+ bridgeFeeUsd,
2433
+ totalFeeUsd
2434
+ };
2361
2435
  }
2362
2436
  async function addNetworkFeesToQuote(quote, chainRegistry, chains) {
2363
2437
  if (!quote || !chains) {
@@ -2375,7 +2449,9 @@ async function addNetworkFeesToQuote(quote, chainRegistry, chains) {
2375
2449
  if (!strategy) continue;
2376
2450
  const chain2 = chains.find((c2) => c2.chainKey === chainKey);
2377
2451
  if (!chain2) continue;
2378
- const stepsForChain = quote.steps.filter((step) => step.chainKey === chainKey);
2452
+ const stepsForChain = quote.steps.filter(
2453
+ (step) => step.chainKey === chainKey
2454
+ );
2379
2455
  if (!stepsForChain.length) continue;
2380
2456
  try {
2381
2457
  const networkFeeHuman = await strategy.estimateNetworkFee(stepsForChain);
@@ -2392,7 +2468,10 @@ async function addNetworkFeesToQuote(quote, chainRegistry, chains) {
2392
2468
  });
2393
2469
  }
2394
2470
  } catch (error) {
2395
- console.warn(`Failed to estimate network fee for chain ${chainKey}:`, error);
2471
+ console.warn(
2472
+ `Failed to estimate network fee for chain ${chainKey}:`,
2473
+ error
2474
+ );
2396
2475
  }
2397
2476
  }
2398
2477
  return {
@@ -2866,7 +2945,7 @@ const TokenSymbol = ({
2866
2945
  };
2867
2946
  function useFeeBreakdown() {
2868
2947
  const { quote } = useBridgeQuoteStore();
2869
- const { tokens, selectedAssetSymbol, assetMatrix } = useTokensStore();
2948
+ const { tokens, allTokens, selectedAssetSymbol, assetMatrix } = useTokensStore();
2870
2949
  const { fromChain, chains } = useChainsStore();
2871
2950
  return react.useMemo(() => {
2872
2951
  const srcToken = resolveTokenOnChainFromMatrix$1(
@@ -2874,8 +2953,8 @@ function useFeeBreakdown() {
2874
2953
  selectedAssetSymbol,
2875
2954
  fromChain?.chainKey
2876
2955
  );
2877
- return computeFeeBreakdownUsd(quote, srcToken, tokens, chains);
2878
- }, [quote, tokens, chains, selectedAssetSymbol, assetMatrix, fromChain]);
2956
+ return computeFeeBreakdownUsd(quote, srcToken, allTokens ?? tokens, chains);
2957
+ }, [quote, allTokens, tokens, chains, selectedAssetSymbol, assetMatrix, fromChain]);
2879
2958
  }
2880
2959
  function useBridgeExternalData(options) {
2881
2960
  const selectedAssetSymbol = useTokensStore(
@@ -2883,6 +2962,7 @@ function useBridgeExternalData(options) {
2883
2962
  );
2884
2963
  const assetMatrix = useTokensStore((state2) => state2.assetMatrix);
2885
2964
  const tokens = useTokensStore((state2) => state2.tokens);
2965
+ const allTokens = useTokensStore((state2) => state2.allTokens);
2886
2966
  const fromChain = useChainsStore((state2) => state2.fromChain);
2887
2967
  const toChain = useChainsStore((state2) => state2.toChain);
2888
2968
  const chains = useChainsStore((state2) => state2.chains);
@@ -2897,7 +2977,7 @@ function useBridgeExternalData(options) {
2897
2977
  dstChain: toChain,
2898
2978
  assetMatrix,
2899
2979
  chains,
2900
- tokens,
2980
+ tokens: allTokens ?? tokens,
2901
2981
  quote,
2902
2982
  slippageBps
2903
2983
  }),
@@ -2908,6 +2988,7 @@ function useBridgeExternalData(options) {
2908
2988
  toChain,
2909
2989
  assetMatrix,
2910
2990
  chains,
2991
+ allTokens,
2911
2992
  tokens,
2912
2993
  quote,
2913
2994
  slippageBps
@@ -3024,6 +3105,8 @@ const Details = () => {
3024
3105
  1,
3025
3106
  Math.round(bridgeData.quoteDetails?.etaSeconds / 60)
3026
3107
  )}m` : "—";
3108
+ const messageFeeDisplay = !quote ? "—" : fees.messageFeeAmount > 0 ? `${truncateToDecimals(fees.messageFeeAmount, 6)} ${fees.messageFeeSymbol}` : "—";
3109
+ const bridgeFeeDisplay = !quote ? "—" : fees.bridgeFeeAmount > 0 ? `${truncateToDecimals(fees.bridgeFeeAmount, 6)} ${fees.bridgeFeeSymbol}` : "—";
3027
3110
  const totalFeeDisplay = !quote ? "—" : formatUsd(fees.totalFeeUsd);
3028
3111
  const currentSlippageText = !quote ? "—" : formatPercentage(slippageBps);
3029
3112
  const routeText = getRouteDisplayName(quote?.route);
@@ -3065,6 +3148,24 @@ const Details = () => {
3065
3148
  value: currentSlippageText
3066
3149
  }
3067
3150
  ),
3151
+ /* @__PURE__ */ jsxRuntime.jsx(
3152
+ DetailsRow,
3153
+ {
3154
+ label: t2("transaction.messageFee"),
3155
+ tooltip: t2("transaction.messageFeeTooltip"),
3156
+ value: messageFeeDisplay,
3157
+ isLoading
3158
+ }
3159
+ ),
3160
+ /* @__PURE__ */ jsxRuntime.jsx(
3161
+ DetailsRow,
3162
+ {
3163
+ label: t2("transaction.bridgeFee"),
3164
+ tooltip: t2("transaction.bridgeFeeTooltip"),
3165
+ value: bridgeFeeDisplay,
3166
+ isLoading
3167
+ }
3168
+ ),
3068
3169
  /* @__PURE__ */ jsxRuntime.jsx(
3069
3170
  DetailsRow,
3070
3171
  {
@@ -25735,7 +25836,7 @@ class WalletConnectModal {
25735
25836
  }
25736
25837
  async initUi() {
25737
25838
  if (typeof window !== "undefined") {
25738
- await Promise.resolve().then(() => require("./index-CRWwEw3g.cjs"));
25839
+ await Promise.resolve().then(() => require("./index-C7NE-Dmd.cjs"));
25739
25840
  const modal = document.createElement("wcm-modal");
25740
25841
  document.body.insertAdjacentElement("beforeend", modal);
25741
25842
  OptionsCtrl.setIsUiLoaded(true);
@@ -26581,4 +26682,4 @@ exports.useSettingsStore = useSettingsStore;
26581
26682
  exports.useSwapModel = useSwapModel;
26582
26683
  exports.useTokensStore = useTokensStore;
26583
26684
  exports.useTransactionStore = useTransactionStore;
26584
- //# sourceMappingURL=index-UMHkIgdO.cjs.map
26685
+ //# sourceMappingURL=index-CCfRExBc.cjs.map