@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.
@@ -1074,6 +1074,49 @@ const useTokensStore = zustand.create((set2) => ({
1074
1074
  });
1075
1075
  }
1076
1076
  }));
1077
+ const ALLOWED_TO_CHAINS = /* @__PURE__ */ new Set([
1078
+ "ethereum",
1079
+ "manta",
1080
+ "opbnb",
1081
+ "polygon",
1082
+ "conflux",
1083
+ "ton",
1084
+ "tron",
1085
+ "megaeth",
1086
+ "mantle",
1087
+ "base",
1088
+ "plasma",
1089
+ "monad",
1090
+ "celo",
1091
+ "linea",
1092
+ "blast",
1093
+ "scroll",
1094
+ "cronosevm",
1095
+ "optimism",
1096
+ "gnosis",
1097
+ "sonic",
1098
+ "fantom",
1099
+ "zksync",
1100
+ "metis",
1101
+ "zkevm",
1102
+ "moonbeam",
1103
+ "moonriver",
1104
+ "kava",
1105
+ "klaytn",
1106
+ "avalanche",
1107
+ "arbitrum",
1108
+ "bsc",
1109
+ "aurora"
1110
+ ]);
1111
+ const ALLOWED_FROM_CHAINS = new Set(
1112
+ [...ALLOWED_TO_CHAINS].filter((k2) => k2 !== "tron")
1113
+ );
1114
+ function isAllowedFromChain(chainKey) {
1115
+ return ALLOWED_FROM_CHAINS.has(chainKey);
1116
+ }
1117
+ function isAllowedToChain(chainKey) {
1118
+ return ALLOWED_TO_CHAINS.has(chainKey);
1119
+ }
1077
1120
  async function getChains() {
1078
1121
  const res = await fetch("https://stargate.finance/api/v1/chains", {
1079
1122
  credentials: "same-origin"
@@ -1082,7 +1125,8 @@ async function getChains() {
1082
1125
  throw new Error(`Failed to load chains: ${res.status}`);
1083
1126
  }
1084
1127
  const data = await res.json();
1085
- return Array.isArray(data) ? data : data.chains ?? [];
1128
+ const all = Array.isArray(data) ? data : data.chains ?? [];
1129
+ return all.filter((c2) => ALLOWED_TO_CHAINS.has(c2.chainKey));
1086
1130
  }
1087
1131
  async function getTokens() {
1088
1132
  const res = await fetch("https://stargate.finance/api/v1/tokens", {
@@ -1225,17 +1269,18 @@ const ChainSelectModal = ({
1225
1269
  );
1226
1270
  const groupedChains = react.useMemo(() => {
1227
1271
  const q3 = query.trim().toLowerCase();
1228
- const filtered = q3 ? (items ?? []).filter(
1229
- (c2) => c2.name.toLowerCase().includes(q3) || c2.chainKey.toLowerCase().includes(q3)
1230
- ) : items ?? [];
1272
+ const isAllowed = isSource ? isAllowedFromChain : isAllowedToChain;
1273
+ const filtered = (items ?? []).filter((c2) => isAllowed(c2.chainKey)).filter(
1274
+ (c2) => !q3 || c2.name.toLowerCase().includes(q3) || c2.chainKey.toLowerCase().includes(q3)
1275
+ );
1231
1276
  const groups = {
1232
1277
  available: [],
1233
1278
  willChangeSrc: [],
1234
1279
  willChangeTokenAndSrc: []
1235
1280
  };
1236
1281
  for (const chain2 of filtered) {
1237
- const isAllowed = allowedItems?.some((c2) => c2.chainKey === chain2.chainKey) || false;
1238
- if (isAllowed) {
1282
+ const isAllowed2 = allowedItems?.some((c2) => c2.chainKey === chain2.chainKey) || false;
1283
+ if (isAllowed2) {
1239
1284
  groups.available.push(chain2);
1240
1285
  } else {
1241
1286
  const compatibleSrc = findCompatibleSrcChain(chain2);
@@ -1258,7 +1303,8 @@ const ChainSelectModal = ({
1258
1303
  query,
1259
1304
  allowedItems,
1260
1305
  findCompatibleSrcChain,
1261
- findCompatibleTokenAndSrcChain
1306
+ findCompatibleTokenAndSrcChain,
1307
+ isSource
1262
1308
  ]);
1263
1309
  const PRIORITY_CHAINS = react.useMemo(
1264
1310
  () => ["ethereum", "arbitrum", "bsc", "polygon", "optimism", "base"],
@@ -2357,9 +2403,9 @@ function calculateMinReceived(quote, slippageBps, dstToken) {
2357
2403
  const minAmountLD = dstAmountLD * BigInt(1e4 - slippageBps) / BigInt(1e4);
2358
2404
  return fromLD(minAmountLD.toString(), dstToken.decimals);
2359
2405
  }
2360
- function getQuoteDetails(quote, srcToken, dstToken, tokens, chains, slippageBps) {
2406
+ function getQuoteDetails(quote, srcToken, dstToken, tokens, chains, slippageBps, srcChain, dstChain) {
2361
2407
  const amounts = getQuoteAmounts(quote, srcToken, dstToken);
2362
- const fees = computeFeeBreakdownUsd(quote, srcToken, tokens, chains);
2408
+ const fees = computeFeeBreakdownUsd(quote, srcToken, tokens, chains, srcChain, dstChain);
2363
2409
  const minimumReceived = calculateMinReceived(quote, slippageBps, dstToken);
2364
2410
  return {
2365
2411
  inputAmount: amounts.inputHuman,
@@ -2379,14 +2425,20 @@ function getRouteDisplayName(route) {
2379
2425
  if (routeLower.includes("v2")) return "Stargate V2";
2380
2426
  return route.split(/[/\-_]/).map((part) => part.charAt(0).toUpperCase() + part.slice(1)).join(" ");
2381
2427
  }
2382
- function computeFeeBreakdownUsd(quote, srcToken, tokens, chains) {
2428
+ function computeFeeBreakdownUsd(quote, srcToken, tokens, chains, srcChain, dstChain) {
2429
+ const defaultMsgSymbol = srcChain?.nativeCurrency?.symbol?.toUpperCase() ?? "";
2430
+ const defaultBridgeSymbol = srcToken?.symbol?.toUpperCase() ?? "";
2431
+ const defaultDstGasSymbol = dstChain?.nativeCurrency?.symbol?.toUpperCase() ?? "";
2383
2432
  const empty = {
2384
2433
  messageFeeAmount: 0,
2385
- messageFeeSymbol: "",
2434
+ messageFeeSymbol: defaultMsgSymbol,
2386
2435
  messageFeeUsd: 0,
2387
2436
  bridgeFeeAmount: 0,
2388
- bridgeFeeSymbol: "",
2437
+ bridgeFeeSymbol: defaultBridgeSymbol,
2389
2438
  bridgeFeeUsd: 0,
2439
+ dstGasAmount: 0,
2440
+ dstGasSymbol: defaultDstGasSymbol,
2441
+ dstGasUsd: 0,
2390
2442
  totalFeeUsd: 0
2391
2443
  };
2392
2444
  if (!quote || !srcToken) return empty;
@@ -2422,7 +2474,25 @@ function computeFeeBreakdownUsd(quote, srcToken, tokens, chains) {
2422
2474
  bridgeFeeAmount = diff;
2423
2475
  bridgeFeeUsd = (srcToken.price?.usd ?? 0) * diff;
2424
2476
  }
2425
- const totalFeeUsd = messageFeeUsd + bridgeFeeUsd;
2477
+ let dstGasAmount = 0;
2478
+ let dstGasSymbol = "";
2479
+ let dstGasUsd = 0;
2480
+ const dstNativeAmountLD = quote.dstNativeAmount;
2481
+ if (dstNativeAmountLD && BigInt(dstNativeAmountLD || "0") > 0n) {
2482
+ const dstChain2 = chains?.find((c2) => c2.chainKey === quote.dstChainKey);
2483
+ if (dstChain2) {
2484
+ const { decimals, priceUsd } = lookupTokenMeta(
2485
+ tokens,
2486
+ chains,
2487
+ dstChain2.chainKey,
2488
+ dstChain2.nativeCurrency.address
2489
+ );
2490
+ dstGasAmount = fromLD(dstNativeAmountLD, decimals);
2491
+ dstGasSymbol = dstChain2.nativeCurrency.symbol?.toUpperCase() ?? "";
2492
+ dstGasUsd = dstGasAmount * (priceUsd ?? 0);
2493
+ }
2494
+ }
2495
+ const totalFeeUsd = messageFeeUsd + bridgeFeeUsd + dstGasUsd;
2426
2496
  return {
2427
2497
  messageFeeAmount,
2428
2498
  messageFeeSymbol,
@@ -2430,6 +2500,9 @@ function computeFeeBreakdownUsd(quote, srcToken, tokens, chains) {
2430
2500
  bridgeFeeAmount,
2431
2501
  bridgeFeeSymbol,
2432
2502
  bridgeFeeUsd,
2503
+ dstGasAmount,
2504
+ dstGasSymbol,
2505
+ dstGasUsd,
2433
2506
  totalFeeUsd
2434
2507
  };
2435
2508
  }
@@ -2673,7 +2746,7 @@ const useChainDerivations = () => {
2673
2746
  return [];
2674
2747
  const byChain = assetMatrix[selectedAssetSymbol.toUpperCase()];
2675
2748
  const keys2 = new Set(Object.keys(byChain ?? {}));
2676
- const result = chains.filter((c2) => keys2.has(c2.chainKey));
2749
+ const result = chains.filter((c2) => keys2.has(c2.chainKey) && isAllowedFromChain(c2.chainKey));
2677
2750
  return result;
2678
2751
  }, [selectedAssetSymbol, assetMatrix, chains]);
2679
2752
  react.useEffect(() => {
@@ -2737,7 +2810,7 @@ const useChainDerivations = () => {
2737
2810
  return !!symbolMatch;
2738
2811
  });
2739
2812
  const keys2 = new Set(filteredDest.map((t2) => t2.chainKey));
2740
- let list = chains.filter((c2) => keys2.has(c2.chainKey));
2813
+ let list = chains.filter((c2) => keys2.has(c2.chainKey) && isAllowedToChain(c2.chainKey));
2741
2814
  if (fromChain?.chainKey) {
2742
2815
  list = list.filter((c2) => c2.chainKey !== fromChain.chainKey);
2743
2816
  }
@@ -2971,15 +3044,15 @@ const TokenSymbol = ({
2971
3044
  function useFeeBreakdown() {
2972
3045
  const { quote } = useBridgeQuoteStore();
2973
3046
  const { tokens, allTokens, selectedAssetSymbol, assetMatrix } = useTokensStore();
2974
- const { fromChain, chains } = useChainsStore();
3047
+ const { fromChain, toChain, chains } = useChainsStore();
2975
3048
  return react.useMemo(() => {
2976
3049
  const srcToken = resolveTokenOnChainFromMatrix$1(
2977
3050
  assetMatrix,
2978
3051
  selectedAssetSymbol,
2979
3052
  fromChain?.chainKey
2980
3053
  );
2981
- return computeFeeBreakdownUsd(quote, srcToken, allTokens ?? tokens, chains);
2982
- }, [quote, allTokens, tokens, chains, selectedAssetSymbol, assetMatrix, fromChain]);
3054
+ return computeFeeBreakdownUsd(quote, srcToken, allTokens ?? tokens, chains, fromChain, toChain);
3055
+ }, [quote, allTokens, tokens, chains, selectedAssetSymbol, assetMatrix, fromChain, toChain]);
2983
3056
  }
2984
3057
  function useBridgeExternalData(options) {
2985
3058
  const selectedAssetSymbol = useTokensStore(
@@ -3066,7 +3139,9 @@ function buildBridgeExternalData({
3066
3139
  destinationToken,
3067
3140
  tokens,
3068
3141
  chains,
3069
- slippageBps
3142
+ slippageBps,
3143
+ fromChain,
3144
+ toChain
3070
3145
  );
3071
3146
  const etaText = quoteDetails.etaSeconds != null ? `≈ ${Math.max(1, Math.round(quoteDetails.etaSeconds / 60))}m` : "—";
3072
3147
  const currentSlippageText = !quote ? "—" : formatPercentage(slippageBps);
@@ -26023,7 +26098,7 @@ class WalletConnectModal {
26023
26098
  }
26024
26099
  async initUi() {
26025
26100
  if (typeof window !== "undefined") {
26026
- await Promise.resolve().then(() => require("./index-BO18yuE2.cjs"));
26101
+ await Promise.resolve().then(() => require("./index-CQTSauOr.cjs"));
26027
26102
  const modal = document.createElement("wcm-modal");
26028
26103
  document.body.insertAdjacentElement("beforeend", modal);
26029
26104
  OptionsCtrl.setIsUiLoaded(true);
@@ -26899,6 +26974,8 @@ exports.getRouteDisplayName = getRouteDisplayName;
26899
26974
  exports.getTokens = getTokens;
26900
26975
  exports.getTonBalances = getTonBalances;
26901
26976
  exports.getTronBalances = getTronBalances;
26977
+ exports.isAllowedFromChain = isAllowedFromChain;
26978
+ exports.isAllowedToChain = isAllowedToChain;
26902
26979
  exports.isNativeAddrEqual = isNativeAddrEqual;
26903
26980
  exports.isNativeAddress = isNativeAddress;
26904
26981
  exports.isZeroAddr = isZeroAddr;
@@ -26921,4 +26998,4 @@ exports.useSettingsStore = useSettingsStore;
26921
26998
  exports.useSwapModel = useSwapModel;
26922
26999
  exports.useTokensStore = useTokensStore;
26923
27000
  exports.useTransactionStore = useTransactionStore;
26924
- //# sourceMappingURL=index-B3z_l7uV.cjs.map
27001
+ //# sourceMappingURL=index-DXcV5o9h.cjs.map