@rash2x/bridge-widget 0.6.62 → 0.6.64
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-CcNV1b5l.js → index-7Pgd_WWn.js} +2 -2
- package/dist/{index-CcNV1b5l.js.map → index-7Pgd_WWn.js.map} +1 -1
- package/dist/{index-C0BTirT_.js → index-BEeiBKNi.js} +224 -216
- package/dist/index-BEeiBKNi.js.map +1 -0
- package/dist/{index-Dwxz-LHk.cjs → index-BuYPjNSX.cjs} +2 -2
- package/dist/{index-Dwxz-LHk.cjs.map → index-BuYPjNSX.cjs.map} +1 -1
- package/dist/{index-CAc7tJ3r.cjs → index-DYJQfOaf.cjs} +198 -190
- package/dist/index-DYJQfOaf.cjs.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 {
|
|
@@ -2917,6 +2923,7 @@ function useGasEstimate(amountNum) {
|
|
|
2917
2923
|
const isNativeSelected = nativeSym === (selectedAssetSymbol || "").toUpperCase();
|
|
2918
2924
|
let requiredNative = 0;
|
|
2919
2925
|
let quoteFeesAvailable = false;
|
|
2926
|
+
console.log(quoteFees);
|
|
2920
2927
|
if (quoteFees && quoteSrcChainKey === chainKey) {
|
|
2921
2928
|
const fees = quoteFees;
|
|
2922
2929
|
const feesInNative = fees.filter(
|
|
@@ -2929,16 +2936,16 @@ function useGasEstimate(amountNum) {
|
|
|
2929
2936
|
requiredNative = Number(feesInNative) / Math.pow(10, decimals);
|
|
2930
2937
|
quoteFeesAvailable = true;
|
|
2931
2938
|
}
|
|
2932
|
-
if (networkFeeKnown) {
|
|
2933
|
-
requiredNative += networkFeeEstimate;
|
|
2934
|
-
}
|
|
2935
2939
|
let hasEnoughGas = true;
|
|
2936
2940
|
if (isNativeSelected) {
|
|
2937
2941
|
hasEnoughGas = nativeBalance - (amountNum ?? 0) >= requiredNative;
|
|
2938
2942
|
} else {
|
|
2939
2943
|
hasEnoughGas = nativeBalance >= requiredNative;
|
|
2940
2944
|
}
|
|
2941
|
-
|
|
2945
|
+
console.log("nativeBalance", nativeBalance);
|
|
2946
|
+
console.log("requiredNative", requiredNative);
|
|
2947
|
+
console.log("nativeBalance - (amountNum ?? 0)", nativeBalance - (amountNum ?? 0));
|
|
2948
|
+
const shouldCheckGas = balancesKnown && quoteFeesAvailable;
|
|
2942
2949
|
return {
|
|
2943
2950
|
nativeSym,
|
|
2944
2951
|
nativeBalance,
|
|
@@ -2957,9 +2964,7 @@ function useGasEstimate(amountNum) {
|
|
|
2957
2964
|
quoteSrcChainKey,
|
|
2958
2965
|
amountNum,
|
|
2959
2966
|
balancesKnown,
|
|
2960
|
-
nativeBalanceValue
|
|
2961
|
-
networkFeeEstimate,
|
|
2962
|
-
networkFeeKnown
|
|
2967
|
+
nativeBalanceValue
|
|
2963
2968
|
]);
|
|
2964
2969
|
return result;
|
|
2965
2970
|
}
|
|
@@ -3671,6 +3676,8 @@ function useBalanceCheck(amountNum, gas) {
|
|
|
3671
3676
|
};
|
|
3672
3677
|
}
|
|
3673
3678
|
const hasEnoughGasForTx = gas.nativeBalance >= gasReserve;
|
|
3679
|
+
console.log("rawBalance", rawBalance);
|
|
3680
|
+
console.log("amountNum", amountNum);
|
|
3674
3681
|
return {
|
|
3675
3682
|
availableBalance: rawBalance,
|
|
3676
3683
|
hasInsufficientBalance: amountNum > rawBalance || !hasEnoughGasForTx,
|
|
@@ -4239,7 +4246,7 @@ const ProgressStep = ({
|
|
|
4239
4246
|
title: t2("transaction.steps.completed")
|
|
4240
4247
|
}
|
|
4241
4248
|
];
|
|
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: [
|
|
4249
|
+
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
4250
|
icon,
|
|
4244
4251
|
/* @__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
4252
|
/* @__PURE__ */ jsxRuntime.jsxs("div", { className: "relative", children: [
|
|
@@ -4266,8 +4273,8 @@ const FailedStep = ({
|
|
|
4266
4273
|
}) => {
|
|
4267
4274
|
const { current, reset } = useTransactionStore();
|
|
4268
4275
|
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: [
|
|
4276
|
+
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: [
|
|
4277
|
+
/* @__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
4278
|
icon,
|
|
4272
4279
|
/* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex flex-col gap-2 pt-4 pb-2 text-center", children: [
|
|
4273
4280
|
/* @__PURE__ */ jsxRuntime.jsx(dialog.DialogTitle, { children: t2("transaction.failed") }),
|
|
@@ -4458,9 +4465,9 @@ const SuccessStep = ({
|
|
|
4458
4465
|
dialog.DialogContent,
|
|
4459
4466
|
{
|
|
4460
4467
|
showCloseButton: true,
|
|
4461
|
-
className: "overflow-hidden md:max-w-[420px] p-0",
|
|
4468
|
+
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
4469
|
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: [
|
|
4470
|
+
/* @__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
4471
|
icon,
|
|
4465
4472
|
/* @__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
4473
|
/* @__PURE__ */ jsxRuntime.jsxs("div", { className: "w-full space-y-2 mt-3 relative z-10 pb-14", children: [
|
|
@@ -4545,7 +4552,7 @@ const ConfirmStep = ({
|
|
|
4545
4552
|
}) => {
|
|
4546
4553
|
const { t: t2 } = useBridgeTranslation();
|
|
4547
4554
|
const { formatTime } = useCountdown(90);
|
|
4548
|
-
return /* @__PURE__ */ jsxRuntime.jsx(dialog.DialogContent, {
|
|
4555
|
+
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
4556
|
icon,
|
|
4550
4557
|
/* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex flex-col gap-2 pt-4 pb-2 text-center", children: [
|
|
4551
4558
|
/* @__PURE__ */ jsxRuntime.jsx(dialog.DialogTitle, { children: t2("transaction.confirm") }),
|
|
@@ -6940,7 +6947,7 @@ const TokenSelectModal = ({
|
|
|
6940
6947
|
return /* @__PURE__ */ jsxRuntime.jsx(dialog.Dialog, { open: isOpen, onOpenChange: (open) => !open && handleClose(), children: /* @__PURE__ */ jsxRuntime.jsxs(
|
|
6941
6948
|
dialog.DialogContent,
|
|
6942
6949
|
{
|
|
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
|
|
6950
|
+
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
6951
|
closeButtonClassName: "right-6 md:right-10",
|
|
6945
6952
|
children: [
|
|
6946
6953
|
/* @__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 +25830,7 @@ class WalletConnectModal {
|
|
|
25823
25830
|
}
|
|
25824
25831
|
async initUi() {
|
|
25825
25832
|
if (typeof window !== "undefined") {
|
|
25826
|
-
await Promise.resolve().then(() => require("./index-
|
|
25833
|
+
await Promise.resolve().then(() => require("./index-BuYPjNSX.cjs"));
|
|
25827
25834
|
const modal = document.createElement("wcm-modal");
|
|
25828
25835
|
document.body.insertAdjacentElement("beforeend", modal);
|
|
25829
25836
|
OptionsCtrl.setIsUiLoaded(true);
|
|
@@ -26542,6 +26549,7 @@ exports.RouteType = RouteType;
|
|
|
26542
26549
|
exports.RouterCtrl = RouterCtrl;
|
|
26543
26550
|
exports.ThemeCtrl = ThemeCtrl;
|
|
26544
26551
|
exports.ToastCtrl = ToastCtrl;
|
|
26552
|
+
exports.addNetworkFeesToQuote = addNetworkFeesToQuote;
|
|
26545
26553
|
exports.addrForApi = addrForApi;
|
|
26546
26554
|
exports.buildAssetMatrix = buildAssetMatrix;
|
|
26547
26555
|
exports.calculateMinReceived = calculateMinReceived;
|
|
@@ -26589,4 +26597,4 @@ exports.useSettingsStore = useSettingsStore;
|
|
|
26589
26597
|
exports.useSwapModel = useSwapModel;
|
|
26590
26598
|
exports.useTokensStore = useTokensStore;
|
|
26591
26599
|
exports.useTransactionStore = useTransactionStore;
|
|
26592
|
-
//# sourceMappingURL=index-
|
|
26600
|
+
//# sourceMappingURL=index-DYJQfOaf.cjs.map
|