@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.
Files changed (199) hide show
  1. package/.eslintrc.json +9 -5
  2. package/CHANGELOG.md +16 -0
  3. package/README.md +2 -1
  4. package/dist/index.d.mts +106 -20
  5. package/dist/index.d.ts +106 -20
  6. package/dist/index.global.js +856 -307
  7. package/dist/index.global.js.map +1 -0
  8. package/dist/index.js +105 -3564
  9. package/dist/index.js.map +1 -0
  10. package/dist/index.mjs +105 -3534
  11. package/dist/index.mjs.map +1 -0
  12. package/nodemon.json +1 -1
  13. package/package.json +16 -9
  14. package/postcss.config.js +8 -1
  15. package/src/{components → assets}/icons/ArrowDownIcon.tsx +1 -2
  16. package/src/assets/icons/ArrowDownLongIcon.tsx +12 -0
  17. package/src/{components → assets}/icons/ArrowLeftIcon.tsx +1 -5
  18. package/src/{components → assets}/icons/ArrowRightIcon.tsx +1 -5
  19. package/src/assets/icons/ArrowUpIcon.tsx +12 -0
  20. package/src/{components → assets}/icons/ArrowUpRightIcon.tsx +1 -5
  21. package/src/assets/icons/CashbacklIcon.tsx +28 -0
  22. package/src/{components → assets}/icons/CheckIcon.tsx +1 -5
  23. package/src/assets/icons/ChevronDownIcon.tsx +12 -0
  24. package/src/assets/icons/ChevronUpIcon.tsx +7 -0
  25. package/src/{components → assets}/icons/CircularProgressIcon.tsx +1 -2
  26. package/src/assets/icons/CloseIcon.tsx +15 -0
  27. package/src/{components → assets}/icons/CoinsIcon.tsx +0 -2
  28. package/src/assets/icons/CopyIcon.tsx +15 -0
  29. package/src/assets/icons/DotGreenIcon.tsx +12 -0
  30. package/src/{components → assets}/icons/DownArrorIcon.tsx +0 -2
  31. package/src/{components → assets}/icons/ErrorIcon.tsx +0 -1
  32. package/src/assets/icons/ErrorModalStatusIcon.tsx +31 -0
  33. package/src/assets/icons/HelpIcon.tsx +21 -0
  34. package/src/assets/icons/HistoryGradientBgIcon.tsx +32 -0
  35. package/src/assets/icons/HistoryIcon.tsx +12 -0
  36. package/src/{components → assets}/icons/HourGlassIcon.tsx +1 -5
  37. package/src/assets/icons/Icon.tsx +5 -0
  38. package/src/{components → assets}/icons/InfoIcon.tsx +0 -1
  39. package/src/assets/icons/LinkExternalIcon.tsx +15 -0
  40. package/src/{components → assets}/icons/PercentageIcon.tsx +0 -1
  41. package/src/assets/icons/RankIcon.tsx +28 -0
  42. package/src/assets/icons/SettingsGradientBgIcon.tsx +32 -0
  43. package/src/assets/icons/SettingsIcon.tsx +12 -0
  44. package/src/{components → assets}/icons/SignIcon.tsx +0 -2
  45. package/src/{components → assets}/icons/SuccessIcon.tsx +0 -1
  46. package/src/assets/icons/SuccessModalStatusIcon.tsx +31 -0
  47. package/src/assets/icons/ThumbUpRoundedIcon.tsx +15 -0
  48. package/src/{components → assets}/icons/TimerIcon.tsx +0 -1
  49. package/src/assets/icons/TokensIcon.tsx +16 -0
  50. package/src/assets/icons/WaitingIcon.tsx +15 -0
  51. package/src/{components → assets}/icons/XMarkIcon.tsx +1 -5
  52. package/src/assets/icons/XPowerIcon.tsx +28 -0
  53. package/src/{components → assets}/icons/index.ts +16 -0
  54. package/src/components/Alert/index.tsx +1 -1
  55. package/src/components/Button/index.tsx +57 -0
  56. package/src/components/MessageBar/SnackMessage.tsx +32 -0
  57. package/src/components/MessageBar/index.tsx +44 -0
  58. package/src/components/Modal/index.tsx +52 -0
  59. package/src/components/PoweredBy/index.tsx +12 -0
  60. package/src/components/SafeInput/index.tsx +51 -0
  61. package/src/components/Skeleton/index.tsx +5 -9
  62. package/src/components/Spinner/index.tsx +6 -8
  63. package/src/components/Swap/Header/Controls/index.tsx +57 -0
  64. package/src/components/Swap/Header/index.tsx +16 -0
  65. package/src/components/Swap/HistoryView/index.tsx +34 -0
  66. package/src/components/Swap/SettingsView/Delivery/index.tsx +42 -0
  67. package/src/components/Swap/SettingsView/Slippage/index.tsx +80 -0
  68. package/src/components/Swap/SettingsView/index.tsx +11 -0
  69. package/src/components/Swap/SwapView/ConfirmationView/TxOverview/ArrowIcon.tsx +13 -0
  70. package/src/components/Swap/SwapView/ConfirmationView/TxOverview/Header/index.tsx +37 -0
  71. package/src/components/Swap/SwapView/ConfirmationView/TxOverview/Steps/index.tsx +145 -0
  72. package/src/components/Swap/SwapView/ConfirmationView/TxOverview/SwapPanel/index.tsx +61 -0
  73. package/src/components/Swap/SwapView/ConfirmationView/TxOverview/index.tsx +291 -0
  74. package/src/components/Swap/SwapView/ConfirmationView/TxResult/TokenItem/index.tsx +24 -0
  75. package/src/components/Swap/SwapView/ConfirmationView/TxResult/index.tsx +84 -0
  76. package/src/components/Swap/SwapView/ConfirmationView/index.tsx +17 -0
  77. package/src/components/Swap/SwapView/FeesPanel/DeliveryInfo/index.tsx +25 -0
  78. package/src/components/Swap/SwapView/FeesPanel/Fee/index.tsx +18 -0
  79. package/src/components/Swap/SwapView/FeesPanel/Fees/index.tsx +71 -0
  80. package/src/components/Swap/SwapView/FeesPanel/index.tsx +67 -0
  81. package/src/components/Swap/SwapView/SwapButton/index.tsx +154 -0
  82. package/src/components/Swap/SwapView/SwapPanel/AmountPanel/Balance/index.tsx +23 -0
  83. package/src/components/Swap/SwapView/SwapPanel/AmountPanel/index.tsx +56 -0
  84. package/src/components/Swap/SwapView/SwapPanel/ChainPanel/ChainPicker/ChainItem/index.tsx +70 -0
  85. package/src/components/Swap/SwapView/SwapPanel/ChainPanel/ChainPicker/index.tsx +62 -0
  86. package/src/components/Swap/SwapView/SwapPanel/ChainPanel/index.tsx +74 -0
  87. package/src/components/Swap/SwapView/SwapPanel/MaxPanel/index.tsx +35 -0
  88. package/src/components/Swap/SwapView/SwapPanel/TokenPanel/TokenPicker/QuickPickTokenItem/index.tsx +40 -0
  89. package/src/components/Swap/SwapView/SwapPanel/TokenPanel/TokenPicker/TokenItem/index.tsx +62 -0
  90. package/src/components/Swap/SwapView/SwapPanel/TokenPanel/TokenPicker/index.tsx +399 -0
  91. package/src/components/Swap/SwapView/SwapPanel/TokenPanel/index.tsx +104 -0
  92. package/src/components/Swap/SwapView/SwapPanel/index.tsx +42 -0
  93. package/src/components/Swap/SwapView/index.tsx +20 -0
  94. package/src/components/Swap/index.tsx +34 -0
  95. package/src/components/TextInput/index.tsx +67 -0
  96. package/src/components/Timer/index.tsx +57 -0
  97. package/src/components/ToggleButton/index.tsx +24 -0
  98. package/src/components/{UnknownTokenLogo/UnknownTokenLogo.tsx → TokenLogo/Unknown/index.tsx} +3 -4
  99. package/src/components/TokenLogo/WithChain/index.tsx +34 -0
  100. package/src/components/TokenLogo/index.tsx +22 -0
  101. package/src/components/Tooltip/index.tsx +108 -0
  102. package/src/components/TxConfigForm/index.tsx +63 -42
  103. package/src/components/TxDataCard/TokenDetails/index.tsx +30 -0
  104. package/src/components/TxDataCard/TxDataCardUI/index.tsx +133 -0
  105. package/src/components/TxDataCard/index.tsx +30 -0
  106. package/src/components/TxStatusButton/index.tsx +64 -108
  107. package/src/components/global.css +115 -4
  108. package/src/components/index.ts +18 -1
  109. package/src/config/fonts.ts +114 -0
  110. package/src/config/global.d.ts +4 -0
  111. package/src/config/init.tsx +35 -31
  112. package/src/constants/crosschainEstimationTimes.ts +52 -0
  113. package/src/constants/index.ts +8 -0
  114. package/src/context/GlobalDataProvider.tsx +165 -0
  115. package/src/context/HistoryProvider.tsx +339 -0
  116. package/src/context/ModalProvider.tsx +47 -0
  117. package/src/context/SwapProvider.tsx +664 -0
  118. package/src/context/TransactionProvider.tsx +86 -0
  119. package/src/context/TxUIWrapper.tsx +388 -0
  120. package/src/context/index.ts +5 -0
  121. package/src/contracts/abi/CustomXSwapRouter.json +953 -0
  122. package/src/contracts/abi/StakingStableAPR.json +1438 -0
  123. package/src/contracts/abi/XSwapRouter.json +1242 -0
  124. package/src/contracts/abi/XSwapTokenFeeDistributor.json +350 -0
  125. package/src/contracts/abi/index.ts +8 -0
  126. package/src/contracts/addresses.ts +24 -6
  127. package/src/fonts/Satoshi-Black.woff2 +0 -0
  128. package/src/fonts/Satoshi-BlackItalic.woff2 +0 -0
  129. package/src/fonts/Satoshi-Bold.woff2 +0 -0
  130. package/src/fonts/Satoshi-BoldItalic.woff2 +0 -0
  131. package/src/fonts/Satoshi-Light.woff2 +0 -0
  132. package/src/fonts/Satoshi-LightItalic.woff2 +0 -0
  133. package/src/fonts/Satoshi-Medium.woff2 +0 -0
  134. package/src/fonts/Satoshi-MediumItalic.woff2 +0 -0
  135. package/src/fonts/Satoshi-Regular.woff2 +0 -0
  136. package/src/fonts/Satoshi-RegularItalic.woff2 +0 -0
  137. package/src/fonts/Satoshi-Variable.woff2 +0 -0
  138. package/src/fonts/Satoshi-VariableItalic.woff2 +0 -0
  139. package/src/hooks/index.ts +5 -0
  140. package/src/hooks/networkManagement/clientToSigner.tsx +17 -0
  141. package/src/hooks/networkManagement/useNetworks.ts +51 -0
  142. package/src/hooks/useBatchQuery.ts +46 -0
  143. package/src/hooks/useDebounce.tsx +28 -0
  144. package/src/hooks/useEvmContractApi.ts +85 -0
  145. package/src/hooks/usePortal.ts +79 -0
  146. package/src/hooks/useXPower.ts +58 -0
  147. package/src/models/Addresses.ts +8 -2
  148. package/src/models/TokenData.ts +13 -0
  149. package/src/models/TransactionHistory.ts +2 -0
  150. package/src/models/TxUIWrapper.ts +51 -0
  151. package/src/models/XSwapConfig.ts +1 -0
  152. package/src/models/index.ts +1 -0
  153. package/src/models/payloads/GetBalancesPayload.ts +3 -0
  154. package/src/models/payloads/GetFinishedLeaderboardQuestsPayload.ts +3 -0
  155. package/src/models/payloads/GetLeaderboardChangePayload.ts +4 -0
  156. package/src/models/payloads/{GetSwapTxPayload.ts → ModalIntegrationPayload.ts} +3 -1
  157. package/src/models/payloads/index.ts +5 -2
  158. package/src/services/api.ts +34 -5
  159. package/src/services/integrations/monitoring.ts +49 -37
  160. package/src/services/integrations/transactions.ts +50 -6
  161. package/src/utils/contracts.ts +29 -0
  162. package/src/utils/index.ts +3 -3
  163. package/src/utils/numbers.ts +14 -0
  164. package/src/utils/parseWeb3Error.ts +7 -3
  165. package/tailwind.config.js +15 -5
  166. package/tsconfig.json +7 -7
  167. package/tsup.config.ts +62 -0
  168. package/xswap.config.ts +1 -0
  169. package/dist/index.css +0 -1
  170. package/src/components/TxConfigForm/BalanceComponent.tsx +0 -52
  171. package/src/components/TxConfigForm/Button.tsx +0 -20
  172. package/src/components/TxConfigForm/ChainListElement.tsx +0 -36
  173. package/src/components/TxConfigForm/ConfirmationAmount.tsx +0 -91
  174. package/src/components/TxConfigForm/ConfirmationView/ErrorView.tsx +0 -38
  175. package/src/components/TxConfigForm/ConfirmationView/SuccessView.tsx +0 -159
  176. package/src/components/TxConfigForm/ConfirmationView/index.tsx +0 -149
  177. package/src/components/TxConfigForm/ConnectWalletPrompt.tsx +0 -21
  178. package/src/components/TxConfigForm/Description.tsx +0 -17
  179. package/src/components/TxConfigForm/ErrorField.tsx +0 -19
  180. package/src/components/TxConfigForm/FeesDetails.tsx +0 -117
  181. package/src/components/TxConfigForm/Form.tsx +0 -574
  182. package/src/components/TxConfigForm/History.tsx +0 -131
  183. package/src/components/TxConfigForm/HistoryCard.tsx +0 -182
  184. package/src/components/TxConfigForm/PoweredBy.tsx +0 -12
  185. package/src/components/TxConfigForm/Settings.tsx +0 -143
  186. package/src/components/TxConfigForm/Summary.tsx +0 -105
  187. package/src/components/TxConfigForm/SwapPanel.tsx +0 -185
  188. package/src/components/TxConfigForm/TokenPicker.tsx +0 -176
  189. package/src/components/TxConfigForm/TopBar.tsx +0 -58
  190. package/src/components/TxConfigForm/UsdPrice.tsx +0 -44
  191. package/src/components/icons/ChevronDownIcon.tsx +0 -15
  192. package/src/components/icons/ChevronUpIcon.tsx +0 -10
  193. package/src/components/icons/CloseIcon.tsx +0 -15
  194. package/src/components/icons/HistoryIcon.tsx +0 -16
  195. package/src/components/icons/SettingsIcon.tsx +0 -16
  196. /package/src/{components → assets}/icons/ChainlinkCCIPIcon.tsx +0 -0
  197. /package/src/{components → assets}/icons/SearchIcon.tsx +0 -0
  198. /package/src/{components → assets}/icons/XSwapBadgeIcon.tsx +0 -0
  199. /package/src/{components → assets}/icons/XSwapLogo.tsx +0 -0
