@xswap-link/sdk 0.2.5 → 0.3.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 (47) hide show
  1. package/.github/workflows/main.yml +2 -2
  2. package/.github/workflows/publish.yml +2 -2
  3. package/CHANGELOG.md +12 -0
  4. package/dist/index.css +325 -257
  5. package/dist/index.d.mts +4 -2
  6. package/dist/index.d.ts +4 -2
  7. package/dist/index.js +1296 -516
  8. package/dist/index.mjs +1323 -537
  9. package/package.json +1 -1
  10. package/src/components/Alert/index.tsx +1 -1
  11. package/src/components/Skeleton/index.tsx +3 -1
  12. package/src/components/Spinner/index.tsx +28 -0
  13. package/src/components/TxConfigForm/BalanceComponent.tsx +1 -1
  14. package/src/components/TxConfigForm/Button.tsx +1 -1
  15. package/src/components/TxConfigForm/ChainListElement.tsx +2 -2
  16. package/src/components/TxConfigForm/ConfirmationAmount.tsx +91 -0
  17. package/src/components/TxConfigForm/Description.tsx +5 -3
  18. package/src/components/TxConfigForm/ErrorField.tsx +4 -2
  19. package/src/components/TxConfigForm/FeesDetails.tsx +25 -31
  20. package/src/components/TxConfigForm/Form.tsx +763 -118
  21. package/src/components/TxConfigForm/History.tsx +5 -5
  22. package/src/components/TxConfigForm/HistoryCard.tsx +33 -40
  23. package/src/components/TxConfigForm/PoweredBy.tsx +2 -2
  24. package/src/components/TxConfigForm/Settings.tsx +33 -27
  25. package/src/components/TxConfigForm/Summary.tsx +33 -31
  26. package/src/components/TxConfigForm/SwapPanel.tsx +12 -15
  27. package/src/components/TxConfigForm/TokenPicker.tsx +36 -34
  28. package/src/components/TxConfigForm/TopBar.tsx +8 -8
  29. package/src/components/TxConfigForm/UsdPrice.tsx +4 -14
  30. package/src/components/TxConfigForm/index.tsx +37 -10
  31. package/src/components/TxStatusButton/index.tsx +42 -28
  32. package/src/components/UnknownTokenLogo/UnknownTokenLogo.tsx +1 -1
  33. package/src/components/global.css +7 -5
  34. package/src/components/icons/CircularProgressIcon.tsx +1 -1
  35. package/src/components/icons/ErrorIcon.tsx +32 -0
  36. package/src/components/icons/SignIcon.tsx +17 -0
  37. package/src/components/icons/SuccessIcon.tsx +29 -0
  38. package/src/components/icons/index.ts +3 -0
  39. package/src/config/init.tsx +42 -24
  40. package/src/constants/index.ts +2 -2
  41. package/src/models/payloads/GetSwapTxPayload.ts +2 -0
  42. package/src/services/integrations/monitoring.ts +10 -3
  43. package/src/services/integrations/transactions.ts +9 -3
  44. package/src/utils/contracts.ts +18 -0
  45. package/src/utils/index.ts +1 -0
  46. package/src/utils/parseWeb3Error.ts +93 -0
  47. package/tailwind.config.js +40 -0
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@xswap-link/sdk",
3
- "version": "0.2.5",
3
+ "version": "0.3.0",
4
4
  "description": "JavaScript SDK for XSwap platform",
5
5
  "homepage": "https://github.com/xswap-link/xswap-sdk",
