@rash2x/bridge-widget 0.3.9 → 0.4.1
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 +122 -204
- package/dist/evaa-bridge.cjs.map +1 -1
- package/dist/evaa-bridge.mjs +122 -183
- package/dist/evaa-bridge.mjs.map +1 -1
- package/dist/index.d.ts +1 -1
- package/dist/styles.css +1 -1
- package/package.json +1 -6
package/dist/evaa-bridge.mjs
CHANGED
|
@@ -24,8 +24,7 @@ import { Accordion, AccordionItem, AccordionTrigger, AccordionContent } from "@/
|
|
|
24
24
|
import { Tooltip, TooltipTrigger, TooltipContent } from "@/components/ui/tooltip";
|
|
25
25
|
import { toast, Toaster } from "sonner";
|
|
26
26
|
import { DialogDescription as DialogDescription$1 } from "@radix-ui/react-dialog";
|
|
27
|
-
import {
|
|
28
|
-
import { isAddress, formatUnits } from "viem";
|
|
27
|
+
import { isAddress, formatUnits, parseUnits } from "viem";
|
|
29
28
|
import { TronLinkAdapterName } from "@tronweb3/tronwallet-adapters";
|
|
30
29
|
import { CardHeader, CardTitle, CardAction, Card, CardContent, CardFooter } from "@/components/ui/card";
|
|
31
30
|
import { Badge } from "@/components/ui/badge";
|
|
@@ -409,16 +408,10 @@ function buildAssetMatrix(tokens) {
|
|
|
409
408
|
if (!symbol) continue;
|
|
410
409
|
(m[symbol] || (m[symbol] = {}))[t.chainKey] = t;
|
|
411
410
|
}
|
|
412
|
-
const chainStats = {};
|
|
413
411
|
Object.values(m).forEach((byChain) => {
|
|
414
412
|
Object.keys(byChain).forEach((chainKey) => {
|
|
415
|
-
chainStats[chainKey] = (chainStats[chainKey] || 0) + 1;
|
|
416
413
|
});
|
|
417
414
|
});
|
|
418
|
-
console.log(
|
|
419
|
-
`[DEBUG] Asset matrix built: ${Object.keys(m).length} assets across chains:`,
|
|
420
|
-
chainStats
|
|
421
|
-
);
|
|
422
415
|
return m;
|
|
423
416
|
}
|
|
424
417
|
function listAssetsForSelect(tokens) {
|
|
@@ -1527,12 +1520,6 @@ const useChainDerivations = () => {
|
|
|
1527
1520
|
const byChain = assetMatrix[selectedAssetSymbol.toUpperCase()];
|
|
1528
1521
|
const keys = new Set(Object.keys(byChain ?? {}));
|
|
1529
1522
|
const result = chains.filter((c) => keys.has(c.chainKey));
|
|
1530
|
-
console.log(
|
|
1531
|
-
`[DEBUG] supportedFrom for ${selectedAssetSymbol}:`,
|
|
1532
|
-
`${result.length} of ${chains.length} chains`,
|
|
1533
|
-
result.map((c) => c.chainKey),
|
|
1534
|
-
`| Has Arbitrum: ${result.some((c) => c.chainKey === "arbitrum")}`
|
|
1535
|
-
);
|
|
1536
1523
|
return result;
|
|
1537
1524
|
}, [selectedAssetSymbol, assetMatrix, chains]);
|
|
1538
1525
|
useEffect(() => {
|
|
@@ -1601,13 +1588,6 @@ const useChainDerivations = () => {
|
|
|
1601
1588
|
if (fromChain?.chainKey) {
|
|
1602
1589
|
list = list.filter((c) => c.chainKey !== fromChain.chainKey);
|
|
1603
1590
|
}
|
|
1604
|
-
console.log(
|
|
1605
|
-
`[DEBUG] allowedToChains from ${fromChain?.chainKey}:`,
|
|
1606
|
-
`${list.length} destinations`,
|
|
1607
|
-
list.map((c) => c.chainKey),
|
|
1608
|
-
`| Has Arbitrum: ${list.some((c) => c.chainKey === "arbitrum")}`,
|
|
1609
|
-
`| API returned ${dest.length} tokens, filtered to ${filteredDest.length}`
|
|
1610
|
-
);
|
|
1611
1591
|
setAllowedToChains(list);
|
|
1612
1592
|
if (!toChain || !list.some((c) => c.chainKey === toChain.chainKey)) {
|
|
1613
1593
|
setToChain(list[0]);
|
|
@@ -1642,7 +1622,7 @@ const useChainDerivations = () => {
|
|
|
1642
1622
|
isLoadingToChains
|
|
1643
1623
|
};
|
|
1644
1624
|
};
|
|
1645
|
-
function useBalances(chainKey, address
|
|
1625
|
+
function useBalances(chainKey, address) {
|
|
1646
1626
|
const { chainRegistry } = useChainStrategies();
|
|
1647
1627
|
const { assetMatrix } = useTokensStore();
|
|
1648
1628
|
const tokensOnChain = useMemo(() => {
|
|
@@ -1656,27 +1636,13 @@ function useBalances(chainKey, address, priorityTokenSymbol) {
|
|
|
1656
1636
|
}
|
|
1657
1637
|
return tokensList;
|
|
1658
1638
|
}, [assetMatrix, chainKey]);
|
|
1659
|
-
const priorityToken = useMemo(() => {
|
|
1660
|
-
if (!priorityTokenSymbol || !chainKey || !assetMatrix) return void 0;
|
|
1661
|
-
const normalizedSymbol = normalizeTickerSymbol$1(priorityTokenSymbol);
|
|
1662
|
-
const token = assetMatrix[normalizedSymbol]?.[chainKey];
|
|
1663
|
-
if (token && token.address && token.address.length > 2) {
|
|
1664
|
-
return token;
|
|
1665
|
-
}
|
|
1666
|
-
return void 0;
|
|
1667
|
-
}, [priorityTokenSymbol, chainKey, assetMatrix]);
|
|
1668
1639
|
const query = useQuery({
|
|
1669
|
-
queryKey: ["balances", chainKey, address
|
|
1640
|
+
queryKey: ["balances", chainKey, address],
|
|
1670
1641
|
queryFn: async () => {
|
|
1671
1642
|
if (!address || !chainKey)
|
|
1672
1643
|
return {};
|
|
1673
1644
|
if (!isAddressValidForChain(chainKey, address)) return {};
|
|
1674
|
-
return await chainRegistry.getBalances(
|
|
1675
|
-
chainKey,
|
|
1676
|
-
address,
|
|
1677
|
-
tokensOnChain,
|
|
1678
|
-
priorityToken
|
|
1679
|
-
);
|
|
1645
|
+
return await chainRegistry.getBalances(chainKey, address, tokensOnChain);
|
|
1680
1646
|
},
|
|
1681
1647
|
enabled: !!address && !!chainKey && !!assetMatrix && tokensOnChain.length > 0 && isAddressValidForChain(chainKey, address),
|
|
1682
1648
|
staleTime: 6e4,
|
|
@@ -1715,13 +1681,11 @@ function useSwapModel() {
|
|
|
1715
1681
|
const { allowedFromChains, allowedToChains, isLoadingToChains } = useChainDerivations();
|
|
1716
1682
|
const srcBalances = useBalances(
|
|
1717
1683
|
chainsStore.fromChain?.chainKey,
|
|
1718
|
-
srcAddress
|
|
1719
|
-
tokensStore.selectedAssetSymbol
|
|
1684
|
+
srcAddress
|
|
1720
1685
|
);
|
|
1721
1686
|
const dstBalances = useBalances(
|
|
1722
1687
|
chainsStore.toChain?.chainKey,
|
|
1723
|
-
dstAddress
|
|
1724
|
-
tokensStore.selectedAssetSymbol
|
|
1688
|
+
dstAddress
|
|
1725
1689
|
);
|
|
1726
1690
|
const { loading } = useBridgeQuote();
|
|
1727
1691
|
const { inputAmount, setInputAmount, resetWithIdle } = useBridgeQuoteStore();
|
|
@@ -2425,13 +2389,13 @@ const SearchInput = ({
|
|
|
2425
2389
|
className
|
|
2426
2390
|
}) => {
|
|
2427
2391
|
return /* @__PURE__ */ jsxs("div", { className: cn("rounded-xs relative"), children: [
|
|
2428
|
-
/* @__PURE__ */ jsx(SearchIcon, { className: "w-6 h-6 absolute left-5 top-0 bottom-0 my-auto text-foreground" }),
|
|
2392
|
+
/* @__PURE__ */ jsx(SearchIcon, { className: "w-6 h-6 absolute z-10 left-5 top-0 bottom-0 my-auto text-foreground" }),
|
|
2429
2393
|
/* @__PURE__ */ jsx(
|
|
2430
2394
|
Input,
|
|
2431
2395
|
{
|
|
2432
2396
|
placeholder,
|
|
2433
2397
|
className: cn(
|
|
2434
|
-
"w-full outline-none px-5 py-4 relative
|
|
2398
|
+
"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 focus-visible:border focus-visible:border-ring",
|
|
2435
2399
|
className
|
|
2436
2400
|
),
|
|
2437
2401
|
value,
|
|
@@ -2648,15 +2612,15 @@ const EditIcon = (props) => {
|
|
|
2648
2612
|
xmlns: "http://www.w3.org/2000/svg",
|
|
2649
2613
|
...props,
|
|
2650
2614
|
children: [
|
|
2651
|
-
/* @__PURE__ */ jsxs("g", {
|
|
2615
|
+
/* @__PURE__ */ jsxs("g", { clipPath: "url(#clip0_551_3851)", children: [
|
|
2652
2616
|
/* @__PURE__ */ jsx(
|
|
2653
2617
|
"path",
|
|
2654
2618
|
{
|
|
2655
2619
|
d: "M9.76159 5.01068L4.91742 9.85489C4.72585 10.0465 4.54793 10.4023 4.50687 10.6622L4.24687 12.5096C4.15108 13.1801 4.61636 13.6454 5.28688 13.5496L7.13425 13.2896C7.39425 13.2486 7.76372 13.0707 7.94161 12.8791L12.7858 8.03491C13.6206 7.20018 14.0174 6.2286 12.7858 4.99702C11.5679 3.77913 10.5963 4.17594 9.76159 5.01068Z",
|
|
2656
2620
|
stroke: "currentColor",
|
|
2657
|
-
|
|
2658
|
-
|
|
2659
|
-
|
|
2621
|
+
strokeMiterlimit: "10",
|
|
2622
|
+
strokeLinecap: "round",
|
|
2623
|
+
strokeLinejoin: "round"
|
|
2660
2624
|
}
|
|
2661
2625
|
),
|
|
2662
2626
|
/* @__PURE__ */ jsx(
|
|
@@ -2664,9 +2628,9 @@ const EditIcon = (props) => {
|
|
|
2664
2628
|
{
|
|
2665
2629
|
d: "M9.0625 5.70312C9.47303 7.18102 10.6225 8.33049 12.1004 8.74101",
|
|
2666
2630
|
stroke: "currentColor",
|
|
2667
|
-
|
|
2668
|
-
|
|
2669
|
-
|
|
2631
|
+
strokeMiterlimit: "10",
|
|
2632
|
+
strokeLinecap: "round",
|
|
2633
|
+
strokeLinejoin: "round"
|
|
2670
2634
|
}
|
|
2671
2635
|
)
|
|
2672
2636
|
] }),
|
|
@@ -3751,7 +3715,7 @@ function useSilentValidations(amountString) {
|
|
|
3751
3715
|
]);
|
|
3752
3716
|
return validationResult;
|
|
3753
3717
|
}
|
|
3754
|
-
const
|
|
3718
|
+
const MainButton = () => {
|
|
3755
3719
|
const { t } = useBridgeTranslation();
|
|
3756
3720
|
const { chainRegistry } = useChainStrategies();
|
|
3757
3721
|
const { srcAddress, dstAddress } = useAddresses();
|
|
@@ -3829,11 +3793,11 @@ const SubmitButton = () => {
|
|
|
3829
3793
|
]);
|
|
3830
3794
|
const handleClick = async () => {
|
|
3831
3795
|
if (isBusy) return;
|
|
3832
|
-
if (missingSrc
|
|
3796
|
+
if (missingSrc) {
|
|
3833
3797
|
onOpen("src");
|
|
3834
3798
|
return;
|
|
3835
3799
|
}
|
|
3836
|
-
if (missingDst
|
|
3800
|
+
if (missingDst) {
|
|
3837
3801
|
onOpen("dst");
|
|
3838
3802
|
return;
|
|
3839
3803
|
}
|
|
@@ -3846,7 +3810,7 @@ const SubmitButton = () => {
|
|
|
3846
3810
|
return;
|
|
3847
3811
|
}
|
|
3848
3812
|
};
|
|
3849
|
-
const disabled = isBusy ||
|
|
3813
|
+
const disabled = isBusy || status === "loading" || !missingSrc && !missingDst && (amountNum <= 0 || isBalanceLoading || hasInsufficientBalance || hasAmountTooLarge || !gas.hasEnoughGas || noRoute || !isValidForTransfer);
|
|
3850
3814
|
return /* @__PURE__ */ jsx("div", { className: "pt-4", children: /* @__PURE__ */ jsx(
|
|
3851
3815
|
Button,
|
|
3852
3816
|
{
|
|
@@ -4073,9 +4037,9 @@ const ProgressStep = ({
|
|
|
4073
4037
|
icon = /* @__PURE__ */ jsx(Loader2, { className: "w-16 h-16 animate-spin" })
|
|
4074
4038
|
}) => {
|
|
4075
4039
|
const { t } = useBridgeTranslation();
|
|
4076
|
-
return /* @__PURE__ */ jsx(DialogContent, { showCloseButton: false, children: /* @__PURE__ */ jsxs("div", { className: "flex relative flex-col gap-4
|
|
4040
|
+
return /* @__PURE__ */ jsx(DialogContent, { showCloseButton: false, className: "overflow-hidden", children: /* @__PURE__ */ jsxs("div", { className: "flex relative flex-col gap-4 flex-1 items-center justify-start text-center noise bg-background", children: [
|
|
4077
4041
|
icon,
|
|
4078
|
-
/* @__PURE__ */ jsx(DialogHeader, { children: /* @__PURE__ */ jsx(DialogTitle, { children: t("transaction.inProgress") }) }),
|
|
4042
|
+
/* @__PURE__ */ jsx(DialogHeader, { className: "pr-0", children: /* @__PURE__ */ jsx(DialogTitle, { children: t("transaction.inProgress") }) }),
|
|
4079
4043
|
/* @__PURE__ */ jsx("div", { className: "relative mt-5 z-10", children: /* @__PURE__ */ jsx("div", { className: "absolute dot-vertical h-full left-5 top-0 bottom-0 z-0" }) })
|
|
4080
4044
|
] }) });
|
|
4081
4045
|
};
|
|
@@ -4084,10 +4048,10 @@ const FailedStep = ({
|
|
|
4084
4048
|
}) => {
|
|
4085
4049
|
const { current, reset } = useTransactionStore();
|
|
4086
4050
|
const { t } = useBridgeTranslation();
|
|
4087
|
-
return /* @__PURE__ */ jsxs(DialogContent, { showCloseButton:
|
|
4088
|
-
/* @__PURE__ */ jsxs("div", { className: "flex flex-col relative gap-4
|
|
4051
|
+
return /* @__PURE__ */ jsxs(DialogContent, { showCloseButton: true, className: "overflow-hidden", children: [
|
|
4052
|
+
/* @__PURE__ */ jsxs("div", { className: "flex flex-col relative gap-4 flex-1 items-center justify-start text-center noise", children: [
|
|
4089
4053
|
icon,
|
|
4090
|
-
/* @__PURE__ */ jsxs(DialogHeader, { children: [
|
|
4054
|
+
/* @__PURE__ */ jsxs(DialogHeader, { className: "pr-0", children: [
|
|
4091
4055
|
/* @__PURE__ */ jsx(DialogTitle, { children: t("transaction.failed") }),
|
|
4092
4056
|
current?.errorCode && /* @__PURE__ */ jsx(DialogDescription$1, { children: t(
|
|
4093
4057
|
`errors.${current.errorCode}`,
|
|
@@ -4199,10 +4163,10 @@ const SuccessStep = ({
|
|
|
4199
4163
|
openTransactionInExplorer(srcChainKey, srcTxHash);
|
|
4200
4164
|
}
|
|
4201
4165
|
};
|
|
4202
|
-
return /* @__PURE__ */ jsxs(DialogContent, { showCloseButton:
|
|
4203
|
-
/* @__PURE__ */ jsxs("div", { className: "flex flex-col gap-4
|
|
4166
|
+
return /* @__PURE__ */ jsxs(DialogContent, { showCloseButton: true, className: "overflow-hidden", children: [
|
|
4167
|
+
/* @__PURE__ */ jsxs("div", { className: "flex flex-col gap-4 flex-1 justify-start items-center text-center noise bg-background", children: [
|
|
4204
4168
|
icon,
|
|
4205
|
-
/* @__PURE__ */ jsx(DialogHeader, { children: /* @__PURE__ */ jsx(DialogTitle, { children: t("transaction.success") }) }),
|
|
4169
|
+
/* @__PURE__ */ jsx(DialogHeader, { className: "pr-0", children: /* @__PURE__ */ jsx(DialogTitle, { children: t("transaction.success") }) }),
|
|
4206
4170
|
/* @__PURE__ */ jsxs("div", { className: "w-full space-y-2 mt-4 relative z-10 pb-14", children: [
|
|
4207
4171
|
metadata?.srcAmountHuman && /* @__PURE__ */ jsxs("div", { className: "flex justify-between items-center", children: [
|
|
4208
4172
|
/* @__PURE__ */ jsx("span", { className: "text-muted-foreground", children: t("transaction.bridged") }),
|
|
@@ -4250,7 +4214,7 @@ const SuccessStep = ({
|
|
|
4250
4214
|
] })
|
|
4251
4215
|
] })
|
|
4252
4216
|
] }),
|
|
4253
|
-
/* @__PURE__ */ jsx(
|
|
4217
|
+
/* @__PURE__ */ jsx(DialogFooter, { children: /* @__PURE__ */ jsx(Button, { onClick: reset, className: "w-full", children: t("transaction.done") }) })
|
|
4254
4218
|
] });
|
|
4255
4219
|
};
|
|
4256
4220
|
const useCountdown = (initialSeconds) => {
|
|
@@ -4275,9 +4239,9 @@ const ConfirmStep = ({
|
|
|
4275
4239
|
}) => {
|
|
4276
4240
|
const { t } = useBridgeTranslation();
|
|
4277
4241
|
const { formatTime } = useCountdown(90);
|
|
4278
|
-
return /* @__PURE__ */ jsx(DialogContent, { showCloseButton: false, children: /* @__PURE__ */ jsxs("div", { className: "flex flex-col relative gap-4
|
|
4242
|
+
return /* @__PURE__ */ jsx(DialogContent, { showCloseButton: false, className: "overflow-hidden", children: /* @__PURE__ */ jsxs("div", { className: "flex flex-col relative gap-4 flex-1 items-center justify-start text-center noise", children: [
|
|
4279
4243
|
icon,
|
|
4280
|
-
/* @__PURE__ */ jsxs(DialogHeader, { children: [
|
|
4244
|
+
/* @__PURE__ */ jsxs(DialogHeader, { className: "pr-0", children: [
|
|
4281
4245
|
/* @__PURE__ */ jsx(DialogTitle, { children: t("transaction.confirm") }),
|
|
4282
4246
|
/* @__PURE__ */ jsx(DialogDescription, { children: t("transaction.signTransaction") })
|
|
4283
4247
|
] }),
|
|
@@ -4287,7 +4251,7 @@ const ConfirmStep = ({
|
|
|
4287
4251
|
const StatusStepsDialog = ({
|
|
4288
4252
|
icons
|
|
4289
4253
|
}) => {
|
|
4290
|
-
const { current } = useTransactionStore();
|
|
4254
|
+
const { current, reset } = useTransactionStore();
|
|
4291
4255
|
const status = current?.status;
|
|
4292
4256
|
if (!status || status === "idle") return null;
|
|
4293
4257
|
let step = null;
|
|
@@ -4297,14 +4261,13 @@ const StatusStepsDialog = ({
|
|
|
4297
4261
|
if (status === "processing") {
|
|
4298
4262
|
step = /* @__PURE__ */ jsx(ProgressStep, { icon: icons?.progress });
|
|
4299
4263
|
}
|
|
4300
|
-
if (status === "
|
|
4264
|
+
if (status === "completed") {
|
|
4301
4265
|
step = /* @__PURE__ */ jsx(FailedStep, { icon: icons?.failed });
|
|
4302
4266
|
}
|
|
4303
|
-
if (status === "
|
|
4267
|
+
if (status === "failed") {
|
|
4304
4268
|
step = /* @__PURE__ */ jsx(SuccessStep, { icon: icons?.success });
|
|
4305
4269
|
}
|
|
4306
|
-
return /* @__PURE__ */ jsx(Dialog, { open: true, onOpenChange: () =>
|
|
4307
|
-
}, children: step });
|
|
4270
|
+
return /* @__PURE__ */ jsx(Dialog, { open: true, onOpenChange: () => reset(), children: step });
|
|
4308
4271
|
};
|
|
4309
4272
|
const useTokens = () => {
|
|
4310
4273
|
const { setTokens, setSelectedToken, setSelectedAssetSymbol } = useTokensStore();
|
|
@@ -4356,10 +4319,6 @@ const useChains = () => {
|
|
|
4356
4319
|
});
|
|
4357
4320
|
useEffect(() => {
|
|
4358
4321
|
if (query.isSuccess && query.data?.length) {
|
|
4359
|
-
console.log(
|
|
4360
|
-
`[DEBUG] Loaded ${query.data.length} chains from API:`,
|
|
4361
|
-
query.data.map((c) => c.chainKey)
|
|
4362
|
-
);
|
|
4363
4322
|
setChains(query.data);
|
|
4364
4323
|
if (!fromChain) {
|
|
4365
4324
|
setFromChain(query.data[0]);
|
|
@@ -4401,10 +4360,10 @@ class ChainStrategyRegistry {
|
|
|
4401
4360
|
const strategy = this.getStrategy(chainKey);
|
|
4402
4361
|
return strategy?.isConnected() || false;
|
|
4403
4362
|
}
|
|
4404
|
-
async getBalances(chainKey, address, tokens
|
|
4363
|
+
async getBalances(chainKey, address, tokens) {
|
|
4405
4364
|
const strategy = this.getStrategy(chainKey);
|
|
4406
4365
|
if (!strategy) return {};
|
|
4407
|
-
return await strategy.getBalances(address, tokens
|
|
4366
|
+
return await strategy.getBalances(address, tokens);
|
|
4408
4367
|
}
|
|
4409
4368
|
isAddressValid(chainKey, address) {
|
|
4410
4369
|
const strategy = this.getStrategy(chainKey);
|
|
@@ -4472,7 +4431,7 @@ function parseTonAddress(address) {
|
|
|
4472
4431
|
}
|
|
4473
4432
|
return Address$1.parse(address);
|
|
4474
4433
|
}
|
|
4475
|
-
async function getEvmBalances(publicClient, address, tokens
|
|
4434
|
+
async function getEvmBalances(publicClient, address, tokens) {
|
|
4476
4435
|
const balances = {};
|
|
4477
4436
|
try {
|
|
4478
4437
|
if (!address || !isAddress(address)) {
|
|
@@ -4484,56 +4443,8 @@ async function getEvmBalances(publicClient, address, tokens, priorityToken) {
|
|
|
4484
4443
|
}
|
|
4485
4444
|
const nativeTokens = tokens.filter((t) => isNativeAddress(t.address));
|
|
4486
4445
|
const erc20Tokens = tokens.filter(
|
|
4487
|
-
(t) => !isNativeAddress(t.address) && isAddress(t.address)
|
|
4446
|
+
(t) => !isNativeAddress(t.address) && isAddress(t.address)
|
|
4488
4447
|
);
|
|
4489
|
-
if (priorityToken) {
|
|
4490
|
-
try {
|
|
4491
|
-
const isPriorityNative = isNativeAddress(priorityToken.address);
|
|
4492
|
-
if (isPriorityNative) {
|
|
4493
|
-
const ethBalance = await publicClient.getBalance({
|
|
4494
|
-
address
|
|
4495
|
-
});
|
|
4496
|
-
const balance = parseFloat(
|
|
4497
|
-
formatUnits(ethBalance, priorityToken.decimals)
|
|
4498
|
-
);
|
|
4499
|
-
if (balance > 0) {
|
|
4500
|
-
balances[priorityToken.symbol] = { balance, address };
|
|
4501
|
-
}
|
|
4502
|
-
} else if (isAddress(priorityToken.address)) {
|
|
4503
|
-
const tokenBalance = await publicClient.readContract({
|
|
4504
|
-
address: priorityToken.address,
|
|
4505
|
-
abi: [
|
|
4506
|
-
{
|
|
4507
|
-
name: "balanceOf",
|
|
4508
|
-
type: "function",
|
|
4509
|
-
stateMutability: "view",
|
|
4510
|
-
inputs: [{ name: "owner", type: "address" }],
|
|
4511
|
-
outputs: [{ name: "balance", type: "uint256" }]
|
|
4512
|
-
}
|
|
4513
|
-
],
|
|
4514
|
-
functionName: "balanceOf",
|
|
4515
|
-
args: [address]
|
|
4516
|
-
});
|
|
4517
|
-
const balance = parseFloat(
|
|
4518
|
-
formatUnits(tokenBalance, priorityToken.decimals)
|
|
4519
|
-
);
|
|
4520
|
-
if (balance > 0) {
|
|
4521
|
-
balances[priorityToken.symbol] = { balance, address };
|
|
4522
|
-
}
|
|
4523
|
-
}
|
|
4524
|
-
} catch (error) {
|
|
4525
|
-
const errorMessage = error instanceof Error ? error.message : String(error);
|
|
4526
|
-
const isZeroDataError = errorMessage.includes(
|
|
4527
|
-
'returned no data ("0x")'
|
|
4528
|
-
);
|
|
4529
|
-
if (!isZeroDataError) {
|
|
4530
|
-
console.debug(
|
|
4531
|
-
`Failed to get priority token balance for ${priorityToken.symbol}:`,
|
|
4532
|
-
error
|
|
4533
|
-
);
|
|
4534
|
-
}
|
|
4535
|
-
}
|
|
4536
|
-
}
|
|
4537
4448
|
for (const token of nativeTokens) {
|
|
4538
4449
|
try {
|
|
4539
4450
|
const ethBalance = await publicClient.getBalance({
|
|
@@ -4757,13 +4668,11 @@ const ERC20_ABI = [
|
|
|
4757
4668
|
class EvmChainStrategy {
|
|
4758
4669
|
constructor(config) {
|
|
4759
4670
|
__publicField(this, "config");
|
|
4760
|
-
__publicField(this, "
|
|
4671
|
+
__publicField(this, "walletClient");
|
|
4761
4672
|
__publicField(this, "publicClient");
|
|
4762
4673
|
this.config = config;
|
|
4674
|
+
this.walletClient = config.walletClient;
|
|
4763
4675
|
this.publicClient = config.publicClient;
|
|
4764
|
-
if (config.walletClient) {
|
|
4765
|
-
this.provider = new BrowserProvider(config.walletClient.transport);
|
|
4766
|
-
}
|
|
4767
4676
|
}
|
|
4768
4677
|
canHandle(chainKey) {
|
|
4769
4678
|
const key = chainKey.toLowerCase();
|
|
@@ -4799,9 +4708,9 @@ class EvmChainStrategy {
|
|
|
4799
4708
|
return t("wallets.connectEvmWallet");
|
|
4800
4709
|
}
|
|
4801
4710
|
getClient() {
|
|
4802
|
-
return this.
|
|
4711
|
+
return this.walletClient;
|
|
4803
4712
|
}
|
|
4804
|
-
async getBalances(address, tokens
|
|
4713
|
+
async getBalances(address, tokens) {
|
|
4805
4714
|
if (!this.publicClient) {
|
|
4806
4715
|
console.warn("No publicClient available for balance query");
|
|
4807
4716
|
return {};
|
|
@@ -4809,8 +4718,7 @@ class EvmChainStrategy {
|
|
|
4809
4718
|
return await getEvmBalances(
|
|
4810
4719
|
this.publicClient,
|
|
4811
4720
|
address,
|
|
4812
|
-
tokens
|
|
4813
|
-
priorityToken
|
|
4721
|
+
tokens
|
|
4814
4722
|
);
|
|
4815
4723
|
}
|
|
4816
4724
|
isAddressValid(address) {
|
|
@@ -4836,7 +4744,7 @@ class EvmChainStrategy {
|
|
|
4836
4744
|
}
|
|
4837
4745
|
}
|
|
4838
4746
|
async executeSteps(steps, _context, onFirstHash) {
|
|
4839
|
-
if (!this.isConnected() || !this.
|
|
4747
|
+
if (!this.isConnected() || !this.walletClient) {
|
|
4840
4748
|
throw new WalletNotConnectedError("evm");
|
|
4841
4749
|
}
|
|
4842
4750
|
this.validateSteps(steps);
|
|
@@ -4880,18 +4788,18 @@ class EvmChainStrategy {
|
|
|
4880
4788
|
}
|
|
4881
4789
|
async waitForCompletion(txHash) {
|
|
4882
4790
|
try {
|
|
4883
|
-
const
|
|
4884
|
-
if (!
|
|
4791
|
+
const publicClient = this.publicClient;
|
|
4792
|
+
if (!publicClient) {
|
|
4885
4793
|
throw new ProviderNotAvailableError("evm");
|
|
4886
4794
|
}
|
|
4887
4795
|
console.log(
|
|
4888
4796
|
`Waiting for ${EVM_CONFIG.requiredConfirmations} confirmations for tx: ${txHash}`
|
|
4889
4797
|
);
|
|
4890
|
-
const receipt = await
|
|
4891
|
-
txHash,
|
|
4892
|
-
EVM_CONFIG.requiredConfirmations,
|
|
4893
|
-
EVM_CONFIG.timeout
|
|
4894
|
-
);
|
|
4798
|
+
const receipt = await publicClient.waitForTransactionReceipt({
|
|
4799
|
+
hash: txHash,
|
|
4800
|
+
confirmations: EVM_CONFIG.requiredConfirmations,
|
|
4801
|
+
timeout: EVM_CONFIG.timeout
|
|
4802
|
+
});
|
|
4895
4803
|
if (!receipt) {
|
|
4896
4804
|
const error = new TransactionTimeoutError("evm", txHash);
|
|
4897
4805
|
return {
|
|
@@ -4899,7 +4807,7 @@ class EvmChainStrategy {
|
|
|
4899
4807
|
error: error.message
|
|
4900
4808
|
};
|
|
4901
4809
|
}
|
|
4902
|
-
if (receipt.status !==
|
|
4810
|
+
if (receipt.status !== "success") {
|
|
4903
4811
|
const error = new TransactionRevertedError("evm", txHash);
|
|
4904
4812
|
return {
|
|
4905
4813
|
completed: false,
|
|
@@ -4912,11 +4820,10 @@ class EvmChainStrategy {
|
|
|
4912
4820
|
let actualFeeValue;
|
|
4913
4821
|
try {
|
|
4914
4822
|
const gasUsed = receipt.gasUsed;
|
|
4915
|
-
const effectiveGasPrice = receipt.
|
|
4823
|
+
const effectiveGasPrice = receipt.effectiveGasPrice;
|
|
4916
4824
|
if (gasUsed && effectiveGasPrice) {
|
|
4917
4825
|
const feeWei = gasUsed * effectiveGasPrice;
|
|
4918
|
-
const
|
|
4919
|
-
const feeInNative = formatUnits2(feeWei, 18);
|
|
4826
|
+
const feeInNative = formatUnits(feeWei, 18);
|
|
4920
4827
|
actualFeeValue = feeInNative;
|
|
4921
4828
|
console.log(`EVM transaction fee: ${feeInNative} (native token)`);
|
|
4922
4829
|
}
|
|
@@ -4943,11 +4850,10 @@ class EvmChainStrategy {
|
|
|
4943
4850
|
try {
|
|
4944
4851
|
const receipt = error.receipt;
|
|
4945
4852
|
const gasUsed = receipt.gasUsed;
|
|
4946
|
-
const effectiveGasPrice = receipt.
|
|
4853
|
+
const effectiveGasPrice = receipt.effectiveGasPrice;
|
|
4947
4854
|
if (gasUsed && effectiveGasPrice) {
|
|
4948
4855
|
const feeWei = gasUsed * effectiveGasPrice;
|
|
4949
|
-
const
|
|
4950
|
-
const feeInNative = formatUnits2(feeWei, 18);
|
|
4856
|
+
const feeInNative = formatUnits(feeWei, 18);
|
|
4951
4857
|
actualFeeValue = feeInNative;
|
|
4952
4858
|
console.log(
|
|
4953
4859
|
`Replacement transaction fee: ${feeInNative} (native token)`
|
|
@@ -4981,8 +4887,10 @@ class EvmChainStrategy {
|
|
|
4981
4887
|
}
|
|
4982
4888
|
}
|
|
4983
4889
|
async executeTransaction(step) {
|
|
4984
|
-
const
|
|
4985
|
-
|
|
4890
|
+
const walletClient = this.walletClient;
|
|
4891
|
+
if (!walletClient) {
|
|
4892
|
+
throw new WalletNotConnectedError("evm");
|
|
4893
|
+
}
|
|
4986
4894
|
if (!step.transaction) {
|
|
4987
4895
|
throw new InvalidTransactionDataError(
|
|
4988
4896
|
"evm",
|
|
@@ -4990,21 +4898,22 @@ class EvmChainStrategy {
|
|
|
4990
4898
|
);
|
|
4991
4899
|
}
|
|
4992
4900
|
const tx = step.transaction;
|
|
4993
|
-
const
|
|
4901
|
+
const hash = await walletClient.sendTransaction({
|
|
4994
4902
|
to: tx.to,
|
|
4995
4903
|
data: tx.data,
|
|
4996
|
-
|
|
4997
|
-
|
|
4998
|
-
|
|
4999
|
-
|
|
5000
|
-
|
|
5001
|
-
const txResponse = await signer?.sendTransaction(txRequest);
|
|
5002
|
-
return txResponse?.hash || "";
|
|
4904
|
+
account: tx.from || this.config.evmAddress,
|
|
4905
|
+
value: tx.value ? BigInt(tx.value) : void 0,
|
|
4906
|
+
chain: walletClient.chain
|
|
4907
|
+
});
|
|
4908
|
+
return hash;
|
|
5003
4909
|
}
|
|
5004
4910
|
async approveTransaction(step) {
|
|
5005
4911
|
try {
|
|
5006
|
-
const
|
|
5007
|
-
const
|
|
4912
|
+
const walletClient = this.walletClient;
|
|
4913
|
+
const publicClient = this.publicClient;
|
|
4914
|
+
if (!walletClient || !publicClient) {
|
|
4915
|
+
throw new WalletNotConnectedError("evm");
|
|
4916
|
+
}
|
|
5008
4917
|
if (!step.transaction) {
|
|
5009
4918
|
throw new InvalidTransactionDataError(
|
|
5010
4919
|
"evm",
|
|
@@ -5027,16 +4936,26 @@ class EvmChainStrategy {
|
|
|
5027
4936
|
);
|
|
5028
4937
|
}
|
|
5029
4938
|
const spenderAddress = "0x" + data.slice(34, 74);
|
|
5030
|
-
const amount = "0x" + data.slice(74, 138);
|
|
5031
|
-
const
|
|
5032
|
-
|
|
5033
|
-
|
|
5034
|
-
|
|
5035
|
-
|
|
4939
|
+
const amount = BigInt("0x" + data.slice(74, 138));
|
|
4940
|
+
const currentAllowance = await publicClient.readContract({
|
|
4941
|
+
address: tokenAddress,
|
|
4942
|
+
abi: ERC20_ABI,
|
|
4943
|
+
functionName: "allowance",
|
|
4944
|
+
args: [this.config.evmAddress, spenderAddress]
|
|
4945
|
+
});
|
|
5036
4946
|
if (currentAllowance > 0n) {
|
|
5037
4947
|
try {
|
|
5038
|
-
const
|
|
5039
|
-
|
|
4948
|
+
const resetHash = await walletClient.writeContract({
|
|
4949
|
+
address: tokenAddress,
|
|
4950
|
+
abi: ERC20_ABI,
|
|
4951
|
+
functionName: "approve",
|
|
4952
|
+
args: [spenderAddress, 0n],
|
|
4953
|
+
account: this.config.evmAddress,
|
|
4954
|
+
chain: walletClient.chain
|
|
4955
|
+
});
|
|
4956
|
+
await publicClient.waitForTransactionReceipt({
|
|
4957
|
+
hash: resetHash
|
|
4958
|
+
});
|
|
5040
4959
|
} catch (resetError) {
|
|
5041
4960
|
throw new TransactionFailedError(
|
|
5042
4961
|
"evm",
|
|
@@ -5049,8 +4968,15 @@ class EvmChainStrategy {
|
|
|
5049
4968
|
console.log("USDT allowance is 0, no reset needed");
|
|
5050
4969
|
}
|
|
5051
4970
|
try {
|
|
5052
|
-
const
|
|
5053
|
-
|
|
4971
|
+
const approveHash = await walletClient.writeContract({
|
|
4972
|
+
address: tokenAddress,
|
|
4973
|
+
abi: ERC20_ABI,
|
|
4974
|
+
functionName: "approve",
|
|
4975
|
+
args: [spenderAddress, amount],
|
|
4976
|
+
account: this.config.evmAddress,
|
|
4977
|
+
chain: walletClient.chain
|
|
4978
|
+
});
|
|
4979
|
+
return approveHash;
|
|
5054
4980
|
} catch (approveError) {
|
|
5055
4981
|
throw new TransactionFailedError(
|
|
5056
4982
|
"evm",
|
|
@@ -5068,13 +4994,24 @@ class EvmChainStrategy {
|
|
|
5068
4994
|
}
|
|
5069
4995
|
async checkAllowance(tokenAddress, spenderAddress, amount) {
|
|
5070
4996
|
try {
|
|
5071
|
-
const
|
|
5072
|
-
|
|
5073
|
-
|
|
5074
|
-
|
|
5075
|
-
|
|
5076
|
-
|
|
5077
|
-
|
|
4997
|
+
const publicClient = this.publicClient;
|
|
4998
|
+
if (!publicClient) {
|
|
4999
|
+
return false;
|
|
5000
|
+
}
|
|
5001
|
+
const allowance = await publicClient.readContract({
|
|
5002
|
+
address: tokenAddress,
|
|
5003
|
+
abi: ERC20_ABI,
|
|
5004
|
+
functionName: "allowance",
|
|
5005
|
+
args: [
|
|
5006
|
+
this.config.evmAddress,
|
|
5007
|
+
spenderAddress
|
|
5008
|
+
]
|
|
5009
|
+
});
|
|
5010
|
+
const decimals = await publicClient.readContract({
|
|
5011
|
+
address: tokenAddress,
|
|
5012
|
+
abi: ERC20_ABI,
|
|
5013
|
+
functionName: "decimals"
|
|
5014
|
+
});
|
|
5078
5015
|
const requiredAmount = parseUnits(amount, decimals);
|
|
5079
5016
|
return allowance >= requiredAmount;
|
|
5080
5017
|
} catch (error) {
|
|
@@ -5095,11 +5032,13 @@ class EvmChainStrategy {
|
|
|
5095
5032
|
*/
|
|
5096
5033
|
async checkFinality(blockNumber) {
|
|
5097
5034
|
try {
|
|
5098
|
-
const
|
|
5099
|
-
if (!
|
|
5035
|
+
const publicClient = this.publicClient;
|
|
5036
|
+
if (!publicClient) {
|
|
5100
5037
|
return false;
|
|
5101
5038
|
}
|
|
5102
|
-
const finalizedBlock = await
|
|
5039
|
+
const finalizedBlock = await publicClient.getBlock({
|
|
5040
|
+
blockTag: "finalized"
|
|
5041
|
+
});
|
|
5103
5042
|
if (!finalizedBlock) {
|
|
5104
5043
|
console.debug(
|
|
5105
5044
|
"Finalized block not available (pre-merge or unsupported)"
|
|
@@ -6883,7 +6822,7 @@ const EvaaBridgeContent = ({
|
|
|
6883
6822
|
}
|
|
6884
6823
|
),
|
|
6885
6824
|
/* @__PURE__ */ jsx(AnotherAddress, {}),
|
|
6886
|
-
/* @__PURE__ */ jsx(
|
|
6825
|
+
/* @__PURE__ */ jsx(MainButton, {})
|
|
6887
6826
|
] }),
|
|
6888
6827
|
/* @__PURE__ */ jsx(CardFooter, { className: "p-0", children: /* @__PURE__ */ jsx(Details, {}) })
|
|
6889
6828
|
]
|