@rash2x/bridge-widget 0.8.3 → 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.
- package/dist/evaa-bridge.cjs +1 -1
- package/dist/evaa-bridge.mjs +1 -1
- package/dist/{index-0JKTjlKW.js → index-B1odZ4FL.js} +2 -2
- package/dist/{index-0JKTjlKW.js.map → index-B1odZ4FL.js.map} +1 -1
- package/dist/{index-D2zkzmLE.js → index-BIpr23sm.js} +110 -42
- package/dist/index-BIpr23sm.js.map +1 -0
- package/dist/{index-egFmHlPu.cjs → index-CytmPXNr.cjs} +110 -42
- package/dist/index-CytmPXNr.cjs.map +1 -0
- package/dist/{index-s4FyGXJW.cjs → index-DiFbb5zn.cjs} +2 -2
- package/dist/{index-s4FyGXJW.cjs.map → index-DiFbb5zn.cjs.map} +1 -1
- package/package.json +1 -1
- package/dist/index-D2zkzmLE.js.map +0 -1
- package/dist/index-egFmHlPu.cjs.map +0 -1
|
@@ -1194,6 +1194,25 @@ const SearchInput = ({
|
|
|
1194
1194
|
) })
|
|
1195
1195
|
] });
|
|
1196
1196
|
};
|
|
1197
|
+
const TOKEN_EQUIVALENTS = {
|
|
1198
|
+
USDT: ["USDT0"],
|
|
1199
|
+
USDT0: ["USDT"]
|
|
1200
|
+
};
|
|
1201
|
+
function getEquivalentSymbols(symbol) {
|
|
1202
|
+
return TOKEN_EQUIVALENTS[symbol.toUpperCase()] ?? [];
|
|
1203
|
+
}
|
|
1204
|
+
const BRIDGE_PREFERRED_TOKENS = /* @__PURE__ */ new Set(["USDT0"]);
|
|
1205
|
+
function getBridgeTokenSymbol(symbol, assetMatrix, chainKey) {
|
|
1206
|
+
if (!assetMatrix || !chainKey) return symbol.toUpperCase();
|
|
1207
|
+
const candidates = [symbol.toUpperCase(), ...getEquivalentSymbols(symbol)];
|
|
1208
|
+
for (const sym of candidates) {
|
|
1209
|
+
if (BRIDGE_PREFERRED_TOKENS.has(sym) && assetMatrix[sym]?.[chainKey]) return sym;
|
|
1210
|
+
}
|
|
1211
|
+
for (const sym of candidates) {
|
|
1212
|
+
if (assetMatrix[sym]?.[chainKey]) return sym;
|
|
1213
|
+
}
|
|
1214
|
+
return symbol.toUpperCase();
|
|
1215
|
+
}
|
|
1197
1216
|
const ChainSelectModal = ({
|
|
1198
1217
|
isOpen,
|
|
1199
1218
|
onClose,
|
|
@@ -1221,10 +1240,14 @@ const ChainSelectModal = ({
|
|
|
1221
1240
|
"optimism",
|
|
1222
1241
|
"base"
|
|
1223
1242
|
];
|
|
1224
|
-
const
|
|
1225
|
-
|
|
1243
|
+
const allSymbols = [
|
|
1244
|
+
selectedAssetSymbol.toUpperCase(),
|
|
1245
|
+
...getEquivalentSymbols(selectedAssetSymbol).map((s2) => s2.toUpperCase())
|
|
1246
|
+
];
|
|
1247
|
+
const hasTokenOrEquiv = (chainKey) => allSymbols.some((sym) => !!assetMatrix[sym]?.[chainKey]);
|
|
1248
|
+
if (!hasTokenOrEquiv(dstChain.chainKey)) return void 0;
|
|
1226
1249
|
const availableChains = chains.filter(
|
|
1227
|
-
(c2) =>
|
|
1250
|
+
(c2) => hasTokenOrEquiv(c2.chainKey) && c2.chainKey !== fromChain?.chainKey && c2.chainKey !== dstChain.chainKey
|
|
1228
1251
|
);
|
|
1229
1252
|
for (const chainKey of PRIORITY_CHAINS2) {
|
|
1230
1253
|
const chain2 = availableChains.find((c2) => c2.chainKey === chainKey);
|
|
@@ -1308,9 +1331,20 @@ const ChainSelectModal = ({
|
|
|
1308
1331
|
[]
|
|
1309
1332
|
);
|
|
1310
1333
|
const [isPickLoading, setIsPickLoading] = useState(false);
|
|
1334
|
+
const switchToEquivalentIfNeeded = useCallback(
|
|
1335
|
+
(chainKey) => {
|
|
1336
|
+
if (!selectedAssetSymbol || !assetMatrix) return;
|
|
1337
|
+
const effectiveSym = getBridgeTokenSymbol(selectedAssetSymbol, assetMatrix, chainKey);
|
|
1338
|
+
if (effectiveSym !== selectedAssetSymbol.toUpperCase()) {
|
|
1339
|
+
setSelectedAssetSymbol(effectiveSym);
|
|
1340
|
+
}
|
|
1341
|
+
},
|
|
1342
|
+
[selectedAssetSymbol, assetMatrix, setSelectedAssetSymbol]
|
|
1343
|
+
);
|
|
1311
1344
|
const onChainPick = useCallback(
|
|
1312
1345
|
async (chain2, willChangeSrc = false, willChangeTokenAndSrc = false) => {
|
|
1313
1346
|
if (!willChangeSrc && !willChangeTokenAndSrc) {
|
|
1347
|
+
switchToEquivalentIfNeeded(chain2.chainKey);
|
|
1314
1348
|
onChangeChain(chain2);
|
|
1315
1349
|
handleClose();
|
|
1316
1350
|
return;
|
|
@@ -1342,7 +1376,18 @@ const ChainSelectModal = ({
|
|
|
1342
1376
|
onChangeChain(chain2);
|
|
1343
1377
|
}
|
|
1344
1378
|
} else if (willChangeSrc && selectedAssetSymbol) {
|
|
1345
|
-
|
|
1379
|
+
let dstToken = assetMatrix?.[selectedAssetSymbol.toUpperCase()]?.[chain2.chainKey];
|
|
1380
|
+
let resolvedSym = selectedAssetSymbol;
|
|
1381
|
+
if (!dstToken?.address) {
|
|
1382
|
+
for (const eq of getEquivalentSymbols(selectedAssetSymbol)) {
|
|
1383
|
+
const eqToken = assetMatrix?.[eq]?.[chain2.chainKey];
|
|
1384
|
+
if (eqToken?.address) {
|
|
1385
|
+
dstToken = eqToken;
|
|
1386
|
+
resolvedSym = eq;
|
|
1387
|
+
break;
|
|
1388
|
+
}
|
|
1389
|
+
}
|
|
1390
|
+
}
|
|
1346
1391
|
if (!dstToken?.address) return;
|
|
1347
1392
|
const availableSources = await getDestTokens(chain2.chainKey, dstToken.address);
|
|
1348
1393
|
const sourceChainKeys = new Set(availableSources.map((t22) => t22.chainKey ?? ""));
|
|
@@ -1359,6 +1404,9 @@ const ChainSelectModal = ({
|
|
|
1359
1404
|
);
|
|
1360
1405
|
}
|
|
1361
1406
|
if (validSrc) {
|
|
1407
|
+
if (resolvedSym.toUpperCase() !== selectedAssetSymbol.toUpperCase()) {
|
|
1408
|
+
setSelectedAssetSymbol(resolvedSym);
|
|
1409
|
+
}
|
|
1362
1410
|
setFromChain(validSrc);
|
|
1363
1411
|
onChangeChain(chain2);
|
|
1364
1412
|
}
|
|
@@ -1376,6 +1424,7 @@ const ChainSelectModal = ({
|
|
|
1376
1424
|
selectedAssetSymbol,
|
|
1377
1425
|
assetMatrix,
|
|
1378
1426
|
findCompatibleTokenAndSrcChain,
|
|
1427
|
+
switchToEquivalentIfNeeded,
|
|
1379
1428
|
setSelectedAssetSymbol,
|
|
1380
1429
|
setFromChain,
|
|
1381
1430
|
onChangeChain,
|
|
@@ -2445,6 +2494,7 @@ function computeFeeBreakdownUsd(quote, srcToken, dstToken, tokens, chains, srcCh
|
|
|
2445
2494
|
let messageFeeUsd = 0;
|
|
2446
2495
|
let messageFeeAmount = 0;
|
|
2447
2496
|
let messageFeeSymbol = "";
|
|
2497
|
+
let messageFeeTokenPriceUsd = 0;
|
|
2448
2498
|
const messageFees = quote.fees.filter((f4) => f4.type === "message");
|
|
2449
2499
|
for (const f4 of messageFees) {
|
|
2450
2500
|
const { decimals, priceUsd } = lookupTokenMeta(
|
|
@@ -2462,6 +2512,7 @@ function computeFeeBreakdownUsd(quote, srcToken, dstToken, tokens, chains, srcCh
|
|
|
2462
2512
|
(t2) => t2.chainKey === f4.chainKey && t2.address.toLowerCase() === f4.token.toLowerCase()
|
|
2463
2513
|
);
|
|
2464
2514
|
messageFeeSymbol = token?.symbol?.toUpperCase() ?? chain2?.nativeCurrency?.symbol?.toUpperCase() ?? "";
|
|
2515
|
+
messageFeeTokenPriceUsd = priceUsd ?? 0;
|
|
2465
2516
|
}
|
|
2466
2517
|
}
|
|
2467
2518
|
let bridgeFeeAmount = 0;
|
|
@@ -2492,7 +2543,14 @@ function computeFeeBreakdownUsd(quote, srcToken, dstToken, tokens, chains, srcCh
|
|
|
2492
2543
|
dstGasUsd = dstGasAmount * (priceUsd ?? 0);
|
|
2493
2544
|
}
|
|
2494
2545
|
}
|
|
2495
|
-
|
|
2546
|
+
if (dstGasAmount > 0 && messageFeeSymbol) {
|
|
2547
|
+
if (messageFeeSymbol === dstGasSymbol) {
|
|
2548
|
+
messageFeeAmount += dstGasAmount;
|
|
2549
|
+
} else if (messageFeeTokenPriceUsd > 0) {
|
|
2550
|
+
messageFeeAmount += dstGasUsd / messageFeeTokenPriceUsd;
|
|
2551
|
+
}
|
|
2552
|
+
}
|
|
2553
|
+
const totalFeeUsd = messageFeeUsd + bridgeFeeUsd;
|
|
2496
2554
|
return {
|
|
2497
2555
|
messageFeeAmount,
|
|
2498
2556
|
messageFeeSymbol,
|
|
@@ -2588,22 +2646,16 @@ function useBridgeQuote() {
|
|
|
2588
2646
|
const { chainRegistry } = useChainStrategies();
|
|
2589
2647
|
const publicClient = usePublicClient();
|
|
2590
2648
|
const input = inputAmount;
|
|
2591
|
-
const srcTokenOnFrom = useMemo(
|
|
2592
|
-
()
|
|
2593
|
-
|
|
2594
|
-
|
|
2595
|
-
|
|
2596
|
-
|
|
2597
|
-
|
|
2598
|
-
|
|
2599
|
-
|
|
2600
|
-
|
|
2601
|
-
assetMatrix,
|
|
2602
|
-
selectedAssetSymbol,
|
|
2603
|
-
toChain?.chainKey
|
|
2604
|
-
),
|
|
2605
|
-
[assetMatrix, selectedAssetSymbol, toChain?.chainKey]
|
|
2606
|
-
);
|
|
2649
|
+
const srcTokenOnFrom = useMemo(() => {
|
|
2650
|
+
if (!assetMatrix || !selectedAssetSymbol || !fromChain?.chainKey) return void 0;
|
|
2651
|
+
const sym = getBridgeTokenSymbol(selectedAssetSymbol, assetMatrix, fromChain.chainKey);
|
|
2652
|
+
return resolveTokenOnChainFromMatrix$1(assetMatrix, sym, fromChain.chainKey);
|
|
2653
|
+
}, [assetMatrix, selectedAssetSymbol, fromChain?.chainKey]);
|
|
2654
|
+
const dstTokenOnTo = useMemo(() => {
|
|
2655
|
+
if (!assetMatrix || !selectedAssetSymbol || !toChain?.chainKey) return void 0;
|
|
2656
|
+
const sym = getBridgeTokenSymbol(selectedAssetSymbol, assetMatrix, toChain.chainKey);
|
|
2657
|
+
return resolveTokenOnChainFromMatrix$1(assetMatrix, sym, toChain.chainKey);
|
|
2658
|
+
}, [assetMatrix, selectedAssetSymbol, toChain?.chainKey]);
|
|
2607
2659
|
const [loading, setLoading] = useState(false);
|
|
2608
2660
|
useEffect(() => {
|
|
2609
2661
|
if (!input || input === "") {
|
|
@@ -2635,14 +2687,9 @@ function useBridgeQuote() {
|
|
|
2635
2687
|
try {
|
|
2636
2688
|
setLoading(true);
|
|
2637
2689
|
setQuoteLoading?.();
|
|
2638
|
-
if (
|
|
2639
|
-
|
|
2640
|
-
|
|
2641
|
-
if (!cancelled) {
|
|
2642
|
-
resetUi();
|
|
2643
|
-
}
|
|
2644
|
-
return;
|
|
2645
|
-
}
|
|
2690
|
+
if (!srcTokenOnFrom || !dstTokenOnTo) {
|
|
2691
|
+
if (!cancelled) resetUi();
|
|
2692
|
+
return;
|
|
2646
2693
|
}
|
|
2647
2694
|
const srcAmountLD = toLD(input, srcTokenOnFrom.decimals);
|
|
2648
2695
|
const srcAddrApi = addrForApi(fromChain.chainKey, srcAddress);
|
|
@@ -2748,6 +2795,11 @@ const useChainDerivations = () => {
|
|
|
2748
2795
|
return [];
|
|
2749
2796
|
const byChain = assetMatrix[selectedAssetSymbol.toUpperCase()];
|
|
2750
2797
|
const keys2 = new Set(Object.keys(byChain ?? {}));
|
|
2798
|
+
for (const eq of getEquivalentSymbols(selectedAssetSymbol)) {
|
|
2799
|
+
for (const ck of Object.keys(assetMatrix[eq] ?? {})) {
|
|
2800
|
+
keys2.add(ck);
|
|
2801
|
+
}
|
|
2802
|
+
}
|
|
2751
2803
|
const result = chains.filter((c2) => keys2.has(c2.chainKey) && isAllowedFromChain(c2.chainKey));
|
|
2752
2804
|
return result;
|
|
2753
2805
|
}, [selectedAssetSymbol, assetMatrix, chains]);
|
|
@@ -2789,11 +2841,8 @@ const useChainDerivations = () => {
|
|
|
2789
2841
|
setAllowedToChains([]);
|
|
2790
2842
|
return;
|
|
2791
2843
|
}
|
|
2792
|
-
const
|
|
2793
|
-
|
|
2794
|
-
selectedAssetSymbol,
|
|
2795
|
-
fromChain.chainKey
|
|
2796
|
-
);
|
|
2844
|
+
const srcSym = getBridgeTokenSymbol(selectedAssetSymbol, assetMatrix, fromChain.chainKey);
|
|
2845
|
+
const srcToken = resolveTokenOnChainFromMatrix(assetMatrix, srcSym, fromChain.chainKey);
|
|
2797
2846
|
const srcAddr = srcToken?.address;
|
|
2798
2847
|
if (!srcAddr) {
|
|
2799
2848
|
setAllowedToChains([]);
|
|
@@ -2805,11 +2854,18 @@ const useChainDerivations = () => {
|
|
|
2805
2854
|
const dest = await getDestTokens(fromChain.chainKey, srcAddr);
|
|
2806
2855
|
if (ignore) return;
|
|
2807
2856
|
const byChainSameSymbol = assetMatrix?.[selectedAssetSymbol.toUpperCase()] ?? {};
|
|
2857
|
+
const equivalentSymbols = /* @__PURE__ */ new Set([
|
|
2858
|
+
selectedAssetSymbol.toUpperCase(),
|
|
2859
|
+
...getEquivalentSymbols(selectedAssetSymbol).map((s2) => s2.toUpperCase())
|
|
2860
|
+
]);
|
|
2808
2861
|
const filteredDest = dest.filter((t2) => {
|
|
2809
2862
|
const ck = t2.chainKey ?? t2.dstChainKey ?? "";
|
|
2810
|
-
const
|
|
2811
|
-
|
|
2812
|
-
|
|
2863
|
+
const destSymbol = (t2.symbol ?? "").toUpperCase();
|
|
2864
|
+
if (!equivalentSymbols.has(destSymbol)) return false;
|
|
2865
|
+
const hasInMatrix = !!byChainSameSymbol[ck] || getEquivalentSymbols(selectedAssetSymbol).some(
|
|
2866
|
+
(eq) => !!assetMatrix?.[eq.toUpperCase()]?.[ck]
|
|
2867
|
+
);
|
|
2868
|
+
return hasInMatrix;
|
|
2813
2869
|
});
|
|
2814
2870
|
const keys2 = new Set(filteredDest.map((t2) => t2.chainKey));
|
|
2815
2871
|
let list = chains.filter((c2) => keys2.has(c2.chainKey) && isAllowedToChain(c2.chainKey));
|
|
@@ -3584,7 +3640,18 @@ function useBalances(chainKey, address) {
|
|
|
3584
3640
|
);
|
|
3585
3641
|
if (typeof byAddress === "number") return byAddress;
|
|
3586
3642
|
}
|
|
3587
|
-
|
|
3643
|
+
const directBalance = balanceBySymbol.get(symbolUpper) ?? 0;
|
|
3644
|
+
if (directBalance > 0) return directBalance;
|
|
3645
|
+
for (const eq of getEquivalentSymbols(symbolUpper)) {
|
|
3646
|
+
const eqToken = chainKey ? assetMatrix?.[eq]?.[chainKey] : void 0;
|
|
3647
|
+
if (eqToken?.address) {
|
|
3648
|
+
const b2 = balanceByTokenKey.get(makeTokenBalanceKey(eqToken.address));
|
|
3649
|
+
if (typeof b2 === "number" && b2 > 0) return b2;
|
|
3650
|
+
}
|
|
3651
|
+
const eqBalance = balanceBySymbol.get(eq) ?? 0;
|
|
3652
|
+
if (eqBalance > 0) return eqBalance;
|
|
3653
|
+
}
|
|
3654
|
+
return directBalance;
|
|
3588
3655
|
},
|
|
3589
3656
|
[assetMatrix, balanceBySymbol, balanceByTokenKey, chainKey]
|
|
3590
3657
|
);
|
|
@@ -3650,8 +3717,9 @@ function useSwapModel() {
|
|
|
3650
3717
|
if (!isAllowedFromChain(toChain.chainKey)) return;
|
|
3651
3718
|
chainsStore.setAllowedToChains([]);
|
|
3652
3719
|
chainsStore.setFromChain(toChain);
|
|
3653
|
-
const
|
|
3654
|
-
|
|
3720
|
+
const matrix = tokensStore.assetMatrix;
|
|
3721
|
+
const hasTokenOnNewFrom = !!matrix?.[sym]?.[toChain.chainKey] || getEquivalentSymbols(sym).some((eq) => !!matrix?.[eq]?.[toChain.chainKey]);
|
|
3722
|
+
if (hasTokenOnNewFrom) {
|
|
3655
3723
|
chainsStore.setToChain(fromChain);
|
|
3656
3724
|
} else {
|
|
3657
3725
|
chainsStore.setToChain(void 0);
|
|
@@ -26536,7 +26604,7 @@ class WalletConnectModal {
|
|
|
26536
26604
|
}
|
|
26537
26605
|
async initUi() {
|
|
26538
26606
|
if (typeof window !== "undefined") {
|
|
26539
|
-
await import("./index-
|
|
26607
|
+
await import("./index-B1odZ4FL.js");
|
|
26540
26608
|
const modal = document.createElement("wcm-modal");
|
|
26541
26609
|
document.body.insertAdjacentElement("beforeend", modal);
|
|
26542
26610
|
OptionsCtrl.setIsUiLoaded(true);
|
|
@@ -27441,4 +27509,4 @@ export {
|
|
|
27441
27509
|
calculateMinReceived as y,
|
|
27442
27510
|
getQuoteDetails as z
|
|
27443
27511
|
};
|
|
27444
|
-
//# sourceMappingURL=index-
|
|
27512
|
+
//# sourceMappingURL=index-BIpr23sm.js.map
|