@xswap-link/sdk 0.0.13 → 0.1.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.
Files changed (81) hide show
  1. package/.github/workflows/main.yml +1 -1
  2. package/.github/workflows/publish.yml +1 -1
  3. package/.prettierrc +7 -0
  4. package/CHANGELOG.md +12 -1
  5. package/README.md +23 -14
  6. package/dist/index.css +1012 -0
  7. package/dist/index.d.mts +209 -52
  8. package/dist/index.d.ts +209 -52
  9. package/dist/index.js +33963 -88
  10. package/dist/index.mjs +33949 -76
  11. package/package.json +8 -2
  12. package/postcss.config.js +3 -0
  13. package/src/components/Alert/index.tsx +9 -0
  14. package/src/components/Skeleton/index.tsx +10 -0
  15. package/src/components/TxConfigForm/Form.tsx +567 -0
  16. package/src/components/TxConfigForm/History.tsx +159 -0
  17. package/src/components/TxConfigForm/HistoryCard.tsx +209 -0
  18. package/src/components/TxConfigForm/TokenPicker.tsx +165 -0
  19. package/src/components/TxConfigForm/index.jsx +100 -0
  20. package/src/components/global.css +34 -0
  21. package/src/components/global.d.ts +6 -0
  22. package/src/components/icons/ArrowRightIcon.tsx +11 -0
  23. package/src/components/icons/ArrowUpRightIcon.tsx +11 -0
  24. package/src/components/icons/CheckIcon.tsx +11 -0
  25. package/src/components/icons/ChevronDownIcon.tsx +15 -0
  26. package/src/components/icons/ChevronUpIcon.tsx +15 -0
  27. package/src/components/icons/CircularProgressIcon.tsx +24 -0
  28. package/src/components/icons/CloseIcon.tsx +15 -0
  29. package/src/components/icons/CoinsIcon.tsx +15 -0
  30. package/src/components/icons/DownArrorIcon.tsx +17 -0
  31. package/src/components/icons/HistoryIcon.tsx +13 -0
  32. package/src/components/icons/HourGlassIcon.tsx +11 -0
  33. package/src/components/icons/PercentageIcon.tsx +29 -0
  34. package/src/components/icons/SearchIcon.tsx +15 -0
  35. package/src/components/icons/XMarkIcon.tsx +11 -0
  36. package/src/components/icons/index.ts +14 -0
  37. package/src/components/index.ts +3 -0
  38. package/src/constants/index.ts +6 -5
  39. package/src/contracts/abi/BatchQuery.json +52 -0
  40. package/src/contracts/abi/index.ts +2 -0
  41. package/src/contracts/addresses.ts +34 -0
  42. package/src/contracts/index.ts +1 -0
  43. package/src/hooks/index.ts +1 -0
  44. package/src/hooks/useDebounce.tsx +21 -0
  45. package/src/index.ts +6 -0
  46. package/src/models/Addresses.ts +12 -0
  47. package/src/models/Route.ts +17 -5
  48. package/src/models/TokenData.ts +45 -0
  49. package/src/models/TransactionHistory.ts +48 -0
  50. package/src/models/XSwapConfig.ts +3 -0
  51. package/src/models/forms/TxConfigFormData.ts +8 -0
  52. package/src/models/forms/index.ts +1 -0
  53. package/src/models/index.ts +6 -6
  54. package/src/models/integrations/GenerateStakingCallsParams.ts +8 -0
  55. package/src/models/integrations/index.ts +1 -0
  56. package/src/models/payloads/GetPricesPayload.ts +4 -0
  57. package/src/models/payloads/GetRoutePayload.ts +1 -3
  58. package/src/models/payloads/GetSwapTxPayload.ts +8 -0
  59. package/src/models/payloads/index.ts +2 -0
  60. package/src/services/api.ts +46 -64
  61. package/src/services/index.ts +1 -0
  62. package/src/services/integrations/customCalls/index.ts +1 -0
  63. package/src/services/integrations/customCalls/staking.ts +83 -0
  64. package/src/services/integrations/index.ts +2 -0
  65. package/src/services/integrations/transactions.ts +30 -0
  66. package/src/utils/contracts.ts +153 -11
  67. package/src/utils/index.ts +49 -1
  68. package/src/utils/numbers.ts +47 -0
  69. package/src/utils/strings.ts +6 -0
  70. package/tailwind.config.js +14 -0
  71. package/test/api.test.ts +1 -1
  72. package/tsconfig.json +10 -1
  73. package/xswap.config.ts +18 -0
  74. package/index.ts +0 -5
  75. package/src/models/ApiOverrides.ts +0 -3
  76. package/src/models/Chain.ts +0 -20
  77. package/src/models/Prices.ts +0 -9
  78. package/src/models/Token.ts +0 -10
  79. package/src/models/XSwapFee.ts +0 -4
  80. package/src/models/XSwapFees.ts +0 -7
  81. package/src/utils/bigNumbers.ts +0 -7
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@xswap-link/sdk",
3
- "version": "0.0.13",
3
+ "version": "0.1.0",
4
4
  "description": "JavaScript SDK for XSwap platform",
