@xswap-link/sdk 0.1.4 → 0.2.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.
- package/.github/workflows/publish.yml +21 -2
- package/CHANGELOG.md +6 -0
- package/dist/index.js +24 -24
- package/dist/index.mjs +25 -26
- package/package.json +1 -1
- package/src/components/TxConfigForm/index.tsx +40 -32
|
@@ -27,11 +27,30 @@ jobs:
|
|
|
27
27
|
|
|
28
28
|
- run: pnpm install
|
|
29
29
|
- run: pnpm install react@18.2.0 react-dom@18.2.0 @types/react@18.2.0 @types/react-dom@18.2.0
|
|
30
|
+
|
|
30
31
|
- name: Create Release Pull Request or Publish
|
|
31
32
|
id: changesets
|
|
32
|
-
uses: changesets
|
|
33
|
+
uses: xswap-link/changesets-action@v1
|
|
33
34
|
with:
|
|
34
35
|
publish: pnpm run release
|
|
35
36
|
env:
|
|
36
37
|
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
|
|
37
|
-
NPM_TOKEN: ${{ secrets.NPM_TOKEN }}
|
|
38
|
+
NPM_TOKEN: ${{ secrets.NPM_TOKEN }}
|
|
39
|
+
|
|
40
|
+
- name: Get latest created release info
|
|
41
|
+
if: steps.changesets.outputs.published == 'true'
|
|
42
|
+
id: latest_release_info
|
|
43
|
+
uses: jossef/action-latest-release-info@v1.2.1
|
|
44
|
+
env:
|
|
45
|
+
GITHUB_TOKEN: ${{ github.token }}
|
|
46
|
+
|
|
47
|
+
- name: Publish index.css
|
|
48
|
+
if: steps.changesets.outputs.published == 'true'
|
|
49
|
+
uses: actions/upload-release-asset@v1
|
|
50
|
+
env:
|
|
51
|
+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
|
|
52
|
+
with:
|
|
53
|
+
upload_url: ${{ steps.latest_release_info.outputs.upload_url }}
|
|
54
|
+
asset_path: ./dist/index.css
|
|
55
|
+
asset_name: index.css
|
|
56
|
+
asset_content_type: text/plain
|
package/CHANGELOG.md
CHANGED
package/dist/index.js
CHANGED
|
@@ -995,14 +995,12 @@ var import_react = require("react");
|
|
|
995
995
|
var useDebounce = (value, delay) => {
|
|
996
996
|
const timeoutRef = (0, import_react.useRef)(null);
|
|
997
997
|
(0, import_react.useEffect)(() => {
|
|
998
|
-
if (timeoutRef.current)
|
|
999
|
-
clearTimeout(timeoutRef.current);
|
|
998
|
+
if (timeoutRef.current) clearTimeout(timeoutRef.current);
|
|
1000
999
|
timeoutRef.current = setTimeout(() => {
|
|
1001
1000
|
setValue(value);
|
|
1002
1001
|
}, delay);
|
|
1003
1002
|
return () => {
|
|
1004
|
-
if (timeoutRef.current)
|
|
1005
|
-
clearTimeout(timeoutRef.current);
|
|
1003
|
+
if (timeoutRef.current) clearTimeout(timeoutRef.current);
|
|
1006
1004
|
};
|
|
1007
1005
|
}, [value, delay]);
|
|
1008
1006
|
const [debouncedValue, setValue] = (0, import_react.useState)(value);
|
|
@@ -1575,8 +1573,7 @@ var History = ({ signer, supportedChains }) => {
|
|
|
1575
1573
|
continue;
|
|
1576
1574
|
}
|
|
1577
1575
|
let status;
|
|
1578
|
-
if (entry.failed)
|
|
1579
|
-
status = "REVERTED";
|
|
1576
|
+
if (entry.failed) status = "REVERTED";
|
|
1580
1577
|
if (!!entry.target) {
|
|
1581
1578
|
status = "DONE";
|
|
1582
1579
|
} else {
|
|
@@ -1607,8 +1604,7 @@ var History = ({ signer, supportedChains }) => {
|
|
|
1607
1604
|
}
|
|
1608
1605
|
}, [signer, getHistory]);
|
|
1609
1606
|
(0, import_react3.useEffect)(() => {
|
|
1610
|
-
if (!historyLoadedOnce)
|
|
1611
|
-
fetchHistory();
|
|
1607
|
+
if (!historyLoadedOnce) fetchHistory();
|
|
1612
1608
|
const timer = setInterval(() => {
|
|
1613
1609
|
fetchHistory();
|
|
1614
1610
|
}, 6e4);
|
|
@@ -2092,10 +2088,8 @@ var import_bignumber3 = __toESM(require("bignumber.js"));
|
|
|
2092
2088
|
var import_jsx_runtime33 = require("react/jsx-runtime");
|
|
2093
2089
|
var BalanceComponent = ({ srcToken, balances }) => {
|
|
2094
2090
|
const balanceText = (0, import_react8.useMemo)(() => {
|
|
2095
|
-
if (!balances || !srcToken)
|
|
2096
|
-
|
|
2097
|
-
if (balances[srcToken.address]?.toString() === "0")
|
|
2098
|
-
return "0";
|
|
2091
|
+
if (!balances || !srcToken) return "0";
|
|
2092
|
+
if (balances[srcToken.address]?.toString() === "0") return "0";
|
|
2099
2093
|
const fullHumanReadable = weiToHumanReadable({
|
|
2100
2094
|
amount: balances[srcToken.address]?.toString() || "0",
|
|
2101
2095
|
decimals: srcToken.decimals,
|
|
@@ -2179,8 +2173,7 @@ var SwapPanel = ({
|
|
|
2179
2173
|
className: "p-0 border-none outline-none bg-transparent text-2xl overflow-ellipsis",
|
|
2180
2174
|
value: amount,
|
|
2181
2175
|
onChange: (e) => {
|
|
2182
|
-
if (e.target.value === ".")
|
|
2183
|
-
return;
|
|
2176
|
+
if (e.target.value === ".") return;
|
|
2184
2177
|
if (NUMBER_INPUT_REGEX.test(e.target.value)) {
|
|
2185
2178
|
setAmount(e.target.value.replace(/,/g, "."));
|
|
2186
2179
|
}
|
|
@@ -2446,8 +2439,7 @@ var Form = ({
|
|
|
2446
2439
|
}, [srcChain, signer]);
|
|
2447
2440
|
const handleSubmit = (event) => {
|
|
2448
2441
|
event.preventDefault();
|
|
2449
|
-
if (route)
|
|
2450
|
-
onSubmit(route);
|
|
2442
|
+
if (route) onSubmit(route);
|
|
2451
2443
|
};
|
|
2452
2444
|
const handleSwitchChain = async () => {
|
|
2453
2445
|
await switchChainAsync({ chainId: Number(srcChain?.chainId) });
|
|
@@ -2531,6 +2523,9 @@ var Form = ({
|
|
|
2531
2523
|
);
|
|
2532
2524
|
};
|
|
2533
2525
|
|
|
2526
|
+
// package.json
|
|
2527
|
+
var version = "0.2.0";
|
|
2528
|
+
|
|
2534
2529
|
// src/components/TxConfigForm/index.tsx
|
|
2535
2530
|
var import_jsx_runtime39 = require("react/jsx-runtime");
|
|
2536
2531
|
var TxConfigForm = ({
|
|
@@ -2598,7 +2593,7 @@ var openTxConfigForm = async ({
|
|
|
2598
2593
|
}) => {
|
|
2599
2594
|
try {
|
|
2600
2595
|
return await new Promise((resolve) => {
|
|
2601
|
-
|
|
2596
|
+
xswapRoot.render(
|
|
2602
2597
|
/* @__PURE__ */ (0, import_jsx_runtime39.jsx)(
|
|
2603
2598
|
TxConfigForm,
|
|
2604
2599
|
{
|
|
@@ -2609,10 +2604,10 @@ var openTxConfigForm = async ({
|
|
|
2609
2604
|
supportedChains,
|
|
2610
2605
|
onSubmit: (route) => {
|
|
2611
2606
|
resolve(route);
|
|
2612
|
-
|
|
2607
|
+
xswapRoot.render("");
|
|
2613
2608
|
},
|
|
2614
2609
|
onClose: () => {
|
|
2615
|
-
|
|
2610
|
+
xswapRoot.render("");
|
|
2616
2611
|
}
|
|
2617
2612
|
}
|
|
2618
2613
|
)
|
|
@@ -2622,12 +2617,17 @@ var openTxConfigForm = async ({
|
|
|
2622
2617
|
throw new Error(`XSwap component error, ${err}`);
|
|
2623
2618
|
}
|
|
2624
2619
|
};
|
|
2625
|
-
var
|
|
2620
|
+
var xswapRoot;
|
|
2626
2621
|
if (typeof document !== "undefined") {
|
|
2627
|
-
const
|
|
2628
|
-
|
|
2629
|
-
|
|
2630
|
-
|
|
2622
|
+
const xswapStyleElement = document.createElement("link");
|
|
2623
|
+
xswapStyleElement.rel = "stylesheet";
|
|
2624
|
+
xswapStyleElement.type = "text/css";
|
|
2625
|
+
xswapStyleElement.href = `${xswap_config_default.apiUrl}/sdk/css/${version}`;
|
|
2626
|
+
document.head.appendChild(xswapStyleElement);
|
|
2627
|
+
const xswapModalElement = document.createElement("div");
|
|
2628
|
+
xswapModalElement.setAttribute("id", "xswap-modal");
|
|
2629
|
+
document.body.appendChild(xswapModalElement);
|
|
2630
|
+
xswapRoot = (0, import_client.createRoot)(xswapModalElement);
|
|
2631
2631
|
}
|
|
2632
2632
|
|
|
2633
2633
|
// src/components/TxHistoryButton/index.tsx
|
package/dist/index.mjs
CHANGED
|
@@ -1,8 +1,7 @@
|
|
|
1
1
|
var __require = /* @__PURE__ */ ((x) => typeof require !== "undefined" ? require : typeof Proxy !== "undefined" ? new Proxy(x, {
|
|
2
2
|
get: (a, b) => (typeof require !== "undefined" ? require : a)[b]
|
|
3
3
|
}) : x)(function(x) {
|
|
4
|
-
if (typeof require !== "undefined")
|
|
5
|
-
return require.apply(this, arguments);
|
|
4
|
+
if (typeof require !== "undefined") return require.apply(this, arguments);
|
|
6
5
|
throw Error('Dynamic require of "' + x + '" is not supported');
|
|
7
6
|
});
|
|
8
7
|
|
|
@@ -918,14 +917,12 @@ import { useEffect, useRef, useState } from "react";
|
|
|
918
917
|
var useDebounce = (value, delay) => {
|
|
919
918
|
const timeoutRef = useRef(null);
|
|
920
919
|
useEffect(() => {
|
|
921
|
-
if (timeoutRef.current)
|
|
922
|
-
clearTimeout(timeoutRef.current);
|
|
920
|
+
if (timeoutRef.current) clearTimeout(timeoutRef.current);
|
|
923
921
|
timeoutRef.current = setTimeout(() => {
|
|
924
922
|
setValue(value);
|
|
925
923
|
}, delay);
|
|
926
924
|
return () => {
|
|
927
|
-
if (timeoutRef.current)
|
|
928
|
-
clearTimeout(timeoutRef.current);
|
|
925
|
+
if (timeoutRef.current) clearTimeout(timeoutRef.current);
|
|
929
926
|
};
|
|
930
927
|
}, [value, delay]);
|
|
931
928
|
const [debouncedValue, setValue] = useState(value);
|
|
@@ -1498,8 +1495,7 @@ var History = ({ signer, supportedChains }) => {
|
|
|
1498
1495
|
continue;
|
|
1499
1496
|
}
|
|
1500
1497
|
let status;
|
|
1501
|
-
if (entry.failed)
|
|
1502
|
-
status = "REVERTED";
|
|
1498
|
+
if (entry.failed) status = "REVERTED";
|
|
1503
1499
|
if (!!entry.target) {
|
|
1504
1500
|
status = "DONE";
|
|
1505
1501
|
} else {
|
|
@@ -1530,8 +1526,7 @@ var History = ({ signer, supportedChains }) => {
|
|
|
1530
1526
|
}
|
|
1531
1527
|
}, [signer, getHistory]);
|
|
1532
1528
|
useEffect2(() => {
|
|
1533
|
-
if (!historyLoadedOnce)
|
|
1534
|
-
fetchHistory();
|
|
1529
|
+
if (!historyLoadedOnce) fetchHistory();
|
|
1535
1530
|
const timer = setInterval(() => {
|
|
1536
1531
|
fetchHistory();
|
|
1537
1532
|
}, 6e4);
|
|
@@ -2015,10 +2010,8 @@ import BigNumber3 from "bignumber.js";
|
|
|
2015
2010
|
import { Fragment as Fragment5, jsx as jsx32, jsxs as jsxs14 } from "react/jsx-runtime";
|
|
2016
2011
|
var BalanceComponent = ({ srcToken, balances }) => {
|
|
2017
2012
|
const balanceText = useMemo5(() => {
|
|
2018
|
-
if (!balances || !srcToken)
|
|
2019
|
-
|
|
2020
|
-
if (balances[srcToken.address]?.toString() === "0")
|
|
2021
|
-
return "0";
|
|
2013
|
+
if (!balances || !srcToken) return "0";
|
|
2014
|
+
if (balances[srcToken.address]?.toString() === "0") return "0";
|
|
2022
2015
|
const fullHumanReadable = weiToHumanReadable({
|
|
2023
2016
|
amount: balances[srcToken.address]?.toString() || "0",
|
|
2024
2017
|
decimals: srcToken.decimals,
|
|
@@ -2102,8 +2095,7 @@ var SwapPanel = ({
|
|
|
2102
2095
|
className: "p-0 border-none outline-none bg-transparent text-2xl overflow-ellipsis",
|
|
2103
2096
|
value: amount,
|
|
2104
2097
|
onChange: (e) => {
|
|
2105
|
-
if (e.target.value === ".")
|
|
2106
|
-
return;
|
|
2098
|
+
if (e.target.value === ".") return;
|
|
2107
2099
|
if (NUMBER_INPUT_REGEX.test(e.target.value)) {
|
|
2108
2100
|
setAmount(e.target.value.replace(/,/g, "."));
|
|
2109
2101
|
}
|
|
@@ -2369,8 +2361,7 @@ var Form = ({
|
|
|
2369
2361
|
}, [srcChain, signer]);
|
|
2370
2362
|
const handleSubmit = (event) => {
|
|
2371
2363
|
event.preventDefault();
|
|
2372
|
-
if (route)
|
|
2373
|
-
onSubmit(route);
|
|
2364
|
+
if (route) onSubmit(route);
|
|
2374
2365
|
};
|
|
2375
2366
|
const handleSwitchChain = async () => {
|
|
2376
2367
|
await switchChainAsync({ chainId: Number(srcChain?.chainId) });
|
|
@@ -2454,6 +2445,9 @@ var Form = ({
|
|
|
2454
2445
|
);
|
|
2455
2446
|
};
|
|
2456
2447
|
|
|
2448
|
+
// package.json
|
|
2449
|
+
var version = "0.2.0";
|
|
2450
|
+
|
|
2457
2451
|
// src/components/TxConfigForm/index.tsx
|
|
2458
2452
|
import { jsx as jsx38, jsxs as jsxs17 } from "react/jsx-runtime";
|
|
2459
2453
|
var TxConfigForm = ({
|
|
@@ -2521,7 +2515,7 @@ var openTxConfigForm = async ({
|
|
|
2521
2515
|
}) => {
|
|
2522
2516
|
try {
|
|
2523
2517
|
return await new Promise((resolve) => {
|
|
2524
|
-
|
|
2518
|
+
xswapRoot.render(
|
|
2525
2519
|
/* @__PURE__ */ jsx38(
|
|
2526
2520
|
TxConfigForm,
|
|
2527
2521
|
{
|
|
@@ -2532,10 +2526,10 @@ var openTxConfigForm = async ({
|
|
|
2532
2526
|
supportedChains,
|
|
2533
2527
|
onSubmit: (route) => {
|
|
2534
2528
|
resolve(route);
|
|
2535
|
-
|
|
2529
|
+
xswapRoot.render("");
|
|
2536
2530
|
},
|
|
2537
2531
|
onClose: () => {
|
|
2538
|
-
|
|
2532
|
+
xswapRoot.render("");
|
|
2539
2533
|
}
|
|
2540
2534
|
}
|
|
2541
2535
|
)
|
|
@@ -2545,12 +2539,17 @@ var openTxConfigForm = async ({
|
|
|
2545
2539
|
throw new Error(`XSwap component error, ${err}`);
|
|
2546
2540
|
}
|
|
2547
2541
|
};
|
|
2548
|
-
var
|
|
2542
|
+
var xswapRoot;
|
|
2549
2543
|
if (typeof document !== "undefined") {
|
|
2550
|
-
const
|
|
2551
|
-
|
|
2552
|
-
|
|
2553
|
-
|
|
2544
|
+
const xswapStyleElement = document.createElement("link");
|
|
2545
|
+
xswapStyleElement.rel = "stylesheet";
|
|
2546
|
+
xswapStyleElement.type = "text/css";
|
|
2547
|
+
xswapStyleElement.href = `${xswap_config_default.apiUrl}/sdk/css/${version}`;
|
|
2548
|
+
document.head.appendChild(xswapStyleElement);
|
|
2549
|
+
const xswapModalElement = document.createElement("div");
|
|
2550
|
+
xswapModalElement.setAttribute("id", "xswap-modal");
|
|
2551
|
+
document.body.appendChild(xswapModalElement);
|
|
2552
|
+
xswapRoot = createRoot(xswapModalElement);
|
|
2554
2553
|
}
|
|
2555
2554
|
|
|
2556
2555
|
// src/components/TxHistoryButton/index.tsx
|
package/package.json
CHANGED
|
@@ -8,6 +8,8 @@ import { Chain, ContractCall, Route } from "@src/models";
|
|
|
8
8
|
import { CloseIcon } from "@src/components/icons/CloseIcon";
|
|
9
9
|
import { Form } from "./Form";
|
|
10
10
|
import { ChainlinkCCIPIcon, XSwapBadgeIcon } from "../icons";
|
|
11
|
+
import { version } from "../../../package.json";
|
|
12
|
+
import xswapConfig from "../../../xswap.config";
|
|
11
13
|
|
|
12
14
|
export type TxConfigFormProps = {
|
|
13
15
|
dstChainId: string;
|
|
@@ -46,34 +48,34 @@ const TxConfigForm = ({
|
|
|
46
48
|
return (
|
|
47
49
|
<WagmiProvider config={wagmiConfig}>
|
|
48
50
|
<QueryClientProvider client={queryClient}>
|
|
49
|
-
<div
|
|
50
|
-
className="top-0 left-0 right-0 bottom-0 bg-[rgba(0,0,0,0.8)] fixed flex items-center justify-center z-10"
|
|
51
|
-
onClick={onBackdropClick}
|
|
52
|
-
>
|
|
53
|
-
<div className="relative bg-black rounded-3xl w-lg overflow-auto text-white border-2 border-solid border-[rgba(255,255,255,0.1)]">
|
|
54
|
-
<Form
|
|
55
|
-
dstChainId={dstChainId}
|
|
56
|
-
dstTokenAddr={dstTokenAddr}
|
|
57
|
-
customContractCalls={customContractCalls}
|
|
58
|
-
desc={desc}
|
|
59
|
-
supportedChains={supportedChains}
|
|
60
|
-
onSubmit={onSubmit}
|
|
61
|
-
/>
|
|
62
51
|
<div
|
|
63
|
-
className="
|
|
64
|
-
onClick={
|
|
52
|
+
className="top-0 left-0 right-0 bottom-0 bg-[rgba(0,0,0,0.8)] fixed flex items-center justify-center z-10"
|
|
53
|
+
onClick={onBackdropClick}
|
|
65
54
|
>
|
|
66
|
-
<
|
|
67
|
-
|
|
55
|
+
<div className="relative bg-black rounded-3xl w-lg overflow-auto text-white border-2 border-solid border-[rgba(255,255,255,0.1)]">
|
|
56
|
+
<Form
|
|
57
|
+
dstChainId={dstChainId}
|
|
58
|
+
dstTokenAddr={dstTokenAddr}
|
|
59
|
+
customContractCalls={customContractCalls}
|
|
60
|
+
desc={desc}
|
|
61
|
+
supportedChains={supportedChains}
|
|
62
|
+
onSubmit={onSubmit}
|
|
63
|
+
/>
|
|
64
|
+
<div
|
|
65
|
+
className="absolute top-7 right-4 cursor-pointer text-white"
|
|
66
|
+
onClick={onClose}
|
|
67
|
+
>
|
|
68
|
+
<CloseIcon />
|
|
69
|
+
</div>
|
|
68
70
|
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
71
|
+
<div className="swappage__poweredby">
|
|
72
|
+
<span>Powered by</span>
|
|
73
|
+
<XSwapBadgeIcon />
|
|
74
|
+
<span>✕</span>
|
|
75
|
+
<ChainlinkCCIPIcon />
|
|
76
|
+
</div>
|
|
77
|
+
</div>
|
|
74
78
|
</div>
|
|
75
|
-
</div>
|
|
76
|
-
</div>
|
|
77
79
|
</QueryClientProvider>
|
|
78
80
|
</WagmiProvider>
|
|
79
81
|
);
|
|
@@ -88,7 +90,7 @@ export const openTxConfigForm = async ({
|
|
|
88
90
|
}: TxConfigFormProps): Promise<Route> => {
|
|
89
91
|
try {
|
|
90
92
|
return await new Promise((resolve) => {
|
|
91
|
-
|
|
93
|
+
xswapRoot.render(
|
|
92
94
|
<TxConfigForm
|
|
93
95
|
dstChainId={dstChainId}
|
|
94
96
|
dstTokenAddr={dstTokenAddr}
|
|
@@ -97,10 +99,10 @@ export const openTxConfigForm = async ({
|
|
|
97
99
|
supportedChains={supportedChains}
|
|
98
100
|
onSubmit={(route) => {
|
|
99
101
|
resolve(route);
|
|
100
|
-
|
|
102
|
+
xswapRoot.render("");
|
|
101
103
|
}}
|
|
102
104
|
onClose={() => {
|
|
103
|
-
|
|
105
|
+
xswapRoot.render("");
|
|
104
106
|
}}
|
|
105
107
|
/>,
|
|
106
108
|
);
|
|
@@ -111,10 +113,16 @@ export const openTxConfigForm = async ({
|
|
|
111
113
|
};
|
|
112
114
|
|
|
113
115
|
// skip on server-side integrations
|
|
114
|
-
let
|
|
116
|
+
let xswapRoot: Root;
|
|
115
117
|
if (typeof document !== "undefined") {
|
|
116
|
-
const
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
118
|
+
const xswapStyleElement = document.createElement("link");
|
|
119
|
+
xswapStyleElement.rel = "stylesheet";
|
|
120
|
+
xswapStyleElement.type = "text/css";
|
|
121
|
+
xswapStyleElement.href = `${xswapConfig.apiUrl}/sdk/css/${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);
|
|
120
128
|
}
|