@rash2x/bridge-widget 0.7.3 → 0.7.5

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.
@@ -1073,6 +1073,49 @@ const useTokensStore = create((set2) => ({
1073
1073
  });
1074
1074
  }
1075
1075
  }));
1076
+ const ALLOWED_TO_CHAINS = /* @__PURE__ */ new Set([
1077
+ "ethereum",
1078
+ "manta",
1079
+ "opbnb",
1080
+ "polygon",
1081
+ "conflux",
1082
+ "ton",
1083
+ "tron",
1084
+ "megaeth",
1085
+ "mantle",
1086
+ "base",
1087
+ "plasma",
1088
+ "monad",
1089
+ "celo",
1090
+ "linea",
1091
+ "blast",
1092
+ "scroll",
1093
+ "cronosevm",
1094
+ "optimism",
1095
+ "gnosis",
1096
+ "sonic",
1097
+ "fantom",
1098
+ "zksync",
1099
+ "metis",
1100
+ "zkevm",
1101
+ "moonbeam",
1102
+ "moonriver",
1103
+ "kava",
1104
+ "klaytn",
1105
+ "avalanche",
1106
+ "arbitrum",
1107
+ "bsc",
1108
+ "aurora"
1109
+ ]);
1110
+ const ALLOWED_FROM_CHAINS = new Set(
1111
+ [...ALLOWED_TO_CHAINS].filter((k2) => k2 !== "tron")
1112
+ );
1113
+ function isAllowedFromChain(chainKey) {
1114
+ return ALLOWED_FROM_CHAINS.has(chainKey);
1115
+ }
1116
+ function isAllowedToChain(chainKey) {
1117
+ return ALLOWED_TO_CHAINS.has(chainKey);
1118
+ }
1076
1119
  async function getChains() {
1077
1120
  const res = await fetch("https://stargate.finance/api/v1/chains", {
1078
1121
  credentials: "same-origin"
@@ -1081,7 +1124,8 @@ async function getChains() {
1081
1124
  throw new Error(`Failed to load chains: ${res.status}`);
1082
1125
  }
1083
1126
  const data = await res.json();
1084
- return Array.isArray(data) ? data : data.chains ?? [];
1127
+ const all = Array.isArray(data) ? data : data.chains ?? [];
1128
+ return all.filter((c2) => ALLOWED_TO_CHAINS.has(c2.chainKey));
1085
1129
  }
1086
1130
  async function getTokens() {
1087
1131
  const res = await fetch("https://stargate.finance/api/v1/tokens", {
@@ -1224,17 +1268,18 @@ const ChainSelectModal = ({
1224
1268
  );
1225
1269
  const groupedChains = useMemo(() => {
1226
1270
  const q3 = query.trim().toLowerCase();
1227
- const filtered = q3 ? (items ?? []).filter(
1228
- (c2) => c2.name.toLowerCase().includes(q3) || c2.chainKey.toLowerCase().includes(q3)
1229
- ) : items ?? [];
1271
+ const isAllowed = isSource ? isAllowedFromChain : isAllowedToChain;
1272
+ const filtered = (items ?? []).filter((c2) => isAllowed(c2.chainKey)).filter(
1273
+ (c2) => !q3 || c2.name.toLowerCase().includes(q3) || c2.chainKey.toLowerCase().includes(q3)
1274
+ );
1230
1275
  const groups = {
1231
1276
  available: [],
1232
1277
  willChangeSrc: [],
1233
1278
  willChangeTokenAndSrc: []
1234
1279
  };
1235
1280
  for (const chain2 of filtered) {
1236
- const isAllowed = allowedItems?.some((c2) => c2.chainKey === chain2.chainKey) || false;
1237
- if (isAllowed) {
1281
+ const isAllowed2 = allowedItems?.some((c2) => c2.chainKey === chain2.chainKey) || false;
1282
+ if (isAllowed2) {
1238
1283
  groups.available.push(chain2);
1239
1284
  } else {
1240
1285
  const compatibleSrc = findCompatibleSrcChain(chain2);
@@ -1257,7 +1302,8 @@ const ChainSelectModal = ({
1257
1302
  query,
1258
1303
  allowedItems,
1259
1304
  findCompatibleSrcChain,
1260
- findCompatibleTokenAndSrcChain
1305
+ findCompatibleTokenAndSrcChain,
1306
+ isSource
1261
1307
  ]);
1262
1308
  const PRIORITY_CHAINS = useMemo(
1263
1309
  () => ["ethereum", "arbitrum", "bsc", "polygon", "optimism", "base"],
@@ -2356,9 +2402,9 @@ function calculateMinReceived(quote, slippageBps, dstToken) {
2356
2402
  const minAmountLD = dstAmountLD * BigInt(1e4 - slippageBps) / BigInt(1e4);
2357
2403
  return fromLD(minAmountLD.toString(), dstToken.decimals);
2358
2404
  }
2359
- function getQuoteDetails(quote, srcToken, dstToken, tokens, chains, slippageBps) {
2405
+ function getQuoteDetails(quote, srcToken, dstToken, tokens, chains, slippageBps, srcChain, dstChain) {
2360
2406
  const amounts = getQuoteAmounts(quote, srcToken, dstToken);
2361
- const fees = computeFeeBreakdownUsd(quote, srcToken, tokens, chains);
2407
+ const fees = computeFeeBreakdownUsd(quote, srcToken, tokens, chains, srcChain, dstChain);
2362
2408
  const minimumReceived = calculateMinReceived(quote, slippageBps, dstToken);
2363
2409
  return {
2364
2410
  inputAmount: amounts.inputHuman,
@@ -2378,14 +2424,20 @@ function getRouteDisplayName(route) {
2378
2424
  if (routeLower.includes("v2")) return "Stargate V2";
2379
2425
  return route.split(/[/\-_]/).map((part) => part.charAt(0).toUpperCase() + part.slice(1)).join(" ");
2380
2426
  }
2381
- function computeFeeBreakdownUsd(quote, srcToken, tokens, chains) {
2427
+ function computeFeeBreakdownUsd(quote, srcToken, tokens, chains, srcChain, dstChain) {
2428
+ const defaultMsgSymbol = srcChain?.nativeCurrency?.symbol?.toUpperCase() ?? "";
2429
+ const defaultBridgeSymbol = srcToken?.symbol?.toUpperCase() ?? "";
2430
+ const defaultDstGasSymbol = dstChain?.nativeCurrency?.symbol?.toUpperCase() ?? "";
2382
2431
  const empty = {
2383
2432
  messageFeeAmount: 0,
2384
- messageFeeSymbol: "",
2433
+ messageFeeSymbol: defaultMsgSymbol,
2385
2434
  messageFeeUsd: 0,
2386
2435
  bridgeFeeAmount: 0,
2387
- bridgeFeeSymbol: "",
2436
+ bridgeFeeSymbol: defaultBridgeSymbol,
2388
2437
  bridgeFeeUsd: 0,
2438
+ dstGasAmount: 0,
2439
+ dstGasSymbol: defaultDstGasSymbol,
2440
+ dstGasUsd: 0,
2389
2441
  totalFeeUsd: 0
2390
2442
  };
2391
2443
  if (!quote || !srcToken) return empty;
@@ -2421,7 +2473,25 @@ function computeFeeBreakdownUsd(quote, srcToken, tokens, chains) {
2421
2473
  bridgeFeeAmount = diff;
2422
2474
  bridgeFeeUsd = (srcToken.price?.usd ?? 0) * diff;
2423
2475
  }
2424
- const totalFeeUsd = messageFeeUsd + bridgeFeeUsd;
2476
+ let dstGasAmount = 0;
2477
+ let dstGasSymbol = "";
2478
+ let dstGasUsd = 0;
2479
+ const dstNativeAmountLD = quote.dstNativeAmount;
2480
+ if (dstNativeAmountLD && BigInt(dstNativeAmountLD || "0") > 0n) {
2481
+ const dstChain2 = chains?.find((c2) => c2.chainKey === quote.dstChainKey);
2482
+ if (dstChain2) {
2483
+ const { decimals, priceUsd } = lookupTokenMeta(
2484
+ tokens,
2485
+ chains,
2486
+ dstChain2.chainKey,
2487
+ dstChain2.nativeCurrency.address
2488
+ );
2489
+ dstGasAmount = fromLD(dstNativeAmountLD, decimals);
2490
+ dstGasSymbol = dstChain2.nativeCurrency.symbol?.toUpperCase() ?? "";
2491
+ dstGasUsd = dstGasAmount * (priceUsd ?? 0);
2492
+ }
2493
+ }
2494
+ const totalFeeUsd = messageFeeUsd + bridgeFeeUsd + dstGasUsd;
2425
2495
  return {
2426
2496
  messageFeeAmount,
2427
2497
  messageFeeSymbol,
@@ -2429,6 +2499,9 @@ function computeFeeBreakdownUsd(quote, srcToken, tokens, chains) {
2429
2499
  bridgeFeeAmount,
2430
2500
  bridgeFeeSymbol,
2431
2501
  bridgeFeeUsd,
2502
+ dstGasAmount,
2503
+ dstGasSymbol,
2504
+ dstGasUsd,
2432
2505
  totalFeeUsd
2433
2506
  };
2434
2507
  }
@@ -2672,7 +2745,7 @@ const useChainDerivations = () => {
2672
2745
  return [];
2673
2746
  const byChain = assetMatrix[selectedAssetSymbol.toUpperCase()];
2674
2747
  const keys2 = new Set(Object.keys(byChain ?? {}));
2675
- const result = chains.filter((c2) => keys2.has(c2.chainKey));
2748
+ const result = chains.filter((c2) => keys2.has(c2.chainKey) && isAllowedFromChain(c2.chainKey));
2676
2749
  return result;
2677
2750
  }, [selectedAssetSymbol, assetMatrix, chains]);
2678
2751
  useEffect(() => {
@@ -2736,7 +2809,7 @@ const useChainDerivations = () => {
2736
2809
  return !!symbolMatch;
2737
2810
  });
2738
2811
  const keys2 = new Set(filteredDest.map((t2) => t2.chainKey));
2739
- let list = chains.filter((c2) => keys2.has(c2.chainKey));
2812
+ let list = chains.filter((c2) => keys2.has(c2.chainKey) && isAllowedToChain(c2.chainKey));
2740
2813
  if (fromChain?.chainKey) {
2741
2814
  list = list.filter((c2) => c2.chainKey !== fromChain.chainKey);
2742
2815
  }
@@ -2970,15 +3043,15 @@ const TokenSymbol = ({
2970
3043
  function useFeeBreakdown() {
2971
3044
  const { quote } = useBridgeQuoteStore();
2972
3045
  const { tokens, allTokens, selectedAssetSymbol, assetMatrix } = useTokensStore();
2973
- const { fromChain, chains } = useChainsStore();
3046
+ const { fromChain, toChain, chains } = useChainsStore();
2974
3047
  return useMemo(() => {
2975
3048
  const srcToken = resolveTokenOnChainFromMatrix$1(
2976
3049
  assetMatrix,
2977
3050
  selectedAssetSymbol,
2978
3051
  fromChain?.chainKey
2979
3052
  );
2980
- return computeFeeBreakdownUsd(quote, srcToken, allTokens ?? tokens, chains);
2981
- }, [quote, allTokens, tokens, chains, selectedAssetSymbol, assetMatrix, fromChain]);
3053
+ return computeFeeBreakdownUsd(quote, srcToken, allTokens ?? tokens, chains, fromChain, toChain);
3054
+ }, [quote, allTokens, tokens, chains, selectedAssetSymbol, assetMatrix, fromChain, toChain]);
2982
3055
  }
2983
3056
  function useBridgeExternalData(options) {
2984
3057
  const selectedAssetSymbol = useTokensStore(
@@ -3065,7 +3138,9 @@ function buildBridgeExternalData({
3065
3138
  destinationToken,
3066
3139
  tokens,
3067
3140
  chains,
3068
- slippageBps
3141
+ slippageBps,
3142
+ fromChain,
3143
+ toChain
3069
3144
  );
3070
3145
  const etaText = quoteDetails.etaSeconds != null ? `≈ ${Math.max(1, Math.round(quoteDetails.etaSeconds / 60))}m` : "—";
3071
3146
  const currentSlippageText = !quote ? "—" : formatPercentage(slippageBps);
@@ -26022,7 +26097,7 @@ class WalletConnectModal {
26022
26097
  }
26023
26098
  async initUi() {
26024
26099
  if (typeof window !== "undefined") {
26025
- await import("./index-hG98qwY3.js");
26100
+ await import("./index-HUIu1V_6.js");
26026
26101
  const modal = document.createElement("wcm-modal");
26027
26102
  document.body.insertAdjacentElement("beforeend", modal);
26028
26103
  OptionsCtrl.setIsUiLoaded(true);
@@ -26861,7 +26936,7 @@ const EvaaBridgeContent = ({
26861
26936
  };
26862
26937
  const EvaaBridge = EvaaBridgeWithProviders;
26863
26938
  export {
26864
- isNativeAddress as $,
26939
+ getDestTokens as $,
26865
26940
  getRouteDisplayName as A,
26866
26941
  computeFeeBreakdownUsd as B,
26867
26942
  ConfigCtrl as C,
@@ -26885,17 +26960,19 @@ export {
26885
26960
  findNativeMeta as U,
26886
26961
  lookupTokenMeta as V,
26887
26962
  normalizeTickerSymbol$1 as W,
26888
- getChains as X,
26889
- getTokens as Y,
26890
- getDestTokens as Z,
26891
- getQuotesByPriority as _,
26963
+ isAllowedFromChain as X,
26964
+ isAllowedToChain as Y,
26965
+ getChains as Z,
26966
+ getTokens as _,
26892
26967
  ThemeCtrl as a,
26893
- getEvmBalances as a0,
26894
- getTonBalances as a1,
26895
- getTronBalances as a2,
26896
- getDeliveryStatus as a3,
26897
- pollUntilDelivered as a4,
26898
- reportBridgeTransaction as a5,
26968
+ getQuotesByPriority as a0,
26969
+ isNativeAddress as a1,
26970
+ getEvmBalances as a2,
26971
+ getTonBalances as a3,
26972
+ getTronBalances as a4,
26973
+ getDeliveryStatus as a5,
26974
+ pollUntilDelivered as a6,
26975
+ reportBridgeTransaction as a7,
26899
26976
  ExplorerCtrl as b,
26900
26977
  CoreUtil as c,
26901
26978
  EvaaBridge as d,
@@ -26922,4 +26999,4 @@ export {
26922
26999
  calculateMinReceived as y,
26923
27000
  getQuoteDetails as z
26924
27001
  };
26925
- //# sourceMappingURL=index-hcTHOiGQ.js.map
27002
+ //# sourceMappingURL=index-CeW-ueEx.js.map