@@ -1,34 +1,42 @@
1
- import "@src/global.css";
2
- import { MouseEvent, useMemo, useState } from "react";
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 TxConfigFormProps = {
11
- integratorId: string;
15
+ export type TxConfigFormPayload = Omit<
16
+ ModalIntegrationPayload,
17
+ "dstChain" | "dstToken" | "dstDisplayToken" | "srcChain" | "srcToken"
18
+ > & {
12
19
  dstChainId: string;
13
20
  dstTokenAddr: string;
14
- customContractCalls: ContractCall[];
15
- desc?: string;
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
- }: TxConfigFormProps & {
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
- <div
54
- className="xpay-top-0 xpay-left-0 xpay-right-0 xpay-bottom-0 xpay-bg-[rgba(0,0,0,0.8)] xpay-fixed xpay-flex xpay-items-center xpay-justify-center xpay-z-10"
55
- onMouseDown={onBackdropClick}
56
- >
57
- <div className="xpay-relative xpay-bg-black xpay-rounded-3xl xpay-overflow-auto xpay-text-white xpay-border-2 xpay-border-solid xpay-border-[rgba(255,255,255,0.1)]">
58
- <Form
59
- integratorId={integratorId}
60
- dstChainId={dstChainId}
61
- dstTokenAddr={dstTokenAddr}
62
- customContractCalls={customContractCalls}
63
- desc={desc}
64
- supportedChains={supportedChains}
65
- wagmiConfig={wagmiConfig}
66
- returnTransactions={!!returnTransactions}
67
- dstDisplayTokenAddr={dstDisplayTokenAddr}
68
- onSubmit={onSubmit}
69
- onClose={onClose}
70
- setBackdropClickDisabled={(disabled: boolean) =>
71
- setBackdropClickDisabled(disabled)
72
- }
73
- />
74
- <PoweredBy />
75
- </div>
76
- </div>
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
- }: TxConfigFormProps): Promise<Route> => {
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 { FC, useMemo, useState } from "react";
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 { UnknownTokenLogo } from "../UnknownTokenLogo/UnknownTokenLogo";
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: MonitoredTransaction;
9
+ transaction: Transaction;
10
+ supportedChains: Chain[];
11
+ srcToken?: Token;
12
+ dstToken?: Token;
17
13
  }
