@xswap-link/sdk 0.2.1 → 0.2.2
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/CHANGELOG.md +6 -0
- package/dist/index.css +19 -12
- package/dist/index.d.mts +2 -177
- package/dist/index.d.ts +2 -177
- package/dist/index.js +527 -756
- package/dist/index.mjs +525 -706
- package/package.json +1 -1
- package/src/components/TxConfigForm/PoweredBy.tsx +12 -0
- package/src/components/TxConfigForm/index.tsx +3 -27
- package/src/components/{TxHistoryButton → TxStatusButton}/index.tsx +7 -15
- package/src/components/global.css +4 -0
- package/src/components/index.ts +1 -1
- package/src/config/index.ts +1 -0
- package/src/config/init.ts +31 -0
- package/src/index.ts +6 -6
- package/src/services/integrations/monitoring.ts +4 -4
- package/tailwind.config.js +1 -0
package/package.json
CHANGED
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { ChainlinkCCIPIcon, XSwapBadgeIcon } from "@src/components/icons";
|
|
2
|
+
|
|
3
|
+
export const PoweredBy = () => {
|
|
4
|
+
return (
|
|
5
|
+
<div className="flex justify-center items-center gap-2 my-3">
|
|
6
|
+
<span className="text-x_grey">Powered by</span>
|
|
7
|
+
<XSwapBadgeIcon />
|
|
8
|
+
<span>✕</span>
|
|
9
|
+
<ChainlinkCCIPIcon />
|
|
10
|
+
</div>
|
|
11
|
+
);
|
|
12
|
+
};
|
|
@@ -1,15 +1,12 @@
|
|
|
1
1
|
import "@src/global.css";
|
|
2
2
|
import { MouseEvent, useMemo } from "react";
|
|
3
|
-
import { createRoot, Root } from "react-dom/client";
|
|
4
3
|
import { QueryClient, QueryClientProvider } from "@tanstack/react-query";
|
|
5
4
|
import { WagmiProvider } from "wagmi";
|
|
6
|
-
import { getWagmiConfig } from "@src/config";
|
|
5
|
+
import { getWagmiConfig, xswapRoot } from "@src/config";
|
|
7
6
|
import { Chain, ContractCall, Route } from "@src/models";
|
|
8
7
|
import { CloseIcon } from "@src/components/icons/CloseIcon";
|
|
8
|
+
import { PoweredBy } from "@src/components/TxConfigForm/PoweredBy";
|
|
9
9
|
import { Form } from "./Form";
|
|
10
|
-
import { ChainlinkCCIPIcon, XSwapBadgeIcon } from "../icons";
|
|
11
|
-
import { version } from "../../../package.json";
|
|
12
|
-
import xswapConfig from "../../../xswap.config";
|
|
13
10
|
|
|
14
11
|
export type TxConfigFormProps = {
|
|
15
12
|
dstChainId: string;
|
|
@@ -67,13 +64,7 @@ const TxConfigForm = ({
|
|
|
67
64
|
>
|
|
68
65
|
<CloseIcon />
|
|
69
66
|
</div>
|
|
70
|
-
|
|
71
|
-
<div className="swappage__poweredby">
|
|
72
|
-
<span>Powered by</span>
|
|
73
|
-
<XSwapBadgeIcon />
|
|
74
|
-
<span>✕</span>
|
|
75
|
-
<ChainlinkCCIPIcon />
|
|
76
|
-
</div>
|
|
67
|
+
<PoweredBy />
|
|
77
68
|
</div>
|
|
78
69
|
</div>
|
|
79
70
|
</QueryClientProvider>
|
|
@@ -111,18 +102,3 @@ export const openTxConfigForm = async ({
|
|
|
111
102
|
throw new Error(`XSwap component error, ${err}`);
|
|
112
103
|
}
|
|
113
104
|
};
|
|
114
|
-
|
|
115
|
-
// skip on server-side integrations
|
|
116
|
-
let xswapRoot: Root;
|
|
117
|
-
if (typeof document !== "undefined") {
|
|
118
|
-
const xswapStyleElement = document.createElement("link");
|
|
119
|
-
xswapStyleElement.rel = "stylesheet";
|
|
120
|
-
xswapStyleElement.type = "text/css";
|
|
121
|
-
xswapStyleElement.href = `${xswapConfig.apiUrl}/sdk/css?data={"version": "${version}"}`;
|
|
122
|
-
document.head.appendChild(xswapStyleElement);
|
|
123
|
-
|
|
124
|
-
const xswapModalElement = document.createElement("div");
|
|
125
|
-
xswapModalElement.setAttribute("id", "xswap-modal");
|
|
126
|
-
document.body.appendChild(xswapModalElement);
|
|
127
|
-
xswapRoot = createRoot(xswapModalElement);
|
|
128
|
-
}
|
|
@@ -1,19 +1,20 @@
|
|
|
1
1
|
import { FC, useMemo, useState } from "react";
|
|
2
|
-
import { createRoot } from "react-dom/client";
|
|
3
2
|
import {
|
|
4
3
|
ArrowLeftIcon,
|
|
5
4
|
ArrowRightIcon,
|
|
6
5
|
CheckIcon,
|
|
7
6
|
CircularProgressIcon,
|
|
7
|
+
ArrowUpRightIcon,
|
|
8
|
+
XSwapLogo,
|
|
8
9
|
} from "../icons";
|
|
9
|
-
import { ArrowUpRightIcon, XSwapLogo } from "../icons";
|
|
10
10
|
import { MonitoredTransaction } from "@src/models";
|
|
11
|
+
import { txStatusRoot } from "@src/config";
|
|
11
12
|
|
|
12
13
|
interface Props {
|
|
13
14
|
transaction: MonitoredTransaction;
|
|
14
15
|
}
|
|
15
16
|
|
|
16
|
-
export const
|
|
17
|
+
export const TxStatusButton: FC<Props> = ({ transaction }) => {
|
|
17
18
|
const {
|
|
18
19
|
fromChain,
|
|
19
20
|
fromChainImage,
|
|
@@ -141,18 +142,9 @@ export const updateTransactionDoneInRenderedTransactions = (txHash: string) => {
|
|
|
141
142
|
}
|
|
142
143
|
};
|
|
143
144
|
|
|
144
|
-
const
|
|
145
|
-
historyElement.setAttribute("id", "xswap-history");
|
|
146
|
-
historyElement.setAttribute(
|
|
147
|
-
"class",
|
|
148
|
-
"absolute bottom-5 right-2 flex flex-col gap-3 pl-9 items-end w-full z-50",
|
|
149
|
-
);
|
|
150
|
-
document.body.appendChild(historyElement);
|
|
151
|
-
const txHistoryButtonRoot = createRoot(historyElement);
|
|
152
|
-
|
|
153
|
-
export const renderTxHistoryButtons = () => {
|
|
145
|
+
export const renderTxStatusButtons = () => {
|
|
154
146
|
const buttons = renderedTransactions.map((item) => (
|
|
155
|
-
<
|
|
147
|
+
<TxStatusButton key={item.txHash} transaction={item} />
|
|
156
148
|
));
|
|
157
|
-
|
|
149
|
+
txStatusRoot.render(buttons);
|
|
158
150
|
};
|
package/src/components/index.ts
CHANGED
package/src/config/index.ts
CHANGED
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import { createRoot, Root } from "react-dom/client";
|
|
2
|
+
import xswapConfig from "../../xswap.config";
|
|
3
|
+
import { version } from "../../package.json";
|
|
4
|
+
|
|
5
|
+
export let xswapRoot: Root;
|
|
6
|
+
export let txStatusRoot: Root;
|
|
7
|
+
|
|
8
|
+
export const initDocument = () => {
|
|
9
|
+
if (typeof document === "undefined") {
|
|
10
|
+
throw new Error("Can't render XPay components from server side.");
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
fetch(`${xswapConfig.apiUrl}/sdk/css?data={"version": "${version}"}`).then(
|
|
14
|
+
async (css) => {
|
|
15
|
+
const style = document.createElement("style");
|
|
16
|
+
style.textContent = await css.text();
|
|
17
|
+
document.body.appendChild(style);
|
|
18
|
+
},
|
|
19
|
+
);
|
|
20
|
+
|
|
21
|
+
const xswapElement = document.createElement("div");
|
|
22
|
+
xswapElement.setAttribute("id", "xswap-modal");
|
|
23
|
+
document.body.appendChild(xswapElement);
|
|
24
|
+
xswapRoot = createRoot(xswapElement);
|
|
25
|
+
|
|
26
|
+
const txStatusElement = document.createElement("div");
|
|
27
|
+
txStatusElement.setAttribute("id", "xswap-tx-status");
|
|
28
|
+
txStatusElement.setAttribute("class", "xswap-tx-status");
|
|
29
|
+
document.body.appendChild(txStatusElement);
|
|
30
|
+
txStatusRoot = createRoot(txStatusElement);
|
|
31
|
+
};
|
package/src/index.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
export * from "
|
|
6
|
-
export
|
|
1
|
+
import { initDocument } from "@src/config/init";
|
|
2
|
+
|
|
3
|
+
initDocument();
|
|
4
|
+
|
|
5
|
+
export * from "@src/models";
|
|
6
|
+
export { getSwapTx, monitorTransactionStatus } from "@src/services";
|
|
@@ -13,7 +13,7 @@ import {
|
|
|
13
13
|
import {
|
|
14
14
|
addTransactionToRenderedTransactions,
|
|
15
15
|
removeTransactionFromRenderedTransactions,
|
|
16
|
-
|
|
16
|
+
renderTxStatusButtons,
|
|
17
17
|
updateTransactionDoneInRenderedTransactions,
|
|
18
18
|
} from "@src/components";
|
|
19
19
|
import { ADDRESSES } from "@src/contracts";
|
|
@@ -87,7 +87,7 @@ export const monitorTransactionStatus = async (
|
|
|
87
87
|
};
|
|
88
88
|
|
|
89
89
|
addTransactionToRenderedTransactions(transaction);
|
|
90
|
-
|
|
90
|
+
renderTxStatusButtons();
|
|
91
91
|
|
|
92
92
|
// start listening
|
|
93
93
|
// TODO if someone will provide tx which already is done then we will never get the event. Will need to add status endpoint on backend for transactions to check if they are done or not.
|
|
@@ -113,12 +113,12 @@ export const monitorTransactionStatus = async (
|
|
|
113
113
|
|
|
114
114
|
const onSuccess = async () => {
|
|
115
115
|
updateTransactionDoneInRenderedTransactions(txHash);
|
|
116
|
-
|
|
116
|
+
renderTxStatusButtons();
|
|
117
117
|
await new Promise((resolve) =>
|
|
118
118
|
setTimeout(() => resolve(true), TX_RECEIPT_STATUS_LIFETIME),
|
|
119
119
|
);
|
|
120
120
|
removeTransactionFromRenderedTransactions(txHash);
|
|
121
|
-
|
|
121
|
+
renderTxStatusButtons();
|
|
122
122
|
};
|
|
123
123
|
xSwapRouterOnDestination.once(msgReceivedEventFilter, () => onSuccess());
|
|
124
124
|
};
|
package/tailwind.config.js
CHANGED