@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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@xswap-link/sdk",
3
- "version": "0.2.1",
3
+ "version": "0.2.2",
4
4
  "description": "JavaScript SDK for XSwap platform",
5
5
  "homepage": "https://github.com/xswap-link/xswap-sdk",
6
6
  "repository": {
@@ -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 TxHistoryButton: FC<Props> = ({ transaction }) => {
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 historyElement = document.createElement("div");
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
- <TxHistoryButton key={item.txHash} transaction={item} />
147
+ <TxStatusButton key={item.txHash} transaction={item} />
156
148
  ));
157
- txHistoryButtonRoot.render(buttons);
149
+ txStatusRoot.render(buttons);
158
150
  };
@@ -28,3 +28,7 @@
28
28
  border: 1px solid rgba(255, 255, 255, 0.1);
29
29
  }
30
30
  }
31
+
32
+ .xswap-tx-status {
33
+ @apply absolute bottom-5 right-2 flex flex-col gap-3 pl-9 items-end w-full z-50;
34
+ }
@@ -1,4 +1,4 @@
1
1
  export * from "./Alert";
2
2
  export * from "./TxConfigForm";
3
- export * from "./TxHistoryButton";
3
+ export * from "./TxStatusButton";
4
4
  export * from "./Skeleton";
@@ -1 +1,2 @@
1
1
  export * from "./wagmiConfig";
2
+ export * from "./init";
@@ -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
- export * from "./components";
2
- export * from "./constants";
3
- export * from "./contracts";
4
- export * from "./models";
5
- export * from "./services";
6
- export * from "./utils";
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
- renderTxHistoryButtons,
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
- renderTxHistoryButtons();
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
- renderTxHistoryButtons();
116
+ renderTxStatusButtons();
117
117
  await new Promise((resolve) =>
118
118
  setTimeout(() => resolve(true), TX_RECEIPT_STATUS_LIFETIME),
119
119
  );
120
120
  removeTransactionFromRenderedTransactions(txHash);
121
- renderTxHistoryButtons();
121
+ renderTxStatusButtons();
122
122
  };
123
123
  xSwapRouterOnDestination.once(msgReceivedEventFilter, () => onSuccess());
124
124
  };
@@ -8,6 +8,7 @@ module.exports = {
8
8
  x_alert_light: "rgb(255,226,183)",
9
9
  x_blue: "#3396FF",
10
10
  x_green: "#66bb6a",
11
+ x_grey: "#ffffff80",
11
12
  x_error_background: "rgba(255,202,40,0.1)",
12
13
  x_error_border: "rgba(255,111,0,1)",
13
14
  x_blue_light: "rgba(54,129,198,1)",