6
6
  "repository": {
@@ -2,7 +2,7 @@ import React from "react";
2
2
 
3
3
  export const Alert = ({ desc }: { desc: string }) => {
4
4
  return (
5
- <div className="border border-solid border-x_alert rounded-3xl text-x_alert_light text-xs py-0.5 px-2">
5
+ <div className="xpay-border xpay-border-solid xpay-border-x_alert xpay-rounded-3xl xpay-text-x_alert_light xpay-text-xs xpay-py-0.5 xpay-px-2">
6
6
  ⚠️ {desc}
7
7
  </div>
8
8
  );
@@ -8,6 +8,8 @@ type Props = {
8
8
 
9
9
  export const Skeleton = ({ width, height }: Props) => {
10
10
  return (
11
- <div className={`bg-current rounded animate-pulse ${width} ${height}`} />
11
+ <div
12
+ className={`xpay-bg-gray-700 xpay-rounded xpay-animate-pulse ${width} ${height}`}
13
+ />
12
14
  );
13
15
  };
@@ -0,0 +1,28 @@
1
+ type Props = {
2
+ width: string;
3
+ height: string;
4
+ other?: string;
5
+ };
6
+
7
+ export const Spinner = ({ width, height }: Props) => {
8
+ return (
9
+ <div role="status">
10
+ <svg
11
+ aria-hidden="true"
12
+ className={`xpay-w-${width} xpay-h-${height} xpay-text-gray-200 xpay-animate-spin dark:xpay-text-gray-600 xpay-fill-[rgba(54,129,198,1)]`}
13
+ viewBox="0 0 100 101"
14
+ fill="none"
15
+ xmlns="http://www.w3.org/2000/svg"
16
+ >
17
+ <path
18
+ d="M100 50.5908C100 78.2051 77.6142 100.591 50 100.591C22.3858 100.591 0 78.2051 0 50.5908C0 22.9766 22.3858 0.59082 50 0.59082C77.6142 0.59082 100 22.9766 100 50.5908ZM9.08144 50.5908C9.08144 73.1895 27.4013 91.5094 50 91.5094C72.5987 91.5094 90.9186 73.1895 90.9186 50.5908C90.9186 27.9921 72.5987 9.67226 50 9.67226C27.4013 9.67226 9.08144 27.9921 9.08144 50.5908Z"
19
+ fill="currentColor"
20
+ />
21
+ <path
22
+ d="M93.9676 39.0409C96.393 38.4038 97.8624 35.9116 97.0079 33.5539C95.2932 28.8227 92.871 24.3692 89.8167 20.348C85.8452 15.1192 80.8826 10.7238 75.2124 7.41289C69.5422 4.10194 63.2754 1.94025 56.7698 1.05124C51.7666 0.367541 46.6976 0.446843 41.7345 1.27873C39.2613 1.69328 37.813 4.19778 38.4501 6.62326C39.0873 9.04874 41.5694 10.4717 44.0505 10.1071C47.8511 9.54855 51.7191 9.52689 55.5402 10.0491C60.8642 10.7766 65.9928 12.5457 70.6331 15.2552C75.2735 17.9648 79.3347 21.5619 82.5849 25.841C84.9175 28.9121 86.7997 32.2913 88.1811 35.8758C89.083 38.2158 91.5421 39.6781 93.9676 39.0409Z"
23
+ fill="currentFill"
24
+ />
25
+ </svg>
26
+ </div>
27
+ );
28
+ };
@@ -43,7 +43,7 @@ export const BalanceComponent: FC<Props> = ({ srcToken, balances }) => {
43
43
  precisionFractionalPlaces: 4,
44
44
  })
45
45
  : 0}
46
- <span className="bg-gradient-to-r from-x_blue_light to-x_blue_dark bg-clip-text text-transparent">
46
+ <span className="xpay-bg-gradient-to-r xpay-from-x_blue_light xpay-to-x_blue_dark xpay-bg-clip-text xpay-text-transparent">
47
47
  Max
48
48
  </span>
49
49
  </>
@@ -9,7 +9,7 @@ interface Props {
9
9
  export const Button: FC<Props> = ({ children, onClick, type, disabled }) => {
10
10
  return (
11
11
  <button
12
- className="text-white border-none rounded-2xl text-xl py-4 cursor-pointer w-full bg-gradient-to-r from-[#3681c6] to-[#2b4a9d] disabled:opacity-25"
12
+ className="xpay-text-white xpay-border-none xpay-rounded-2xl xpay-text-xl xpay-py-4 xpay-cursor-pointer xpay-w-full xpay-bg-gradient-to-r xpay-from-[#3681c6] xpay-to-[#2b4a9d] disabled:xpay-opacity-25"
13
13
  onClick={onClick}
14
14
  type={type}
15
15
  disabled={disabled}
@@ -19,7 +19,7 @@ export const ChainListElement: FC<Props> = ({
19
19
  return (
20
20
  <div key={`${chain.ecosystem}-${chain.chainId}`}>
21
21
  <li
22
- className="bg-transparent border-none flex gap-1 items-center cursor-pointer py-2 w-full"
22
+ className="xpay-bg-transparent xpay-border-none xpay-flex xpay-gap-1 xpay-items-center xpay-cursor-pointer xpay-py-2 xpay-w-full"
23
23
  onClick={() => {
24
24
  setSrcChain(chain);
25
25
  setChainListShown(false);
@@ -29,7 +29,7 @@ export const ChainListElement: FC<Props> = ({
29
29
  {chain.displayName}
30
30
  </li>
31
31
  {index !== length - 1 && (
32
- <div className="h-px mx-2 bg-[rgba(255,255,255,0.15)]"></div>
32
+ <div className="xpay-h-px xpay-mx-2 xpay-bg-[rgba(255,255,255,0.15)]"></div>
33
33
  )}
34
34
  </div>
35
35
  );
@@ -0,0 +1,91 @@
1
+ import { FC, useEffect, useMemo, useState } from "react";
2
+ import { weiToHumanReadable } from "@src/utils";
3
+ import { Chain, Token, TokenPrices } from "@src/models";
4
+ import { UsdPrice } from "@src/components/TxConfigForm/UsdPrice";
5
+ import { getPrices } from "@src/services";
6
+ import { UnknownTokenLogo } from "../UnknownTokenLogo/UnknownTokenLogo";
7
+
8
+ interface Props {
9
+ amount: string;
10
+ token?: Token;
11
+ chain?: Chain;
12
+ type: "src" | "dst";
13
+ }
14
+
15
+ export const ConfirmationAmount: FC<Props> = ({
16
+ amount,
17
+ token,
18
+ chain,
19
+ type,
20
+ }) => {
21
+ const [prices, setPrices] = useState<TokenPrices>();
22
+
23
+ const amountReadable = useMemo(() => {
24
+ return weiToHumanReadable({
25
+ amount: amount || "0",
26
+ decimals: token?.decimals || 18,
27
+ precisionFractionalPlaces: 8,
28
+ });
29
+ }, [amount, token]);
30
+
31
+ useEffect(() => {
32
+ if (chain) {
33
+ getPrices({ chainId: chain.chainId, currency: "USD" }).then((prices) =>
34
+ setPrices(prices),
35
+ );
36
+ }
37
+ }, [chain]);
38
+
39
+ return (
40
+ <div className="xpay-flex xpay-flex-col xpay-globalBorder xpay-rounded-xl xpay-bg-gradient-to-r xpay-from-x_blue_300_20 xpay-to-x_blue_400_20 xpay-p-4 xpay-relative">
41
+ <div className="xpay-flex xpay-justify-between">
42
+ <div className="xpay-flex xpay-flex-col xpay-gap-1">
43
+ <p className="xpay-text-white xpay-opacity-60 xpay-text-xs sm:xpay-text-sm xpay-font-medium">
44
+ {type === "src" ? "You pay" : "You receive"}
45
+ </p>
46
+ <div
47
+ className={`xpay-flex xpay-gap-2 xpay-items-center xpay-text-xl sm:xpay-text-3xl ${
48
+ type === "dst"
49
+ ? "xpay-text-[rgba(54,129,198,1)]"
50
+ : "xpay-text-white"
51
+ }`}
52
+ >
53
+ {amountReadable}
54
+ </div>
55
+
56
+ <UsdPrice
57
+ prices={prices}
58
+ token={token}
59
+ amount={amountReadable}
60
+ loading={false}
61
+ />
62
+ </div>
63
+ <div className="xpay-flex xpay-gap-2 xpay-text-sm xpay-justify-center xpay-items-center">
64
+ <div className="xpay-flex xpay-flex-col xpay-justify-center xpay-items-end xpay-gap-1">
65
+ <p className="xpay-text-base sm:xpay-text-xl">{token?.name}</p>
66
+ <div className="xpay-flex xpay-justify-center xpay-items-center xpay-gap-1">
67
+ <p className="xpay-text-[rgba(255,255,255,0.6)] xpay-text-xs xpay-text-right">
68
+ {chain?.displayName}
69
+ </p>
70
+ </div>
71
+ </div>
72
+
73
+ <div className="xpay-w-10 xpay-h-10">
74
+ {token?.image ? (
75
+ <img
76
+ className="xpay-w-10 xpay-h-10"
77
+ src={token?.image}
78
+ alt={token?.name}
79
+ />
80
+ ) : (
81
+ <UnknownTokenLogo
82
+ tokenName={"?"}
83
+ className="xpay-w-10 xpay-h-10"
84
+ />
85
+ )}
86
+ </div>
87
+ </div>
88
+ </div>
89
+ </div>
90
+ );
91
+ };
@@ -6,9 +6,11 @@ interface Props {
6
6
 
7
7
  export const Description: FC<Props> = ({ description }) => {
8
8
  return (
9
- <div className="flex flex-col items-start rounded-lg px-4 py-2">
10
- <div className="w-full flex gap-4 items-start justify-between text-xl">
11
- {description}
9
+ <div className="xpay-flex xpay-flex-col xpay-gap-3 xpay-global-border xpay-rounded-lg xpay-bg-[rgba(15,15,15,1)] xpay-p-2 sm:xpay-p-4 ">
10
+ <div className="xpay-flex xpay-w-full xpay-items-center xpay-justify-between xpay-text-xs sm:xpay-text-sm">
11
+ <div className="xpay-flex xpay-items-center xpay-gap-1 xpay-font-medium xpay-text-white xpay-opacity-60">
12
+ {description}
13
+ </div>
12
14
  </div>
13
15
  </div>
14
16
  );
@@ -7,8 +7,10 @@ interface Props {
7
7
  export const ErrorField: FC<Props> = ({ error }) => {
8
8
  return (
9
9
  <div
10
- className={`flex justify-center mb-1 items-center w-full rounded-2xl bg-x_error_background border border-solid ${
11
- error.length > 0 ? "border-x_error_border" : "border-transparent"
10
+ className={`xpay-flex xpay-justify-center xpay-mb-1 xpay-items-center xpay-w-full xpay-rounded-2xl xpay-bg-x_error_background xpay-border xpay-border-solid ${
11
+ error.length > 0
12
+ ? "xpay-border-x_error_border"
13
+ : "xpay-border-transparent"
12
14
  }`}
13
15
  >
14
16
  {error}
@@ -9,10 +9,9 @@ interface Props {
9
9
  isGettingRoute: boolean;
10
10
  paymentToken: Token | undefined;
11
11
  dstToken: Token | undefined;
12
- expressChecked: boolean;
13
- exceedsExpressDeliveryLimit: boolean;
14
12
  slippage: string | undefined;
15
13
  feesDetailsShown: boolean;
14
+ isExpressDelivery: boolean;
16
15
  setFeesDetailsShown: React.Dispatch<React.SetStateAction<boolean>>;
17
16
  }
18
17
 
@@ -21,24 +20,19 @@ export const FeesDetails: FC<Props> = ({
21
20
  route,
22
21
  paymentToken,
23
22
  dstToken,
24
- expressChecked,
25
- exceedsExpressDeliveryLimit,
26
23
  slippage,
27
24
  feesDetailsShown,
25
+ isExpressDelivery,
28
26
  setFeesDetailsShown,
29
27
  }) => {
30
- const isExpressDeliveryPossible = useMemo(() => {
31
- return expressChecked && !exceedsExpressDeliveryLimit;
32
- }, [expressChecked, exceedsExpressDeliveryLimit]);
33
-
34
28
  return (
35
- <div className="flex flex-col gap-3 globalBorder rounded-lg bg-[rgba(15,15,15,1)] p-2 sm:p-4 mb-1">
36
- <div className="flex w-full items-center justify-between text-xs sm:text-sm">
37
- <div className="flex items-center gap-1 font-medium text-white opacity-60">
29
+ <div className="xpay-flex xpay-flex-col xpay-gap-3 xpay-global-border xpay-rounded-lg xpay-bg-[rgba(15,15,15,1)] xpay-p-2 sm:xpay-p-4 ">
30
+ <div className="xpay-flex xpay-w-full xpay-items-center xpay-justify-between xpay-text-xs sm:xpay-text-sm">
31
+ <div className="xpay-flex xpay-items-center xpay-gap-1 xpay-font-medium xpay-text-white xpay-opacity-60">
38
32
  <CoinsIcon />
39
- <div className="mr-1">Fees:</div>
33
+ <div className="xpay-mr-1">Fees:</div>
40
34
  {isGettingRoute ? (
41
- <Skeleton width="w-20" height="h-4" />
35
+ <Skeleton width="xpay-w-20" height="xpay-h-4" />
42
36
  ) : (
43
37
  ` ${weiToHumanReadable({
44
38
  amount: safeBigNumberFrom(
@@ -54,33 +48,33 @@ export const FeesDetails: FC<Props> = ({
54
48
  })} ${paymentToken?.symbol}`
55
49
  )}
56
50
  </div>
57
- <div className="flex gap-1 items-center">
51
+ <div className="xpay-flex xpay-gap-1 xpay-items-center">
58
52
  {route?.xSwapFees.expressDeliveryFee && !isGettingRoute && (
59
53
  <div
60
- className={`flex gap-1 items-center font-medium ${
61
- isExpressDeliveryPossible
62
- ? "text-x_green"
63
- : "text-white opacity-60"
54
+ className={`xpay-flex xpay-gap-1 xpay-items-center xpay-font-medium ${
55
+ isExpressDelivery
56
+ ? "xpay-text-x_green"
57
+ : "xpay-text-white xpay-opacity-60"
64
58
  }`}
65
59
  >
66
60
  <TimerIcon />
67
- {isExpressDeliveryPossible ? "Fast ~ 30sec " : "Normal ~ 30min"}
61
+ {isExpressDelivery ? "Fast ~ 30sec " : "Normal ~ 30min"}
68
62
  </div>
69
63
  )}
70
64
  <div
71
65
  onClick={() => setFeesDetailsShown((x) => !x)}
72
- className="font-medium text-white opacity-60 cursor-pointer flex items-center w-[15px] h-[9px]"
66
+ className="xpay-font-medium xpay-text-white xpay-opacity-60 xpay-cursor-pointer xpay-flex xpay-items-center xpay-w-[15px] xpay-h-[9px]"
73
67
  >
74
68
  {feesDetailsShown ? <ChevronUpIcon /> : <ChevronDownIcon />}
75
69
  </div>
76
70
  </div>
77
71
  </div>
78
72
  {feesDetailsShown && (
79
- <div className="flex w-full items-center justify-between gap-2">
80
- <div className="flex flex-col text-[10px] gap-1">
81
- <div className="flex justify-between font-medium text-white opacity-60 gap-1">
73
+ <div className="xpay-flex xpay-w-full xpay-items-center xpay-justify-between xpay-gap-2">
74
+ <div className="xpay-flex xpay-flex-col xpay-text-[10px] xpay-gap-1">
75
+ <div className="xpay-flex xpay-justify-between xpay-font-medium xpay-text-white xpay-opacity-60 xpay-gap-1">
82
76
  <div>CCIP Fee:</div>
83
- <div className="whitespace-nowrap">
77
+ <div className="xpay-whitespace-nowrap">
84
78
  {` ${weiToHumanReadable({
85
79
  amount: route?.xSwapFees.ccipFee || "0",
86
80
  decimals: 18,
@@ -88,9 +82,9 @@ export const FeesDetails: FC<Props> = ({
88
82
  })} ${paymentToken?.symbol}`}
89
83
  </div>
90
84
  </div>
91
- <div className="flex justify-between font-medium text-white opacity-60 gap-1">
85
+ <div className="xpay-flex xpay-justify-between xpay-font-medium xpay-text-white xpay-opacity-60 xpay-gap-1">
92
86
  <div>Native Fee:</div>
93
- <div className="whitespace-nowrap">
87
+ <div className="xpay-whitespace-nowrap">
94
88
  {` ${weiToHumanReadable({
95
89
  amount: route?.xSwapFees.xSwapFee.nativeFee || "0",
96
90
  decimals: 18,
@@ -99,14 +93,14 @@ export const FeesDetails: FC<Props> = ({
99
93
  </div>
100
94
  </div>
101
95
  </div>
102
- <div className="flex flex-col text-[10px] gap-1">
103
- <div className="flex justify-between font-medium text-white opacity-60 gap-1">
96
+ <div className="xpay-flex xpay-flex-col xpay-text-[10px] xpay-gap-1">
97
+ <div className="xpay-flex xpay-justify-between xpay-font-medium xpay-text-white xpay-opacity-60 xpay-gap-1">
104
98
  <div>Slippage:</div>
105
- <div className="whitespace-nowrap">{`${slippage}%`}</div>
99
+ <div className="xpay-whitespace-nowrap">{`${slippage}%`}</div>
106
100
  </div>
107
- <div className="flex justify-between font-medium text-white opacity-60 gap-1">
101
+ <div className="xpay-flex xpay-justify-between xpay-font-medium xpay-text-white xpay-opacity-60 xpay-gap-1">
108
102
  <div>Min amount out:</div>
109
- <div className="whitespace-nowrap">
103
+ <div className="xpay-whitespace-nowrap">
110
104
  {weiToHumanReadable({
111
105
  amount: route?.minAmountOut || "0",
112
106
  decimals: dstToken?.decimals || 18,