@xswap-link/sdk 0.2.6 → 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 (34) hide show
  1. package/.github/workflows/main.yml +2 -2
  2. package/.github/workflows/publish.yml +2 -2
  3. package/CHANGELOG.md +6 -0
  4. package/dist/index.css +99 -2
  5. package/dist/index.d.mts +4 -2
  6. package/dist/index.d.ts +4 -2
  7. package/dist/index.js +1178 -409
  8. package/dist/index.mjs +1205 -430
  9. package/package.json +1 -1
  10. package/src/components/Skeleton/index.tsx +1 -1
  11. package/src/components/Spinner/index.tsx +28 -0
  12. package/src/components/TxConfigForm/ConfirmationAmount.tsx +91 -0
  13. package/src/components/TxConfigForm/Description.tsx +5 -3
  14. package/src/components/TxConfigForm/FeesDetails.tsx +5 -11
  15. package/src/components/TxConfigForm/Form.tsx +763 -118
  16. package/src/components/TxConfigForm/HistoryCard.tsx +1 -1
  17. package/src/components/TxConfigForm/Summary.tsx +9 -8
  18. package/src/components/TxConfigForm/SwapPanel.tsx +1 -4
  19. package/src/components/TxConfigForm/UsdPrice.tsx +3 -13
  20. package/src/components/TxConfigForm/index.tsx +33 -6
  21. package/src/components/TxStatusButton/index.tsx +12 -2
  22. package/src/components/icons/ErrorIcon.tsx +32 -0
  23. package/src/components/icons/SignIcon.tsx +17 -0
  24. package/src/components/icons/SuccessIcon.tsx +29 -0
  25. package/src/components/icons/index.ts +3 -0
  26. package/src/config/init.tsx +27 -10
  27. package/src/constants/index.ts +2 -2
  28. package/src/models/payloads/GetSwapTxPayload.ts +2 -0
  29. package/src/services/integrations/monitoring.ts +10 -3
  30. package/src/services/integrations/transactions.ts +9 -3
  31. package/src/utils/contracts.ts +18 -0
  32. package/src/utils/index.ts +1 -0
  33. package/src/utils/parseWeb3Error.ts +93 -0
  34. package/tailwind.config.js +39 -0
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@xswap-link/sdk",
3
- "version": "0.2.6",
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": {
@@ -9,7 +9,7 @@ type Props = {
9
9
  export const Skeleton = ({ width, height }: Props) => {
10
10
  return (
11
11
  <div
12
- className={`xpay-bg-current xpay-rounded xpay-animate-pulse ${width} ${height}`}
12
+ className={`xpay-bg-gray-700 xpay-rounded xpay-animate-pulse ${width} ${height}`}
13
13
  />
14
14
  );
15
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
+ };
@@ -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="xpay-flex xpay-flex-col xpay-items-start xpay-rounded-lg xpay-px-4 xpay-py-2">
10
- <div className="xpay-w-full xpay-flex xpay-gap-4 xpay-items-start xpay-justify-between xpay-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
  );
@@ -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,18 +20,13 @@ 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="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 xpay-mb-1">
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 ">
36
30
  <div className="xpay-flex xpay-w-full xpay-items-center xpay-justify-between xpay-text-xs sm:xpay-text-sm">
37
31
  <div className="xpay-flex xpay-items-center xpay-gap-1 xpay-font-medium xpay-text-white xpay-opacity-60">
38
32
  <CoinsIcon />
@@ -58,13 +52,13 @@ export const FeesDetails: FC<Props> = ({
58
52
  {route?.xSwapFees.expressDeliveryFee && !isGettingRoute && (
59
53
  <div
60
54
  className={`xpay-flex xpay-gap-1 xpay-items-center xpay-font-medium ${
61
- isExpressDeliveryPossible
55
+ isExpressDelivery
62
56
  ? "xpay-text-x_green"
63
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