@rash2x/bridge-widget 0.8.4 → 0.8.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.
@@ -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,20 @@ 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 effectiveSym = getBridgeTokenSymbol(selectedAssetSymbol, assetMatrix, chainKey);
1355
+ if (effectiveSym !== selectedAssetSymbol.toUpperCase()) {
1356
+ setSelectedAssetSymbol(effectiveSym);
1357
+ }
1358
+ },
1359
+ [selectedAssetSymbol, assetMatrix, setSelectedAssetSymbol]
1360
+ );
1328
1361
  const onChainPick = React.useCallback(
1329
1362
  async (chain2, willChangeSrc = false, willChangeTokenAndSrc = false) => {
1330
1363
  if (!willChangeSrc && !willChangeTokenAndSrc) {
1364
+ switchToEquivalentIfNeeded(chain2.chainKey);
1331
1365
  onChangeChain(chain2);
1332
1366
  handleClose();
1333
1367
  return;
@@ -1359,7 +1393,18 @@ const ChainSelectModal = ({
1359
1393
  onChangeChain(chain2);
1360
1394
  }
1361
1395
  } else if (willChangeSrc && selectedAssetSymbol) {
1362
- const dstToken = assetMatrix?.[selectedAssetSymbol.toUpperCase()]?.[chain2.chainKey];
1396
+ let dstToken = assetMatrix?.[selectedAssetSymbol.toUpperCase()]?.[chain2.chainKey];
1397
+ let resolvedSym = selectedAssetSymbol;
1398
+ if (!dstToken?.address) {
1399
+ for (const eq of getEquivalentSymbols(selectedAssetSymbol)) {
1400
+ const eqToken = assetMatrix?.[eq]?.[chain2.chainKey];
1401
+ if (eqToken?.address) {
1402
+ dstToken = eqToken;
1403
+ resolvedSym = eq;
1404
+ break;
1405
+ }
1406
+ }
1407
+ }
1363
1408
  if (!dstToken?.address) return;
1364
1409
  const availableSources = await getDestTokens(chain2.chainKey, dstToken.address);
1365
1410
  const sourceChainKeys = new Set(availableSources.map((t22) => t22.chainKey ?? ""));
@@ -1376,6 +1421,9 @@ const ChainSelectModal = ({
1376
1421
  );
1377
1422
  }
1378
1423
  if (validSrc) {
1424
+ if (resolvedSym.toUpperCase() !== selectedAssetSymbol.toUpperCase()) {
1425
+ setSelectedAssetSymbol(resolvedSym);
1426
+ }
1379
1427
  setFromChain(validSrc);
1380
1428
  onChangeChain(chain2);
1381
1429
  }
@@ -1393,6 +1441,7 @@ const ChainSelectModal = ({
1393
1441
  selectedAssetSymbol,
1394
1442
  assetMatrix,
1395
1443
  findCompatibleTokenAndSrcChain,
1444
+ switchToEquivalentIfNeeded,
1396
1445
  setSelectedAssetSymbol,
1397
1446
  setFromChain,
1398
1447
  onChangeChain,
@@ -2614,22 +2663,16 @@ function useBridgeQuote() {
2614
2663
  const { chainRegistry } = useChainStrategies();
2615
2664
  const publicClient = wagmi.usePublicClient();
2616
2665
  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
- );
2666
+ const srcTokenOnFrom = React.useMemo(() => {
2667
+ if (!assetMatrix || !selectedAssetSymbol || !fromChain?.chainKey) return void 0;
2668
+ const sym = getBridgeTokenSymbol(selectedAssetSymbol, assetMatrix, fromChain.chainKey);
2669
+ return resolveTokenOnChainFromMatrix$1(assetMatrix, sym, fromChain.chainKey);
2670
+ }, [assetMatrix, selectedAssetSymbol, fromChain?.chainKey]);
2671
+ const dstTokenOnTo = React.useMemo(() => {
2672
+ if (!assetMatrix || !selectedAssetSymbol || !toChain?.chainKey) return void 0;
2673
+ const sym = getBridgeTokenSymbol(selectedAssetSymbol, assetMatrix, toChain.chainKey);
2674
+ return resolveTokenOnChainFromMatrix$1(assetMatrix, sym, toChain.chainKey);
2675
+ }, [assetMatrix, selectedAssetSymbol, toChain?.chainKey]);
2633
2676
  const [loading, setLoading] = React.useState(false);
2634
2677
  React.useEffect(() => {
2635
2678
  if (!input2 || input2 === "") {
@@ -2661,14 +2704,9 @@ function useBridgeQuote() {
2661
2704
  try {
2662
2705
  setLoading(true);
2663
2706
  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
- }
2707
+ if (!srcTokenOnFrom || !dstTokenOnTo) {
2708
+ if (!cancelled) resetUi();
2709
+ return;
2672
2710
  }
2673
2711
  const srcAmountLD = toLD(input2, srcTokenOnFrom.decimals);
2674
2712
  const srcAddrApi = addrForApi(fromChain.chainKey, srcAddress);
@@ -2774,6 +2812,11 @@ const useChainDerivations = () => {
2774
2812
  return [];
2775
2813
  const byChain = assetMatrix[selectedAssetSymbol.toUpperCase()];
2776
2814
  const keys2 = new Set(Object.keys(byChain ?? {}));
2815
+ for (const eq of getEquivalentSymbols(selectedAssetSymbol)) {
2816
+ for (const ck of Object.keys(assetMatrix[eq] ?? {})) {
2817
+ keys2.add(ck);
2818
+ }
2819
+ }
2777
2820
  const result = chains.filter((c2) => keys2.has(c2.chainKey) && isAllowedFromChain(c2.chainKey));
2778
2821
  return result;
2779
2822
  }, [selectedAssetSymbol, assetMatrix, chains]);
@@ -2815,11 +2858,8 @@ const useChainDerivations = () => {
2815
2858
  setAllowedToChains([]);
2816
2859
  return;
2817
2860
  }
2818
- const srcToken = resolveTokenOnChainFromMatrix(
2819
- assetMatrix,
2820
- selectedAssetSymbol,
2821
- fromChain.chainKey
2822
- );
2861
+ const srcSym = getBridgeTokenSymbol(selectedAssetSymbol, assetMatrix, fromChain.chainKey);
2862
+ const srcToken = resolveTokenOnChainFromMatrix(assetMatrix, srcSym, fromChain.chainKey);
2823
2863
  const srcAddr = srcToken?.address;
2824
2864
  if (!srcAddr) {
2825
2865
  setAllowedToChains([]);
@@ -2831,11 +2871,18 @@ const useChainDerivations = () => {
2831
2871
  const dest = await getDestTokens(fromChain.chainKey, srcAddr);
2832
2872
  if (ignore) return;
2833
2873
  const byChainSameSymbol = assetMatrix?.[selectedAssetSymbol.toUpperCase()] ?? {};
2874
+ const equivalentSymbols = /* @__PURE__ */ new Set([
2875
+ selectedAssetSymbol.toUpperCase(),
2876
+ ...getEquivalentSymbols(selectedAssetSymbol).map((s2) => s2.toUpperCase())
2877
+ ]);
2834
2878
  const filteredDest = dest.filter((t2) => {
2835
2879
  const ck = t2.chainKey ?? t2.dstChainKey ?? "";
2836
- const matrixToken = byChainSameSymbol[ck];
2837
- const symbolMatch = matrixToken && (t2.symbol ?? "").toUpperCase() === selectedAssetSymbol.toUpperCase();
2838
- return !!symbolMatch;
2880
+ const destSymbol = (t2.symbol ?? "").toUpperCase();
2881
+ if (!equivalentSymbols.has(destSymbol)) return false;
2882
+ const hasInMatrix = !!byChainSameSymbol[ck] || getEquivalentSymbols(selectedAssetSymbol).some(
2883
+ (eq) => !!assetMatrix?.[eq.toUpperCase()]?.[ck]
2884
+ );
2885
+ return hasInMatrix;
2839
2886
  });
2840
2887
  const keys2 = new Set(filteredDest.map((t2) => t2.chainKey));
2841
2888
  let list = chains.filter((c2) => keys2.has(c2.chainKey) && isAllowedToChain(c2.chainKey));
@@ -3610,7 +3657,18 @@ function useBalances(chainKey, address) {
3610
3657
  );
3611
3658
  if (typeof byAddress === "number") return byAddress;
3612
3659
  }
3613
- return balanceBySymbol.get(symbolUpper) ?? 0;
3660
+ const directBalance = balanceBySymbol.get(symbolUpper) ?? 0;
3661
+ if (directBalance > 0) return directBalance;
3662
+ for (const eq of getEquivalentSymbols(symbolUpper)) {
3663
+ const eqToken = chainKey ? assetMatrix?.[eq]?.[chainKey] : void 0;
3664
+ if (eqToken?.address) {
3665
+ const b2 = balanceByTokenKey.get(makeTokenBalanceKey(eqToken.address));
3666
+ if (typeof b2 === "number" && b2 > 0) return b2;
3667
+ }
3668
+ const eqBalance = balanceBySymbol.get(eq) ?? 0;
3669
+ if (eqBalance > 0) return eqBalance;
3670
+ }
3671
+ return directBalance;
3614
3672
  },
3615
3673
  [assetMatrix, balanceBySymbol, balanceByTokenKey, chainKey]
3616
3674
  );
@@ -3676,8 +3734,9 @@ function useSwapModel() {
3676
3734
  if (!isAllowedFromChain(toChain.chainKey)) return;
3677
3735
  chainsStore.setAllowedToChains([]);
3678
3736
  chainsStore.setFromChain(toChain);
3679
- const tokenOnNewFrom = tokensStore.assetMatrix?.[sym]?.[toChain.chainKey];
3680
- if (tokenOnNewFrom) {
3737
+ const matrix = tokensStore.assetMatrix;
3738
+ const hasTokenOnNewFrom = !!matrix?.[sym]?.[toChain.chainKey] || getEquivalentSymbols(sym).some((eq) => !!matrix?.[eq]?.[toChain.chainKey]);
3739
+ if (hasTokenOnNewFrom) {
3681
3740
  chainsStore.setToChain(fromChain);
3682
3741
  } else {
3683
3742
  chainsStore.setToChain(void 0);
@@ -26562,7 +26621,7 @@ class WalletConnectModal {
26562
26621
  }
26563
26622
  async initUi() {
26564
26623
  if (typeof window !== "undefined") {
26565
- await Promise.resolve().then(() => require("./index-BdfMMh_j.cjs"));
26624
+ await Promise.resolve().then(() => require("./index-DiFbb5zn.cjs"));
26566
26625
  const modal = document.createElement("wcm-modal");
26567
26626
  document.body.insertAdjacentElement("beforeend", modal);
26568
26627
  OptionsCtrl.setIsUiLoaded(true);
@@ -27465,4 +27524,4 @@ exports.useSettingsStore = useSettingsStore;
27465
27524
  exports.useSwapModel = useSwapModel;
27466
27525
  exports.useTokensStore = useTokensStore;
27467
27526
  exports.useTransactionStore = useTransactionStore;
27468
- //# sourceMappingURL=index-BDGHvxEQ.cjs.map
27527
+ //# sourceMappingURL=index-CytmPXNr.cjs.map