18
14
 
19
- export const TxStatusButton: FC<Props> = ({ transaction }) => {
20
- const {
21
- srcChain: fromChain,
22
- srcChainImage: fromChainImage,
23
- srcToken: fromToken,
24
- srcTokenImage: fromTokenImage,
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
- isDone
36
- ? "xpay-bg-[rgba(2,2,2,1)] xpay-bg-gradient-to-r xpay-from-[rgba(76,175,80,0.2)] xpay-to-[rgba(46,125,50,0.2)]"
37
- : "xpay-bg-[rgba(2,2,2,1)] xpay-bg-gradient-to-r xpay-from-[rgba(54,129,198,0.2)] xpay-to-[rgba(43,74,157,0.2)]",
38
- [isDone],
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
- isDone
44
- ? "xpay-border xpay-border-solid xpay-border-x_green_dark"
45
- : "xpay-border xpay-border-solid xpay-border-x_blue_dark",
46
- [isDone],
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="xpay-flex xpay-gap-2"
41
+ className="flex gap-2 items-end justify-end flex-wrap"
52
42
  onClick={() => setIsWide((x: boolean) => !x)}
53
43
  >
54
44
  {isWide && (
55
- <div
56
- className={`xpay-flex xpay-items-center xpay-min-w-60 sm:xpay-w-[520px] xpay-text-white xpay-h-14 xpay-px-4 xpay-text-sm xpay-gap-3 xpay-rounded-xl ${background} ${border}`}
57
- >
58
- <div className="xpay-flex xpay-justify-between xpay-flex-col xpay-gap-2 sm:xpay-gap-5 sm:xpay-flex-row xpay-w-full">
59
- <div className="xpay-flex xpay-items-center xpay-gap-2">
60
- <img
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={`xpay-text-white xpay-rounded-xl xpay-cursor-pointer ${background} ${border}`}
53
+ className={`text-white rounded-xl h-14 w-20 mb-2 cursor-pointer ${background} ${border}`}
108
54
  >
109
- <div className="xpay-flex xpay-gap-2 xpay-items-center xpay-h-14 xpay-w-20 xpay-justify-center">
110
- <ArrowLeftIcon />
111
- <div className="xpay-relative xpay-flex xpay-items-center xpay-justify-center xpay-w-9 xpay-h-9">
112
- {isDone ? (
113
- <div className="xpay-text-x_green xpay-w-5 xpay-h-5">
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="xpay-w-5 xpay-h-5">
66
+ <div className="w-5 h-5">
119
67
  <XSwapLogo />
120
68
  </div>
121
- <div className="xpay-absolute xpay-flex xpay-items-center xpay-justify-center xpay-top-0 xpay-left-0 xpay-right-0 xpay-bottom-0 xpay-text-white">
122
- <Spinner width="10" height="10" />
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: MonitoredTransaction[] = [];
81
+ let renderedTransactions: Props[] = [];
134
82
 
135
- export const addTransactionToRenderedTransactions = (
136
- transaction: MonitoredTransaction,
137
- ) => {
138
- if (!renderedTransactions.some(({ txHash }) => txHash === transaction.txHash))
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 = (txHash: string) => {
92
+ export const removeTransactionFromRenderedTransactions = (hash: string) => {
143
93
  const filteredRenderedTransactions = renderedTransactions.filter(
144
- (item) => item.txHash !== txHash,
94
+ (item) => item.transaction.hash !== hash,
145
95
  );
146
96
  renderedTransactions = [...filteredRenderedTransactions];
147
97
  };
148
98
 
149
- export const updateTransactionDoneInRenderedTransactions = (txHash: string) => {
150
- const transaction = renderedTransactions.find(
151
- (item) => item.txHash === txHash,
152
- );
153
- if (transaction) {
154
- transaction.isDone = true;
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.txHash} transaction={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="xpay-fixed xpay-bottom-5 xpay-right-2 xpay-flex xpay-flex-col xpay-gap-3 xpay-pl-9 xpay-items-end xpay-w-full xpay-z-50">
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
  );