@xswap-link/sdk 0.3.5 → 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/.eslintrc.json +9 -5
- package/CHANGELOG.md +16 -0
- package/README.md +2 -1
- package/dist/index.d.mts +106 -20
- package/dist/index.d.ts +106 -20
- package/dist/index.global.js +856 -307
- package/dist/index.global.js.map +1 -0
- package/dist/index.js +105 -3564
- package/dist/index.js.map +1 -0
- package/dist/index.mjs +105 -3534
- package/dist/index.mjs.map +1 -0
- package/nodemon.json +1 -1
- package/package.json +16 -9
- package/postcss.config.js +8 -1
- package/src/{components → assets}/icons/ArrowDownIcon.tsx +1 -2
- package/src/assets/icons/ArrowDownLongIcon.tsx +12 -0
- package/src/{components → assets}/icons/ArrowLeftIcon.tsx +1 -5
- package/src/{components → assets}/icons/ArrowRightIcon.tsx +1 -5
- package/src/assets/icons/ArrowUpIcon.tsx +12 -0
- package/src/{components → assets}/icons/ArrowUpRightIcon.tsx +1 -5
- package/src/assets/icons/CashbacklIcon.tsx +28 -0
- package/src/{components → assets}/icons/CheckIcon.tsx +1 -5
- package/src/assets/icons/ChevronDownIcon.tsx +12 -0
- package/src/assets/icons/ChevronUpIcon.tsx +7 -0
- package/src/{components → assets}/icons/CircularProgressIcon.tsx +1 -2
- package/src/assets/icons/CloseIcon.tsx +15 -0
- package/src/{components → assets}/icons/CoinsIcon.tsx +0 -2
- package/src/assets/icons/CopyIcon.tsx +15 -0
- package/src/assets/icons/DotGreenIcon.tsx +12 -0
- package/src/{components → assets}/icons/DownArrorIcon.tsx +0 -2
- package/src/{components → assets}/icons/ErrorIcon.tsx +0 -1
- package/src/assets/icons/ErrorModalStatusIcon.tsx +31 -0
- package/src/assets/icons/HelpIcon.tsx +21 -0
- package/src/assets/icons/HistoryGradientBgIcon.tsx +32 -0
- package/src/assets/icons/HistoryIcon.tsx +12 -0
- package/src/{components → assets}/icons/HourGlassIcon.tsx +1 -5
- package/src/assets/icons/Icon.tsx +5 -0
- package/src/{components → assets}/icons/InfoIcon.tsx +0 -1
- package/src/assets/icons/LinkExternalIcon.tsx +15 -0
- package/src/{components → assets}/icons/PercentageIcon.tsx +0 -1
- package/src/assets/icons/RankIcon.tsx +28 -0
- package/src/assets/icons/SettingsGradientBgIcon.tsx +32 -0
- package/src/assets/icons/SettingsIcon.tsx +12 -0
- package/src/{components → assets}/icons/SignIcon.tsx +0 -2
- package/src/{components → assets}/icons/SuccessIcon.tsx +0 -1
- package/src/assets/icons/SuccessModalStatusIcon.tsx +31 -0
- package/src/assets/icons/ThumbUpRoundedIcon.tsx +15 -0
- package/src/{components → assets}/icons/TimerIcon.tsx +0 -1
- package/src/assets/icons/TokensIcon.tsx +16 -0
- package/src/assets/icons/WaitingIcon.tsx +15 -0
- package/src/{components → assets}/icons/XMarkIcon.tsx +1 -5
- package/src/assets/icons/XPowerIcon.tsx +28 -0
- package/src/{components → assets}/icons/index.ts +16 -0
- package/src/components/Alert/index.tsx +1 -1
- package/src/components/Button/index.tsx +57 -0
- package/src/components/MessageBar/SnackMessage.tsx +32 -0
- package/src/components/MessageBar/index.tsx +44 -0
- package/src/components/Modal/index.tsx +52 -0
- package/src/components/PoweredBy/index.tsx +12 -0
- package/src/components/SafeInput/index.tsx +51 -0
- package/src/components/Skeleton/index.tsx +5 -9
- package/src/components/Spinner/index.tsx +6 -8
- package/src/components/Swap/Header/Controls/index.tsx +57 -0
- package/src/components/Swap/Header/index.tsx +16 -0
- package/src/components/Swap/HistoryView/index.tsx +34 -0
- package/src/components/Swap/SettingsView/Delivery/index.tsx +42 -0
- package/src/components/Swap/SettingsView/Slippage/index.tsx +80 -0
- package/src/components/Swap/SettingsView/index.tsx +11 -0
- package/src/components/Swap/SwapView/ConfirmationView/TxOverview/ArrowIcon.tsx +13 -0
- package/src/components/Swap/SwapView/ConfirmationView/TxOverview/Header/index.tsx +37 -0
- package/src/components/Swap/SwapView/ConfirmationView/TxOverview/Steps/index.tsx +145 -0
- package/src/components/Swap/SwapView/ConfirmationView/TxOverview/SwapPanel/index.tsx +61 -0
- package/src/components/Swap/SwapView/ConfirmationView/TxOverview/index.tsx +291 -0
- package/src/components/Swap/SwapView/ConfirmationView/TxResult/TokenItem/index.tsx +24 -0
- package/src/components/Swap/SwapView/ConfirmationView/TxResult/index.tsx +84 -0
- package/src/components/Swap/SwapView/ConfirmationView/index.tsx +17 -0
- package/src/components/Swap/SwapView/FeesPanel/DeliveryInfo/index.tsx +25 -0
- package/src/components/Swap/SwapView/FeesPanel/Fee/index.tsx +18 -0
- package/src/components/Swap/SwapView/FeesPanel/Fees/index.tsx +71 -0
- package/src/components/Swap/SwapView/FeesPanel/index.tsx +67 -0
- package/src/components/Swap/SwapView/SwapButton/index.tsx +154 -0
- package/src/components/Swap/SwapView/SwapPanel/AmountPanel/Balance/index.tsx +23 -0
- package/src/components/Swap/SwapView/SwapPanel/AmountPanel/index.tsx +56 -0
- package/src/components/Swap/SwapView/SwapPanel/ChainPanel/ChainPicker/ChainItem/index.tsx +70 -0
- package/src/components/Swap/SwapView/SwapPanel/ChainPanel/ChainPicker/index.tsx +62 -0
- package/src/components/Swap/SwapView/SwapPanel/ChainPanel/index.tsx +74 -0
- package/src/components/Swap/SwapView/SwapPanel/MaxPanel/index.tsx +35 -0
- package/src/components/Swap/SwapView/SwapPanel/TokenPanel/TokenPicker/QuickPickTokenItem/index.tsx +40 -0
- package/src/components/Swap/SwapView/SwapPanel/TokenPanel/TokenPicker/TokenItem/index.tsx +62 -0
- package/src/components/Swap/SwapView/SwapPanel/TokenPanel/TokenPicker/index.tsx +399 -0
- package/src/components/Swap/SwapView/SwapPanel/TokenPanel/index.tsx +104 -0
- package/src/components/Swap/SwapView/SwapPanel/index.tsx +42 -0
- package/src/components/Swap/SwapView/index.tsx +20 -0
- package/src/components/Swap/index.tsx +34 -0
- package/src/components/TextInput/index.tsx +67 -0
- package/src/components/Timer/index.tsx +57 -0
- package/src/components/ToggleButton/index.tsx +24 -0
- package/src/components/{UnknownTokenLogo/UnknownTokenLogo.tsx → TokenLogo/Unknown/index.tsx} +3 -4
- package/src/components/TokenLogo/WithChain/index.tsx +34 -0
- package/src/components/TokenLogo/index.tsx +22 -0
- package/src/components/Tooltip/index.tsx +108 -0
- package/src/components/TxConfigForm/index.tsx +63 -42
- package/src/components/TxDataCard/TokenDetails/index.tsx +30 -0
- package/src/components/TxDataCard/TxDataCardUI/index.tsx +133 -0
- package/src/components/TxDataCard/index.tsx +30 -0
- package/src/components/TxStatusButton/index.tsx +64 -108
- package/src/components/global.css +115 -4
- package/src/components/index.ts +18 -1
- package/src/config/fonts.ts +114 -0
- package/src/config/global.d.ts +4 -0
- package/src/config/init.tsx +35 -31
- package/src/constants/crosschainEstimationTimes.ts +52 -0
- package/src/constants/index.ts +8 -0
- package/src/context/GlobalDataProvider.tsx +165 -0
- package/src/context/HistoryProvider.tsx +339 -0
- package/src/context/ModalProvider.tsx +47 -0
- package/src/context/SwapProvider.tsx +664 -0
- package/src/context/TransactionProvider.tsx +86 -0
- package/src/context/TxUIWrapper.tsx +388 -0
- package/src/context/index.ts +5 -0
- package/src/contracts/abi/CustomXSwapRouter.json +953 -0
- package/src/contracts/abi/StakingStableAPR.json +1438 -0
- package/src/contracts/abi/XSwapRouter.json +1242 -0
- package/src/contracts/abi/XSwapTokenFeeDistributor.json +350 -0
- package/src/contracts/abi/index.ts +8 -0
- package/src/contracts/addresses.ts +24 -6
- package/src/fonts/Satoshi-Black.woff2 +0 -0
- package/src/fonts/Satoshi-BlackItalic.woff2 +0 -0
- package/src/fonts/Satoshi-Bold.woff2 +0 -0
- package/src/fonts/Satoshi-BoldItalic.woff2 +0 -0
- package/src/fonts/Satoshi-Light.woff2 +0 -0
- package/src/fonts/Satoshi-LightItalic.woff2 +0 -0
- package/src/fonts/Satoshi-Medium.woff2 +0 -0
- package/src/fonts/Satoshi-MediumItalic.woff2 +0 -0
- package/src/fonts/Satoshi-Regular.woff2 +0 -0
- package/src/fonts/Satoshi-RegularItalic.woff2 +0 -0
- package/src/fonts/Satoshi-Variable.woff2 +0 -0
- package/src/fonts/Satoshi-VariableItalic.woff2 +0 -0
- package/src/hooks/index.ts +5 -0
- package/src/hooks/networkManagement/clientToSigner.tsx +17 -0
- package/src/hooks/networkManagement/useNetworks.ts +51 -0
- package/src/hooks/useBatchQuery.ts +46 -0
- package/src/hooks/useDebounce.tsx +28 -0
- package/src/hooks/useEvmContractApi.ts +85 -0
- package/src/hooks/usePortal.ts +79 -0
- package/src/hooks/useXPower.ts +58 -0
- package/src/models/Addresses.ts +8 -2
- package/src/models/TokenData.ts +13 -0
- package/src/models/TransactionHistory.ts +2 -0
- package/src/models/TxUIWrapper.ts +51 -0
- package/src/models/XSwapConfig.ts +1 -0
- package/src/models/index.ts +1 -0
- package/src/models/payloads/GetBalancesPayload.ts +3 -0
- package/src/models/payloads/GetFinishedLeaderboardQuestsPayload.ts +3 -0
- package/src/models/payloads/GetLeaderboardChangePayload.ts +4 -0
- package/src/models/payloads/{GetSwapTxPayload.ts → ModalIntegrationPayload.ts} +3 -1
- package/src/models/payloads/index.ts +5 -2
- package/src/services/api.ts +34 -5
- package/src/services/integrations/monitoring.ts +49 -37
- package/src/services/integrations/transactions.ts +50 -6
- package/src/utils/contracts.ts +29 -0
- package/src/utils/index.ts +3 -3
- package/src/utils/numbers.ts +14 -0
- package/src/utils/parseWeb3Error.ts +7 -3
- package/tailwind.config.js +15 -5
- package/tsconfig.json +7 -7
- package/tsup.config.ts +62 -0
- package/xswap.config.ts +1 -0
- package/dist/index.css +0 -1
- package/src/components/TxConfigForm/BalanceComponent.tsx +0 -52
- package/src/components/TxConfigForm/Button.tsx +0 -20
- package/src/components/TxConfigForm/ChainListElement.tsx +0 -36
- package/src/components/TxConfigForm/ConfirmationAmount.tsx +0 -91
- package/src/components/TxConfigForm/ConfirmationView/ErrorView.tsx +0 -38
- package/src/components/TxConfigForm/ConfirmationView/SuccessView.tsx +0 -159
- package/src/components/TxConfigForm/ConfirmationView/index.tsx +0 -149
- package/src/components/TxConfigForm/ConnectWalletPrompt.tsx +0 -21
- package/src/components/TxConfigForm/Description.tsx +0 -17
- package/src/components/TxConfigForm/ErrorField.tsx +0 -19
- package/src/components/TxConfigForm/FeesDetails.tsx +0 -117
- package/src/components/TxConfigForm/Form.tsx +0 -574
- package/src/components/TxConfigForm/History.tsx +0 -131
- package/src/components/TxConfigForm/HistoryCard.tsx +0 -182
- package/src/components/TxConfigForm/PoweredBy.tsx +0 -12
- package/src/components/TxConfigForm/Settings.tsx +0 -143
- package/src/components/TxConfigForm/Summary.tsx +0 -105
- package/src/components/TxConfigForm/SwapPanel.tsx +0 -185
- package/src/components/TxConfigForm/TokenPicker.tsx +0 -176
- package/src/components/TxConfigForm/TopBar.tsx +0 -58
- package/src/components/TxConfigForm/UsdPrice.tsx +0 -44
- package/src/components/icons/ChevronDownIcon.tsx +0 -15
- package/src/components/icons/ChevronUpIcon.tsx +0 -10
- package/src/components/icons/CloseIcon.tsx +0 -15
- package/src/components/icons/HistoryIcon.tsx +0 -16
- package/src/components/icons/SettingsIcon.tsx +0 -16
- /package/src/{components → assets}/icons/ChainlinkCCIPIcon.tsx +0 -0
- /package/src/{components → assets}/icons/SearchIcon.tsx +0 -0
- /package/src/{components → assets}/icons/XSwapBadgeIcon.tsx +0 -0
- /package/src/{components → assets}/icons/XSwapLogo.tsx +0 -0
|
@@ -1,34 +1,42 @@
|
|
|
1
|
-
import "@src/
|
|
2
|
-
import {
|
|
1
|
+
import { PoweredBy, Swap } from "@src/components";
|
|
2
|
+
import { getWagmiConfig, waitForInitialization, xpayRoot } from "@src/config";
|
|
3
|
+
import {
|
|
4
|
+
HistoryProvider,
|
|
5
|
+
SwapProvider,
|
|
6
|
+
TransactionProvider,
|
|
7
|
+
TxUIWrapper,
|
|
8
|
+
} from "@src/context";
|
|
9
|
+
import { ModalProvider } from "@src/context/ModalProvider";
|
|
10
|
+
import { Chain, ModalIntegrationPayload, Route } from "@src/models";
|
|
3
11
|
import { QueryClient, QueryClientProvider } from "@tanstack/react-query";
|
|
12
|
+
import { MouseEvent, useMemo, useState } from "react";
|
|
4
13
|
import { WagmiProvider } from "wagmi";
|
|
5
|
-
import { getWagmiConfig, waitForInitialization, xpayRoot } from "@src/config";
|
|
6
|
-
import { Chain, ContractCall, Route } from "@src/models";
|
|
7
|
-
import { PoweredBy } from "@src/components/TxConfigForm/PoweredBy";
|
|
8
|
-
import { Form } from "./Form";
|
|
9
14
|
|
|
10
|
-
export type
|
|
11
|
-
|
|
15
|
+
export type TxConfigFormPayload = Omit<
|
|
16
|
+
ModalIntegrationPayload,
|
|
17
|
+
"dstChain" | "dstToken" | "dstDisplayToken" | "srcChain" | "srcToken"
|
|
18
|
+
> & {
|
|
12
19
|
dstChainId: string;
|
|
13
20
|
dstTokenAddr: string;
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
supportedChains: Chain[];
|
|
17
|
-
returnTransactions?: boolean;
|
|
21
|
+
srcChainId?: string;
|
|
22
|
+
srcTokenAddr?: string;
|
|
18
23
|
dstDisplayTokenAddr?: string;
|
|
24
|
+
supportedChains: Chain[];
|
|
19
25
|
};
|
|
20
26
|
const TxConfigForm = ({
|
|
21
27
|
integratorId,
|
|
22
28
|
dstChainId,
|
|
23
29
|
dstTokenAddr,
|
|
30
|
+
srcChainId,
|
|
31
|
+
srcTokenAddr,
|
|
24
32
|
customContractCalls,
|
|
25
33
|
desc,
|
|
26
|
-
supportedChains,
|
|
27
34
|
returnTransactions,
|
|
28
35
|
dstDisplayTokenAddr,
|
|
36
|
+
supportedChains,
|
|
29
37
|
onSubmit,
|
|
30
38
|
onClose,
|
|
31
|
-
}:
|
|
39
|
+
}: TxConfigFormPayload & {
|
|
32
40
|
onSubmit: (route: Route) => void;
|
|
33
41
|
onClose: () => void;
|
|
34
42
|
}) => {
|
|
@@ -44,36 +52,45 @@ const TxConfigForm = ({
|
|
|
44
52
|
const queryClient = new QueryClient();
|
|
45
53
|
const wagmiConfig = useMemo(
|
|
46
54
|
() => getWagmiConfig(supportedChains),
|
|
47
|
-
supportedChains,
|
|
55
|
+
[supportedChains],
|
|
48
56
|
);
|
|
49
57
|
|
|
50
58
|
return (
|
|
51
59
|
<WagmiProvider config={wagmiConfig}>
|
|
52
60
|
<QueryClientProvider client={queryClient}>
|
|
53
|
-
<
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
61
|
+
<HistoryProvider>
|
|
62
|
+
<SwapProvider
|
|
63
|
+
integrationConfig={{
|
|
64
|
+
integratorId,
|
|
65
|
+
dstChainId,
|
|
66
|
+
dstTokenAddr,
|
|
67
|
+
srcChainId,
|
|
68
|
+
srcTokenAddr,
|
|
69
|
+
customContractCalls,
|
|
70
|
+
desc,
|
|
71
|
+
dstDisplayTokenAddr,
|
|
72
|
+
returnTransactions,
|
|
73
|
+
}}
|
|
74
|
+
supportedChains={supportedChains}
|
|
75
|
+
wagmiConfig={wagmiConfig}
|
|
76
|
+
>
|
|
77
|
+
<TransactionProvider>
|
|
78
|
+
<TxUIWrapper>
|
|
79
|
+
<ModalProvider>
|
|
80
|
+
<div
|
|
81
|
+
className="top-0 left-0 right-0 bottom-0 bg-[rgba(0,0,0,0.8)] fixed flex items-center justify-center z-10"
|
|
82
|
+
onMouseDown={onBackdropClick}
|
|
83
|
+
>
|
|
84
|
+
<div className="relative bg-black rounded-3xl overflow-auto text-white border-2 border-solid border-[rgba(255,255,255,0.1)] min-w-x_modal max-w-x_modal min-h-[432px] w-full">
|
|
85
|
+
<Swap onSubmit={onSubmit} onClose={onClose} />
|
|
86
|
+
<PoweredBy />
|
|
87
|
+
</div>
|
|
88
|
+
</div>
|
|
89
|
+
</ModalProvider>
|
|
90
|
+
</TxUIWrapper>
|
|
91
|
+
</TransactionProvider>
|
|
92
|
+
</SwapProvider>
|
|
93
|
+
</HistoryProvider>
|
|
77
94
|
</QueryClientProvider>
|
|
78
95
|
</WagmiProvider>
|
|
79
96
|
);
|
|
@@ -83,12 +100,14 @@ export const openTxConfigForm = async ({
|
|
|
83
100
|
integratorId,
|
|
84
101
|
dstChainId,
|
|
85
102
|
dstTokenAddr,
|
|
103
|
+
srcChainId,
|
|
104
|
+
srcTokenAddr,
|
|
86
105
|
customContractCalls,
|
|
87
106
|
desc,
|
|
88
|
-
supportedChains,
|
|
89
107
|
returnTransactions,
|
|
90
108
|
dstDisplayTokenAddr,
|
|
91
|
-
|
|
109
|
+
supportedChains,
|
|
110
|
+
}: TxConfigFormPayload): Promise<Route> => {
|
|
92
111
|
try {
|
|
93
112
|
if (xpayRoot === null) {
|
|
94
113
|
throw new Error("XPay was incorrectly initialised");
|
|
@@ -103,11 +122,13 @@ export const openTxConfigForm = async ({
|
|
|
103
122
|
integratorId={integratorId}
|
|
104
123
|
dstChainId={dstChainId}
|
|
105
124
|
dstTokenAddr={dstTokenAddr}
|
|
125
|
+
srcChainId={srcChainId}
|
|
126
|
+
srcTokenAddr={srcTokenAddr}
|
|
106
127
|
customContractCalls={customContractCalls}
|
|
107
128
|
desc={desc}
|
|
108
|
-
supportedChains={supportedChains}
|
|
109
129
|
returnTransactions={returnTransactions}
|
|
110
130
|
dstDisplayTokenAddr={dstDisplayTokenAddr}
|
|
131
|
+
supportedChains={supportedChains}
|
|
111
132
|
onSubmit={(route) => {
|
|
112
133
|
if (returnTransactions) {
|
|
113
134
|
resolve(route);
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import { TokenLogoWithChain } from "@src/components";
|
|
2
|
+
import { Chain, Token } from "@src/models";
|
|
3
|
+
|
|
4
|
+
type Props = {
|
|
5
|
+
chain: Chain | undefined;
|
|
6
|
+
token: Token | undefined;
|
|
7
|
+
amount: string;
|
|
8
|
+
};
|
|
9
|
+
|
|
10
|
+
export const TokenDetails = ({ chain, token, amount }: Props) => {
|
|
11
|
+
return (
|
|
12
|
+
<div className="flex gap-2">
|
|
13
|
+
<TokenLogoWithChain
|
|
14
|
+
token={token}
|
|
15
|
+
chain={chain}
|
|
16
|
+
tokenLogoClassName="min-w-9 w-9"
|
|
17
|
+
generatedLogoClassName="min-w-9 w-9 text-[16px]"
|
|
18
|
+
chainLogoClassName="min-w-5 w-5"
|
|
19
|
+
/>
|
|
20
|
+
<div className="flex flex-col text-[12px]">
|
|
21
|
+
<div className="text-white text-nowrap">
|
|
22
|
+
{`${Number(amount) < 0.0001 ? "<0.0001" : amount} ${
|
|
23
|
+
token?.symbol ? token?.symbol : "unknown"
|
|
24
|
+
}`}
|
|
25
|
+
</div>
|
|
26
|
+
<div className="text-xs text-x_gray_200">{chain?.displayName}</div>
|
|
27
|
+
</div>
|
|
28
|
+
</div>
|
|
29
|
+
);
|
|
30
|
+
};
|
|
@@ -0,0 +1,133 @@
|
|
|
1
|
+
import {
|
|
2
|
+
faArrowRight,
|
|
3
|
+
faArrowUpRightFromSquare,
|
|
4
|
+
faHourglassHalf,
|
|
5
|
+
} from "@fortawesome/free-solid-svg-icons";
|
|
6
|
+
import { FontAwesomeIcon } from "@fortawesome/react-fontawesome";
|
|
7
|
+
import { Timer, TimerDisplayFormat } from "@src/components";
|
|
8
|
+
import { CCIP_EXPLORER } from "@src/constants";
|
|
9
|
+
import { Chain, Token, Transaction } from "@src/models";
|
|
10
|
+
import { weiToHumanReadable } from "@src/utils";
|
|
11
|
+
import { format } from "date-fns";
|
|
12
|
+
import { useCallback } from "react";
|
|
13
|
+
import { TokenDetails } from "../TokenDetails";
|
|
14
|
+
|
|
15
|
+
interface Props {
|
|
16
|
+
transaction: Transaction;
|
|
17
|
+
supportedChains: Chain[];
|
|
18
|
+
srcToken?: Token;
|
|
19
|
+
dstToken?: Token;
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
export const TxDataCardUI = ({
|
|
23
|
+
transaction,
|
|
24
|
+
supportedChains,
|
|
25
|
+
srcToken,
|
|
26
|
+
dstToken,
|
|
27
|
+
}: Props) => {
|
|
28
|
+
const getDate = useCallback((blockTimestamp: number) => {
|
|
29
|
+
// JS uses ms in timestamps
|
|
30
|
+
return format(new Date(blockTimestamp * 1000), "d MMM yyyy HH:mm:ss");
|
|
31
|
+
}, []);
|
|
32
|
+
|
|
33
|
+
const date = getDate(transaction.timestamp);
|
|
34
|
+
|
|
35
|
+
const transferredAmount = weiToHumanReadable({
|
|
36
|
+
amount: transaction.amountWei,
|
|
37
|
+
decimals: srcToken?.decimals || 18,
|
|
38
|
+
precisionFractionalPlaces: 4,
|
|
39
|
+
});
|
|
40
|
+
const receivedAmount = weiToHumanReadable({
|
|
41
|
+
amount: transaction?.tokenOutAmount || "0",
|
|
42
|
+
decimals: dstToken?.decimals || 18,
|
|
43
|
+
precisionFractionalPlaces: 4,
|
|
44
|
+
});
|
|
45
|
+
|
|
46
|
+
const srcChain = supportedChains.find(
|
|
47
|
+
(chain) => chain.chainId === transaction.sourceChainId,
|
|
48
|
+
);
|
|
49
|
+
|
|
50
|
+
const dstChain = supportedChains.find(
|
|
51
|
+
(chain) => chain.chainId === transaction.targetChainId,
|
|
52
|
+
);
|
|
53
|
+
|
|
54
|
+
return (
|
|
55
|
+
<div className="flex flex-col border border-white border-opacity-10 rounded-lg bg-x_gray_500 p-4 gap-4 mb-2">
|
|
56
|
+
<div className="flex items-center gap-2 border-b border-solid border-white border-opacity-10 pb-1">
|
|
57
|
+
<div className="text-xs text-white opacity-60">{date}</div>
|
|
58
|
+
<div className="flex grow justify-end items-center h-6">
|
|
59
|
+
{transaction.status === "IN_PROGRESS" ? (
|
|
60
|
+
<div className="flex items-center grow justify-end text-xs">
|
|
61
|
+
<FontAwesomeIcon
|
|
62
|
+
icon={faHourglassHalf}
|
|
63
|
+
className="w-4 h-4 mr-1 text-[#FAC864]"
|
|
64
|
+
/>
|
|
65
|
+
<div className="text-xs text-[#FAC864] min-w-[108px]">
|
|
66
|
+
In progress (
|
|
67
|
+
<Timer
|
|
68
|
+
displayFormat={TimerDisplayFormat.Minutes}
|
|
69
|
+
expiryTimestamp={
|
|
70
|
+
new Date(transaction.estimatedDeliveryTimestamp)
|
|
71
|
+
}
|
|
72
|
+
customTextOnExpire="finalizing"
|
|
73
|
+
/>
|
|
74
|
+
)
|
|
75
|
+
</div>
|
|
76
|
+
</div>
|
|
77
|
+
) : transaction.status === "DONE" ? (
|
|
78
|
+
<div className="flex items-center grow justify-end text-xs">
|
|
79
|
+
<div className=" mr-1 text-[#64C864]">Done</div>
|
|
80
|
+
</div>
|
|
81
|
+
) : transaction.status === "REVERTED" ? (
|
|
82
|
+
<div className="flex items-center grow justify-end text-xs">
|
|
83
|
+
<div className="w-4 h-4 mr-1 text-[#FF6464]">Reverted</div>
|
|
84
|
+
</div>
|
|
85
|
+
) : null}
|
|
86
|
+
|
|
87
|
+
<a
|
|
88
|
+
href={`${
|
|
89
|
+
transaction.messageId
|
|
90
|
+
? `${CCIP_EXPLORER}${transaction.messageId}`
|
|
91
|
+
: `${
|
|
92
|
+
supportedChains.find(
|
|
93
|
+
(chain) => chain.chainId === transaction.sourceChainId,
|
|
94
|
+
)?.transactionExplorer
|
|
95
|
+
}/${transaction.hash}`
|
|
96
|
+
} `}
|
|
97
|
+
target="_blank"
|
|
98
|
+
rel="noreferrer"
|
|
99
|
+
className="no-underline ml-1.5 text-white "
|
|
100
|
+
aria-label="Show the transaction in the chain explorer"
|
|
101
|
+
>
|
|
102
|
+
<FontAwesomeIcon
|
|
103
|
+
icon={faArrowUpRightFromSquare}
|
|
104
|
+
className="w-[14px] h-[14px] text-white"
|
|
105
|
+
/>
|
|
106
|
+
</a>
|
|
107
|
+
</div>
|
|
108
|
+
</div>
|
|
109
|
+
<div className="flex flex-wrap gap-8">
|
|
110
|
+
<div className="flex items-center gap-2">
|
|
111
|
+
<TokenDetails
|
|
112
|
+
chain={srcChain}
|
|
113
|
+
token={srcToken}
|
|
114
|
+
amount={transferredAmount}
|
|
115
|
+
/>
|
|
116
|
+
{transaction.tokenOutAddress && (
|
|
117
|
+
<>
|
|
118
|
+
<FontAwesomeIcon
|
|
119
|
+
icon={faArrowRight}
|
|
120
|
+
className="w-5 h-5 text-white opacity-60 mx-1.5"
|
|
121
|
+
/>
|
|
122
|
+
<TokenDetails
|
|
123
|
+
chain={dstChain}
|
|
124
|
+
token={dstToken}
|
|
125
|
+
amount={receivedAmount}
|
|
126
|
+
/>
|
|
127
|
+
</>
|
|
128
|
+
)}
|
|
129
|
+
</div>
|
|
130
|
+
</div>
|
|
131
|
+
</div>
|
|
132
|
+
);
|
|
133
|
+
};
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import { useSwapContext } from "@src/context";
|
|
2
|
+
import { Transaction } from "@src/models";
|
|
3
|
+
import { TxDataCardUI } from "./TxDataCardUI";
|
|
4
|
+
|
|
5
|
+
interface Props {
|
|
6
|
+
transaction: Transaction;
|
|
7
|
+
}
|
|
8
|
+
|
|
9
|
+
export const TxDataCard = ({ transaction }: Props) => {
|
|
10
|
+
const { supportedChains, findTokenDataByAddressAndChain } = useSwapContext();
|
|
11
|
+
|
|
12
|
+
const srcToken = findTokenDataByAddressAndChain(
|
|
13
|
+
transaction.tokenAddress.toLowerCase(),
|
|
14
|
+
transaction.sourceChainId,
|
|
15
|
+
);
|
|
16
|
+
const dstToken = transaction.tokenOutAddress
|
|
17
|
+
? findTokenDataByAddressAndChain(
|
|
18
|
+
transaction.tokenOutAddress?.toLowerCase(),
|
|
19
|
+
transaction.targetChainId,
|
|
20
|
+
)
|
|
21
|
+
: undefined;
|
|
22
|
+
return (
|
|
23
|
+
<TxDataCardUI
|
|
24
|
+
transaction={transaction}
|
|
25
|
+
supportedChains={supportedChains}
|
|
26
|
+
srcToken={srcToken}
|
|
27
|
+
dstToken={dstToken}
|
|
28
|
+
/>
|
|
29
|
+
);
|
|
30
|
+
};
|
|
@@ -1,125 +1,73 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
3
|
-
ArrowLeftIcon,
|
|
4
|
-
ArrowRightIcon,
|
|
5
|
-
CheckIcon,
|
|
6
|
-
CircularProgressIcon,
|
|
7
|
-
ArrowUpRightIcon,
|
|
8
|
-
XSwapLogo,
|
|
9
|
-
} from "../icons";
|
|
10
|
-
import { MonitoredTransaction } from "@src/models";
|
|
1
|
+
import { ArrowLeftIcon, CheckIcon, XSwapLogo } from "@src/assets/icons";
|
|
11
2
|
import { xpayTxStatusRoot } from "@src/config";
|
|
12
|
-
import {
|
|
3
|
+
import { Chain, Token, Transaction } from "@src/models";
|
|
4
|
+
import { FC, useMemo, useState } from "react";
|
|
13
5
|
import { Spinner } from "../Spinner";
|
|
6
|
+
import { TxDataCardUI } from "../TxDataCard/TxDataCardUI";
|
|
14
7
|
|
|
15
8
|
interface Props {
|
|
16
|
-
transaction:
|
|
9
|
+
transaction: Transaction;
|
|
10
|
+
supportedChains: Chain[];
|
|
11
|
+
srcToken?: Token;
|
|
12
|
+
dstToken?: Token;
|
|
17
13
|
}
|
|
18
14
|
|
|
19
|
-
export const TxStatusButton: FC<Props> = ({
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
srcAmount: fromAmount,
|
|
26
|
-
dstChain: toChain,
|
|
27
|
-
dstChainImage: toChainImage,
|
|
28
|
-
isDone,
|
|
29
|
-
explorer,
|
|
30
|
-
} = transaction;
|
|
15
|
+
export const TxStatusButton: FC<Props> = ({
|
|
16
|
+
transaction,
|
|
17
|
+
supportedChains,
|
|
18
|
+
srcToken,
|
|
19
|
+
dstToken,
|
|
20
|
+
}) => {
|
|
31
21
|
const [isWide, setIsWide] = useState(false);
|
|
32
22
|
|
|
33
23
|
const background = useMemo(
|
|
34
24
|
() =>
|
|
35
|
-
|
|
36
|
-
? "
|
|
37
|
-
: "
|
|
38
|
-
[
|
|
25
|
+
transaction?.status === "DONE"
|
|
26
|
+
? "bg-[rgba(2,2,2,1)] bg-gradient-to-r from-[rgba(76,175,80,0.2)] to-[rgba(46,125,50,0.2)]"
|
|
27
|
+
: "bg-[rgba(2,2,2,1)] bg-gradient-to-r from-[rgba(54,129,198,0.2)] to-[rgba(43,74,157,0.2)]",
|
|
28
|
+
[transaction],
|
|
39
29
|
);
|
|
40
30
|
|
|
41
31
|
const border = useMemo(
|
|
42
32
|
() =>
|
|
43
|
-
|
|
44
|
-
? "
|
|
45
|
-
: "
|
|
46
|
-
[
|
|
33
|
+
transaction?.status === "DONE"
|
|
34
|
+
? "border border-solid border-x_green_dark"
|
|
35
|
+
: "border border-solid border-x_blue_dark",
|
|
36
|
+
[transaction],
|
|
47
37
|
);
|
|
48
38
|
|
|
49
39
|
return (
|
|
50
40
|
<div
|
|
51
|
-
className="
|
|
41
|
+
className="flex gap-2 items-end justify-end flex-wrap"
|
|
52
42
|
onClick={() => setIsWide((x: boolean) => !x)}
|
|
53
43
|
>
|
|
54
44
|
{isWide && (
|
|
55
|
-
<
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
className="xpay-w-5 xpay-h-5"
|
|
62
|
-
src={fromChainImage}
|
|
63
|
-
alt="source chain"
|
|
64
|
-
/>
|
|
65
|
-
<div>{fromChain}</div>
|
|
66
|
-
<div className="xpay-w-3.5 xpay-h-3.5">
|
|
67
|
-
<ArrowRightIcon />
|
|
68
|
-
</div>
|
|
69
|
-
<img
|
|
70
|
-
className="xpay-w-5 xpay-h-5"
|
|
71
|
-
src={toChainImage}
|
|
72
|
-
alt="to chain"
|
|
73
|
-
/>
|
|
74
|
-
<div>{toChain}</div>
|
|
75
|
-
</div>
|
|
76
|
-
|
|
77
|
-
<div className="xpay-flex xpay-items-center xpay-gap-2">
|
|
78
|
-
<div>Sent</div>
|
|
79
|
-
<div>{fromAmount}</div>
|
|
80
|
-
<div>{fromToken}</div>
|
|
81
|
-
|
|
82
|
-
{fromTokenImage ? (
|
|
83
|
-
<img
|
|
84
|
-
className="xpay-w-5 xpay-h-5"
|
|
85
|
-
src={fromTokenImage}
|
|
86
|
-
alt="source token"
|
|
87
|
-
/>
|
|
88
|
-
) : (
|
|
89
|
-
<UnknownTokenLogo tokenName={"?"} />
|
|
90
|
-
)}
|
|
91
|
-
</div>
|
|
92
|
-
</div>
|
|
93
|
-
<a
|
|
94
|
-
href={explorer}
|
|
95
|
-
target="_blank"
|
|
96
|
-
rel="noreferrer"
|
|
97
|
-
className="xpay-no-underline xpay-cursor-pointer"
|
|
98
|
-
aria-label="Show the transaction in the chain explorer"
|
|
99
|
-
>
|
|
100
|
-
<div className="xpay-w-3.5 xpay-h-3.5">
|
|
101
|
-
<ArrowUpRightIcon />
|
|
102
|
-
</div>
|
|
103
|
-
</a>
|
|
104
|
-
</div>
|
|
45
|
+
<TxDataCardUI
|
|
46
|
+
transaction={transaction}
|
|
47
|
+
supportedChains={supportedChains}
|
|
48
|
+
srcToken={srcToken}
|
|
49
|
+
dstToken={dstToken}
|
|
50
|
+
/>
|
|
105
51
|
)}
|
|
106
52
|
<div
|
|
107
|
-
className={`
|
|
53
|
+
className={`text-white rounded-xl h-14 w-20 mb-2 cursor-pointer ${background} ${border}`}
|
|
108
54
|
>
|
|
109
|
-
<div className="
|
|
110
|
-
<
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
55
|
+
<div className="flex gap-2 items-center h-14 w-20 justify-center fill-white">
|
|
56
|
+
<div className={`${isWide ? "rotate-180" : ""}`}>
|
|
57
|
+
<ArrowLeftIcon />
|
|
58
|
+
</div>
|
|
59
|
+
<div className="relative flex items-center justify-center w-9 h-9">
|
|
60
|
+
{transaction?.status === "DONE" ? (
|
|
61
|
+
<div className="w-5 h-5 fill-x_green_400">
|
|
114
62
|
<CheckIcon />
|
|
115
63
|
</div>
|
|
116
64
|
) : (
|
|
117
65
|
<>
|
|
118
|
-
<div className="
|
|
66
|
+
<div className="w-5 h-5">
|
|
119
67
|
<XSwapLogo />
|
|
120
68
|
</div>
|
|
121
|
-
<div className="
|
|
122
|
-
<Spinner
|
|
69
|
+
<div className="absolute flex items-center justify-center top-0 left-0 right-0 bottom-0 text-white">
|
|
70
|
+
<Spinner className="w-10 h-10" />
|
|
123
71
|
</div>
|
|
124
72
|
</>
|
|
125
73
|
)}
|
|
@@ -130,34 +78,42 @@ export const TxStatusButton: FC<Props> = ({ transaction }) => {
|
|
|
130
78
|
);
|
|
131
79
|
};
|
|
132
80
|
|
|
133
|
-
let renderedTransactions:
|
|
81
|
+
let renderedTransactions: Props[] = [];
|
|
134
82
|
|
|
135
|
-
export const addTransactionToRenderedTransactions = (
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
83
|
+
export const addTransactionToRenderedTransactions = (transaction: Props) => {
|
|
84
|
+
if (
|
|
85
|
+
!renderedTransactions.some(
|
|
86
|
+
({ transaction }) => transaction.hash === transaction.hash,
|
|
87
|
+
)
|
|
88
|
+
)
|
|
139
89
|
renderedTransactions.push(transaction);
|
|
140
90
|
};
|
|
141
91
|
|
|
142
|
-
export const removeTransactionFromRenderedTransactions = (
|
|
92
|
+
export const removeTransactionFromRenderedTransactions = (hash: string) => {
|
|
143
93
|
const filteredRenderedTransactions = renderedTransactions.filter(
|
|
144
|
-
(item) => item.
|
|
94
|
+
(item) => item.transaction.hash !== hash,
|
|
145
95
|
);
|
|
146
96
|
renderedTransactions = [...filteredRenderedTransactions];
|
|
147
97
|
};
|
|
148
98
|
|
|
149
|
-
export const updateTransactionDoneInRenderedTransactions = (
|
|
150
|
-
|
|
151
|
-
(item
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
99
|
+
export const updateTransactionDoneInRenderedTransactions = (hash: string) => {
|
|
100
|
+
renderedTransactions = renderedTransactions.map((item) => {
|
|
101
|
+
if (item.transaction.hash === hash) {
|
|
102
|
+
return {
|
|
103
|
+
...item,
|
|
104
|
+
transaction: {
|
|
105
|
+
...item.transaction,
|
|
106
|
+
status: "DONE",
|
|
107
|
+
},
|
|
108
|
+
};
|
|
109
|
+
}
|
|
110
|
+
return item;
|
|
111
|
+
});
|
|
156
112
|
};
|
|
157
113
|
|
|
158
114
|
export const renderTxStatusButtons = () => {
|
|
159
115
|
const buttons = renderedTransactions.map((item) => (
|
|
160
|
-
<TxStatusButton key={item.
|
|
116
|
+
<TxStatusButton key={item.transaction.hash} {...item} />
|
|
161
117
|
));
|
|
162
118
|
|
|
163
119
|
if (xpayTxStatusRoot === null) {
|
|
@@ -165,7 +121,7 @@ export const renderTxStatusButtons = () => {
|
|
|
165
121
|
}
|
|
166
122
|
|
|
167
123
|
xpayTxStatusRoot.render(
|
|
168
|
-
<div className="
|
|
124
|
+
<div className="fixed bottom-5 right-2 flex flex-col gap-3 pl-9 items-end w-full z-50">
|
|
169
125
|
{buttons}
|
|
170
126
|
</div>,
|
|
171
127
|
);
|