@xswap-link/sdk 0.3.3 → 0.3.5

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@xswap-link/sdk",
3
- "version": "0.3.3",
3
+ "version": "0.3.5",
4
4
  "description": "JavaScript SDK for XSwap platform",
5
5
  "homepage": "https://github.com/xswap-link/xswap-sdk",
6
6
  "repository": {
@@ -72,7 +72,7 @@
72
72
  },
73
73
  "scripts": {
74
74
  "build": "tsup src/index.ts --format cjs,esm --dts && pnpm build:cdn",
75
- "build:cdn": "tsup src/index.ts --format iife --minify --global-name XPay",
75
+ "build:cdn": "tsup src/index.ts --format iife --minify --global-name XPay --env.NODE_ENV production",
76
76
  "watch": "pnpm build && nodemon",
77
77
  "release": "pnpm build && changeset publish",
78
78
  "lint": "tsc && eslint . --ext .ts",
@@ -0,0 +1,38 @@
1
+ import { CloseIcon, ErrorIcon } from "@src/components/icons";
2
+ import { parseWeb3Error } from "@src/utils";
3
+ import React from "react";
4
+
5
+ type Props = {
6
+ txError: string | null;
7
+ onClose: () => void;
8
+ };
9
+ export const ErrorView = ({ txError, onClose }: Props) => {
10
+ return (
11
+ <div>
12
+ <div className="xpay-flex xpay-w-full xpay-justify-end xpay-items-center xpay-mx-auto xpay-p-2">
13
+ <div className="xpay-cursor-pointer xpay-text-white" onClick={onClose}>
14
+ <CloseIcon />
15
+ </div>
16
+ </div>
17
+
18
+ <div className="xpay-flex xpay-flex-col xpay-w-full xpay-justify-center xpay-items-center xpay-mx-auto xpay-p-2 xpay-gap-4">
19
+ <div>
20
+ <ErrorIcon />
21
+ </div>
22
+
23
+ <div className="xpay-flex xpay-flex-col">
24
+ <div>
25
+ <p className="xpay-text-2xl xpay-font-bold xpay-leading-8 xpay-text-center xpay-text-white">
26
+ Transaction error!
27
+ </p>
28
+ </div>
29
+ <div>
30
+ <p className="xpay-text-sm xpay-text-center xpay-text-white xpay-opacity-50">
31
+ {parseWeb3Error(txError)}
32
+ </p>
33
+ </div>
34
+ </div>
35
+ </div>
36
+ </div>
37
+ );
38
+ };
@@ -0,0 +1,159 @@
1
+ import {
2
+ ArrowRightIcon,
3
+ ArrowUpRightIcon,
4
+ CloseIcon,
5
+ SuccessIcon,
6
+ } from "@src/components/icons";
7
+ import { UnknownTokenLogo } from "@src/components/UnknownTokenLogo/UnknownTokenLogo";
8
+ import { weiToHumanReadable } from "@src/utils";
9
+ import { CCIP_EXPLORER } from "@src/constants";
10
+ import React, { useMemo } from "react";
11
+ import { Chain, Route, Token } from "@src/models";
12
+
13
+ type Props = {
14
+ onClose: () => void;
15
+ txSuccessHash?: string;
16
+ srcChain?: Chain;
17
+ dstChain?: Chain;
18
+ isExpressDelivery: boolean;
19
+ srcToken?: Token;
20
+ amount: string;
21
+ dstDisplayToken?: Token;
22
+ dstToken?: Token;
23
+ route?: Route;
24
+ supportedChains: Chain[];
25
+ };
26
+ export const SuccessView = ({
27
+ onClose,
28
+ srcChain,
29
+ dstChain,
30
+ isExpressDelivery,
31
+ srcToken,
32
+ amount,
33
+ dstDisplayToken,
34
+ dstToken,
35
+ route,
36
+ txSuccessHash,
37
+ supportedChains,
38
+ }: Props) => {
39
+ const dstTokenToDisplay = useMemo(() => {
40
+ return dstDisplayToken ? dstDisplayToken : dstToken;
41
+ }, [dstDisplayToken, dstToken]);
42
+
43
+ return (
44
+ <div>
45
+ <div className="xpay-flex xpay-w-full xpay-justify-end xpay-items-center xpay-mx-auto xpay-p-2">
46
+ <div className="xpay-cursor-pointer xpay-text-white" onClick={onClose}>
47
+ <CloseIcon />
48
+ </div>
49
+ </div>
50
+
51
+ <div className="xpay-flex xpay-flex-col xpay-w-full xpay-justify-center xpay-items-center xpay-mx-auto xpay-p-2 xpay-gap-4">
52
+ <div>
53
+ <SuccessIcon />
54
+ </div>
55
+ <div className="xpay-flex xpay-flex-col">
56
+ <div>
57
+ <p className="xpay-text-2xl xpay-font-bold xpay-leading-8 xpay-text-center xpay-text-white">
58
+ Transaction success!
59
+ </p>
60
+ </div>
61
+ {srcChain?.chainId !== dstChain?.chainId ? (
62
+ <div>
63
+ <p className="xpay-text-sm xpay-text-center xpay-text-white xpay-opacity-50">
64
+ Approximated time of delivery:{" "}
65
+ {isExpressDelivery ? "30 seconds" : "30 minutes"}
66
+ </p>
67
+ </div>
68
+ ) : (
69
+ <></>
70
+ )}
71
+ </div>
72
+
73
+ <div className="xpay-flex xpay-gap-4 xpay-items-center">
74
+ <div className="xpay-flex xpay-gap-2">
75
+ <div className="xpay-w-10 xpay-h-10">
76
+ {srcToken?.image ? (
77
+ <img
78
+ className="xpay-w-10 xpay-h-10"
79
+ src={srcToken?.image}
80
+ alt={srcToken?.name}
81
+ />
82
+ ) : (
83
+ <UnknownTokenLogo
84
+ tokenName={"?"}
85
+ className="xpay-w-10 xpay-h-10"
86
+ />
87
+ )}
88
+ </div>
89
+ <div className="xpay-flex xpay-flex-col xpay-items-start">
90
+ <div className="xpay-flex">{`${amount} ${srcToken?.symbol}`}</div>
91
+ <div className="xpay-text-sm xpay-text-center xpay-text-white xpay-opacity-50">
92
+ {srcChain?.displayName}
93
+ </div>
94
+ </div>
95
+ </div>
96
+
97
+ <div className="xpay-w-3.5 xpay-h-3.5">
98
+ <ArrowRightIcon />
99
+ </div>
100
+
101
+ <div className="xpay-flex xpay-gap-2">
102
+ <div className="xpay-w-10 xpay-h-10">
103
+ {dstTokenToDisplay?.image ? (
104
+ <img
105
+ className="xpay-w-10 xpay-h-10"
106
+ src={dstTokenToDisplay?.image}
107
+ alt={dstTokenToDisplay?.name}
108
+ />
109
+ ) : (
110
+ <UnknownTokenLogo
111
+ tokenName={"?"}
112
+ className="xpay-w-10 xpay-h-10"
113
+ />
114
+ )}
115
+ </div>
116
+ <div className="xpay-flex xpay-flex-col xpay-items-start">
117
+ <div className="xpay-flex">
118
+ {weiToHumanReadable({
119
+ amount: route?.estAmountOut || "0",
120
+ decimals: dstTokenToDisplay?.decimals || 18,
121
+ precisionFractionalPlaces: 4,
122
+ })}{" "}
123
+ {dstTokenToDisplay?.symbol}
124
+ </div>
125
+ <div className="xpay-text-sm xpay-text-center xpay-text-white xpay-opacity-50">
126
+ {dstChain?.displayName}
127
+ </div>
128
+ </div>
129
+ </div>
130
+ </div>
131
+
132
+ <div>
133
+ <a
134
+ href={
135
+ srcChain?.chainId !== dstChain?.chainId
136
+ ? `${CCIP_EXPLORER}/tx/${txSuccessHash}`
137
+ : `${
138
+ supportedChains.find(
139
+ (chain) => chain.chainId === srcChain?.chainId,
140
+ )?.transactionExplorer
141
+ }/${txSuccessHash}`
142
+ }
143
+ target="_blank"
144
+ rel="noreferrer"
145
+ className="xpay-flex xpay-items-center xpay-gap-2 xpay-font-bold xpay-no-underline xpay-cursor-pointer xpay-text-center"
146
+ aria-label="Show the transaction in the chain explorer"
147
+ >
148
+ <p className="xpay-bg-gradient-to-r xpay-from-x_blue_light xpay-to-x_blue_dark xpay-bg-clip-text xpay-text-transparent xpay-underline">
149
+ View details on Explorer
150
+ </p>
151
+ <div className="xpay-w-3.5 xpay-h-3.5 xpay-bg-gradient-to-r xpay-text-x_blue_dark">
152
+ <ArrowUpRightIcon />
153
+ </div>
154
+ </a>
155
+ </div>
156
+ </div>
157
+ </div>
158
+ );
159
+ };
@@ -0,0 +1,149 @@
1
+ import { ethers } from "ethers";
2
+ import React, { FC } from "react";
3
+ import {
4
+ ArrowDownIcon,
5
+ CheckIcon,
6
+ CloseIcon,
7
+ SignIcon,
8
+ } from "@src/components/icons";
9
+ import { Spinner } from "@src/components/Spinner";
10
+ import { ConfirmationAmount } from "../ConfirmationAmount";
11
+ import { Chain, Route, Token } from "@src/models";
12
+ import { ErrorView } from "./ErrorView";
13
+ import { SuccessView } from "./SuccessView";
14
+
15
+ interface Props {
16
+ txError: string | null;
17
+ onClose: () => void;
18
+ txSuccessHash?: string;
19
+ srcChain?: Chain;
20
+ dstChain?: Chain;
21
+ isExpressDelivery: boolean;
22
+ srcToken?: Token;
23
+ amount: string;
24
+ dstDisplayToken?: Token;
25
+ dstToken?: Token;
26
+ route?: Route;
27
+ supportedChains: Chain[];
28
+ approveTxLoading: boolean;
29
+ approveTxDone: boolean;
30
+ txLoading: boolean;
31
+ }
32
+ export const ConfirmationView: FC<Props> = ({
33
+ txError,
34
+ onClose,
35
+ txSuccessHash,
36
+ srcChain,
37
+ dstChain,
38
+ isExpressDelivery,
39
+ srcToken,
40
+ amount,
41
+ dstDisplayToken,
42
+ dstToken,
43
+ route,
44
+ supportedChains,
45
+ approveTxLoading,
46
+ approveTxDone,
47
+ txLoading,
48
+ }) => {
49
+ return (
50
+ <div className="xpay-flex xpay-flex-col xpay-gap-2 xpay-z-10 xpay-my-0 xpay-p-2 md:xpay-p-4 xpay-rounded-3xl xpay-overflow-hidden xpay-font-light sm:xpay-w-x_desktop xpay-w-screen">
51
+ {txError ? (
52
+ <ErrorView txError={txError} onClose={onClose} />
53
+ ) : txSuccessHash ? (
54
+ <SuccessView
55
+ onClose={onClose}
56
+ isExpressDelivery={isExpressDelivery}
57
+ amount={amount}
58
+ supportedChains={supportedChains}
59
+ txSuccessHash={txSuccessHash}
60
+ srcChain={srcChain}
61
+ dstChain={dstChain}
62
+ srcToken={srcToken}
63
+ dstDisplayToken={dstDisplayToken}
64
+ dstToken={dstToken}
65
+ route={route}
66
+ />
67
+ ) : (
68
+ // Tx Confirmation modal
69
+ <>
70
+ <div className="xpay-flex xpay-w-full xpay-justify-between xpay-items-center xpay-mx-auto xpay-p-2 xpay-font-light ">
71
+ <p className="xpay-text-white xpay-text-xl">Confirmation</p>
72
+ <div className="xpay-flex xpay-w-full xpay-justify-end xpay-items-center xpay-mx-auto xpay-p-2">
73
+ <div
74
+ className="xpay-cursor-pointer xpay-text-white"
75
+ onClick={onClose}
76
+ >
77
+ <CloseIcon />
78
+ </div>
79
+ </div>
80
+ </div>
81
+
82
+ <div className="xpay-flex xpay-flex-col xpay-gap-2">
83
+ <ConfirmationAmount
84
+ amount={ethers.utils
85
+ .parseUnits(amount, srcToken?.decimals)
86
+ .toString()}
87
+ chain={srcChain}
88
+ token={srcToken}
89
+ type="src"
90
+ />
91
+ </div>
92
+
93
+ <div className="xpay-flex xpay-justify-center xpay-globalBorder xpay-rounded-xl xpay-p-[5px] xpay--mt-7 xpay--mb-6 ">
94
+ <div className="xpay-flex xpay-items-center xpay-justify-center xpay-rounded-lg xpay-w-8 xpay-h-8 xpay-bg-gradient-to-l xpay-from-[rgba(54,129,198,1)] xpay-to-[rgba(43,74,157,1)] ">
95
+ <ArrowDownIcon />
96
+ </div>
97
+ </div>
98
+
99
+ <div className="xpay-flex xpay-flex-col xpay-gap-2">
100
+ <ConfirmationAmount
101
+ amount={route?.estAmountOut || "0"}
102
+ chain={dstChain}
103
+ token={dstDisplayToken ? dstDisplayToken : dstToken}
104
+ type="dst"
105
+ />
106
+ </div>
107
+ <div className="xpay-flex xpay-flex-col xpay-globalBorder xpay-p-4 xpay-justify-center xpay-rounded-xl xpay-bg-[rgba(15,15,15,1)] xpay-relative">
108
+ {route?.transactions.approve && (
109
+ <>
110
+ <div className="xpay-flex xpay-justify-between xpay-items-center">
111
+ <div className="xpay-flex xpay-items-center xpay-gap-2">
112
+ <SignIcon />
113
+ <p className="xpay-opacity-50">
114
+ {approveTxLoading
115
+ ? "Wait for approval confirmation"
116
+ : "Approve token spending"}
117
+ </p>
118
+ </div>
119
+ <div className="xpay-flex xpay-items-center">
120
+ {approveTxLoading && <Spinner width="5" height="5" />}
121
+ {approveTxDone && (
122
+ <div className="xpay-text-x_green xpay-w-5 xpay-h-5">
123
+ <CheckIcon />
124
+ </div>
125
+ )}
126
+ </div>
127
+ </div>
128
+ <div className="xpay-w-px xpay-h-6 xpay-mt-1 xpay-mb-1 xpay-ml-2.5 xpay-bg-white xpay-opacity-50"></div>
129
+ </>
130
+ )}
131
+ <div className="xpay-flex xpay-justify-between xpay-items-center">
132
+ <div className="xpay-flex xpay-items-center xpay-gap-2">
133
+ <SignIcon />
134
+ <p className="xpay-opacity-50">
135
+ {txLoading
136
+ ? "Wait for transaction confirmation"
137
+ : "Confirm transaction"}
138
+ </p>
139
+ </div>
140
+ <div className="xpay-flex xpay-items-center">
141
+ {txLoading && <Spinner width="5" height="5" />}
142
+ </div>
143
+ </div>
144
+ </div>
145
+ </>
146
+ )}
147
+ </div>
148
+ );
149
+ };
@@ -0,0 +1,21 @@
1
+ import React from "react";
2
+ import { FC } from "react";
3
+ import { CloseIcon } from "../icons";
4
+
5
+ type Props = {
6
+ onClose: () => void;
7
+ };
8
+ export const ConnectWalletPrompt: FC<Props> = ({ onClose }) => {
9
+ return (
10
+ <div className="xpay-flex xpay-flex-col xpay-gap-2 xpay-z-10 xpay-my-0 xpay-p-2 md:xpay-p-4 xpay-rounded-3xl xpay-overflow-hidden xpay-font-light sm:xpay-w-x_desktop xpay-w-screen">
11
+ <div className="xpay-flex xpay-w-full xpay-justify-end xpay-items-center xpay-mx-auto xpay-p-2">
12
+ <div className="xpay-cursor-pointer xpay-text-white" onClick={onClose}>
13
+ <CloseIcon />
14
+ </div>
15
+ </div>
16
+ <p className="xpay-text-xl xpay-font-bold xpay-leading-8 xpay-text-center xpay-text-white">
17
+ Please connect the wallet first.
18
+ </p>
19
+ </div>
20
+ );
21
+ };