@rash2x/bridge-widget 0.6.62 → 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-Dwxz-LHk.cjs → index-CSE-oDw8.cjs} +2 -2
- package/dist/{index-Dwxz-LHk.cjs.map → index-CSE-oDw8.cjs.map} +1 -1
- package/dist/{index-CAc7tJ3r.cjs → index-CpKOf8oF.cjs} +192 -190
- package/dist/index-CpKOf8oF.cjs.map +1 -0
- package/dist/{index-CcNV1b5l.js → index-DEi2-2_y.js} +2 -2
- package/dist/{index-CcNV1b5l.js.map → index-DEi2-2_y.js.map} +1 -1
- package/dist/{index-C0BTirT_.js → index-HznPfOtP.js} +218 -216
- 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-C0BTirT_.js.map +0 -1
- package/dist/index-CAc7tJ3r.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();
|
|
@@ -2262,48 +2441,6 @@ const useWalletSelectModal = zustand.create((set2) => ({
|
|
|
2262
2441
|
onOpen: (addressType) => set2({ isOpen: true, addressType }),
|
|
2263
2442
|
onClose: () => set2({ isOpen: false, addressType: void 0 })
|
|
2264
2443
|
}));
|
|
2265
|
-
const truncateToDecimals = (num, decimals) => {
|
|
2266
|
-
if (!isFinite(num) || isNaN(num)) return "0";
|
|
2267
|
-
const multiplier = Math.pow(10, decimals);
|
|
2268
|
-
const truncated = Math.floor(num * multiplier) / multiplier;
|
|
2269
|
-
return truncated.toFixed(decimals).replace(/\.?0+$/, "");
|
|
2270
|
-
};
|
|
2271
|
-
const formatTokenAmount = (amount, symbol, options) => {
|
|
2272
|
-
const normalizedSymbol = (symbol ?? "").toUpperCase();
|
|
2273
|
-
if (["USDT", "USDC", "DAI", "BUSD"].includes(normalizedSymbol) && amount >= 1) {
|
|
2274
|
-
return `${Math.floor(amount)} ${normalizedSymbol}`;
|
|
2275
|
-
}
|
|
2276
|
-
if (options?.decimals !== void 0) {
|
|
2277
|
-
return `${amount.toFixed(options.decimals)} ${normalizedSymbol}`;
|
|
2278
|
-
}
|
|
2279
|
-
if (amount >= 1) {
|
|
2280
|
-
return `${amount.toFixed(0)} ${normalizedSymbol}`;
|
|
2281
|
-
} else if (amount >= 1e-3) {
|
|
2282
|
-
return `${amount.toFixed(3)} ${normalizedSymbol}`;
|
|
2283
|
-
} else {
|
|
2284
|
-
return `${amount.toFixed(6)} ${normalizedSymbol}`;
|
|
2285
|
-
}
|
|
2286
|
-
};
|
|
2287
|
-
const formatUsd = (value) => {
|
|
2288
|
-
if (!value || !isFinite(value)) return "$0";
|
|
2289
|
-
if (value >= 1) return `$${value.toFixed(2)}`;
|
|
2290
|
-
return `$${value.toFixed(6).replace(/0+$/, "").replace(/\.$/, "")}`;
|
|
2291
|
-
};
|
|
2292
|
-
const formatPercentage = (bps, decimals = 2) => {
|
|
2293
|
-
return `${(bps / 100).toFixed(decimals).replace(/0+$/, "").replace(/\.$/, "")}%`;
|
|
2294
|
-
};
|
|
2295
|
-
const formatBalance = (amount, decimals = 2) => {
|
|
2296
|
-
if (!isFinite(amount) || isNaN(amount) || amount <= 0) {
|
|
2297
|
-
return "0.00";
|
|
2298
|
-
}
|
|
2299
|
-
return amount.toFixed(decimals);
|
|
2300
|
-
};
|
|
2301
|
-
const formatHash = (hash, startChars = 4, endChars = 4) => {
|
|
2302
|
-
if (!hash) return "";
|
|
2303
|
-
if (hash.length <= startChars + endChars) return hash;
|
|
2304
|
-
return `${hash.slice(0, startChars)}...${hash.slice(-endChars)}`;
|
|
2305
|
-
};
|
|
2306
|
-
const formatAddress = formatHash;
|
|
2307
2444
|
const EditIcon = (props) => {
|
|
2308
2445
|
return /* @__PURE__ */ jsxRuntime.jsxs(
|
|
2309
2446
|
"svg",
|
|
@@ -2753,96 +2890,6 @@ const TokenSymbol = ({
|
|
|
2753
2890
|
const src2 = `${BASE_URL}/${normalizedSymbol}.svg`;
|
|
2754
2891
|
return /* @__PURE__ */ jsxRuntime.jsx("img", { src: src2, alt: alt ?? symbol, className });
|
|
2755
2892
|
};
|
|
2756
|
-
function getQuoteAmounts(quote, srcToken, dstToken) {
|
|
2757
|
-
if (!quote || !srcToken || !dstToken) {
|
|
2758
|
-
return {
|
|
2759
|
-
inputHuman: 0,
|
|
2760
|
-
outputHuman: 0,
|
|
2761
|
-
outputHumanRounded: "0",
|
|
2762
|
-
minReceivedHuman: 0
|
|
2763
|
-
};
|
|
2764
|
-
}
|
|
2765
|
-
const inputHuman = fromLD(quote.srcAmount, srcToken.decimals);
|
|
2766
|
-
const outputHuman = fromLD(quote.dstAmount, dstToken.decimals);
|
|
2767
|
-
const outputHumanRounded = truncateToDecimals(outputHuman, 2);
|
|
2768
|
-
const minReceivedHuman = fromLD(quote.dstAmountMin || "0", dstToken.decimals);
|
|
2769
|
-
return {
|
|
2770
|
-
inputHuman,
|
|
2771
|
-
outputHuman,
|
|
2772
|
-
outputHumanRounded,
|
|
2773
|
-
minReceivedHuman
|
|
2774
|
-
};
|
|
2775
|
-
}
|
|
2776
|
-
function getQuoteFees(quote, tokens, chains, srcToken, dstToken) {
|
|
2777
|
-
if (!quote || !tokens || !chains) {
|
|
2778
|
-
return {
|
|
2779
|
-
fees: { usd: /* @__PURE__ */ new Map(), original: /* @__PURE__ */ new Map(), formatted: /* @__PURE__ */ new Map() },
|
|
2780
|
-
inSrcToken: void 0,
|
|
2781
|
-
inDstToken: void 0
|
|
2782
|
-
};
|
|
2783
|
-
}
|
|
2784
|
-
const feeData = computeFeesUsdFromArray(quote.fees, tokens, chains);
|
|
2785
|
-
let inSrcToken = void 0;
|
|
2786
|
-
let inDstToken = void 0;
|
|
2787
|
-
if (srcToken && quote.srcChainKey) {
|
|
2788
|
-
const feeInSrcLD = sumFeeByTokenLD(
|
|
2789
|
-
quote.fees,
|
|
2790
|
-
srcToken.address,
|
|
2791
|
-
quote.srcChainKey
|
|
2792
|
-
);
|
|
2793
|
-
const feeInSrcHuman = fromLD(feeInSrcLD, srcToken.decimals);
|
|
2794
|
-
if (feeInSrcHuman > 0) {
|
|
2795
|
-
inSrcToken = Number(truncateToDecimals(feeInSrcHuman, 8));
|
|
2796
|
-
} else if ((feeData.usd.get("total") || 0) > 0 && srcToken.price?.usd) {
|
|
2797
|
-
const feeInSrcApprox = (feeData.usd.get("total") || 0) / srcToken.price.usd;
|
|
2798
|
-
inSrcToken = Number(truncateToDecimals(feeInSrcApprox, 8));
|
|
2799
|
-
}
|
|
2800
|
-
}
|
|
2801
|
-
if (dstToken && quote.dstChainKey) {
|
|
2802
|
-
const feeInDstLD = sumFeeByTokenLD(
|
|
2803
|
-
quote.fees,
|
|
2804
|
-
dstToken.address,
|
|
2805
|
-
quote.dstChainKey
|
|
2806
|
-
);
|
|
2807
|
-
const feeInDstHuman = fromLD(feeInDstLD, dstToken.decimals);
|
|
2808
|
-
if (feeInDstHuman > 0) {
|
|
2809
|
-
inDstToken = Number(truncateToDecimals(feeInDstHuman, 8));
|
|
2810
|
-
}
|
|
2811
|
-
}
|
|
2812
|
-
return {
|
|
2813
|
-
fees: feeData,
|
|
2814
|
-
inSrcToken,
|
|
2815
|
-
inDstToken
|
|
2816
|
-
};
|
|
2817
|
-
}
|
|
2818
|
-
function calculateMinReceived(quote, slippageBps, dstToken) {
|
|
2819
|
-
if (!quote || !dstToken) return 0;
|
|
2820
|
-
const dstAmountLD = BigInt(quote.dstAmount);
|
|
2821
|
-
const minAmountLD = dstAmountLD * BigInt(1e4 - slippageBps) / BigInt(1e4);
|
|
2822
|
-
return fromLD(minAmountLD.toString(), dstToken.decimals);
|
|
2823
|
-
}
|
|
2824
|
-
function getQuoteDetails(quote, srcToken, dstToken, tokens, chains, slippageBps) {
|
|
2825
|
-
const amounts = getQuoteAmounts(quote, srcToken, dstToken);
|
|
2826
|
-
const fees = getQuoteFees(quote, tokens, chains, srcToken, dstToken);
|
|
2827
|
-
const minimumReceived = calculateMinReceived(quote, slippageBps, dstToken);
|
|
2828
|
-
return {
|
|
2829
|
-
inputAmount: amounts.inputHuman,
|
|
2830
|
-
outputAmount: amounts.outputHuman,
|
|
2831
|
-
outputAmountRounded: amounts.outputHumanRounded,
|
|
2832
|
-
minimumReceived,
|
|
2833
|
-
etaSeconds: quote?.duration?.estimated,
|
|
2834
|
-
fees
|
|
2835
|
-
};
|
|
2836
|
-
}
|
|
2837
|
-
function getRouteDisplayName(route) {
|
|
2838
|
-
if (!route) return "Stargate Bridge";
|
|
2839
|
-
const routeLower = route.toLowerCase();
|
|
2840
|
-
if (routeLower.includes("taxi")) return "Stargate V2 Fast";
|
|
2841
|
-
if (routeLower.includes("bus")) return "Stargate V2 Economy";
|
|
2842
|
-
if (routeLower.includes("oft")) return "OFT Bridge";
|
|
2843
|
-
if (routeLower.includes("v2")) return "Stargate V2";
|
|
2844
|
-
return route.split(/[/\-_]/).map((part) => part.charAt(0).toUpperCase() + part.slice(1)).join(" ");
|
|
2845
|
-
}
|
|
2846
2893
|
function useGasEstimate(amountNum) {
|
|
2847
2894
|
const { fromChain } = useChainsStore();
|
|
2848
2895
|
const { selectedAssetSymbol } = useTokensStore();
|
|
@@ -2852,9 +2899,6 @@ function useGasEstimate(amountNum) {
|
|
|
2852
2899
|
srcAddress
|
|
2853
2900
|
);
|
|
2854
2901
|
const { quote } = useBridgeQuoteStore();
|
|
2855
|
-
const { chainRegistry } = useChainStrategies();
|
|
2856
|
-
const [networkFeeEstimate, setNetworkFeeEstimate] = react.useState(0);
|
|
2857
|
-
const [networkFeeKnown, setNetworkFeeKnown] = react.useState(false);
|
|
2858
2902
|
const balancesKnown = !balancesLoading;
|
|
2859
2903
|
const chainKey = fromChain?.chainKey;
|
|
2860
2904
|
const nativeCurrencySymbol = fromChain?.nativeCurrency?.symbol;
|
|
@@ -2863,44 +2907,6 @@ function useGasEstimate(amountNum) {
|
|
|
2863
2907
|
const quoteFees = quote?.fees;
|
|
2864
2908
|
const quoteSrcChainKey = quote?.srcChainKey;
|
|
2865
2909
|
const nativeBalanceValue = nativeCurrencySymbol ? Number(balances[nativeCurrencySymbol.toUpperCase()]?.balance ?? 0) : 0;
|
|
2866
|
-
react.useEffect(() => {
|
|
2867
|
-
let cancelled = false;
|
|
2868
|
-
const estimate = async () => {
|
|
2869
|
-
setNetworkFeeEstimate(0);
|
|
2870
|
-
setNetworkFeeKnown(false);
|
|
2871
|
-
if (!chainKey || !quote?.steps?.length) {
|
|
2872
|
-
return;
|
|
2873
|
-
}
|
|
2874
|
-
const strategy = chainRegistry.getStrategy(chainKey);
|
|
2875
|
-
if (!strategy) {
|
|
2876
|
-
setNetworkFeeKnown(true);
|
|
2877
|
-
return;
|
|
2878
|
-
}
|
|
2879
|
-
const steps = quote.steps.filter((step) => step.chainKey === chainKey);
|
|
2880
|
-
if (!steps.length) {
|
|
2881
|
-
setNetworkFeeKnown(true);
|
|
2882
|
-
return;
|
|
2883
|
-
}
|
|
2884
|
-
try {
|
|
2885
|
-
const estimateValue = await strategy.estimateNetworkFee(steps);
|
|
2886
|
-
if (cancelled) return;
|
|
2887
|
-
setNetworkFeeEstimate(
|
|
2888
|
-
Number.isFinite(estimateValue) ? estimateValue : 0
|
|
2889
|
-
);
|
|
2890
|
-
} catch {
|
|
2891
|
-
if (cancelled) return;
|
|
2892
|
-
setNetworkFeeEstimate(0);
|
|
2893
|
-
} finally {
|
|
2894
|
-
if (!cancelled) {
|
|
2895
|
-
setNetworkFeeKnown(true);
|
|
2896
|
-
}
|
|
2897
|
-
}
|
|
2898
|
-
};
|
|
2899
|
-
void estimate();
|
|
2900
|
-
return () => {
|
|
2901
|
-
cancelled = true;
|
|
2902
|
-
};
|
|
2903
|
-
}, [chainKey, quote?.steps, chainRegistry]);
|
|
2904
2910
|
const result = react.useMemo(() => {
|
|
2905
2911
|
if (!chainKey || !nativeCurrencySymbol) {
|
|
2906
2912
|
return {
|
|
@@ -2929,16 +2935,13 @@ function useGasEstimate(amountNum) {
|
|
|
2929
2935
|
requiredNative = Number(feesInNative) / Math.pow(10, decimals);
|
|
2930
2936
|
quoteFeesAvailable = true;
|
|
2931
2937
|
}
|
|
2932
|
-
if (networkFeeKnown) {
|
|
2933
|
-
requiredNative += networkFeeEstimate;
|
|
2934
|
-
}
|
|
2935
2938
|
let hasEnoughGas = true;
|
|
2936
2939
|
if (isNativeSelected) {
|
|
2937
2940
|
hasEnoughGas = nativeBalance - (amountNum ?? 0) >= requiredNative;
|
|
2938
2941
|
} else {
|
|
2939
2942
|
hasEnoughGas = nativeBalance >= requiredNative;
|
|
2940
2943
|
}
|
|
2941
|
-
const shouldCheckGas = balancesKnown && quoteFeesAvailable
|
|
2944
|
+
const shouldCheckGas = balancesKnown && quoteFeesAvailable;
|
|
2942
2945
|
return {
|
|
2943
2946
|
nativeSym,
|
|
2944
2947
|
nativeBalance,
|
|
@@ -2957,9 +2960,7 @@ function useGasEstimate(amountNum) {
|
|
|
2957
2960
|
quoteSrcChainKey,
|
|
2958
2961
|
amountNum,
|
|
2959
2962
|
balancesKnown,
|
|
2960
|
-
nativeBalanceValue
|
|
2961
|
-
networkFeeEstimate,
|
|
2962
|
-
networkFeeKnown
|
|
2963
|
+
nativeBalanceValue
|
|
2963
2964
|
]);
|
|
2964
2965
|
return result;
|
|
2965
2966
|
}
|
|
@@ -4239,7 +4240,7 @@ const ProgressStep = ({
|
|
|
4239
4240
|
title: t2("transaction.steps.completed")
|
|
4240
4241
|
}
|
|
4241
4242
|
];
|
|
4242
|
-
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: [
|
|
4243
4244
|
icon,
|
|
4244
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") }) }),
|
|
4245
4246
|
/* @__PURE__ */ jsxRuntime.jsxs("div", { className: "relative", children: [
|
|
@@ -4266,8 +4267,8 @@ const FailedStep = ({
|
|
|
4266
4267
|
}) => {
|
|
4267
4268
|
const { current, reset } = useTransactionStore();
|
|
4268
4269
|
const { t: t2 } = useBridgeTranslation();
|
|
4269
|
-
return /* @__PURE__ */ jsxRuntime.jsxs(dialog.DialogContent, { showCloseButton: true, className: "overflow-hidden md:max-w-[420px] p-0", children: [
|
|
4270
|
-
/* @__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: [
|
|
4271
4272
|
icon,
|
|
4272
4273
|
/* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex flex-col gap-2 pt-4 pb-2 text-center", children: [
|
|
4273
4274
|
/* @__PURE__ */ jsxRuntime.jsx(dialog.DialogTitle, { children: t2("transaction.failed") }),
|
|
@@ -4458,9 +4459,9 @@ const SuccessStep = ({
|
|
|
4458
4459
|
dialog.DialogContent,
|
|
4459
4460
|
{
|
|
4460
4461
|
showCloseButton: true,
|
|
4461
|
-
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",
|
|
4462
4463
|
children: [
|
|
4463
|
-
/* @__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: [
|
|
4464
4465
|
icon,
|
|
4465
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") }) }),
|
|
4466
4467
|
/* @__PURE__ */ jsxRuntime.jsxs("div", { className: "w-full space-y-2 mt-3 relative z-10 pb-14", children: [
|
|
@@ -4545,7 +4546,7 @@ const ConfirmStep = ({
|
|
|
4545
4546
|
}) => {
|
|
4546
4547
|
const { t: t2 } = useBridgeTranslation();
|
|
4547
4548
|
const { formatTime } = useCountdown(90);
|
|
4548
|
-
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: [
|
|
4549
4550
|
icon,
|
|
4550
4551
|
/* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex flex-col gap-2 pt-4 pb-2 text-center", children: [
|
|
4551
4552
|
/* @__PURE__ */ jsxRuntime.jsx(dialog.DialogTitle, { children: t2("transaction.confirm") }),
|
|
@@ -6940,7 +6941,7 @@ const TokenSelectModal = ({
|
|
|
6940
6941
|
return /* @__PURE__ */ jsxRuntime.jsx(dialog.Dialog, { open: isOpen, onOpenChange: (open) => !open && handleClose(), children: /* @__PURE__ */ jsxRuntime.jsxs(
|
|
6941
6942
|
dialog.DialogContent,
|
|
6942
6943
|
{
|
|
6943
|
-
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",
|
|
6944
6945
|
closeButtonClassName: "right-6 md:right-10",
|
|
6945
6946
|
children: [
|
|
6946
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") }) }),
|
|
@@ -25823,7 +25824,7 @@ class WalletConnectModal {
|
|
|
25823
25824
|
}
|
|
25824
25825
|
async initUi() {
|
|
25825
25826
|
if (typeof window !== "undefined") {
|
|
25826
|
-
await Promise.resolve().then(() => require("./index-
|
|
25827
|
+
await Promise.resolve().then(() => require("./index-CSE-oDw8.cjs"));
|
|
25827
25828
|
const modal = document.createElement("wcm-modal");
|
|
25828
25829
|
document.body.insertAdjacentElement("beforeend", modal);
|
|
25829
25830
|
OptionsCtrl.setIsUiLoaded(true);
|
|
@@ -26542,6 +26543,7 @@ exports.RouteType = RouteType;
|
|
|
26542
26543
|
exports.RouterCtrl = RouterCtrl;
|
|
26543
26544
|
exports.ThemeCtrl = ThemeCtrl;
|
|
26544
26545
|
exports.ToastCtrl = ToastCtrl;
|
|
26546
|
+
exports.addNetworkFeesToQuote = addNetworkFeesToQuote;
|
|
26545
26547
|
exports.addrForApi = addrForApi;
|
|
26546
26548
|
exports.buildAssetMatrix = buildAssetMatrix;
|
|
26547
26549
|
exports.calculateMinReceived = calculateMinReceived;
|
|
@@ -26589,4 +26591,4 @@ exports.useSettingsStore = useSettingsStore;
|
|
|
26589
26591
|
exports.useSwapModel = useSwapModel;
|
|
26590
26592
|
exports.useTokensStore = useTokensStore;
|
|
26591
26593
|
exports.useTransactionStore = useTransactionStore;
|
|
26592
|
-
//# sourceMappingURL=index-
|
|
26594
|
+
//# sourceMappingURL=index-CpKOf8oF.cjs.map
|