@rash2x/bridge-widget 0.8.4 → 0.8.6

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.
@@ -1211,6 +1211,25 @@ const SearchInput = ({
1211
1211
  ) })
1212
1212
  ] });
1213
1213
  };
1214
+ const TOKEN_EQUIVALENTS = {
1215
+ USDT: ["USDT0"],
1216
+ USDT0: ["USDT"]
1217
+ };
1218
+ function getEquivalentSymbols(symbol) {
1219
+ return TOKEN_EQUIVALENTS[symbol.toUpperCase()] ?? [];
1220
+ }
1221
+ const BRIDGE_PREFERRED_TOKENS = /* @__PURE__ */ new Set(["USDT0"]);
1222
+ function getBridgeTokenSymbol(symbol, assetMatrix, chainKey) {
1223
+ if (!assetMatrix || !chainKey) return symbol.toUpperCase();
1224
+ const candidates = [symbol.toUpperCase(), ...getEquivalentSymbols(symbol)];
1225
+ for (const sym of candidates) {
1226
+ if (BRIDGE_PREFERRED_TOKENS.has(sym) && assetMatrix[sym]?.[chainKey]) return sym;
1227
+ }
1228
+ for (const sym of candidates) {
1229
+ if (assetMatrix[sym]?.[chainKey]) return sym;
1230
+ }
1231
+ return symbol.toUpperCase();
1232
+ }
1214
1233
  const ChainSelectModal = ({
1215
1234
  isOpen,
1216
1235
  onClose,
@@ -1238,10 +1257,14 @@ const ChainSelectModal = ({
1238
1257
  "optimism",
1239
1258
  "base"
1240
1259
  ];
1241
- const assetByChain = assetMatrix[selectedAssetSymbol.toUpperCase()];
1242
- if (!assetByChain) return void 0;
1260
+ const allSymbols = [
1261
+ selectedAssetSymbol.toUpperCase(),
1262
+ ...getEquivalentSymbols(selectedAssetSymbol).map((s2) => s2.toUpperCase())
1263
+ ];
1264
+ const hasTokenOrEquiv = (chainKey) => allSymbols.some((sym) => !!assetMatrix[sym]?.[chainKey]);
1265
+ if (!hasTokenOrEquiv(dstChain.chainKey)) return void 0;
1243
1266
  const availableChains = chains.filter(
1244
- (c2) => assetByChain[c2.chainKey] && assetByChain[dstChain.chainKey] && c2.chainKey !== fromChain?.chainKey && c2.chainKey !== dstChain.chainKey
1267
+ (c2) => hasTokenOrEquiv(c2.chainKey) && c2.chainKey !== fromChain?.chainKey && c2.chainKey !== dstChain.chainKey
1245
1268
  );
1246
1269
  for (const chainKey of PRIORITY_CHAINS2) {
1247
1270
  const chain2 = availableChains.find((c2) => c2.chainKey === chainKey);
@@ -1325,9 +1348,25 @@ const ChainSelectModal = ({
1325
1348
  []
1326
1349
  );
1327
1350
  const [isPickLoading, setIsPickLoading] = React.useState(false);
1351
+ const switchToEquivalentIfNeeded = React.useCallback(
1352
+ (chainKey) => {
1353
+ if (!selectedAssetSymbol || !assetMatrix) return;
1354
+ const hasDirectToken = !!assetMatrix[selectedAssetSymbol.toUpperCase()]?.[chainKey];
1355
+ if (!hasDirectToken) {
1356
+ for (const eq of getEquivalentSymbols(selectedAssetSymbol)) {
1357
+ if (assetMatrix[eq]?.[chainKey]) {
1358
+ setSelectedAssetSymbol(eq);
1359
+ break;
1360
+ }
1361
+ }
1362
+ }
1363
+ },
1364
+ [selectedAssetSymbol, assetMatrix, setSelectedAssetSymbol]
1365
+ );
1328
1366
  const onChainPick = React.useCallback(
1329
1367
  async (chain2, willChangeSrc = false, willChangeTokenAndSrc = false) => {
1330
1368
  if (!willChangeSrc && !willChangeTokenAndSrc) {
1369
+ switchToEquivalentIfNeeded(chain2.chainKey);
1331
1370
  onChangeChain(chain2);
1332
1371
  handleClose();
1333
1372
  return;
@@ -1359,7 +1398,18 @@ const ChainSelectModal = ({
1359
1398
  onChangeChain(chain2);
1360
1399
  }
1361
1400
  } else if (willChangeSrc && selectedAssetSymbol) {
1362
- const dstToken = assetMatrix?.[selectedAssetSymbol.toUpperCase()]?.[chain2.chainKey];
1401
+ let dstToken = assetMatrix?.[selectedAssetSymbol.toUpperCase()]?.[chain2.chainKey];
1402
+ let resolvedSym = selectedAssetSymbol;
1403
+ if (!dstToken?.address) {
1404
+ for (const eq of getEquivalentSymbols(selectedAssetSymbol)) {
1405
+ const eqToken = assetMatrix?.[eq]?.[chain2.chainKey];
1406
+ if (eqToken?.address) {
1407
+ dstToken = eqToken;
1408
+ resolvedSym = eq;
1409
+ break;
1410
+ }
1411
+ }
1412
+ }
1363
1413
  if (!dstToken?.address) return;
1364
1414
  const availableSources = await getDestTokens(chain2.chainKey, dstToken.address);
1365
1415
  const sourceChainKeys = new Set(availableSources.map((t22) => t22.chainKey ?? ""));
@@ -1376,6 +1426,9 @@ const ChainSelectModal = ({
1376
1426
  );
1377
1427
  }
1378
1428
  if (validSrc) {
1429
+ if (resolvedSym.toUpperCase() !== selectedAssetSymbol.toUpperCase()) {
1430
+ setSelectedAssetSymbol(resolvedSym);
1431
+ }
1379
1432
  setFromChain(validSrc);
1380
1433
  onChangeChain(chain2);
1381
1434
  }
@@ -1393,6 +1446,7 @@ const ChainSelectModal = ({
1393
1446
  selectedAssetSymbol,
1394
1447
  assetMatrix,
1395
1448
  findCompatibleTokenAndSrcChain,
1449
+ switchToEquivalentIfNeeded,
1396
1450
  setSelectedAssetSymbol,
1397
1451
  setFromChain,
1398
1452
  onChangeChain,
@@ -2271,6 +2325,21 @@ function resolveTokenOnChainFromMatrix$1(assetMatrix, assetSymbol, chainKey) {
2271
2325
  const byChain = assetMatrix[assetSymbol.toUpperCase()];
2272
2326
  return byChain?.[chainKey];
2273
2327
  }
2328
+ function resolveBridgeSourceTokenOnChainFromMatrix(assetMatrix, assetSymbol, chainKey) {
2329
+ if (!assetMatrix || !assetSymbol || !chainKey) return void 0;
2330
+ const resolvedSymbol = getBridgeTokenSymbol(assetSymbol, assetMatrix, chainKey);
2331
+ return resolveTokenOnChainFromMatrix$1(assetMatrix, resolvedSymbol, chainKey);
2332
+ }
2333
+ function resolveBridgeDestinationTokenOnChainFromMatrix(assetMatrix, assetSymbol, chainKey) {
2334
+ if (!assetMatrix || !assetSymbol || !chainKey) return void 0;
2335
+ const direct = resolveTokenOnChainFromMatrix$1(assetMatrix, assetSymbol, chainKey);
2336
+ if (direct) return direct;
2337
+ for (const eq of getEquivalentSymbols(assetSymbol)) {
2338
+ const eqToken = resolveTokenOnChainFromMatrix$1(assetMatrix, eq, chainKey);
2339
+ if (eqToken) return eqToken;
2340
+ }
2341
+ return void 0;
2342
+ }
2274
2343
  const DEFAULT_SLIPPAGE_BPS = 50;
2275
2344
  const lower = (s2) => (s2 ?? "").toLowerCase();
2276
2345
  const normSym = (s2) => (s2 ?? "").toUpperCase().replace(/₮/g, "T").replace(/[^A-Z0-9]/g, "");
@@ -2614,22 +2683,29 @@ function useBridgeQuote() {
2614
2683
  const { chainRegistry } = useChainStrategies();
2615
2684
  const publicClient = wagmi.usePublicClient();
2616
2685
  const input2 = inputAmount;
2617
- const srcTokenOnFrom = React.useMemo(
2618
- () => resolveTokenOnChainFromMatrix$1(
2619
- assetMatrix,
2620
- selectedAssetSymbol,
2621
- fromChain?.chainKey
2622
- ),
2623
- [assetMatrix, selectedAssetSymbol, fromChain?.chainKey]
2624
- );
2625
- const dstTokenOnTo = React.useMemo(
2626
- () => resolveTokenOnChainFromMatrix$1(
2627
- assetMatrix,
2628
- selectedAssetSymbol,
2629
- toChain?.chainKey
2630
- ),
2631
- [assetMatrix, selectedAssetSymbol, toChain?.chainKey]
2632
- );
2686
+ const srcTokenOnFrom = React.useMemo(() => {
2687
+ if (!assetMatrix || !selectedAssetSymbol || !fromChain?.chainKey) return void 0;
2688
+ const sym = getBridgeTokenSymbol(selectedAssetSymbol, assetMatrix, fromChain.chainKey);
2689
+ const token = resolveTokenOnChainFromMatrix$1(assetMatrix, sym, fromChain.chainKey);
2690
+ console.log("[quote] srcToken", { selected: selectedAssetSymbol, resolved: sym, chain: fromChain.chainKey, addr: token?.address });
2691
+ return token;
2692
+ }, [assetMatrix, selectedAssetSymbol, fromChain?.chainKey]);
2693
+ const dstTokenOnTo = React.useMemo(() => {
2694
+ if (!assetMatrix || !selectedAssetSymbol || !toChain?.chainKey) return void 0;
2695
+ const direct = resolveTokenOnChainFromMatrix$1(assetMatrix, selectedAssetSymbol, toChain.chainKey);
2696
+ if (direct) {
2697
+ console.log("[quote] dstToken", { selected: selectedAssetSymbol, resolved: selectedAssetSymbol, chain: toChain.chainKey, addr: direct.address });
2698
+ return direct;
2699
+ }
2700
+ for (const eq of getEquivalentSymbols(selectedAssetSymbol)) {
2701
+ const eqToken = resolveTokenOnChainFromMatrix$1(assetMatrix, eq, toChain.chainKey);
2702
+ if (eqToken) {
2703
+ console.log("[quote] dstToken", { selected: selectedAssetSymbol, resolved: eq, chain: toChain.chainKey, addr: eqToken.address });
2704
+ return eqToken;
2705
+ }
2706
+ }
2707
+ return void 0;
2708
+ }, [assetMatrix, selectedAssetSymbol, toChain?.chainKey]);
2633
2709
  const [loading, setLoading] = React.useState(false);
2634
2710
  React.useEffect(() => {
2635
2711
  if (!input2 || input2 === "") {
@@ -2661,14 +2737,9 @@ function useBridgeQuote() {
2661
2737
  try {
2662
2738
  setLoading(true);
2663
2739
  setQuoteLoading?.();
2664
- if (assetMatrix && selectedAssetSymbol) {
2665
- const tokenMatrix = assetMatrix[selectedAssetSymbol.toUpperCase()];
2666
- if (!tokenMatrix || !tokenMatrix[fromChain.chainKey] || !tokenMatrix[toChain.chainKey]) {
2667
- if (!cancelled) {
2668
- resetUi();
2669
- }
2670
- return;
2671
- }
2740
+ if (!srcTokenOnFrom || !dstTokenOnTo) {
2741
+ if (!cancelled) resetUi();
2742
+ return;
2672
2743
  }
2673
2744
  const srcAmountLD = toLD(input2, srcTokenOnFrom.decimals);
2674
2745
  const srcAddrApi = addrForApi(fromChain.chainKey, srcAddress);
@@ -2774,6 +2845,11 @@ const useChainDerivations = () => {
2774
2845
  return [];
2775
2846
  const byChain = assetMatrix[selectedAssetSymbol.toUpperCase()];
2776
2847
  const keys2 = new Set(Object.keys(byChain ?? {}));
2848
+ for (const eq of getEquivalentSymbols(selectedAssetSymbol)) {
2849
+ for (const ck of Object.keys(assetMatrix[eq] ?? {})) {
2850
+ keys2.add(ck);
2851
+ }
2852
+ }
2777
2853
  const result = chains.filter((c2) => keys2.has(c2.chainKey) && isAllowedFromChain(c2.chainKey));
2778
2854
  return result;
2779
2855
  }, [selectedAssetSymbol, assetMatrix, chains]);
@@ -2815,11 +2891,8 @@ const useChainDerivations = () => {
2815
2891
  setAllowedToChains([]);
2816
2892
  return;
2817
2893
  }
2818
- const srcToken = resolveTokenOnChainFromMatrix(
2819
- assetMatrix,
2820
- selectedAssetSymbol,
2821
- fromChain.chainKey
2822
- );
2894
+ const srcSym = getBridgeTokenSymbol(selectedAssetSymbol, assetMatrix, fromChain.chainKey);
2895
+ const srcToken = resolveTokenOnChainFromMatrix(assetMatrix, srcSym, fromChain.chainKey);
2823
2896
  const srcAddr = srcToken?.address;
2824
2897
  if (!srcAddr) {
2825
2898
  setAllowedToChains([]);
@@ -2831,11 +2904,18 @@ const useChainDerivations = () => {
2831
2904
  const dest = await getDestTokens(fromChain.chainKey, srcAddr);
2832
2905
  if (ignore) return;
2833
2906
  const byChainSameSymbol = assetMatrix?.[selectedAssetSymbol.toUpperCase()] ?? {};
2907
+ const equivalentSymbols = /* @__PURE__ */ new Set([
2908
+ selectedAssetSymbol.toUpperCase(),
2909
+ ...getEquivalentSymbols(selectedAssetSymbol).map((s2) => s2.toUpperCase())
2910
+ ]);
2834
2911
  const filteredDest = dest.filter((t2) => {
2835
2912
  const ck = t2.chainKey ?? t2.dstChainKey ?? "";
2836
- const matrixToken = byChainSameSymbol[ck];
2837
- const symbolMatch = matrixToken && (t2.symbol ?? "").toUpperCase() === selectedAssetSymbol.toUpperCase();
2838
- return !!symbolMatch;
2913
+ const destSymbol = (t2.symbol ?? "").toUpperCase();
2914
+ if (!equivalentSymbols.has(destSymbol)) return false;
2915
+ const hasInMatrix = !!byChainSameSymbol[ck] || getEquivalentSymbols(selectedAssetSymbol).some(
2916
+ (eq) => !!assetMatrix?.[eq.toUpperCase()]?.[ck]
2917
+ );
2918
+ return hasInMatrix;
2839
2919
  });
2840
2920
  const keys2 = new Set(filteredDest.map((t2) => t2.chainKey));
2841
2921
  let list = chains.filter((c2) => keys2.has(c2.chainKey) && isAllowedToChain(c2.chainKey));
@@ -3610,7 +3690,18 @@ function useBalances(chainKey, address) {
3610
3690
  );
3611
3691
  if (typeof byAddress === "number") return byAddress;
3612
3692
  }
3613
- return balanceBySymbol.get(symbolUpper) ?? 0;
3693
+ const directBalance = balanceBySymbol.get(symbolUpper) ?? 0;
3694
+ if (directBalance > 0) return directBalance;
3695
+ for (const eq of getEquivalentSymbols(symbolUpper)) {
3696
+ const eqToken = chainKey ? assetMatrix?.[eq]?.[chainKey] : void 0;
3697
+ if (eqToken?.address) {
3698
+ const b2 = balanceByTokenKey.get(makeTokenBalanceKey(eqToken.address));
3699
+ if (typeof b2 === "number" && b2 > 0) return b2;
3700
+ }
3701
+ const eqBalance = balanceBySymbol.get(eq) ?? 0;
3702
+ if (eqBalance > 0) return eqBalance;
3703
+ }
3704
+ return directBalance;
3614
3705
  },
3615
3706
  [assetMatrix, balanceBySymbol, balanceByTokenKey, chainKey]
3616
3707
  );
@@ -3676,8 +3767,9 @@ function useSwapModel() {
3676
3767
  if (!isAllowedFromChain(toChain.chainKey)) return;
3677
3768
  chainsStore.setAllowedToChains([]);
3678
3769
  chainsStore.setFromChain(toChain);
3679
- const tokenOnNewFrom = tokensStore.assetMatrix?.[sym]?.[toChain.chainKey];
3680
- if (tokenOnNewFrom) {
3770
+ const matrix = tokensStore.assetMatrix;
3771
+ const hasTokenOnNewFrom = !!matrix?.[sym]?.[toChain.chainKey] || getEquivalentSymbols(sym).some((eq) => !!matrix?.[eq]?.[toChain.chainKey]);
3772
+ if (hasTokenOnNewFrom) {
3681
3773
  chainsStore.setToChain(fromChain);
3682
3774
  } else {
3683
3775
  chainsStore.setToChain(void 0);
@@ -3833,12 +3925,12 @@ function useFeeBreakdown() {
3833
3925
  const { tokens, allTokens, selectedAssetSymbol, assetMatrix } = useTokensStore();
3834
3926
  const { fromChain, toChain, chains } = useChainsStore();
3835
3927
  return React.useMemo(() => {
3836
- const srcToken = resolveTokenOnChainFromMatrix$1(
3928
+ const srcToken = resolveBridgeSourceTokenOnChainFromMatrix(
3837
3929
  assetMatrix,
3838
3930
  selectedAssetSymbol,
3839
3931
  fromChain?.chainKey
3840
3932
  );
3841
- const dstToken = resolveTokenOnChainFromMatrix$1(
3933
+ const dstToken = resolveBridgeDestinationTokenOnChainFromMatrix(
3842
3934
  assetMatrix,
3843
3935
  selectedAssetSymbol,
3844
3936
  toChain?.chainKey
@@ -3915,12 +4007,12 @@ function buildBridgeExternalData({
3915
4007
  dstChain: toChain?.chainKey,
3916
4008
  amount: normalizedAmount || void 0
3917
4009
  };
3918
- const sourceToken = resolveTokenOnChainFromMatrix$1(
4010
+ const sourceToken = resolveBridgeSourceTokenOnChainFromMatrix(
3919
4011
  assetMatrix,
3920
4012
  selectedAssetSymbol,
3921
4013
  fromChain?.chainKey
3922
4014
  );
3923
- const destinationToken = resolveTokenOnChainFromMatrix$1(
4015
+ const destinationToken = resolveBridgeDestinationTokenOnChainFromMatrix(
3924
4016
  assetMatrix,
3925
4017
  selectedAssetSymbol,
3926
4018
  toChain?.chainKey
@@ -4548,7 +4640,7 @@ function useBridgeTransaction() {
4548
4640
  const txStore = useTransactionStore();
4549
4641
  const gas = useGasEstimate();
4550
4642
  const srcToken = React.useMemo(
4551
- () => resolveTokenOnChainFromMatrix$1(
4643
+ () => resolveBridgeSourceTokenOnChainFromMatrix(
4552
4644
  assetMatrix,
4553
4645
  selectedAssetSymbol,
4554
4646
  quote?.srcChainKey
@@ -4556,7 +4648,7 @@ function useBridgeTransaction() {
4556
4648
  [assetMatrix, selectedAssetSymbol, quote?.srcChainKey]
4557
4649
  );
4558
4650
  const dstToken = React.useMemo(
4559
- () => resolveTokenOnChainFromMatrix$1(
4651
+ () => resolveBridgeDestinationTokenOnChainFromMatrix(
4560
4652
  assetMatrix,
4561
4653
  selectedAssetSymbol,
4562
4654
  quote?.dstChainKey
@@ -4854,8 +4946,13 @@ function useSilentValidations(amountString) {
4854
4946
  const hasTooManyDecimals = (() => {
4855
4947
  if (!amountString || !fromChain?.chainKey || !selectedAssetSymbol)
4856
4948
  return false;
4949
+ const resolvedSym = getBridgeTokenSymbol(
4950
+ selectedAssetSymbol,
4951
+ assetMatrix,
4952
+ fromChain.chainKey
4953
+ );
4857
4954
  const sourceToken = tokens?.find(
4858
- (t2) => t2.chainKey === fromChain.chainKey && (t2.symbol ?? "").toUpperCase() === (selectedAssetSymbol ?? "").toUpperCase()
4955
+ (t2) => t2.chainKey === fromChain.chainKey && (t2.symbol ?? "").toUpperCase() === resolvedSym
4859
4956
  );
4860
4957
  if (!sourceToken) return false;
4861
4958
  const decimalPart = amountString.split(".")[1];
@@ -4866,11 +4963,18 @@ function useSilentValidations(amountString) {
4866
4963
  if (!selectedAssetSymbol || !fromChain?.chainKey || !toChain?.chainKey)
4867
4964
  return false;
4868
4965
  if (!assetMatrix) return false;
4869
- const normalizedSymbol = selectedAssetSymbol.toUpperCase();
4870
- const tokenMatrix = assetMatrix[normalizedSymbol];
4871
- if (!tokenMatrix) return true;
4872
- const existsOnSource = !!tokenMatrix[fromChain.chainKey];
4873
- const existsOnDestination = !!tokenMatrix[toChain.chainKey];
4966
+ const allSymbols = [
4967
+ selectedAssetSymbol.toUpperCase(),
4968
+ ...getEquivalentSymbols(selectedAssetSymbol).map(
4969
+ (s2) => s2.toUpperCase()
4970
+ )
4971
+ ];
4972
+ const existsOnSource = allSymbols.some(
4973
+ (sym) => !!assetMatrix[sym]?.[fromChain.chainKey]
4974
+ );
4975
+ const existsOnDestination = allSymbols.some(
4976
+ (sym) => !!assetMatrix[sym]?.[toChain.chainKey]
4977
+ );
4874
4978
  return !existsOnSource || !existsOnDestination;
4875
4979
  })();
4876
4980
  const hasInsufficientLiquidity = (() => {
@@ -26562,7 +26666,7 @@ class WalletConnectModal {
26562
26666
  }
26563
26667
  async initUi() {
26564
26668
  if (typeof window !== "undefined") {
26565
- await Promise.resolve().then(() => require("./index-BdfMMh_j.cjs"));
26669
+ await Promise.resolve().then(() => require("./index-BSfpUPGz.cjs"));
26566
26670
  const modal = document.createElement("wcm-modal");
26567
26671
  document.body.insertAdjacentElement("beforeend", modal);
26568
26672
  OptionsCtrl.setIsUiLoaded(true);
@@ -27275,12 +27379,12 @@ const EvaaBridgeContent = ({
27275
27379
  );
27276
27380
  const outputAmount = React.useMemo(() => {
27277
27381
  if (!quote || loading) return "";
27278
- const srcToken = resolveTokenOnChainFromMatrix$1(
27382
+ const srcToken = resolveBridgeSourceTokenOnChainFromMatrix(
27279
27383
  assetMatrix,
27280
27384
  selectedAssetSymbol,
27281
27385
  fromChain?.chainKey
27282
27386
  );
27283
- const dstToken = resolveTokenOnChainFromMatrix$1(
27387
+ const dstToken = resolveBridgeDestinationTokenOnChainFromMatrix(
27284
27388
  assetMatrix,
27285
27389
  selectedAssetSymbol,
27286
27390
  toChain?.chainKey
@@ -27451,6 +27555,8 @@ exports.makeTokenBalanceKey = makeTokenBalanceKey;
27451
27555
  exports.normalizeTickerSymbol = normalizeTickerSymbol;
27452
27556
  exports.pollUntilDelivered = pollUntilDelivered;
27453
27557
  exports.reportBridgeTransaction = reportBridgeTransaction;
27558
+ exports.resolveBridgeDestinationTokenOnChainFromMatrix = resolveBridgeDestinationTokenOnChainFromMatrix;
27559
+ exports.resolveBridgeSourceTokenOnChainFromMatrix = resolveBridgeSourceTokenOnChainFromMatrix;
27454
27560
  exports.resolveTokenOnChain = resolveTokenOnChain;
27455
27561
  exports.resolveTokenOnChainFromMatrix = resolveTokenOnChainFromMatrix$1;
27456
27562
  exports.toLD = toLD;
@@ -27465,4 +27571,4 @@ exports.useSettingsStore = useSettingsStore;
27465
27571
  exports.useSwapModel = useSwapModel;
27466
27572
  exports.useTokensStore = useTokensStore;
27467
27573
  exports.useTransactionStore = useTransactionStore;
27468
- //# sourceMappingURL=index-BDGHvxEQ.cjs.map
27574
+ //# sourceMappingURL=index-DUoTGuFx.cjs.map