@xswap-link/sdk 0.9.1 → 0.9.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.d.mts +4 -2
- package/dist/index.d.ts +4 -2
- package/dist/index.global.js +92 -683
- package/dist/index.js +7 -7
- package/dist/index.mjs +7 -7
- package/package.json +3 -1
- package/src/components/Swap/SwapView/SwapButton/index.tsx +13 -5
- package/src/components/TxConfigForm/index.tsx +8 -1
- package/src/components/TxWidgetWC/index.tsx +2 -0
- package/src/components/TxWidgetWCWrapped/index.tsx +3 -0
- package/src/config/wagmiConfig.ts +7 -5
- package/src/context/SwapProvider.tsx +18 -0
- package/src/models/payloads/ModalIntegrationPayload.ts +1 -0
- package/src/models/payloads/WidgetIntegrationPayload.ts +1 -0
- package/src/types/global.d.ts +1 -0
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@xswap-link/sdk",
|
|
3
|
-
"version": "0.9.
|
|
3
|
+
"version": "0.9.2",
|
|
4
4
|
"description": "JavaScript SDK for XSwap platform",
|
|
5
5
|
"homepage": "https://github.com/xswap-link/xswap-sdk",
|
|
6
6
|
"repository": {
|
|
@@ -36,6 +36,8 @@
|
|
|
36
36
|
"@fortawesome/react-fontawesome": "^0.2.0",
|
|
37
37
|
"@r2wc/core": "^1.1.0",
|
|
38
38
|
"@tanstack/react-query": "^5.64.2",
|
|
39
|
+
"@wagmi/connectors": "^5.7.5",
|
|
40
|
+
"@wagmi/core": "^2.16.3",
|
|
39
41
|
"async-retry": "^1.3.3",
|
|
40
42
|
"bignumber.js": "4.0.4",
|
|
41
43
|
"date-fns": "^3.6.0",
|
|
@@ -34,6 +34,8 @@ export const SwapButton = () => {
|
|
|
34
34
|
srcTokenBalanceWei,
|
|
35
35
|
isFetchingRoute,
|
|
36
36
|
isAsyncDataLoaded,
|
|
37
|
+
hasOnConnectWalletCallback,
|
|
38
|
+
onConnectWallet,
|
|
37
39
|
} = useSwapContext();
|
|
38
40
|
|
|
39
41
|
const { setTxStatus, setTxMsg, setTxModalOpen, enqueueTransaction } =
|
|
@@ -111,13 +113,19 @@ export const SwapButton = () => {
|
|
|
111
113
|
|
|
112
114
|
if (!address) {
|
|
113
115
|
return {
|
|
114
|
-
text:
|
|
115
|
-
|
|
116
|
-
|
|
116
|
+
text:
|
|
117
|
+
integrationConfig.defaultWalletPicker || hasOnConnectWalletCallback
|
|
118
|
+
? "Connect Wallet"
|
|
119
|
+
: "Connect Wallet First",
|
|
117
120
|
fn: () => {
|
|
118
|
-
|
|
121
|
+
if (integrationConfig.defaultWalletPicker) {
|
|
122
|
+
setConnectWalletModalOpen(true);
|
|
123
|
+
} else if (hasOnConnectWalletCallback) {
|
|
124
|
+
onConnectWallet();
|
|
125
|
+
}
|
|
119
126
|
},
|
|
120
|
-
disabled:
|
|
127
|
+
disabled:
|
|
128
|
+
!integrationConfig.defaultWalletPicker && !hasOnConnectWalletCallback,
|
|
121
129
|
};
|
|
122
130
|
}
|
|
123
131
|
|
|
@@ -32,9 +32,14 @@ const WagmiReload: FC = () => {
|
|
|
32
32
|
const { reconnect } = useReconnect();
|
|
33
33
|
|
|
34
34
|
useEffect(() => {
|
|
35
|
+
let count = 0;
|
|
35
36
|
const interval = setInterval(() => {
|
|
36
37
|
reconnect();
|
|
37
|
-
|
|
38
|
+
count++;
|
|
39
|
+
if (count >= 5) {
|
|
40
|
+
clearInterval(interval);
|
|
41
|
+
}
|
|
42
|
+
}, 1000);
|
|
38
43
|
|
|
39
44
|
return () => {
|
|
40
45
|
clearInterval(interval);
|
|
@@ -91,6 +96,7 @@ export const TxConfigForm = ({
|
|
|
91
96
|
onSrcTokenChange,
|
|
92
97
|
onSrcChainChange,
|
|
93
98
|
bridge,
|
|
99
|
+
onConnectWallet,
|
|
94
100
|
}: TxConfigFormPayload &
|
|
95
101
|
(
|
|
96
102
|
| {
|
|
@@ -156,6 +162,7 @@ export const TxConfigForm = ({
|
|
|
156
162
|
onSrcTokenChange,
|
|
157
163
|
onSrcChainChange,
|
|
158
164
|
bridge,
|
|
165
|
+
onConnectWallet,
|
|
159
166
|
}}
|
|
160
167
|
supportedChains={supportedChains}
|
|
161
168
|
wagmiConfig={wagmiConfig}
|
|
@@ -33,6 +33,7 @@ const TxWidget = ({
|
|
|
33
33
|
onDstChainChange,
|
|
34
34
|
onSrcTokenChange,
|
|
35
35
|
onSrcChainChange,
|
|
36
|
+
onConnectWallet,
|
|
36
37
|
bridge,
|
|
37
38
|
}: WidgetIntegrationPayload) => {
|
|
38
39
|
const [loading, setLoading] = useState(true);
|
|
@@ -95,6 +96,7 @@ const TxWidget = ({
|
|
|
95
96
|
onDstChainChange={onDstChainChange}
|
|
96
97
|
onSrcTokenChange={onSrcTokenChange}
|
|
97
98
|
onSrcChainChange={onSrcChainChange}
|
|
99
|
+
onConnectWallet={onConnectWallet}
|
|
98
100
|
bridge={bridge}
|
|
99
101
|
/>
|
|
100
102
|
)}
|
|
@@ -45,6 +45,7 @@ export const TxWidgetWCWrapped = ({
|
|
|
45
45
|
onDstChainChange,
|
|
46
46
|
onSrcTokenChange,
|
|
47
47
|
onSrcChainChange,
|
|
48
|
+
onConnectWallet,
|
|
48
49
|
bridge,
|
|
49
50
|
}: WidgetIntegrationPayload) => {
|
|
50
51
|
useEffect(() => {
|
|
@@ -55,12 +56,14 @@ export const TxWidgetWCWrapped = ({
|
|
|
55
56
|
window.xPayOnDstChainChange = onDstChainChange;
|
|
56
57
|
window.xPayOnSrcTokenChange = onSrcTokenChange;
|
|
57
58
|
window.xPayOnSrcChainChange = onSrcChainChange;
|
|
59
|
+
window.xPayOnConnectWallet = onConnectWallet;
|
|
58
60
|
}, [
|
|
59
61
|
onPendingTransactionsChange,
|
|
60
62
|
onDstTokenChange,
|
|
61
63
|
onDstChainChange,
|
|
62
64
|
onSrcTokenChange,
|
|
63
65
|
onSrcChainChange,
|
|
66
|
+
onConnectWallet,
|
|
64
67
|
]);
|
|
65
68
|
|
|
66
69
|
return (
|
|
@@ -3,8 +3,8 @@ import { isServer } from "@src/utils";
|
|
|
3
3
|
import { Transport } from "viem";
|
|
4
4
|
import * as WagmiChains from "viem/chains";
|
|
5
5
|
import { mainnet } from "viem/chains";
|
|
6
|
-
import { Config, createConfig, createStorage, http } from "wagmi";
|
|
7
|
-
import { injected,
|
|
6
|
+
import { Config, createConfig, createStorage, http } from "@wagmi/core";
|
|
7
|
+
import { injected, walletConnect, coinbaseWallet } from "@wagmi/connectors";
|
|
8
8
|
|
|
9
9
|
const storage = createStorage({
|
|
10
10
|
key: "xpay.wagmi.store",
|
|
@@ -19,11 +19,13 @@ export const getWagmiConfig = (supportedChains: Chain[]): Config => {
|
|
|
19
19
|
transports,
|
|
20
20
|
connectors: [
|
|
21
21
|
injected(),
|
|
22
|
-
|
|
23
|
-
|
|
22
|
+
coinbaseWallet({
|
|
23
|
+
appLogoUrl: "https://xswap.link/favicon.ico",
|
|
24
|
+
appName: "XSwap",
|
|
25
|
+
}),
|
|
24
26
|
walletConnect({
|
|
25
27
|
projectId: "c392898b45ac587a280b5eb33e92aeb0",
|
|
26
|
-
showQrModal:
|
|
28
|
+
showQrModal: true,
|
|
27
29
|
}),
|
|
28
30
|
],
|
|
29
31
|
storage,
|
|
@@ -109,6 +109,8 @@ type SwapContext = {
|
|
|
109
109
|
chainId: string,
|
|
110
110
|
) => Token | undefined;
|
|
111
111
|
bridgeTokensDictionary: BridgeTokensDictionary | null;
|
|
112
|
+
onConnectWallet: () => void;
|
|
113
|
+
hasOnConnectWalletCallback: boolean;
|
|
112
114
|
};
|
|
113
115
|
|
|
114
116
|
const functionNotImplemented = () => {
|
|
@@ -172,6 +174,8 @@ const init: SwapContext = {
|
|
|
172
174
|
refreshBalance: functionNotImplemented,
|
|
173
175
|
findTokenDataByAddressAndChain: functionNotImplemented,
|
|
174
176
|
bridgeTokensDictionary: null,
|
|
177
|
+
onConnectWallet: functionNotImplemented,
|
|
178
|
+
hasOnConnectWalletCallback: false,
|
|
175
179
|
};
|
|
176
180
|
|
|
177
181
|
const swapContext = createContext(init);
|
|
@@ -923,6 +927,18 @@ export const SwapProvider = ({
|
|
|
923
927
|
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
924
928
|
}, [integrationConfig.onSrcTokenChange, srcToken]);
|
|
925
929
|
|
|
930
|
+
const onConnectWallet = useCallback(() => {
|
|
931
|
+
if (integrationConfig.onConnectWallet) {
|
|
932
|
+
integrationConfig.onConnectWallet();
|
|
933
|
+
} else if (window.xPayOnConnectWallet) {
|
|
934
|
+
window.xPayOnConnectWallet();
|
|
935
|
+
}
|
|
936
|
+
}, [integrationConfig]);
|
|
937
|
+
|
|
938
|
+
const hasOnConnectWalletCallback = useMemo(() => {
|
|
939
|
+
return !!(integrationConfig.onConnectWallet || window.xPayOnConnectWallet);
|
|
940
|
+
}, [integrationConfig.onConnectWallet]);
|
|
941
|
+
|
|
926
942
|
return (
|
|
927
943
|
<swapContext.Provider
|
|
928
944
|
value={{
|
|
@@ -982,6 +998,8 @@ export const SwapProvider = ({
|
|
|
982
998
|
dstTokenLocked,
|
|
983
999
|
dstChainLocked,
|
|
984
1000
|
bridgeTokensDictionary,
|
|
1001
|
+
onConnectWallet,
|
|
1002
|
+
hasOnConnectWalletCallback,
|
|
985
1003
|
}}
|
|
986
1004
|
>
|
|
987
1005
|
{children}
|