5
5
  "homepage": "https://github.com/xswap-link/xswap-sdk",
6
6
  "repository": {
@@ -21,25 +21,31 @@
21
21
  "dependencies": {
22
22
  "@ethersproject/providers": "^5.7.2",
23
23
  "bignumber.js": "4.0.4",
24
+ "date-fns": "^3.6.0",
24
25
  "ethers": "^5.7.2"
25
26
  },
26
27
  "devDependencies": {
27
28
  "@changesets/cli": "^2.27.1",
28
29
  "@types/jest": "^29.5.12",
29
30
  "@types/node": "^20.11.17",
31
+ "@types/react": "^18.2.79",
32
+ "@types/react-dom": "^18.2.25",
30
33
  "@typescript-eslint/eslint-plugin": "^7.1.0",
31
34
  "@typescript-eslint/parser": "^7.1.0",
32
35
  "eslint": "^8.57.0",
33
36
  "jest": "^29.7.0",
34
37
  "jest-fetch": "^1.1.1",
35
38
  "jest-fetch-mock": "^3.0.3",
39
+ "react": "^18.2.0",
40
+ "react-dom": "^18.2.0",
41
+ "tailwindcss": "^3.4.3",
36
42
  "ts-jest": "^29.1.2",
37
43
  "ts-node": "^10.9.2",
38
44
  "tsup": "^8.0.2",
39
45
  "typescript": "^5.3.3"
40
46
  },
41
47
  "scripts": {
42
- "build": "tsup index.ts --format cjs,esm --dts",
48
+ "build": "tsup src/index.ts --format cjs,esm --dts",
43
49
  "release": "pnpm run build && changeset publish",
44
50
  "lint": "tsc && eslint . --ext .ts",
45
51
  "test": "jest"
@@ -0,0 +1,3 @@
1
+ module.exports = {
2
+ plugins: [require("tailwindcss")()],
3
+ };
@@ -0,0 +1,9 @@
1
+ import React from "react";
2
+
3
+ export const Alert = ({ desc }: { desc: string }) => {
4
+ return (
5
+ <div className="border border-solid border-x_alert rounded-3xl text-x_alert_light text-xs py-0.5 px-2">
6
+ ⚠️ {desc}
7
+ </div>
8
+ );
9
+ };
@@ -0,0 +1,10 @@
1
+ import React from "react";
2
+
3
+ export const Skeleton = ({ w, h }: Style) => {
4
+ return <div className={`bg-current rounded animate-pulse ${w} ${h}`} />;
5
+ };
6
+
7
+ type Style = {
8
+ w: string;
9
+ h: string;
10
+ };
@@ -0,0 +1,567 @@
1
+ import "@src/global.css";
2
+ import React, { FC, FormEvent, useEffect, useState } from "react";
3
+ import { ethers } from "ethers";
4
+ import {
5
+ Chain,
6
+ ContractCall,
7
+ Route,
8
+ Token,
9
+ TokenBalances,
10
+ TokenPrices,
11
+ } from "@src/models";
12
+ import { getPrices, getRoute } from "@src/services";
13
+ import {
14
+ getBalances,
15
+ safeBigNumberFrom,
16
+ shortAddress,
17
+ weiToHumanReadable,
18
+ } from "@src/utils";
19
+ import {
20
+ ChevronDownIcon,
21
+ ChevronUpIcon,
22
+ CoinsIcon,
23
+ DownArrowIcon,
24
+ HistoryIcon,
25
+ PercentageIcon,
26
+ } from "@src/components/icons";
27
+ import { SLIPPAGE_PRESETS, NUMBER_INPUT_REGEX } from "@src/constants";
28
+ import { History } from "./History";
29
+ import { Alert } from "@src/components";
30
+ import { useDebounce } from "@src/hooks";
31
+ import { TokenPicker } from "./TokenPicker";
32
+ import { Skeleton } from "@src/components/Skeleton";
33
+ import { ADDRESSES } from "@src/contracts";
34
+
35
+ interface Props {
36
+ dstChainId: string;
37
+ dstTokenAddr: string;
38
+ customContractCalls: ContractCall[];
39
+ desc: string;
40
+ supportedChains: Chain[];
41
+ onSubmit: (route: Route) => void;
42
+ }
43
+
44
+ export const Form: FC<Props> = ({
45
+ dstChainId,
46
+ dstTokenAddr,
47
+ customContractCalls,
48
+ desc,
49
+ supportedChains,
50
+ onSubmit,
51
+ }) => {
52
+ const [signer, setSigner] = useState<string>("");
53
+ const [dstChain, setDstChain] = useState<Chain>();
54
+ const [dstToken, setDstToken] = useState<Token>();
55
+ const [srcChain, setSrcChain] = useState<Chain>();
56
+ const [srcToken, setSrcToken] = useState<Token>();
57
+ const [amount, setAmount] = useState<string>("");
58
+ const [paymentToken, setPaymentToken] = useState<Token>();
59
+ const [slippage, setSlippage] = useState<number>();
60
+ const [slippageActivePresetIndex, setSlippageActivePresetIndex] = useState(1);
61
+ const [usingSlippageInput, setUsingSlippageInput] = useState(false);
62
+ const [chainListShown, setChainListShown] = useState(false);
63
+ const [tokenListShown, setTokenListShown] = useState(false);
64
+ const [route, setRoute] = useState<Route>();
65
+ const [expressChecked, setExpressChecked] = useState(true);
66
+ const [feesDetailsShown, setFeesDetailsShown] = useState(false);
67
+ const [historyTabShown, setHistoryTabShown] = useState(false);
68
+ const [isGettingRoute, setIsGettingRoute] = useState(false);
69
+ const [prices, setPrices] = useState<TokenPrices>();
70
+ const [balances, setBalances] = useState<TokenBalances>();
71
+
72
+ const debouncedAmount = useDebounce(amount, 1000);
73
+ const { ethereum } = window;
74
+
75
+ useEffect(() => {
76
+ setDstChain(supportedChains.find((chain) => chain.chainId === dstChainId));
77
+ }, [supportedChains]);
78
+
79
+ useEffect(() => {
80
+ setDstToken(
81
+ dstChain?.tokens.find(
82
+ (token) => token.address.toLowerCase() === dstTokenAddr.toLowerCase(),
83
+ ),
84
+ );
85
+ }, [dstChain]);
86
+
87
+ useEffect(() => {
88
+ if (!usingSlippageInput) {
89
+ setSlippage(SLIPPAGE_PRESETS[slippageActivePresetIndex]);
90
+ }
91
+ }, [slippageActivePresetIndex, usingSlippageInput]);
92
+
93
+ useEffect(() => {
94
+ if (
95
+ srcChain &&
96
+ srcToken &&
97
+ dstChain &&
98
+ debouncedAmount &&
99
+ paymentToken &&
100
+ slippage
101
+ ) {
102
+ setIsGettingRoute(true);
103
+ setFeesDetailsShown(false);
104
+ getRoute({
105
+ fromAmount: ethers.utils
106
+ .parseUnits(debouncedAmount, srcToken?.decimals)
107
+ .toString(),
108
+ fromAddress: signer || ADDRESSES[srcChain.chainId]!.FeeCollector,
109
+ fromChain: srcChain.chainId,
110
+ fromToken: srcToken.address,
111
+ toAddress: signer || ADDRESSES[dstChain.chainId]!.FeeCollector,
112
+ toChain: dstChainId,
113
+ toToken: dstTokenAddr,
114
+ paymentToken: paymentToken.address,
115
+ slippage,
116
+ expressDelivery: expressChecked,
117
+ customContractCalls,
118
+ })
119
+ .then((response) => setRoute(response))
120
+ .finally(() => setIsGettingRoute(false));
121
+ }
122
+ }, [
123
+ signer,
124
+ srcChain,
125
+ srcToken,
126
+ debouncedAmount,
127
+ paymentToken,
128
+ slippage,
129
+ expressChecked,
130
+ ]);
131
+
132
+ useEffect(() => {
133
+ if (ethereum) {
134
+ ethereum
135
+ .request({ method: "eth_accounts" })
136
+ .then((accounts: string[]) => {
137
+ if (accounts[0]) {
138
+ setSigner(accounts[0]);
139
+ }
140
+ });
141
+
142
+ ethereum.on("accountsChanged", (accounts: string[]) => {
143
+ if (accounts[0]) {
144
+ setSigner(accounts[0]);
145
+ }
146
+ });
147
+ return () => ethereum.removeListener("accountsChanged", () => {});
148
+ }
149
+ }, [ethereum]);
150
+
151
+ useEffect(() => {
152
+ if (
153
+ ethereum &&
154
+ ethereum.request &&
155
+ supportedChains &&
156
+ supportedChains.length > 0
157
+ ) {
158
+ ethereum.request({ method: "eth_chainId" }).then((chainId: string) => {
159
+ setSrcChain(
160
+ supportedChains.find(
161
+ (chain) => chain.chainId === parseInt(chainId, 16).toString(),
162
+ ),
163
+ );
164
+ });
165
+
166
+ ethereum.on("chainChanged", (chainId: string) => {
167
+ setSrcChain(
168
+ supportedChains.find(
169
+ (chain) => chain.chainId === parseInt(chainId, 16).toString(),
170
+ ),
171
+ );
172
+ });
173
+
174
+ return () => ethereum.removeListener("chainChanged", () => {});
175
+ }
176
+ }, [ethereum, supportedChains]);
177
+
178
+ useEffect(() => {
179
+ if (srcChain) {
180
+ setPaymentToken(
181
+ srcChain.tokens.find(
182
+ (token) =>
183
+ token.address.toLowerCase() ===
184
+ ethers.constants.AddressZero.toLowerCase(),
185
+ ),
186
+ );
187
+ }
188
+ }, [srcChain]);
189
+
190
+ useEffect(() => {
191
+ if (srcChain && !srcToken) {
192
+ setSrcToken(srcChain?.tokens[0]);
193
+ }
194
+ }, [srcChain]);
195
+
196
+ useEffect(() => {
197
+ if (srcChain) {
198
+ getPrices({ chainId: srcChain.chainId, currency: "USD" }).then((prices) =>
199
+ setPrices(prices),
200
+ );
201
+ }
202
+ }, [srcChain]);
203
+
204
+ useEffect(() => {
205
+ if (srcChain && signer) {
206
+ getBalances(srcChain, signer).then((balances) => setBalances(balances));
207
+ }
208
+ }, [srcChain, signer]);
209
+
210
+ const handleSubmit = (event: FormEvent<HTMLFormElement>) => {
211
+ event.preventDefault();
212
+ if (route) {
213
+ onSubmit(route);
214
+ } else {
215
+ // TODO error handling (cannot submit if no values)
216
+ }
217
+ };
218
+
219
+ return (
220
+ <form
221
+ className="flex flex-col gap-2 z-10 my-0 mx-auto p-2 rounded-3xl overflow-hidden w-96 sm:w-[482px] min-h-[562px]"
222
+ onSubmit={handleSubmit}
223
+ >
224
+ <div className="flex w-4/5 justify-between mx-auto">
225
+ <div className="rounded-lg text-[rgba(255,255,255,0.6)] py-1 px-2 text-sm whitespace-nowrap globalBorder">
226
+ {signer
227
+ ? `Connected wallet: ${shortAddress(signer)}`
228
+ : `Disconnected`}
229
+ </div>
230
+ {signer && (
231
+ <div
232
+ onClick={() => setHistoryTabShown((x) => !x)}
233
+ className="flex items-center text-xs gap-1 cursor-pointer"
234
+ >
235
+ {!historyTabShown ? (
236
+ <>
237
+ <HistoryIcon />
238
+ <div>History</div>
239
+ </>
240
+ ) : (
241
+ <div>Back</div>
242
+ )}
243
+ </div>
244
+ )}
245
+ </div>
246
+ {historyTabShown ? (
247
+ <div className="flex items-center justify-center w-full">
248
+ <History signer={signer} supportedChains={supportedChains} />
249
+ </div>
250
+ ) : (
251
+ <div className="flex flex-col gap-2">
252
+ {desc && (
253
+ <div className="flex flex-col items-start globalBorder rounded-lg bg-[rgba(15,15,15,1)] p-4">
254
+ <div className="w-full flex gap-4 items-start justify-between mb-4">
255
+ {desc}
256
+ </div>
257
+ </div>
258
+ )}
259
+ <div className="flex flex-col items-start globalBorder rounded-lg bg-[rgba(15,15,15,1)] p-4">
260
+ <div className="w-full flex gap-4 items-start justify-between mb-4">
261
+ <div className="flex flex-col overflow-hidden w-1/2">
262
+ <input
263
+ className="p-0 border-none bg-transparent text-2xl overflow-ellipsis"
264
+ value={amount}
265
+ onChange={(e) => {
266
+ if (e.target.value === ".") return;
267
+ if (NUMBER_INPUT_REGEX.test(e.target.value)) {
268
+ setIsGettingRoute(true);
269
+ setFeesDetailsShown(false);
270
+ setAmount(e.target.value.replace(/,/g, "."));
271
+ }
272
+ }}
273
+ inputMode="decimal"
274
+ spellCheck="false"
275
+ autoComplete="off"
276
+ autoCorrect="off"
277
+ placeholder="0"
278
+ />
279
+ </div>
280
+ <div className="flex flex-col relative items-end gap-2.5 w-1/2">
281
+ <div
282
+ className="flex gap-2 items-center p-2 max-w-full cursor-pointer bg-black text-white text-xs globalBorder rounded-3xl whitespace-nowrap"
283
+ onClick={() => {
284
+ setTokenListShown((state) => !state);
285
+ }}
286
+ >
287
+ <img
288
+ height={16}
289
+ width={16}
290
+ src={srcToken?.image}
291
+ style={{ marginRight: "4px" }}
292
+ alt={srcToken?.name}
293
+ />
294
+ <div>{srcToken?.symbol}</div>
295
+ <DownArrowIcon />
296
+ </div>
297
+
298
+ {tokenListShown && (
299
+ <TokenPicker
300
+ onCloseClick={() => setTokenListShown(false)}
301
+ tokens={srcChain?.tokens}
302
+ signer={signer}
303
+ selectedToken={srcToken}
304
+ setSelectedToken={(token) => setSrcToken(token)}
305
+ balances={balances}
306
+ />
307
+ )}
308
+
309
+ <div className="flex gap-2 items-center text-xs font-medium text-white opacity-60 py-0.5 px-2">
310
+ {signer && (
311
+ <>
312
+ Balance:{" "}
313
+ {srcToken && balances ? (
314
+ weiToHumanReadable({
315
+ amount: balances[srcToken.address]?.toString() || "0",
316
+ decimals: srcToken.decimals,
317
+ precisionFractionalPlaces: 4,
318
+ })
319
+ ) : (
320
+ <Skeleton w="w-12" h="h-3" />
321
+ )}
322
+ </>
323
+ )}
324
+ </div>
325
+ </div>
326
+ </div>
327
+
328
+ <div className="flex justify-between items-center w-full text-xs text-[rgba(255,255,255,0.6)] relative">
329
+ {srcToken ? (
330
+ prices && prices[srcToken.address] ? (
331
+ <div>
332
+ {`$${(
333
+ Number(amount) * Number(prices[srcToken.address])
334
+ ).toFixed(2)}`}
335
+ </div>
336
+ ) : (
337
+ <Alert desc="Unknown price" />
338
+ )
339
+ ) : (
340
+ <>$0.00</>
341
+ )}
342
+ <div
343
+ className="bg-black globalBorder rounded-2xl whitespace-nowrap flex items-center p-2 cursor-pointer gap-1"
344
+ onClick={() => setChainListShown((prev) => !prev)}
345
+ >
346
+ <img
347
+ width={12}
348
+ height={12}
349
+ src={srcChain?.image}
350
+ alt={srcChain?.name}
351
+ />
352
+ <div>{srcChain?.displayName}</div>
353
+ <DownArrowIcon />
354
+ </div>
355
+
356
+ {chainListShown && (
357
+ <ul className="bg-black globalBorder rounded-lg whitespace-nowrap z-1 right-0 top-10 px-2 max-w-full max-h-[40vh] overflow-auto absolute text-sm z-20">
358
+ {supportedChains
359
+ .filter((chain) => chain.chainId !== srcChain?.chainId)
360
+ .map((chain, index) => (
361
+ <div key={`${chain.ecosystem}-${chain.chainId}`}>
362
+ <li
363
+ className="bg-transparent border-none flex gap-1 items-center cursor-pointer py-2 w-full"
364
+ key={index}
365
+ onClick={() => {
366
+ setSrcChain(chain);
367
+ setChainListShown(false);
368
+ }}
369
+ >
370
+ <img
371
+ width={12}
372
+ height={12}
373
+ src={chain.image}
374
+ alt={chain.displayName}
375
+ />
376
+ {chain.displayName}
377
+ </li>
378
+ {index !== supportedChains.length - 1 && (
379
+ <div className="h-px mx-2 bg-[rgba(255,255,255,0.15)]"></div>
380
+ )}
381
+ </div>
382
+ ))}
383
+ </ul>
384
+ )}
385
+ </div>
386
+ </div>
387
+ <div className="flex flex-col items-start globalBorder rounded-lg bg-[rgba(15,15,15,1)] p-4">
388
+ <div className="flex justify-around sm:justify-start gap-4 items-center w-full text-xs text-[rgba(255,255,255,0.6)]">
389
+ <div className="flex flex-col items-center sm:flex-row gap-1">
390
+ You're getting:
391
+ {isGettingRoute && amount.length > 0 ? (
392
+ <div className="bg-current rounded animate-pulse w-[190px] h-7" />
393
+ ) : (
394
+ <div className="flex gap-1">
395
+ <div className="text-white text-lg">
396
+ {weiToHumanReadable({
397
+ amount: route?.estAmountOut || "0",
398
+ decimals: dstToken?.decimals || 18,
399
+ precisionFractionalPlaces: 5,
400
+ })}
401
+ </div>
402
+ <div className="flex items-center gap-1 text-white">
403
+ <div className="w-4 h-4">
404
+ <img src={dstToken?.image} alt={dstToken?.name} />
405
+ </div>
406
+ <div className="text-lg">{dstToken?.symbol}</div>
407
+ </div>
408
+ </div>
409
+ )}
410
+ </div>
411
+ <div className="flex flex-col sm:flex-row gap-1">
412
+ on chain:
413
+ <div className="flex gap-1 text-white">
414
+ <div className="w-4 h-4">
415
+ <img src={dstChain?.image} alt={dstChain?.name} />
416
+ </div>
417
+ <div>{dstChain?.displayName}</div>
418
+ </div>
419
+ </div>
420
+ </div>
421
+ </div>
422
+ <div className="flex flex-col gap-2 globalBorder rounded-lg bg-[rgba(15,15,15,1)] p-4">
423
+ <div className="flex w-full items-center justify-between">
424
+ <div className="flex gap-1 text-xs font-medium text-white opacity-60">
425
+ <CoinsIcon />
426
+ <div className="mr-1">Fees:</div>
427
+ {isGettingRoute ? (
428
+ <div className="bg-current rounded animate-pulse w-20 h-4" />
429
+ ) : (
430
+ ` ${weiToHumanReadable({
431
+ amount: safeBigNumberFrom(
432
+ route?.xSwapFees.xSwapFee.nativeFee || "0",
433
+ )
434
+ .add(safeBigNumberFrom(route?.xSwapFees.ccipFee || "0"))
435
+ .add(
436
+ safeBigNumberFrom(
437
+ route?.xSwapFees.expressDeliveryFee || "0",
438
+ ),
439
+ )
440
+ .toString(),
441
+ decimals: 18,
442
+ precisionFractionalPlaces: 5,
443
+ })} ${paymentToken?.symbol}`
444
+ )}
445
+ </div>
446
+ <div
447
+ onClick={() => setFeesDetailsShown((x) => !x)}
448
+ className="text-xs font-medium text-white opacity-60 cursor-pointer"
449
+ >
450
+ {feesDetailsShown ? <ChevronUpIcon /> : <ChevronDownIcon />}
451
+ </div>
452
+ </div>
453
+ {feesDetailsShown && (
454
+ <div className="flex w-full items-center justify-between ">
455
+ <div className="flex flex-col text-[10px] ">
456
+ <div className="font-medium text-white opacity-60">
457
+ CCIP Fee:
458
+ {` ${weiToHumanReadable({
459
+ amount: route?.xSwapFees.ccipFee || "0",
460
+ decimals: 18,
461
+ precisionFractionalPlaces: 5,
462
+ })} ${paymentToken?.symbol}`}
463
+ </div>
464
+ <div className="font-medium text-white opacity-60">
465
+ Native Fee:
466
+ {` ${weiToHumanReadable({
467
+ amount: route?.xSwapFees.xSwapFee.nativeFee || "0",
468
+ decimals: 18,
469
+ precisionFractionalPlaces: 5,
470
+ })} ${paymentToken?.symbol}`}
471
+ </div>
472
+ </div>
473
+ <div className="flex flex-col text-[10px] ">
474
+ <div className="font-medium text-white opacity-60">
475
+ Slippage: {`${slippage}%`}
476
+ </div>
477
+ <div className="font-medium text-white opacity-60">
478
+ Min amount out:{" "}
479
+ {weiToHumanReadable({
480
+ amount: route?.minAmountOut || "0",
481
+ decimals: dstToken?.decimals || 18,
482
+ precisionFractionalPlaces: 5,
483
+ })}{" "}
484
+ {dstToken?.symbol}
485
+ </div>
486
+ </div>
487
+ </div>
488
+ )}
489
+ </div>
490
+ <div className="flex justify-between">
491
+ <div className="flex flex-col gap-2 ">
492
+ <div className=" text-[rgba(255,255,255,0.6)]">Slippage:</div>
493
+ <div className="flex gap-2">
494
+ <div className="flex items-center bg-[rgba(15,15,15,1)] p-1 globalBorder rounded-xl">
495
+ {SLIPPAGE_PRESETS.map((preset, index) => (
496
+ <div
497
+ key={index}
498
+ className={`transition-all cursor-pointer block rounded-lg p-2 border-none text-sm ${
499
+ index === slippageActivePresetIndex &&
500
+ !usingSlippageInput
501
+ ? "text-white"
502
+ : "text-[rgba(255,255,255,0.2)]"
503
+ } ${
504
+ index === slippageActivePresetIndex &&
505
+ !usingSlippageInput
506
+ ? "bg-gradient-to-r from-[#3681c6] to-[#2b4a9d]"
507
+ : ""
508
+ }`}
509
+ onClick={() => {
510
+ setUsingSlippageInput(false);
511
+ setSlippageActivePresetIndex(index);
512
+ }}
513
+ >
514
+ {`${preset}%`}
515
+ </div>
516
+ ))}
517
+ </div>
518
+ <div className="bg-[rgba(39,39,39,1)] p-2 border border-solid border-[rgba(82,82,82,1)] rounded-xl text-white flex items-center">
519
+ <input
520
+ className="text-white border-none bg-[rgba(39,39,39,1)] w-10 placeholder:text-[rgba(255,255,255,0.2)] focus:outline-none"
521
+ placeholder="1.5"
522
+ value={usingSlippageInput ? slippage : ""}
523
+ onChange={(e) => {
524
+ if (e.target.value.length > 0) {
525
+ if (NUMBER_INPUT_REGEX.test(e.target.value)) {
526
+ setUsingSlippageInput(true);
527
+ setSlippage(Number(e.target.value));
528
+ }
529
+ } else {
530
+ setUsingSlippageInput(false);
531
+ setSlippageActivePresetIndex(1);
532
+ }
533
+ }}
534
+ />
535
+ <PercentageIcon />
536
+ </div>
537
+ </div>
538
+ </div>
539
+
540
+ <div className="flex gap-2 items-center">
541
+ <div className=" text-[rgba(255,255,255,0.6)]">
542
+ Express delivery:
543
+ </div>
544
+ <div>
545
+ <span
546
+ className="inline-flex w-14 h-9 p-3 relative align-middle box-border overflow-hidden cursor-pointer"
547
+ onClick={() => {
548
+ setExpressChecked((x) => !x);
549
+ }}
550
+ >
551
+ <span className="h-full, w-full rounded-lg bg-[rgba(255,255,255,0.3)]"></span>
552
+ <span
553
+ className={`transition-all w-5 h-5 rounded-full absolute translate-y-[-4px]
554
+ ${
555
+ expressChecked ? "translate-x-[12px] bg-x_blue" : "bg-white"
556
+ } `}
557
+ ></span>
558
+ </span>
559
+ </div>
560
+ </div>
561
+ </div>
562
+ <button disabled={!signer || !route || isGettingRoute}>Submit</button>
563
+ </div>
564
+ )}
565
+ </form>
566
+ );
567
+ };