@xswap-link/sdk 0.14.0 → 0.15.0
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/CHANGELOG.md +21 -0
- package/dist/index.d.mts +4 -0
- package/dist/index.d.ts +4 -0
- package/dist/index.global.js +92 -92
- package/dist/index.js +3208 -2862
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +3083 -2740
- package/dist/index.mjs.map +1 -1
- package/localTheme.ts +6 -4
- package/package.json +1 -1
- package/src/assets/icons/AdjustmentsIcon.tsx +5 -7
- package/src/assets/icons/ChainlinkMarkIcon.tsx +4 -5
- package/src/assets/icons/CheckCircleThinIcon.tsx +22 -0
- package/src/assets/icons/ChevronDownThinIcon.tsx +39 -0
- package/src/assets/icons/ChevronDownWideThinIcon.tsx +18 -0
- package/src/assets/icons/ChevronsUpDownThinIcon.tsx +21 -0
- package/src/assets/icons/ClockIcon.tsx +3 -7
- package/src/assets/icons/CloseIcon.tsx +9 -4
- package/src/assets/icons/ErrorCircleThinIcon.tsx +22 -0
- package/src/assets/icons/LinkExternalThinIcon.tsx +19 -0
- package/src/assets/icons/LoadingRingIcon.tsx +22 -0
- package/src/assets/icons/ProgressRingThinIcon.tsx +29 -0
- package/src/assets/icons/SearchThinIcon.tsx +15 -0
- package/src/assets/icons/SignThinIcon.tsx +15 -0
- package/src/assets/icons/WalletCheckThinIcon.tsx +24 -0
- package/src/assets/icons/WarningIcon.tsx +8 -5
- package/src/assets/icons/index.ts +11 -0
- package/src/components/Modal/index.tsx +14 -9
- package/src/components/PoweredBy/index.tsx +6 -8
- package/src/components/Swap/Header/index.tsx +2 -4
- package/src/components/Swap/HistoryView/ActivityCard/index.tsx +110 -115
- package/src/components/Swap/HistoryView/index.tsx +10 -7
- package/src/components/Swap/PickerView/index.tsx +151 -0
- package/src/components/Swap/ReorderButton/ReorderButton.tsx +4 -4
- package/src/components/Swap/SettingsView/Delivery/index.tsx +19 -17
- package/src/components/Swap/SettingsView/InfiniteApproval/index.tsx +19 -17
- package/src/components/Swap/SettingsView/Slippage/index.tsx +55 -49
- package/src/components/Swap/SwapView/ConfirmationView/TokenTiles/index.tsx +69 -0
- package/src/components/Swap/SwapView/ConfirmationView/TxOverview/Header/index.tsx +13 -25
- package/src/components/Swap/SwapView/ConfirmationView/TxOverview/Steps/index.tsx +65 -113
- package/src/components/Swap/SwapView/ConfirmationView/TxOverview/index.tsx +68 -26
- package/src/components/Swap/SwapView/ConfirmationView/TxResult/index.tsx +51 -74
- package/src/components/Swap/SwapView/FeesPanel/DeliveryInfo/index.tsx +1 -1
- package/src/components/Swap/SwapView/FeesPanel/index.tsx +5 -5
- package/src/components/Swap/SwapView/SwapButton/index.tsx +2 -31
- package/src/components/Swap/SwapView/SwapPanel/AmountPanel/Balance/index.tsx +2 -2
- package/src/components/Swap/SwapView/SwapPanel/AmountPanel/index.tsx +2 -2
- package/src/components/Swap/SwapView/SwapPanel/TokenPanel/ChainPicker/index.tsx +143 -0
- package/src/components/Swap/SwapView/SwapPanel/TokenPanel/TokenPicker/NetworkFilter/index.tsx +19 -16
- package/src/components/Swap/SwapView/SwapPanel/TokenPanel/TokenPicker/TokenItem/index.tsx +11 -4
- package/src/components/Swap/SwapView/SwapPanel/TokenPanel/TokenPicker/index.tsx +185 -105
- package/src/components/Swap/SwapView/SwapPanel/TokenPanel/index.tsx +54 -120
- package/src/components/Swap/SwapView/SwapPanel/UsdValue/index.tsx +2 -2
- package/src/components/Swap/SwapView/SwapPanel/WalletPanel/index.tsx +10 -16
- package/src/components/Swap/SwapView/SwapPanel/index.tsx +4 -4
- package/src/components/Swap/SwapView/WalletPicker/index.tsx +131 -139
- package/src/components/Swap/SwapView/index.tsx +11 -7
- package/src/components/Swap/WalletPickerView/index.tsx +65 -0
- package/src/components/Swap/index.tsx +39 -8
- package/src/components/ToggleButton/index.tsx +5 -7
- package/src/components/TokenLogo/index.tsx +1 -1
- package/src/components/TxConfigForm/index.tsx +2 -2
- package/src/components/TxModal/index.tsx +14 -4
- package/src/components/global.css +18 -1
- package/src/constants/index.ts +4 -0
- package/src/context/HistoryProvider.tsx +1 -1
- package/src/context/SwapProvider.tsx +193 -81
- package/src/context/TxUIWrapper.tsx +3 -3
- package/src/hooks/useEvmContractApi.ts +28 -4
- package/src/models/payloads/GetBalancesPayload.ts +1 -0
- package/src/services/api.ts +37 -0
- package/src/utils/index.ts +27 -1
- package/src/utils/tokens.ts +20 -1
- package/src/utils/validation.ts +9 -4
- package/tailwind.config.js +4 -1
- package/src/components/Swap/SwapView/ConfirmationView/TxOverview/ArrowIcon.tsx +0 -13
- package/src/components/Swap/SwapView/ConfirmationView/TxOverview/SwapPanel/index.tsx +0 -72
- package/src/components/Swap/SwapView/ConfirmationView/TxResult/TokenItem/index.tsx +0 -25
|
@@ -27,59 +27,65 @@ export const Slippage = () => {
|
|
|
27
27
|
};
|
|
28
28
|
|
|
29
29
|
return (
|
|
30
|
-
<div className="flex flex-col gap-
|
|
31
|
-
<div className="flex
|
|
32
|
-
<
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
<div className="flex items-center
|
|
42
|
-
<div className="flex items-center gap-3
|
|
43
|
-
<div className="flex items-center
|
|
44
|
-
<
|
|
30
|
+
<div className="flex flex-col gap-6 py-4 px-6 rounded-xl bg-gradient-to-r from-t_bg_tertiary/[0.03] to-t_bg_tertiary/[0.01]">
|
|
31
|
+
<div className="flex flex-col gap-4">
|
|
32
|
+
<div className="flex items-center gap-2">
|
|
33
|
+
<h2 className="text-sm leading-6 tracking-[0.01em] text-t_text_primary">
|
|
34
|
+
Price Tolerance
|
|
35
|
+
</h2>
|
|
36
|
+
<div className="w-0.5 h-0.5 bg-t_text_primary opacity-25 shrink-0" />
|
|
37
|
+
<p className="text-sm leading-6 tracking-[0.01em] text-t_text_primary text-opacity-50">
|
|
38
|
+
{`${Number(slippage).toFixed(2)}%`}
|
|
39
|
+
</p>
|
|
40
|
+
</div>
|
|
41
|
+
<div className="flex items-center gap-4 w-full">
|
|
42
|
+
<div className="flex items-center justify-between flex-1 h-12 gap-3 p-3 rounded-[10px] bg-gradient-to-r from-t_bg_tertiary/[0.02] to-t_bg_tertiary/[0.02] bg-[rgba(40,40,40,0.15)] border border-solid border-t_text_primary border-opacity-5">
|
|
43
|
+
<div className="flex items-center gap-3 min-w-0 flex-1">
|
|
44
|
+
<div className="flex items-center justify-center w-6 h-6 rounded bg-t_bg_tertiary bg-opacity-5 shrink-0">
|
|
45
|
+
<AdjustmentsIcon className="w-3.5 h-3.5 text-t_text_primary" />
|
|
46
|
+
</div>
|
|
47
|
+
<SafeInput
|
|
48
|
+
id="slippage-input"
|
|
49
|
+
placeholder="0.00"
|
|
50
|
+
regex={NUMBER_INPUT_REGEX}
|
|
51
|
+
value={customSlippage}
|
|
52
|
+
onChange={onInputChange}
|
|
53
|
+
className="text-sm leading-6 bg-transparent border-none px-0 w-full min-w-0 placeholder:text-t_text_primary placeholder:text-opacity-50 focus:outline-none text-t_text_primary"
|
|
54
|
+
/>
|
|
45
55
|
</div>
|
|
46
|
-
<
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
56
|
+
<span className="text-sm leading-6 text-t_text_primary text-opacity-50 shrink-0">
|
|
57
|
+
%
|
|
58
|
+
</span>
|
|
59
|
+
</div>
|
|
60
|
+
<div className="w-0.5 h-0.5 bg-t_text_primary opacity-25 shrink-0 hidden sm:block" />
|
|
61
|
+
<div className="flex items-center gap-2">
|
|
62
|
+
{presets.map((preset) => (
|
|
63
|
+
<button
|
|
64
|
+
key={preset}
|
|
65
|
+
type="button"
|
|
66
|
+
onClick={() => onInputChange(preset)}
|
|
67
|
+
className={`w-14 sm:w-[72px] h-12 px-3 rounded-[10px] text-sm leading-6 text-center transition-colors ${
|
|
68
|
+
slippage === preset
|
|
69
|
+
? "border border-solid border-t_main_accent_light/60 bg-gradient-to-r from-t_main_accent_light/10 to-t_main_accent_dark/10 text-t_text_primary"
|
|
70
|
+
: "bg-t_bg_tertiary bg-opacity-[0.04] text-t_text_primary text-opacity-60 hover:bg-opacity-10"
|
|
71
|
+
}`}
|
|
72
|
+
>
|
|
73
|
+
{`${preset}%`}
|
|
74
|
+
</button>
|
|
75
|
+
))}
|
|
54
76
|
</div>
|
|
55
|
-
<span className="text-sm leading-6 text-t_text_primary text-opacity-50 shrink-0">
|
|
56
|
-
%
|
|
57
|
-
</span>
|
|
58
|
-
</div>
|
|
59
|
-
<div className="w-0.5 h-0.5 bg-t_text_primary opacity-25 shrink-0 hidden sm:block" />
|
|
60
|
-
<div className="flex items-center gap-2">
|
|
61
|
-
{presets.map((preset) => (
|
|
62
|
-
<button
|
|
63
|
-
key={preset}
|
|
64
|
-
type="button"
|
|
65
|
-
onClick={() => onInputChange(preset)}
|
|
66
|
-
className={`w-14 sm:w-[72px] px-3 py-2.5 rounded-lg text-sm leading-5 tracking-[0.06em] text-center transition-colors ${
|
|
67
|
-
slippage === preset
|
|
68
|
-
? "bg-gradient-to-r from-t_main_accent_light/40 to-t_main_accent_dark/60 text-t_text_primary"
|
|
69
|
-
: "bg-t_bg_tertiary bg-opacity-5 text-t_text_primary text-opacity-75 hover:bg-opacity-10"
|
|
70
|
-
}`}
|
|
71
|
-
>
|
|
72
|
-
{`${preset}%`}
|
|
73
|
-
</button>
|
|
74
|
-
))}
|
|
75
77
|
</div>
|
|
76
78
|
</div>
|
|
77
|
-
<
|
|
78
|
-
<
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
79
|
+
<div className="flex flex-col gap-3">
|
|
80
|
+
<p className="text-[10px] font-medium leading-4 tracking-[0.015em] text-t_text_primary text-opacity-30">
|
|
81
|
+
NOTE.
|
|
82
|
+
</p>
|
|
83
|
+
<p className="text-sm leading-[18px] tracking-[0.01em] text-t_text_primary text-opacity-40">
|
|
84
|
+
{`Price Tolerance defines how much a price can change before your
|
|
85
|
+
transfer falls back to USDC. If the price moves more than your
|
|
86
|
+
tolerance allows, you'll receive USDC on your destination chain.`}
|
|
87
|
+
</p>
|
|
88
|
+
</div>
|
|
83
89
|
</div>
|
|
84
90
|
);
|
|
85
91
|
};
|
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
import { ChevronDownWideThinIcon } from "@src/assets/icons";
|
|
2
|
+
import { TokenLogoWithChain } from "@src/components";
|
|
3
|
+
import { useSwapContext } from "@src/context";
|
|
4
|
+
import { Ecosystem } from "@src/models";
|
|
5
|
+
import { useMemo } from "react";
|
|
6
|
+
import { SwapPanelType } from "../../index";
|
|
7
|
+
|
|
8
|
+
const TokenTile = ({ type }: { type: SwapPanelType }) => {
|
|
9
|
+
const {
|
|
10
|
+
srcToken,
|
|
11
|
+
srcChain,
|
|
12
|
+
dstToken,
|
|
13
|
+
dstChain,
|
|
14
|
+
srcValue,
|
|
15
|
+
dstValue,
|
|
16
|
+
bridgeUI,
|
|
17
|
+
} = useSwapContext();
|
|
18
|
+
|
|
19
|
+
const token = type === "source" ? srcToken : dstToken;
|
|
20
|
+
const chain = type === "source" ? srcChain : dstChain;
|
|
21
|
+
|
|
22
|
+
const value = useMemo(() => {
|
|
23
|
+
if (
|
|
24
|
+
type === "destination" &&
|
|
25
|
+
bridgeUI &&
|
|
26
|
+
srcChain?.ecosystem === Ecosystem.SOLANA
|
|
27
|
+
) {
|
|
28
|
+
return srcValue;
|
|
29
|
+
}
|
|
30
|
+
return type === "source" ? srcValue : dstValue;
|
|
31
|
+
}, [type, bridgeUI, srcChain?.ecosystem, srcValue, dstValue]);
|
|
32
|
+
|
|
33
|
+
return (
|
|
34
|
+
<div className="flex items-center justify-between gap-4 h-[72px] px-4 sm:px-6 rounded-xl backdrop-blur-[12px] bg-t_bg_tertiary bg-opacity-5">
|
|
35
|
+
<div className="text-2xl leading-6 text-t_text_primary opacity-50 truncate min-w-0">
|
|
36
|
+
{value}
|
|
37
|
+
</div>
|
|
38
|
+
<div className="flex items-center gap-3 shrink-0">
|
|
39
|
+
<p className="text-sm font-medium leading-6 tracking-[0.01em] text-t_text_primary">
|
|
40
|
+
{token?.symbol}
|
|
41
|
+
</p>
|
|
42
|
+
<TokenLogoWithChain
|
|
43
|
+
token={token}
|
|
44
|
+
chain={chain}
|
|
45
|
+
tokenLogoClassName="w-10 h-10"
|
|
46
|
+
generatedLogoClassName="w-10 h-10 text-[16px]"
|
|
47
|
+
chainLogoClassName="w-[18px]"
|
|
48
|
+
/>
|
|
49
|
+
</div>
|
|
50
|
+
</div>
|
|
51
|
+
);
|
|
52
|
+
};
|
|
53
|
+
|
|
54
|
+
/** Source and destination amounts of the pending swap as two stacked tiles
|
|
55
|
+
* with a decorative direction marker between them. */
|
|
56
|
+
export const TokenTiles = () => {
|
|
57
|
+
return (
|
|
58
|
+
<div className="flex flex-col gap-1.5">
|
|
59
|
+
<TokenTile type="source" />
|
|
60
|
+
{/* Zero-height anchor between the tiles, like ReorderButton in SwapView */}
|
|
61
|
+
<div className="h-0 w-full relative z-[1]">
|
|
62
|
+
<div className="absolute left-1/2 -translate-x-1/2 -translate-y-1/2 flex items-center justify-center w-8 h-8 rounded-md backdrop-blur-[24px] bg-t_bg_secondary bg-opacity-50 bg-gradient-to-b from-t_bg_tertiary/10 to-t_bg_tertiary/[0.08]">
|
|
63
|
+
<ChevronDownWideThinIcon className="w-6 h-6 text-t_text_primary opacity-50" />
|
|
64
|
+
</div>
|
|
65
|
+
</div>
|
|
66
|
+
<TokenTile type="destination" />
|
|
67
|
+
</div>
|
|
68
|
+
);
|
|
69
|
+
};
|
|
@@ -1,37 +1,25 @@
|
|
|
1
|
-
import { CloseIcon
|
|
2
|
-
import { Tooltip } from "@src/components/Tooltip/index";
|
|
3
|
-
import { useRef } from "react";
|
|
1
|
+
import { CloseIcon } from "@src/assets/icons";
|
|
4
2
|
|
|
5
3
|
type Props = {
|
|
6
4
|
onCloseClick: () => void;
|
|
7
5
|
};
|
|
8
6
|
|
|
9
7
|
export const Header = ({ onCloseClick }: Props) => {
|
|
10
|
-
const tooltipTriggerRef = useRef<SVGSVGElement>(null);
|
|
11
|
-
|
|
12
8
|
return (
|
|
13
|
-
<div className="flex justify-between items-center
|
|
14
|
-
<div className="text-t_text_primary">
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
<
|
|
24
|
-
ref={tooltipTriggerRef}
|
|
25
|
-
className="cursor-help fill-t_main_accent_light w-[18px] h-[18px]"
|
|
26
|
-
/>
|
|
27
|
-
|
|
28
|
-
<div
|
|
29
|
-
className="w-4 h-4 fill-t_text_primary cursor-pointer"
|
|
30
|
-
onClick={onCloseClick}
|
|
31
|
-
>
|
|
9
|
+
<div className="flex justify-between items-center gap-6">
|
|
10
|
+
<div className="text-2xl leading-8 tracking-[0.01em] text-t_text_primary">
|
|
11
|
+
Confirmation
|
|
12
|
+
</div>
|
|
13
|
+
<button
|
|
14
|
+
type="button"
|
|
15
|
+
onClick={onCloseClick}
|
|
16
|
+
aria-label="Close"
|
|
17
|
+
className="flex items-center justify-center shrink-0 w-8 h-8 rounded-md bg-t_bg_tertiary bg-opacity-5 text-t_text_primary hover:bg-opacity-10 transition-colors"
|
|
18
|
+
>
|
|
19
|
+
<div className="w-4 h-4 opacity-50 fill-t_text_primary flex items-center justify-center">
|
|
32
20
|
<CloseIcon />
|
|
33
21
|
</div>
|
|
34
|
-
</
|
|
22
|
+
</button>
|
|
35
23
|
</div>
|
|
36
24
|
);
|
|
37
25
|
};
|
|
@@ -1,101 +1,57 @@
|
|
|
1
1
|
import {
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
2
|
+
CheckCircleThinIcon,
|
|
3
|
+
ProgressRingThinIcon,
|
|
4
|
+
SignThinIcon,
|
|
5
|
+
WalletCheckThinIcon,
|
|
6
6
|
} from "@src/assets/icons";
|
|
7
7
|
import { useTxUIWrapper } from "@src/context";
|
|
8
8
|
import { TxStatus } from "@src/models";
|
|
9
9
|
import { ReactElement, useMemo } from "react";
|
|
10
10
|
|
|
11
|
+
type StepState = "pending" | "active" | "completed";
|
|
12
|
+
|
|
11
13
|
type Step = {
|
|
12
|
-
icon:
|
|
14
|
+
icon: ReactElement;
|
|
13
15
|
title: string;
|
|
14
|
-
state:
|
|
16
|
+
state: StepState;
|
|
15
17
|
show: boolean;
|
|
16
18
|
};
|
|
17
19
|
|
|
18
|
-
// TODO item's 'show' logic is a bit complicated/weird. Think about an improvement...
|
|
19
20
|
export const Steps = () => {
|
|
20
21
|
const { txStatus, txNeedsApproval, txMsg } = useTxUIWrapper();
|
|
21
22
|
|
|
22
|
-
const items: Step[] = useMemo(
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
title: "sign approval transaction",
|
|
31
|
-
state:
|
|
32
|
-
txStatus === TxStatus.SIGNING_APPROVAL
|
|
33
|
-
? "triggered"
|
|
34
|
-
: txStatus > TxStatus.SIGNING_APPROVAL
|
|
35
|
-
? "completed"
|
|
36
|
-
: "none",
|
|
37
|
-
show: txMsg
|
|
38
|
-
? txStatus === TxStatus.SIGNING_APPROVAL ||
|
|
39
|
-
txStatus === TxStatus.CONFIRMING_APPROVAL
|
|
40
|
-
: txNeedsApproval,
|
|
41
|
-
},
|
|
42
|
-
{
|
|
43
|
-
icon: (className) => (
|
|
44
|
-
<div className={`${className}`}>
|
|
45
|
-
<ThumbUpRoundedIcon />
|
|
46
|
-
</div>
|
|
47
|
-
),
|
|
48
|
-
title: "confirming approval transaction...",
|
|
49
|
-
state:
|
|
50
|
-
txStatus === TxStatus.CONFIRMING_APPROVAL
|
|
51
|
-
? "triggered"
|
|
52
|
-
: txStatus > TxStatus.CONFIRMING_APPROVAL
|
|
53
|
-
? "completed"
|
|
54
|
-
: "none",
|
|
55
|
-
show: txMsg
|
|
56
|
-
? txStatus === TxStatus.SIGNING_APPROVAL ||
|
|
57
|
-
txStatus === TxStatus.CONFIRMING_APPROVAL
|
|
58
|
-
: txNeedsApproval,
|
|
59
|
-
},
|
|
23
|
+
const items: Step[] = useMemo(() => {
|
|
24
|
+
const approvalActive =
|
|
25
|
+
txStatus === TxStatus.SIGNING_APPROVAL ||
|
|
26
|
+
txStatus === TxStatus.CONFIRMING_APPROVAL;
|
|
27
|
+
const txActive =
|
|
28
|
+
txStatus === TxStatus.SIGNING_TX || txStatus === TxStatus.CONFIRMING_TX;
|
|
29
|
+
|
|
30
|
+
return [
|
|
60
31
|
{
|
|
61
|
-
icon:
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
? "completed"
|
|
72
|
-
: "none",
|
|
73
|
-
show: txMsg
|
|
74
|
-
? txStatus === TxStatus.SIGNING_TX ||
|
|
75
|
-
txStatus === TxStatus.CONFIRMING_TX
|
|
76
|
-
: true,
|
|
32
|
+
icon: <SignThinIcon className="w-6 h-6" />,
|
|
33
|
+
title: "Please, approve spending first.",
|
|
34
|
+
state: approvalActive
|
|
35
|
+
? "active"
|
|
36
|
+
: txStatus > TxStatus.CONFIRMING_APPROVAL
|
|
37
|
+
? "completed"
|
|
38
|
+
: "pending",
|
|
39
|
+
// With a custom tx message (e.g. approval reset) the modal only runs
|
|
40
|
+
// that single transaction, so show just the step it is on.
|
|
41
|
+
show: txMsg ? approvalActive : txNeedsApproval,
|
|
77
42
|
},
|
|
78
43
|
{
|
|
79
|
-
icon:
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
? "triggered"
|
|
88
|
-
: txStatus > TxStatus.CONFIRMING_TX
|
|
89
|
-
? "completed"
|
|
90
|
-
: "none",
|
|
91
|
-
show: txMsg
|
|
92
|
-
? txStatus === TxStatus.SIGNING_TX ||
|
|
93
|
-
txStatus === TxStatus.CONFIRMING_TX
|
|
94
|
-
: true,
|
|
44
|
+
icon: <WalletCheckThinIcon className="w-6 h-6" />,
|
|
45
|
+
title: "Confirm transaction in your wallet.",
|
|
46
|
+
state: txActive
|
|
47
|
+
? "active"
|
|
48
|
+
: txStatus > TxStatus.CONFIRMING_TX
|
|
49
|
+
? "completed"
|
|
50
|
+
: "pending",
|
|
51
|
+
show: txMsg ? txActive : true,
|
|
95
52
|
},
|
|
96
|
-
]
|
|
97
|
-
|
|
98
|
-
);
|
|
53
|
+
];
|
|
54
|
+
}, [txMsg, txNeedsApproval, txStatus]);
|
|
99
55
|
|
|
100
56
|
const filteredItems = useMemo(
|
|
101
57
|
() => items.filter(({ show }) => show),
|
|
@@ -103,42 +59,38 @@ export const Steps = () => {
|
|
|
103
59
|
);
|
|
104
60
|
|
|
105
61
|
return (
|
|
106
|
-
<div className="flex flex-col
|
|
107
|
-
{filteredItems.map(({ icon, title, state }
|
|
108
|
-
<div
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
}`}
|
|
124
|
-
>
|
|
125
|
-
{title}
|
|
126
|
-
</div>
|
|
62
|
+
<div className="flex flex-col rounded-xl bg-t_bg_tertiary bg-opacity-[0.02]">
|
|
63
|
+
{filteredItems.map(({ icon, title, state }) => (
|
|
64
|
+
<div
|
|
65
|
+
key={title}
|
|
66
|
+
className={`flex items-center justify-between gap-4 px-4 sm:px-6 py-4 rounded-lg ${
|
|
67
|
+
state === "active"
|
|
68
|
+
? "bg-gradient-to-r from-transparent via-t_bg_tertiary/5 to-transparent"
|
|
69
|
+
: ""
|
|
70
|
+
}`}
|
|
71
|
+
>
|
|
72
|
+
<div className="flex items-center gap-4">
|
|
73
|
+
<div
|
|
74
|
+
className={`text-t_text_primary ${
|
|
75
|
+
state === "active" ? "opacity-50" : "opacity-25"
|
|
76
|
+
}`}
|
|
77
|
+
>
|
|
78
|
+
{icon}
|
|
127
79
|
</div>
|
|
128
|
-
<div
|
|
129
|
-
{
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
<div className="animate-spin-slow fill-t_main_accent_light">
|
|
135
|
-
<WaitingIcon />
|
|
136
|
-
</div>
|
|
137
|
-
) : null}
|
|
80
|
+
<div
|
|
81
|
+
className={`text-sm leading-5 tracking-[0.01em] text-t_text_primary ${
|
|
82
|
+
state === "active" ? "text-opacity-75" : "text-opacity-50"
|
|
83
|
+
}`}
|
|
84
|
+
>
|
|
85
|
+
{title}
|
|
138
86
|
</div>
|
|
139
87
|
</div>
|
|
140
|
-
{
|
|
141
|
-
<
|
|
88
|
+
{state === "completed" ? (
|
|
89
|
+
<CheckCircleThinIcon className="w-6 h-6 shrink-0 text-[#6AE89B]" />
|
|
90
|
+
) : state === "active" ? (
|
|
91
|
+
<ProgressRingThinIcon className="w-6 h-6 shrink-0 animate-spin-slow text-t_text_primary" />
|
|
92
|
+
) : (
|
|
93
|
+
<div className="w-6 h-6 shrink-0 rounded-full border border-solid border-t_text_primary border-opacity-20" />
|
|
142
94
|
)}
|
|
143
95
|
</div>
|
|
144
96
|
))}
|
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
import { Button } from "@src/components";
|
|
2
1
|
import {
|
|
3
2
|
CCIP_ROUTER_PROGRAM_ID,
|
|
4
3
|
FALLBACK_CROSSCHAIN_ESTIMATION_TIME,
|
|
@@ -11,11 +10,12 @@ import {
|
|
|
11
10
|
crosschainEstimationTimes,
|
|
12
11
|
} from "@src/constants";
|
|
13
12
|
import { useHistory, useSwapContext, useTxUIWrapper } from "@src/context";
|
|
14
|
-
import { ADDRESSES, XSwapRouterAbi } from "@src/contracts";
|
|
13
|
+
import { ADDRESSES, ERC20Abi, XSwapRouterAbi } from "@src/contracts";
|
|
15
14
|
import { useEvmContractApi } from "@src/hooks";
|
|
16
15
|
import useNetworks from "@src/hooks/networkManagement/useNetworks";
|
|
17
16
|
import {
|
|
18
17
|
Ecosystem,
|
|
18
|
+
TransactionRequest,
|
|
19
19
|
TxStatus,
|
|
20
20
|
Transaction as EVMTransaction,
|
|
21
21
|
} from "@src/models";
|
|
@@ -23,10 +23,9 @@ import { renderTxStatus } from "@src/services";
|
|
|
23
23
|
import { ContractReceipt, constants, ethers } from "ethers";
|
|
24
24
|
import { useCallback } from "react";
|
|
25
25
|
import { FeesPanel } from "../../FeesPanel";
|
|
26
|
-
import {
|
|
26
|
+
import { TokenTiles } from "../TokenTiles";
|
|
27
27
|
import { Header } from "./Header";
|
|
28
28
|
import { Steps } from "./Steps";
|
|
29
|
-
import { SwapPanel } from "./SwapPanel";
|
|
30
29
|
import { useWallet } from "@solana/wallet-adapter-react";
|
|
31
30
|
|
|
32
31
|
import {
|
|
@@ -206,7 +205,7 @@ export const TxOverview = ({ onCloseClick }: Props) => {
|
|
|
206
205
|
const enqueueSwapTx = useCallback(async () => {
|
|
207
206
|
if (srcToken) {
|
|
208
207
|
if (route && route.ecosystem === Ecosystem.EVM) {
|
|
209
|
-
const enqueueSwap = () => {
|
|
208
|
+
const enqueueSwap = ({ afterApproval = false } = {}) => {
|
|
210
209
|
enqueueTransaction({
|
|
211
210
|
executeTransaction: () => {
|
|
212
211
|
if (!route.transactions.swap || !signer) {
|
|
@@ -216,6 +215,9 @@ export const TxOverview = ({ onCloseClick }: Props) => {
|
|
|
216
215
|
return evmContractApi.executeCalldata(
|
|
217
216
|
signer,
|
|
218
217
|
route.transactions.swap,
|
|
218
|
+
// right after an approval the RPC may not see the new
|
|
219
|
+
// allowance yet, so let the gas estimation retry
|
|
220
|
+
{ retryGasEstimation: afterApproval },
|
|
219
221
|
);
|
|
220
222
|
},
|
|
221
223
|
txStatus: TxStatus.SIGNING_TX,
|
|
@@ -258,7 +260,15 @@ export const TxOverview = ({ onCloseClick }: Props) => {
|
|
|
258
260
|
},
|
|
259
261
|
txStatus: TxStatus.SIGNING_APPROVAL,
|
|
260
262
|
handlers: {
|
|
261
|
-
onSuccess: () =>
|
|
263
|
+
onSuccess: async () => {
|
|
264
|
+
if (signer && route.transactions.approve) {
|
|
265
|
+
await waitForApprovalAllowance(
|
|
266
|
+
signer,
|
|
267
|
+
route.transactions.approve,
|
|
268
|
+
);
|
|
269
|
+
}
|
|
270
|
+
enqueueSwap({ afterApproval: true });
|
|
271
|
+
},
|
|
262
272
|
},
|
|
263
273
|
});
|
|
264
274
|
} else {
|
|
@@ -431,31 +441,29 @@ export const TxOverview = ({ onCloseClick }: Props) => {
|
|
|
431
441
|
]);
|
|
432
442
|
|
|
433
443
|
return (
|
|
434
|
-
<div className="flex flex-col text-t_text_primary gap-
|
|
444
|
+
<div className="flex flex-col text-t_text_primary gap-8">
|
|
435
445
|
<Header onCloseClick={onCloseClick} />
|
|
436
446
|
{txMsg ? (
|
|
437
|
-
<div>
|
|
447
|
+
<div className="text-sm leading-5 tracking-[0.01em] text-t_text_primary text-opacity-75">
|
|
448
|
+
{txMsg}
|
|
449
|
+
</div>
|
|
438
450
|
) : (
|
|
439
|
-
|
|
440
|
-
<div className="relative flex flex-col gap-5 fill-white">
|
|
441
|
-
<SwapPanel type="source" />
|
|
442
|
-
<ArrowIcon />
|
|
443
|
-
<SwapPanel type="destination" />
|
|
444
|
-
</div>
|
|
445
|
-
<FeesPanel />
|
|
446
|
-
</>
|
|
451
|
+
<TokenTiles />
|
|
447
452
|
)}
|
|
453
|
+
<div className="h-px w-full gradient-sections-separator-container" />
|
|
448
454
|
{txStatus === TxStatus.SWAP_INIT ? (
|
|
449
|
-
|
|
450
|
-
|
|
451
|
-
|
|
452
|
-
|
|
453
|
-
|
|
454
|
-
|
|
455
|
-
|
|
456
|
-
|
|
457
|
-
|
|
458
|
-
|
|
455
|
+
<>
|
|
456
|
+
{!txMsg && <FeesPanel />}
|
|
457
|
+
<button
|
|
458
|
+
type="button"
|
|
459
|
+
onClick={() => {
|
|
460
|
+
enqueueSwapTx();
|
|
461
|
+
}}
|
|
462
|
+
className="text-base font-medium leading-6 tracking-[0.01em] w-full px-6 py-3 cursor-pointer rounded-lg border-none transition-[filter] bg-gradient-to-b from-t_main_accent_light from-50% to-t_main_accent_dark text-t_button_pr_text hover:brightness-105"
|
|
463
|
+
>
|
|
464
|
+
Sign and swap
|
|
465
|
+
</button>
|
|
466
|
+
</>
|
|
459
467
|
) : (
|
|
460
468
|
<Steps />
|
|
461
469
|
)}
|
|
@@ -463,6 +471,40 @@ export const TxOverview = ({ onCloseClick }: Props) => {
|
|
|
463
471
|
);
|
|
464
472
|
};
|
|
465
473
|
|
|
474
|
+
const ALLOWANCE_POLL_INTERVAL_MS = 500;
|
|
475
|
+
const ALLOWANCE_POLL_MAX_ATTEMPTS = 10;
|
|
476
|
+
|
|
477
|
+
// After an approval is mined, RPC nodes behind a load balancer may still
|
|
478
|
+
// return the stale allowance for a while, which makes the swap's gas
|
|
479
|
+
// estimation revert. Poll until the approved amount is visible (or give up
|
|
480
|
+
// after ~5s and let the gas estimation retry handle the rest).
|
|
481
|
+
async function waitForApprovalAllowance(
|
|
482
|
+
signer: ethers.Signer,
|
|
483
|
+
approveTx: TransactionRequest,
|
|
484
|
+
) {
|
|
485
|
+
try {
|
|
486
|
+
const erc20 = new ethers.Contract(approveTx.to, ERC20Abi, signer);
|
|
487
|
+
const [spender, amount] = erc20.interface.decodeFunctionData(
|
|
488
|
+
"approve",
|
|
489
|
+
approveTx.data,
|
|
490
|
+
);
|
|
491
|
+
const owner = await signer.getAddress();
|
|
492
|
+
for (let attempt = 0; attempt < ALLOWANCE_POLL_MAX_ATTEMPTS; attempt++) {
|
|
493
|
+
const currentAllowance = await erc20.allowance(owner, spender);
|
|
494
|
+
if (currentAllowance.gte(amount)) {
|
|
495
|
+
return;
|
|
496
|
+
}
|
|
497
|
+
await new Promise((resolve) =>
|
|
498
|
+
setTimeout(resolve, ALLOWANCE_POLL_INTERVAL_MS),
|
|
499
|
+
);
|
|
500
|
+
}
|
|
501
|
+
} catch (err) {
|
|
502
|
+
// best-effort — non-standard approve calldata or a failing allowance
|
|
503
|
+
// call shouldn't block the swap
|
|
504
|
+
console.error("Failed to poll allowance after approval:", err);
|
|
505
|
+
}
|
|
506
|
+
}
|
|
507
|
+
|
|
466
508
|
// Add this function to check token delegation and delegate if necessary
|
|
467
509
|
async function checkAndDelegateTokenAuthority(
|
|
468
510
|
connection: Connection,
|