@rash2x/bridge-widget 0.6.61 → 0.6.63
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 +2 -1
- package/dist/evaa-bridge.cjs.map +1 -1
- package/dist/evaa-bridge.mjs +28 -27
- package/dist/{index-Bl9Q1m-4.cjs → index-CSE-oDw8.cjs} +2 -2
- package/dist/{index-Bl9Q1m-4.cjs.map → index-CSE-oDw8.cjs.map} +1 -1
- package/dist/{index-rAch8BQe.cjs → index-CpKOf8oF.cjs} +196 -193
- package/dist/index-CpKOf8oF.cjs.map +1 -0
- package/dist/{index-yQkayDGz.js → index-DEi2-2_y.js} +2 -2
- package/dist/{index-yQkayDGz.js.map → index-DEi2-2_y.js.map} +1 -1
- package/dist/{index-D0OSdsmf.js → index-HznPfOtP.js} +222 -219
- package/dist/index-HznPfOtP.js.map +1 -0
- package/dist/index.d.ts +80 -0
- package/dist/styles.css +1 -1
- package/package.json +1 -1
- package/dist/index-D0OSdsmf.js.map +0 -1
- package/dist/index-rAch8BQe.cjs.map +0 -1
|
@@ -941,6 +941,179 @@ function useChainStrategies() {
|
|
|
941
941
|
}
|
|
942
942
|
return context;
|
|
943
943
|
}
|
|
944
|
+
const truncateToDecimals = (num, decimals) => {
|
|
945
|
+
if (!isFinite(num) || isNaN(num)) return "0";
|
|
946
|
+
const multiplier = Math.pow(10, decimals);
|
|
947
|
+
const truncated = Math.floor(num * multiplier) / multiplier;
|
|
948
|
+
return truncated.toFixed(decimals).replace(/\.?0+$/, "");
|
|
949
|
+
};
|
|
950
|
+
const formatTokenAmount = (amount, symbol, options) => {
|
|
951
|
+
const normalizedSymbol = (symbol ?? "").toUpperCase();
|
|
952
|
+
if (["USDT", "USDC", "DAI", "BUSD"].includes(normalizedSymbol) && amount >= 1) {
|
|
953
|
+
return `${Math.floor(amount)} ${normalizedSymbol}`;
|
|
954
|
+
}
|
|
955
|
+
if (options?.decimals !== void 0) {
|
|
956
|
+
return `${amount.toFixed(options.decimals)} ${normalizedSymbol}`;
|
|
957
|
+
}
|
|
958
|
+
if (amount >= 1) {
|
|
959
|
+
return `${amount.toFixed(0)} ${normalizedSymbol}`;
|
|
960
|
+
} else if (amount >= 1e-3) {
|
|
961
|
+
return `${amount.toFixed(3)} ${normalizedSymbol}`;
|
|
962
|
+
} else {
|
|
963
|
+
return `${amount.toFixed(6)} ${normalizedSymbol}`;
|
|
964
|
+
}
|
|
965
|
+
};
|
|
966
|
+
const formatUsd = (value) => {
|
|
967
|
+
if (!value || !isFinite(value)) return "$0";
|
|
968
|
+
if (value >= 1) return `$${value.toFixed(2)}`;
|
|
969
|
+
return `$${value.toFixed(6).replace(/0+$/, "").replace(/\.$/, "")}`;
|
|
970
|
+
};
|
|
971
|
+
const formatPercentage = (bps, decimals = 2) => {
|
|
972
|
+
return `${(bps / 100).toFixed(decimals).replace(/0+$/, "").replace(/\.$/, "")}%`;
|
|
973
|
+
};
|
|
974
|
+
const formatBalance = (amount, decimals = 2) => {
|
|
975
|
+
if (!isFinite(amount) || isNaN(amount) || amount <= 0) {
|
|
976
|
+
return "0.00";
|
|
977
|
+
}
|
|
978
|
+
return amount.toFixed(decimals);
|
|
979
|
+
};
|
|
980
|
+
const formatHash = (hash, startChars = 4, endChars = 4) => {
|
|
981
|
+
if (!hash) return "";
|
|
982
|
+
if (hash.length <= startChars + endChars) return hash;
|
|
983
|
+
return `${hash.slice(0, startChars)}...${hash.slice(-endChars)}`;
|
|
984
|
+
};
|
|
985
|
+
const formatAddress = formatHash;
|
|
986
|
+
function getQuoteAmounts(quote, srcToken, dstToken) {
|
|
987
|
+
if (!quote || !srcToken || !dstToken) {
|
|
988
|
+
return {
|
|
989
|
+
inputHuman: 0,
|
|
990
|
+
outputHuman: 0,
|
|
991
|
+
outputHumanRounded: "0",
|
|
992
|
+
minReceivedHuman: 0
|
|
993
|
+
};
|
|
994
|
+
}
|
|
995
|
+
const inputHuman = fromLD(quote.srcAmount, srcToken.decimals);
|
|
996
|
+
const outputHuman = fromLD(quote.dstAmount, dstToken.decimals);
|
|
997
|
+
const outputHumanRounded = truncateToDecimals(outputHuman, 2);
|
|
998
|
+
const minReceivedHuman = fromLD(quote.dstAmountMin || "0", dstToken.decimals);
|
|
999
|
+
return {
|
|
1000
|
+
inputHuman,
|
|
1001
|
+
outputHuman,
|
|
1002
|
+
outputHumanRounded,
|
|
1003
|
+
minReceivedHuman
|
|
1004
|
+
};
|
|
1005
|
+
}
|
|
1006
|
+
function getQuoteFees(quote, tokens, chains, srcToken, dstToken) {
|
|
1007
|
+
if (!quote || !tokens || !chains) {
|
|
1008
|
+
return {
|
|
1009
|
+
fees: { usd: /* @__PURE__ */ new Map(), original: /* @__PURE__ */ new Map(), formatted: /* @__PURE__ */ new Map() },
|
|
1010
|
+
inSrcToken: void 0,
|
|
1011
|
+
inDstToken: void 0
|
|
1012
|
+
};
|
|
1013
|
+
}
|
|
1014
|
+
const feeData = computeFeesUsdFromArray(quote.fees, tokens, chains);
|
|
1015
|
+
let inSrcToken = void 0;
|
|
1016
|
+
let inDstToken = void 0;
|
|
1017
|
+
if (srcToken && quote.srcChainKey) {
|
|
1018
|
+
const feeInSrcLD = sumFeeByTokenLD(
|
|
1019
|
+
quote.fees,
|
|
1020
|
+
srcToken.address,
|
|
1021
|
+
quote.srcChainKey
|
|
1022
|
+
);
|
|
1023
|
+
const feeInSrcHuman = fromLD(feeInSrcLD, srcToken.decimals);
|
|
1024
|
+
if (feeInSrcHuman > 0) {
|
|
1025
|
+
inSrcToken = Number(truncateToDecimals(feeInSrcHuman, 8));
|
|
1026
|
+
} else if ((feeData.usd.get("total") || 0) > 0 && srcToken.price?.usd) {
|
|
1027
|
+
const feeInSrcApprox = (feeData.usd.get("total") || 0) / srcToken.price.usd;
|
|
1028
|
+
inSrcToken = Number(truncateToDecimals(feeInSrcApprox, 8));
|
|
1029
|
+
}
|
|
1030
|
+
}
|
|
1031
|
+
if (dstToken && quote.dstChainKey) {
|
|
1032
|
+
const feeInDstLD = sumFeeByTokenLD(
|
|
1033
|
+
quote.fees,
|
|
1034
|
+
dstToken.address,
|
|
1035
|
+
quote.dstChainKey
|
|
1036
|
+
);
|
|
1037
|
+
const feeInDstHuman = fromLD(feeInDstLD, dstToken.decimals);
|
|
1038
|
+
if (feeInDstHuman > 0) {
|
|
1039
|
+
inDstToken = Number(truncateToDecimals(feeInDstHuman, 8));
|
|
1040
|
+
}
|
|
1041
|
+
}
|
|
1042
|
+
return {
|
|
1043
|
+
fees: feeData,
|
|
1044
|
+
inSrcToken,
|
|
1045
|
+
inDstToken
|
|
1046
|
+
};
|
|
1047
|
+
}
|
|
1048
|
+
function calculateMinReceived(quote, slippageBps, dstToken) {
|
|
1049
|
+
if (!quote || !dstToken) return 0;
|
|
1050
|
+
const dstAmountLD = BigInt(quote.dstAmount);
|
|
1051
|
+
const minAmountLD = dstAmountLD * BigInt(1e4 - slippageBps) / BigInt(1e4);
|
|
1052
|
+
return fromLD(minAmountLD.toString(), dstToken.decimals);
|
|
1053
|
+
}
|
|
1054
|
+
function getQuoteDetails(quote, srcToken, dstToken, tokens, chains, slippageBps) {
|
|
1055
|
+
const amounts = getQuoteAmounts(quote, srcToken, dstToken);
|
|
1056
|
+
const fees = getQuoteFees(quote, tokens, chains, srcToken, dstToken);
|
|
1057
|
+
const minimumReceived = calculateMinReceived(quote, slippageBps, dstToken);
|
|
1058
|
+
return {
|
|
1059
|
+
inputAmount: amounts.inputHuman,
|
|
1060
|
+
outputAmount: amounts.outputHuman,
|
|
1061
|
+
outputAmountRounded: amounts.outputHumanRounded,
|
|
1062
|
+
minimumReceived,
|
|
1063
|
+
etaSeconds: quote?.duration?.estimated,
|
|
1064
|
+
fees
|
|
1065
|
+
};
|
|
1066
|
+
}
|
|
1067
|
+
function getRouteDisplayName(route) {
|
|
1068
|
+
if (!route) return "Stargate Bridge";
|
|
1069
|
+
const routeLower = route.toLowerCase();
|
|
1070
|
+
if (routeLower.includes("taxi")) return "Stargate V2 Fast";
|
|
1071
|
+
if (routeLower.includes("bus")) return "Stargate V2 Economy";
|
|
1072
|
+
if (routeLower.includes("oft")) return "OFT Bridge";
|
|
1073
|
+
if (routeLower.includes("v2")) return "Stargate V2";
|
|
1074
|
+
return route.split(/[/\-_]/).map((part) => part.charAt(0).toUpperCase() + part.slice(1)).join(" ");
|
|
1075
|
+
}
|
|
1076
|
+
async function addNetworkFeesToQuote(quote, chainRegistry, chains) {
|
|
1077
|
+
if (!quote || !chains) {
|
|
1078
|
+
return quote;
|
|
1079
|
+
}
|
|
1080
|
+
const chainKeys = /* @__PURE__ */ new Set();
|
|
1081
|
+
quote.steps.forEach((step) => {
|
|
1082
|
+
if (step.chainKey) {
|
|
1083
|
+
chainKeys.add(step.chainKey);
|
|
1084
|
+
}
|
|
1085
|
+
});
|
|
1086
|
+
const networkFees = [];
|
|
1087
|
+
for (const chainKey of chainKeys) {
|
|
1088
|
+
const strategy = chainRegistry.getStrategy(chainKey);
|
|
1089
|
+
if (!strategy) continue;
|
|
1090
|
+
const chain2 = chains.find((c2) => c2.chainKey === chainKey);
|
|
1091
|
+
if (!chain2) continue;
|
|
1092
|
+
const stepsForChain = quote.steps.filter((step) => step.chainKey === chainKey);
|
|
1093
|
+
if (!stepsForChain.length) continue;
|
|
1094
|
+
try {
|
|
1095
|
+
const networkFeeHuman = await strategy.estimateNetworkFee(stepsForChain);
|
|
1096
|
+
if (networkFeeHuman > 0) {
|
|
1097
|
+
const networkFeeLD = toLD(
|
|
1098
|
+
networkFeeHuman.toString(),
|
|
1099
|
+
chain2.nativeCurrency.decimals
|
|
1100
|
+
);
|
|
1101
|
+
networkFees.push({
|
|
1102
|
+
token: chain2.nativeCurrency.address,
|
|
1103
|
+
chainKey,
|
|
1104
|
+
amount: networkFeeLD,
|
|
1105
|
+
type: "network"
|
|
1106
|
+
});
|
|
1107
|
+
}
|
|
1108
|
+
} catch (error) {
|
|
1109
|
+
console.warn(`Failed to estimate network fee for chain ${chainKey}:`, error);
|
|
1110
|
+
}
|
|
1111
|
+
}
|
|
1112
|
+
return {
|
|
1113
|
+
...quote,
|
|
1114
|
+
fees: [...quote.fees, ...networkFees]
|
|
1115
|
+
};
|
|
1116
|
+
}
|
|
944
1117
|
const toSharedDecimals = (amount, fromDecimals, toDecimals) => {
|
|
945
1118
|
const value = BigInt(amount);
|
|
946
1119
|
const diff = BigInt(toDecimals) - BigInt(fromDecimals);
|
|
@@ -1063,7 +1236,13 @@ function useBridgeQuote() {
|
|
|
1063
1236
|
return;
|
|
1064
1237
|
}
|
|
1065
1238
|
if (cancelled) return;
|
|
1066
|
-
|
|
1239
|
+
const quoteWithNetworkFees = await addNetworkFeesToQuote(
|
|
1240
|
+
quoteRoute,
|
|
1241
|
+
chainRegistry,
|
|
1242
|
+
chains
|
|
1243
|
+
);
|
|
1244
|
+
if (cancelled) return;
|
|
1245
|
+
setQuote(quoteWithNetworkFees);
|
|
1067
1246
|
} catch {
|
|
1068
1247
|
if (!cancelled) {
|
|
1069
1248
|
resetUi();
|
|
@@ -2029,16 +2208,17 @@ const SearchInput = ({
|
|
|
2029
2208
|
placeholder,
|
|
2030
2209
|
value,
|
|
2031
2210
|
onChange,
|
|
2032
|
-
className
|
|
2211
|
+
className,
|
|
2212
|
+
rootClassName
|
|
2033
2213
|
}) => {
|
|
2034
|
-
return /* @__PURE__ */ jsxRuntime.jsxs("div", { className: utils$1.cn("rounded-xs relative"), children: [
|
|
2214
|
+
return /* @__PURE__ */ jsxRuntime.jsxs("div", { className: utils$1.cn("rounded-xs relative", rootClassName), children: [
|
|
2035
2215
|
/* @__PURE__ */ jsxRuntime.jsx(SearchIcon, { className: "w-6 h-6 absolute z-10 left-5 top-0 bottom-0 my-auto text-foreground" }),
|
|
2036
2216
|
/* @__PURE__ */ jsxRuntime.jsx(
|
|
2037
2217
|
input.Input,
|
|
2038
2218
|
{
|
|
2039
2219
|
placeholder,
|
|
2040
2220
|
className: utils$1.cn(
|
|
2041
|
-
"w-full outline-none px-5 py-4 relative pl-16 bg-input border transition-all border-transparent rounded-xs ring-0 leading-0 h-13 text-base
|
|
2221
|
+
"w-full outline-none px-5 py-4 relative pl-16 bg-input border transition-all border-transparent rounded-xs ring-0 leading-0 h-13 text-base",
|
|
2042
2222
|
value && "pr-16",
|
|
2043
2223
|
className
|
|
2044
2224
|
),
|
|
@@ -2261,48 +2441,6 @@ const useWalletSelectModal = zustand.create((set2) => ({
|
|
|
2261
2441
|
onOpen: (addressType) => set2({ isOpen: true, addressType }),
|
|
2262
2442
|
onClose: () => set2({ isOpen: false, addressType: void 0 })
|
|
2263
2443
|
}));
|
|
2264
|
-
const truncateToDecimals = (num, decimals) => {
|
|
2265
|
-
if (!isFinite(num) || isNaN(num)) return "0";
|
|
2266
|
-
const multiplier = Math.pow(10, decimals);
|
|
2267
|
-
const truncated = Math.floor(num * multiplier) / multiplier;
|
|
2268
|
-
return truncated.toFixed(decimals).replace(/\.?0+$/, "");
|
|
2269
|
-
};
|
|
2270
|
-
const formatTokenAmount = (amount, symbol, options) => {
|
|
2271
|
-
const normalizedSymbol = (symbol ?? "").toUpperCase();
|
|
2272
|
-
if (["USDT", "USDC", "DAI", "BUSD"].includes(normalizedSymbol) && amount >= 1) {
|
|
2273
|
-
return `${Math.floor(amount)} ${normalizedSymbol}`;
|
|
2274
|
-
}
|
|
2275
|
-
if (options?.decimals !== void 0) {
|
|
2276
|
-
return `${amount.toFixed(options.decimals)} ${normalizedSymbol}`;
|
|
2277
|
-
}
|
|
2278
|
-
if (amount >= 1) {
|
|
2279
|
-
return `${amount.toFixed(0)} ${normalizedSymbol}`;
|
|
2280
|
-
} else if (amount >= 1e-3) {
|
|
2281
|
-
return `${amount.toFixed(3)} ${normalizedSymbol}`;
|
|
2282
|
-
} else {
|
|
2283
|
-
return `${amount.toFixed(6)} ${normalizedSymbol}`;
|
|
2284
|
-
}
|
|
2285
|
-
};
|
|
2286
|
-
const formatUsd = (value) => {
|
|
2287
|
-
if (!value || !isFinite(value)) return "$0";
|
|
2288
|
-
if (value >= 1) return `$${value.toFixed(2)}`;
|
|
2289
|
-
return `$${value.toFixed(6).replace(/0+$/, "").replace(/\.$/, "")}`;
|
|
2290
|
-
};
|
|
2291
|
-
const formatPercentage = (bps, decimals = 2) => {
|
|
2292
|
-
return `${(bps / 100).toFixed(decimals).replace(/0+$/, "").replace(/\.$/, "")}%`;
|
|
2293
|
-
};
|
|
2294
|
-
const formatBalance = (amount, decimals = 2) => {
|
|
2295
|
-
if (!isFinite(amount) || isNaN(amount) || amount <= 0) {
|
|
2296
|
-
return "0.00";
|
|
2297
|
-
}
|
|
2298
|
-
return amount.toFixed(decimals);
|
|
2299
|
-
};
|
|
2300
|
-
const formatHash = (hash, startChars = 4, endChars = 4) => {
|
|
2301
|
-
if (!hash) return "";
|
|
2302
|
-
if (hash.length <= startChars + endChars) return hash;
|
|
2303
|
-
return `${hash.slice(0, startChars)}...${hash.slice(-endChars)}`;
|
|
2304
|
-
};
|
|
2305
|
-
const formatAddress = formatHash;
|
|
2306
2444
|
const EditIcon = (props) => {
|
|
2307
2445
|
return /* @__PURE__ */ jsxRuntime.jsxs(
|
|
2308
2446
|
"svg",
|
|
@@ -2752,96 +2890,6 @@ const TokenSymbol = ({
|
|
|
2752
2890
|
const src2 = `${BASE_URL}/${normalizedSymbol}.svg`;
|
|
2753
2891
|
return /* @__PURE__ */ jsxRuntime.jsx("img", { src: src2, alt: alt ?? symbol, className });
|
|
2754
2892
|
};
|
|
2755
|
-
function getQuoteAmounts(quote, srcToken, dstToken) {
|
|
2756
|
-
if (!quote || !srcToken || !dstToken) {
|
|
2757
|
-
return {
|
|
2758
|
-
inputHuman: 0,
|
|
2759
|
-
outputHuman: 0,
|
|
2760
|
-
outputHumanRounded: "0",
|
|
2761
|
-
minReceivedHuman: 0
|
|
2762
|
-
};
|
|
2763
|
-
}
|
|
2764
|
-
const inputHuman = fromLD(quote.srcAmount, srcToken.decimals);
|
|
2765
|
-
const outputHuman = fromLD(quote.dstAmount, dstToken.decimals);
|
|
2766
|
-
const outputHumanRounded = truncateToDecimals(outputHuman, 2);
|
|
2767
|
-
const minReceivedHuman = fromLD(quote.dstAmountMin || "0", dstToken.decimals);
|
|
2768
|
-
return {
|
|
2769
|
-
inputHuman,
|
|
2770
|
-
outputHuman,
|
|
2771
|
-
outputHumanRounded,
|
|
2772
|
-
minReceivedHuman
|
|
2773
|
-
};
|
|
2774
|
-
}
|
|
2775
|
-
function getQuoteFees(quote, tokens, chains, srcToken, dstToken) {
|
|
2776
|
-
if (!quote || !tokens || !chains) {
|
|
2777
|
-
return {
|
|
2778
|
-
fees: { usd: /* @__PURE__ */ new Map(), original: /* @__PURE__ */ new Map(), formatted: /* @__PURE__ */ new Map() },
|
|
2779
|
-
inSrcToken: void 0,
|
|
2780
|
-
inDstToken: void 0
|
|
2781
|
-
};
|
|
2782
|
-
}
|
|
2783
|
-
const feeData = computeFeesUsdFromArray(quote.fees, tokens, chains);
|
|
2784
|
-
let inSrcToken = void 0;
|
|
2785
|
-
let inDstToken = void 0;
|
|
2786
|
-
if (srcToken && quote.srcChainKey) {
|
|
2787
|
-
const feeInSrcLD = sumFeeByTokenLD(
|
|
2788
|
-
quote.fees,
|
|
2789
|
-
srcToken.address,
|
|
2790
|
-
quote.srcChainKey
|
|
2791
|
-
);
|
|
2792
|
-
const feeInSrcHuman = fromLD(feeInSrcLD, srcToken.decimals);
|
|
2793
|
-
if (feeInSrcHuman > 0) {
|
|
2794
|
-
inSrcToken = Number(truncateToDecimals(feeInSrcHuman, 8));
|
|
2795
|
-
} else if ((feeData.usd.get("total") || 0) > 0 && srcToken.price?.usd) {
|
|
2796
|
-
const feeInSrcApprox = (feeData.usd.get("total") || 0) / srcToken.price.usd;
|
|
2797
|
-
inSrcToken = Number(truncateToDecimals(feeInSrcApprox, 8));
|
|
2798
|
-
}
|
|
2799
|
-
}
|
|
2800
|
-
if (dstToken && quote.dstChainKey) {
|
|
2801
|
-
const feeInDstLD = sumFeeByTokenLD(
|
|
2802
|
-
quote.fees,
|
|
2803
|
-
dstToken.address,
|
|
2804
|
-
quote.dstChainKey
|
|
2805
|
-
);
|
|
2806
|
-
const feeInDstHuman = fromLD(feeInDstLD, dstToken.decimals);
|
|
2807
|
-
if (feeInDstHuman > 0) {
|
|
2808
|
-
inDstToken = Number(truncateToDecimals(feeInDstHuman, 8));
|
|
2809
|
-
}
|
|
2810
|
-
}
|
|
2811
|
-
return {
|
|
2812
|
-
fees: feeData,
|
|
2813
|
-
inSrcToken,
|
|
2814
|
-
inDstToken
|
|
2815
|
-
};
|
|
2816
|
-
}
|
|
2817
|
-
function calculateMinReceived(quote, slippageBps, dstToken) {
|
|
2818
|
-
if (!quote || !dstToken) return 0;
|
|
2819
|
-
const dstAmountLD = BigInt(quote.dstAmount);
|
|
2820
|
-
const minAmountLD = dstAmountLD * BigInt(1e4 - slippageBps) / BigInt(1e4);
|
|
2821
|
-
return fromLD(minAmountLD.toString(), dstToken.decimals);
|
|
2822
|
-
}
|
|
2823
|
-
function getQuoteDetails(quote, srcToken, dstToken, tokens, chains, slippageBps) {
|
|
2824
|
-
const amounts = getQuoteAmounts(quote, srcToken, dstToken);
|
|
2825
|
-
const fees = getQuoteFees(quote, tokens, chains, srcToken, dstToken);
|
|
2826
|
-
const minimumReceived = calculateMinReceived(quote, slippageBps, dstToken);
|
|
2827
|
-
return {
|
|
2828
|
-
inputAmount: amounts.inputHuman,
|
|
2829
|
-
outputAmount: amounts.outputHuman,
|
|
2830
|
-
outputAmountRounded: amounts.outputHumanRounded,
|
|
2831
|
-
minimumReceived,
|
|
2832
|
-
etaSeconds: quote?.duration?.estimated,
|
|
2833
|
-
fees
|
|
2834
|
-
};
|
|
2835
|
-
}
|
|
2836
|
-
function getRouteDisplayName(route) {
|
|
2837
|
-
if (!route) return "Stargate Bridge";
|
|
2838
|
-
const routeLower = route.toLowerCase();
|
|
2839
|
-
if (routeLower.includes("taxi")) return "Stargate V2 Fast";
|
|
2840
|
-
if (routeLower.includes("bus")) return "Stargate V2 Economy";
|
|
2841
|
-
if (routeLower.includes("oft")) return "OFT Bridge";
|
|
2842
|
-
if (routeLower.includes("v2")) return "Stargate V2";
|
|
2843
|
-
return route.split(/[/\-_]/).map((part) => part.charAt(0).toUpperCase() + part.slice(1)).join(" ");
|
|
2844
|
-
}
|
|
2845
2893
|
function useGasEstimate(amountNum) {
|
|
2846
2894
|
const { fromChain } = useChainsStore();
|
|
2847
2895
|
const { selectedAssetSymbol } = useTokensStore();
|
|
@@ -2851,9 +2899,6 @@ function useGasEstimate(amountNum) {
|
|
|
2851
2899
|
srcAddress
|
|
2852
2900
|
);
|
|
2853
2901
|
const { quote } = useBridgeQuoteStore();
|
|
2854
|
-
const { chainRegistry } = useChainStrategies();
|
|
2855
|
-
const [networkFeeEstimate, setNetworkFeeEstimate] = react.useState(0);
|
|
2856
|
-
const [networkFeeKnown, setNetworkFeeKnown] = react.useState(false);
|
|
2857
2902
|
const balancesKnown = !balancesLoading;
|
|
2858
2903
|
const chainKey = fromChain?.chainKey;
|
|
2859
2904
|
const nativeCurrencySymbol = fromChain?.nativeCurrency?.symbol;
|
|
@@ -2862,44 +2907,6 @@ function useGasEstimate(amountNum) {
|
|
|
2862
2907
|
const quoteFees = quote?.fees;
|
|
2863
2908
|
const quoteSrcChainKey = quote?.srcChainKey;
|
|
2864
2909
|
const nativeBalanceValue = nativeCurrencySymbol ? Number(balances[nativeCurrencySymbol.toUpperCase()]?.balance ?? 0) : 0;
|
|
2865
|
-
react.useEffect(() => {
|
|
2866
|
-
let cancelled = false;
|
|
2867
|
-
const estimate = async () => {
|
|
2868
|
-
setNetworkFeeEstimate(0);
|
|
2869
|
-
setNetworkFeeKnown(false);
|
|
2870
|
-
if (!chainKey || !quote?.steps?.length) {
|
|
2871
|
-
return;
|
|
2872
|
-
}
|
|
2873
|
-
const strategy = chainRegistry.getStrategy(chainKey);
|
|
2874
|
-
if (!strategy) {
|
|
2875
|
-
setNetworkFeeKnown(true);
|
|
2876
|
-
return;
|
|
2877
|
-
}
|
|
2878
|
-
const steps = quote.steps.filter((step) => step.chainKey === chainKey);
|
|
2879
|
-
if (!steps.length) {
|
|
2880
|
-
setNetworkFeeKnown(true);
|
|
2881
|
-
return;
|
|
2882
|
-
}
|
|
2883
|
-
try {
|
|
2884
|
-
const estimateValue = await strategy.estimateNetworkFee(steps);
|
|
2885
|
-
if (cancelled) return;
|
|
2886
|
-
setNetworkFeeEstimate(
|
|
2887
|
-
Number.isFinite(estimateValue) ? estimateValue : 0
|
|
2888
|
-
);
|
|
2889
|
-
} catch {
|
|
2890
|
-
if (cancelled) return;
|
|
2891
|
-
setNetworkFeeEstimate(0);
|
|
2892
|
-
} finally {
|
|
2893
|
-
if (!cancelled) {
|
|
2894
|
-
setNetworkFeeKnown(true);
|
|
2895
|
-
}
|
|
2896
|
-
}
|
|
2897
|
-
};
|
|
2898
|
-
void estimate();
|
|
2899
|
-
return () => {
|
|
2900
|
-
cancelled = true;
|
|
2901
|
-
};
|
|
2902
|
-
}, [chainKey, quote?.steps, chainRegistry]);
|
|
2903
2910
|
const result = react.useMemo(() => {
|
|
2904
2911
|
if (!chainKey || !nativeCurrencySymbol) {
|
|
2905
2912
|
return {
|
|
@@ -2928,16 +2935,13 @@ function useGasEstimate(amountNum) {
|
|
|
2928
2935
|
requiredNative = Number(feesInNative) / Math.pow(10, decimals);
|
|
2929
2936
|
quoteFeesAvailable = true;
|
|
2930
2937
|
}
|
|
2931
|
-
if (networkFeeKnown) {
|
|
2932
|
-
requiredNative += networkFeeEstimate;
|
|
2933
|
-
}
|
|
2934
2938
|
let hasEnoughGas = true;
|
|
2935
2939
|
if (isNativeSelected) {
|
|
2936
2940
|
hasEnoughGas = nativeBalance - (amountNum ?? 0) >= requiredNative;
|
|
2937
2941
|
} else {
|
|
2938
2942
|
hasEnoughGas = nativeBalance >= requiredNative;
|
|
2939
2943
|
}
|
|
2940
|
-
const shouldCheckGas = balancesKnown && quoteFeesAvailable
|
|
2944
|
+
const shouldCheckGas = balancesKnown && quoteFeesAvailable;
|
|
2941
2945
|
return {
|
|
2942
2946
|
nativeSym,
|
|
2943
2947
|
nativeBalance,
|
|
@@ -2956,9 +2960,7 @@ function useGasEstimate(amountNum) {
|
|
|
2956
2960
|
quoteSrcChainKey,
|
|
2957
2961
|
amountNum,
|
|
2958
2962
|
balancesKnown,
|
|
2959
|
-
nativeBalanceValue
|
|
2960
|
-
networkFeeEstimate,
|
|
2961
|
-
networkFeeKnown
|
|
2963
|
+
nativeBalanceValue
|
|
2962
2964
|
]);
|
|
2963
2965
|
return result;
|
|
2964
2966
|
}
|
|
@@ -4238,7 +4240,7 @@ const ProgressStep = ({
|
|
|
4238
4240
|
title: t2("transaction.steps.completed")
|
|
4239
4241
|
}
|
|
4240
4242
|
];
|
|
4241
|
-
return /* @__PURE__ */ jsxRuntime.jsx(dialog.DialogContent, { showCloseButton: false, className: "overflow-hidden md:max-w-[420px] p-0", children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex relative flex-col gap-6 flex-1 items-center justify-start text-center bg-background noise p-10", children: [
|
|
4243
|
+
return /* @__PURE__ */ jsxRuntime.jsx(dialog.DialogContent, { showCloseButton: false, className: "overflow-hidden md:max-w-[420px] p-0 fixed top-0 left-0 right-0 bottom-0 translate-x-0 translate-y-0 md:left-[50%] md:top-[50%] md:translate-x-[-50%] md:translate-y-[-50%] rounded-none md:rounded-lg", children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex relative flex-col gap-6 flex-1 items-center justify-center md:justify-start text-center bg-background noise p-10", children: [
|
|
4242
4244
|
icon,
|
|
4243
4245
|
/* @__PURE__ */ jsxRuntime.jsx("div", { className: "flex flex-col gap-2 pt-4 pb-2 text-center", children: /* @__PURE__ */ jsxRuntime.jsx(dialog.DialogTitle, { children: t2("transaction.inProgress") }) }),
|
|
4244
4246
|
/* @__PURE__ */ jsxRuntime.jsxs("div", { className: "relative", children: [
|
|
@@ -4265,8 +4267,8 @@ const FailedStep = ({
|
|
|
4265
4267
|
}) => {
|
|
4266
4268
|
const { current, reset } = useTransactionStore();
|
|
4267
4269
|
const { t: t2 } = useBridgeTranslation();
|
|
4268
|
-
return /* @__PURE__ */ jsxRuntime.jsxs(dialog.DialogContent, { showCloseButton: true, className: "overflow-hidden md:max-w-[420px] p-0", children: [
|
|
4269
|
-
/* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex flex-col relative gap-4 flex-1 items-center justify-start text-center noise p-10 pb-0", children: [
|
|
4270
|
+
return /* @__PURE__ */ jsxRuntime.jsxs(dialog.DialogContent, { showCloseButton: true, className: "overflow-hidden md:max-w-[420px] p-0 fixed top-0 left-0 right-0 bottom-0 translate-x-0 translate-y-0 md:left-[50%] md:top-[50%] md:translate-x-[-50%] md:translate-y-[-50%] rounded-none md:rounded-lg", children: [
|
|
4271
|
+
/* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex flex-col relative gap-4 flex-1 items-center justify-center md:justify-start text-center noise p-10 pb-0", children: [
|
|
4270
4272
|
icon,
|
|
4271
4273
|
/* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex flex-col gap-2 pt-4 pb-2 text-center", children: [
|
|
4272
4274
|
/* @__PURE__ */ jsxRuntime.jsx(dialog.DialogTitle, { children: t2("transaction.failed") }),
|
|
@@ -4457,9 +4459,9 @@ const SuccessStep = ({
|
|
|
4457
4459
|
dialog.DialogContent,
|
|
4458
4460
|
{
|
|
4459
4461
|
showCloseButton: true,
|
|
4460
|
-
className: "overflow-hidden md:max-w-[420px] p-0",
|
|
4462
|
+
className: "overflow-hidden md:max-w-[420px] p-0 fixed top-0 left-0 right-0 bottom-0 translate-x-0 translate-y-0 md:left-[50%] md:top-[50%] md:translate-x-[-50%] md:translate-y-[-50%] rounded-none md:rounded-lg",
|
|
4461
4463
|
children: [
|
|
4462
|
-
/* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex flex-col gap-4 flex-1 justify-start items-center text-center bg-background noise p-10 pb-0", children: [
|
|
4464
|
+
/* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex flex-col gap-4 flex-1 justify-center md:justify-start items-center text-center bg-background noise p-10 pb-0", children: [
|
|
4463
4465
|
icon,
|
|
4464
4466
|
/* @__PURE__ */ jsxRuntime.jsx("div", { className: "flex flex-col gap-2 pt-4 text-center", children: /* @__PURE__ */ jsxRuntime.jsx(dialog.DialogTitle, { className: "text-[28px]", children: t2("transaction.success") }) }),
|
|
4465
4467
|
/* @__PURE__ */ jsxRuntime.jsxs("div", { className: "w-full space-y-2 mt-3 relative z-10 pb-14", children: [
|
|
@@ -4544,7 +4546,7 @@ const ConfirmStep = ({
|
|
|
4544
4546
|
}) => {
|
|
4545
4547
|
const { t: t2 } = useBridgeTranslation();
|
|
4546
4548
|
const { formatTime } = useCountdown(90);
|
|
4547
|
-
return /* @__PURE__ */ jsxRuntime.jsx(dialog.DialogContent, {
|
|
4549
|
+
return /* @__PURE__ */ jsxRuntime.jsx(dialog.DialogContent, { className: "overflow-hidden md:max-w-[420px] p-0 fixed top-0 left-0 right-0 bottom-0 translate-x-0 translate-y-0 md:left-[50%] md:top-[50%] md:translate-x-[-50%] md:translate-y-[-50%] rounded-none md:rounded-lg", children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex flex-col relative gap-4 flex-1 items-center justify-center md:justify-start text-center noise p-10", children: [
|
|
4548
4550
|
icon,
|
|
4549
4551
|
/* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex flex-col gap-2 pt-4 pb-2 text-center", children: [
|
|
4550
4552
|
/* @__PURE__ */ jsxRuntime.jsx(dialog.DialogTitle, { children: t2("transaction.confirm") }),
|
|
@@ -6939,7 +6941,7 @@ const TokenSelectModal = ({
|
|
|
6939
6941
|
return /* @__PURE__ */ jsxRuntime.jsx(dialog.Dialog, { open: isOpen, onOpenChange: (open) => !open && handleClose(), children: /* @__PURE__ */ jsxRuntime.jsxs(
|
|
6940
6942
|
dialog.DialogContent,
|
|
6941
6943
|
{
|
|
6942
|
-
className: "md:max-h-[90dvh] md:h-[90dvh] overflow-hidden flex flex-col fixed top-0 left-0 right-0 bottom-0 translate-x-0 translate-y-0 md:left-[50%] md:top-[50%] md:translate-x-[-50%] md:translate-y-[-50%] p-6 md:p-10 md:pt-8
|
|
6944
|
+
className: "md:max-h-[90dvh] md:h-[90dvh] overflow-hidden flex flex-col fixed top-0 left-0 right-0 bottom-0 translate-x-0 translate-y-0 md:left-[50%] md:top-[50%] md:translate-x-[-50%] md:translate-y-[-50%] rounded-none md:rounded-lg p-6 md:p-10 md:pt-8",
|
|
6943
6945
|
closeButtonClassName: "right-6 md:right-10",
|
|
6944
6946
|
children: [
|
|
6945
6947
|
/* @__PURE__ */ jsxRuntime.jsx(dialog.DialogHeader, { className: "text-left pb-2", children: /* @__PURE__ */ jsxRuntime.jsx(dialog.DialogTitle, { className: "text-2xl leading-8", children: t2("bridge.selectToken") }) }),
|
|
@@ -25822,7 +25824,7 @@ class WalletConnectModal {
|
|
|
25822
25824
|
}
|
|
25823
25825
|
async initUi() {
|
|
25824
25826
|
if (typeof window !== "undefined") {
|
|
25825
|
-
await Promise.resolve().then(() => require("./index-
|
|
25827
|
+
await Promise.resolve().then(() => require("./index-CSE-oDw8.cjs"));
|
|
25826
25828
|
const modal = document.createElement("wcm-modal");
|
|
25827
25829
|
document.body.insertAdjacentElement("beforeend", modal);
|
|
25828
25830
|
OptionsCtrl.setIsUiLoaded(true);
|
|
@@ -26541,6 +26543,7 @@ exports.RouteType = RouteType;
|
|
|
26541
26543
|
exports.RouterCtrl = RouterCtrl;
|
|
26542
26544
|
exports.ThemeCtrl = ThemeCtrl;
|
|
26543
26545
|
exports.ToastCtrl = ToastCtrl;
|
|
26546
|
+
exports.addNetworkFeesToQuote = addNetworkFeesToQuote;
|
|
26544
26547
|
exports.addrForApi = addrForApi;
|
|
26545
26548
|
exports.buildAssetMatrix = buildAssetMatrix;
|
|
26546
26549
|
exports.calculateMinReceived = calculateMinReceived;
|
|
@@ -26588,4 +26591,4 @@ exports.useSettingsStore = useSettingsStore;
|
|
|
26588
26591
|
exports.useSwapModel = useSwapModel;
|
|
26589
26592
|
exports.useTokensStore = useTokensStore;
|
|
26590
26593
|
exports.useTransactionStore = useTransactionStore;
|
|
26591
|
-
//# sourceMappingURL=index-
|
|
26594
|
+
//# sourceMappingURL=index-CpKOf8oF.cjs.map
|