@xswap-link/sdk 0.9.9 → 0.10.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/CHANGELOG.md +12 -0
- package/dist/index.d.mts +10 -2
- package/dist/index.d.ts +10 -2
- package/dist/index.global.js +61 -61
- package/dist/index.js +9 -9
- package/dist/index.mjs +8 -8
- package/package.json +1 -1
- package/src/components/TxConfigForm/index.tsx +6 -0
- package/src/components/TxWidgetWC/index.tsx +10 -0
- package/src/components/TxWidgetWCWrapped/index.tsx +4 -0
- package/src/context/SwapProvider.tsx +7 -1
- package/src/context/index.ts +0 -1
- package/src/models/payloads/GetRoutePayload.ts +2 -0
- package/src/models/payloads/ModalIntegrationPayload.ts +2 -0
- package/src/models/payloads/WidgetIntegrationPayload.ts +2 -0
- package/src/context/GlobalDataProvider.tsx +0 -165
package/package.json
CHANGED
|
@@ -25,6 +25,8 @@ export type TxConfigFormPayload = Omit<
|
|
|
25
25
|
srcTokenAddr?: string;
|
|
26
26
|
dstDisplayTokenAddr?: string;
|
|
27
27
|
supportedChains: Chain[];
|
|
28
|
+
integratorFee?: number;
|
|
29
|
+
integratorFeeReceiverAddress?: string;
|
|
28
30
|
};
|
|
29
31
|
|
|
30
32
|
const queryClient = new QueryClient();
|
|
@@ -99,6 +101,8 @@ export const TxConfigForm = ({
|
|
|
99
101
|
bridge,
|
|
100
102
|
onConnectWallet,
|
|
101
103
|
override,
|
|
104
|
+
integratorFee,
|
|
105
|
+
integratorFeeReceiverAddress,
|
|
102
106
|
}: TxConfigFormPayload &
|
|
103
107
|
(
|
|
104
108
|
| {
|
|
@@ -170,6 +174,8 @@ export const TxConfigForm = ({
|
|
|
170
174
|
onSrcChainChange,
|
|
171
175
|
bridge,
|
|
172
176
|
onConnectWallet,
|
|
177
|
+
integratorFee,
|
|
178
|
+
integratorFeeReceiverAddress,
|
|
173
179
|
}}
|
|
174
180
|
supportedChains={supportedChains}
|
|
175
181
|
wagmiConfig={wagmiConfig}
|
|
@@ -36,6 +36,8 @@ const TxWidget = ({
|
|
|
36
36
|
onConnectWallet,
|
|
37
37
|
bridge,
|
|
38
38
|
override,
|
|
39
|
+
integratorFee,
|
|
40
|
+
integratorFeeReceiverAddress,
|
|
39
41
|
}: WidgetIntegrationPayload) => {
|
|
40
42
|
const [loading, setLoading] = useState(true);
|
|
41
43
|
const [supportedChains, setSupportedChains] = useState<Chain[]>([]);
|
|
@@ -105,6 +107,8 @@ const TxWidget = ({
|
|
|
105
107
|
onConnectWallet={onConnectWallet}
|
|
106
108
|
bridge={bridge}
|
|
107
109
|
override={override}
|
|
110
|
+
integratorFee={integratorFee}
|
|
111
|
+
integratorFeeReceiverAddress={integratorFeeReceiverAddress}
|
|
108
112
|
/>
|
|
109
113
|
)}
|
|
110
114
|
</>
|
|
@@ -149,6 +153,8 @@ export const createTxWidgetWC = () => {
|
|
|
149
153
|
onSrcTokenChange: "function",
|
|
150
154
|
onSrcChainChange: "function",
|
|
151
155
|
override: "json",
|
|
156
|
+
integratorFee: "number",
|
|
157
|
+
integratorFeeReceiverAddress: "string",
|
|
152
158
|
},
|
|
153
159
|
});
|
|
154
160
|
|
|
@@ -185,4 +191,8 @@ export type TxWidgetWCAttributes = {
|
|
|
185
191
|
"on-src-chain-change"?: WidgetIntegrationPayload["onSrcChainChange"];
|
|
186
192
|
bridge: WidgetIntegrationPayload["bridge"] | undefined;
|
|
187
193
|
override: string | undefined;
|
|
194
|
+
"integrator-fee": WidgetIntegrationPayload["integratorFee"] | undefined;
|
|
195
|
+
"integrator-fee-receiver-address":
|
|
196
|
+
| WidgetIntegrationPayload["integratorFeeReceiverAddress"]
|
|
197
|
+
| undefined;
|
|
188
198
|
};
|
|
@@ -48,6 +48,8 @@ export const TxWidgetWCWrapped = ({
|
|
|
48
48
|
onConnectWallet,
|
|
49
49
|
bridge,
|
|
50
50
|
override,
|
|
51
|
+
integratorFee,
|
|
52
|
+
integratorFeeReceiverAddress,
|
|
51
53
|
}: WidgetIntegrationPayload) => {
|
|
52
54
|
useEffect(() => {
|
|
53
55
|
// We couldn't find a way to pass a function to the web component created by @r2wc/core.
|
|
@@ -86,6 +88,8 @@ export const TxWidgetWCWrapped = ({
|
|
|
86
88
|
src-chain-locked={srcChainLocked}
|
|
87
89
|
bridge={bridge}
|
|
88
90
|
override={JSON.stringify(override)}
|
|
91
|
+
integrator-fee={integratorFee}
|
|
92
|
+
integrator-fee-receiver-address={integratorFeeReceiverAddress}
|
|
89
93
|
></xpay-widget>
|
|
90
94
|
);
|
|
91
95
|
};
|
|
@@ -583,6 +583,9 @@ export const SwapProvider = ({
|
|
|
583
583
|
paymentToken: constants.AddressZero,
|
|
584
584
|
expressDelivery: expressDelivery,
|
|
585
585
|
infiniteApproval: infiniteApproval,
|
|
586
|
+
integratorFee: integrationConfig.integratorFee,
|
|
587
|
+
integratorFeeReceiverAddress:
|
|
588
|
+
integrationConfig.integratorFeeReceiverAddress,
|
|
586
589
|
},
|
|
587
590
|
routeAbortController.current.signal,
|
|
588
591
|
);
|
|
@@ -591,12 +594,15 @@ export const SwapProvider = ({
|
|
|
591
594
|
routeAbortController.current = null;
|
|
592
595
|
} catch (error) {
|
|
593
596
|
if (error !== DEFAULT_REQUEST_ABORT_MSG) {
|
|
597
|
+
routeAbortController.current = null;
|
|
594
598
|
console.error(error);
|
|
595
599
|
setError("Could not find route!");
|
|
596
600
|
setRoute(undefined);
|
|
597
601
|
}
|
|
598
602
|
} finally {
|
|
599
|
-
|
|
603
|
+
if (!routeAbortController.current) {
|
|
604
|
+
setFetchingRoute(false);
|
|
605
|
+
}
|
|
600
606
|
}
|
|
601
607
|
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
602
608
|
}, [
|
package/src/context/index.ts
CHANGED
|
@@ -1,165 +0,0 @@
|
|
|
1
|
-
import { ADDRESSES } from "@src/contracts";
|
|
2
|
-
import { TOTAL_QUESTS_COUNT, XSWAP_STAKING_CHAIN_ID } from "@src/constants";
|
|
3
|
-
import { useXPower } from "@src/hooks";
|
|
4
|
-
import {
|
|
5
|
-
Context,
|
|
6
|
-
Dispatch,
|
|
7
|
-
FC,
|
|
8
|
-
ReactNode,
|
|
9
|
-
SetStateAction,
|
|
10
|
-
createContext,
|
|
11
|
-
useCallback,
|
|
12
|
-
useContext,
|
|
13
|
-
useEffect,
|
|
14
|
-
useState,
|
|
15
|
-
} from "react";
|
|
16
|
-
import { useAccount } from "wagmi";
|
|
17
|
-
import { getFinishedLeaderboardQuests } from "@src/services";
|
|
18
|
-
import { getBalanceOf } from "@src/utils";
|
|
19
|
-
import { useSwapContext } from "@src/context/SwapProvider";
|
|
20
|
-
import { Ecosystem } from "@src/models";
|
|
21
|
-
|
|
22
|
-
export interface GlobalDataState {
|
|
23
|
-
rank: number;
|
|
24
|
-
setRank: Dispatch<SetStateAction<number>>;
|
|
25
|
-
xPower: string;
|
|
26
|
-
updateXPower: () => void;
|
|
27
|
-
xSwapBalance: string;
|
|
28
|
-
updateXSwapBalance: () => void;
|
|
29
|
-
unfinishedQuestsCount: number;
|
|
30
|
-
setUnfinishedQuestsCount: Dispatch<SetStateAction<number>>;
|
|
31
|
-
}
|
|
32
|
-
|
|
33
|
-
const initialValue: GlobalDataState = {
|
|
34
|
-
rank: 0,
|
|
35
|
-
setRank: () => {
|
|
36
|
-
throw new Error("GlobalDataState > setRank is not implemented");
|
|
37
|
-
},
|
|
38
|
-
xPower: "0",
|
|
39
|
-
updateXPower: () => {
|
|
40
|
-
throw new Error("GlobalDataState > updateXPower is not implemented");
|
|
41
|
-
},
|
|
42
|
-
xSwapBalance: "0",
|
|
43
|
-
updateXSwapBalance: () => {
|
|
44
|
-
throw new Error("GlobalDataState > updateXSwapBalance is not implemented");
|
|
45
|
-
},
|
|
46
|
-
unfinishedQuestsCount: 0,
|
|
47
|
-
setUnfinishedQuestsCount: () => {
|
|
48
|
-
throw new Error(
|
|
49
|
-
"GlobalDataState > setUnfinishedQuestsCount is not implemented",
|
|
50
|
-
);
|
|
51
|
-
},
|
|
52
|
-
};
|
|
53
|
-
|
|
54
|
-
const GlobalDataContext: Context<GlobalDataState> =
|
|
55
|
-
createContext<GlobalDataState>({
|
|
56
|
-
rank: initialValue.rank,
|
|
57
|
-
setRank: initialValue.setRank,
|
|
58
|
-
xPower: initialValue.xPower,
|
|
59
|
-
updateXPower: initialValue.updateXPower,
|
|
60
|
-
xSwapBalance: initialValue.xSwapBalance,
|
|
61
|
-
updateXSwapBalance: initialValue.updateXSwapBalance,
|
|
62
|
-
unfinishedQuestsCount: initialValue.unfinishedQuestsCount,
|
|
63
|
-
setUnfinishedQuestsCount: initialValue.setUnfinishedQuestsCount,
|
|
64
|
-
});
|
|
65
|
-
|
|
66
|
-
export const GlobalDataProvider: FC<{ children: ReactNode }> = ({
|
|
67
|
-
children,
|
|
68
|
-
}) => {
|
|
69
|
-
const { address } = useAccount();
|
|
70
|
-
const [unfinishedQuestsCount, setUnfinishedQuestsCount] = useState(
|
|
71
|
-
initialValue.unfinishedQuestsCount,
|
|
72
|
-
);
|
|
73
|
-
const [rank, setRank] = useState(initialValue.rank);
|
|
74
|
-
const [xPower, setXPower] = useState(initialValue.xPower);
|
|
75
|
-
const [xSwapBalance, setXSwapBalance] = useState(initialValue.xSwapBalance);
|
|
76
|
-
const { getXPower } = useXPower(XSWAP_STAKING_CHAIN_ID);
|
|
77
|
-
|
|
78
|
-
const { supportedChains } = useSwapContext();
|
|
79
|
-
|
|
80
|
-
const getFinishedQuests = useCallback(async () => {
|
|
81
|
-
if (!address) {
|
|
82
|
-
return;
|
|
83
|
-
}
|
|
84
|
-
const response = await getFinishedLeaderboardQuests({
|
|
85
|
-
walletAddress: address.toLowerCase(),
|
|
86
|
-
});
|
|
87
|
-
|
|
88
|
-
if (!response.ok) {
|
|
89
|
-
throw Error("Could not fetch quests statuses.");
|
|
90
|
-
}
|
|
91
|
-
const finishedQuestsResponse = await response.json();
|
|
92
|
-
if (finishedQuestsResponse.quests) {
|
|
93
|
-
const questsLeft = Math.max(
|
|
94
|
-
TOTAL_QUESTS_COUNT - (finishedQuestsResponse.quests.length || 0),
|
|
95
|
-
0,
|
|
96
|
-
);
|
|
97
|
-
setUnfinishedQuestsCount(questsLeft);
|
|
98
|
-
}
|
|
99
|
-
}, [address]);
|
|
100
|
-
|
|
101
|
-
const fetchXPower = useCallback(async () => {
|
|
102
|
-
if (address) {
|
|
103
|
-
const response = await getXPower(address);
|
|
104
|
-
setXPower(response);
|
|
105
|
-
} else {
|
|
106
|
-
setXPower("0");
|
|
107
|
-
}
|
|
108
|
-
}, [getXPower, address]);
|
|
109
|
-
|
|
110
|
-
const fetchXSwapBalance = useCallback(async () => {
|
|
111
|
-
const rpcUrl = supportedChains.find(
|
|
112
|
-
(chain) =>
|
|
113
|
-
chain.ecosystem === Ecosystem.EVM &&
|
|
114
|
-
chain.chainId === XSWAP_STAKING_CHAIN_ID,
|
|
115
|
-
)?.publicRpcUrls[0];
|
|
116
|
-
|
|
117
|
-
if (
|
|
118
|
-
address &&
|
|
119
|
-
rpcUrl &&
|
|
120
|
-
ADDRESSES[XSWAP_STAKING_CHAIN_ID] &&
|
|
121
|
-
ADDRESSES[XSWAP_STAKING_CHAIN_ID].XSwapToken
|
|
122
|
-
) {
|
|
123
|
-
const response = await getBalanceOf(
|
|
124
|
-
address,
|
|
125
|
-
ADDRESSES[XSWAP_STAKING_CHAIN_ID].XSwapToken,
|
|
126
|
-
rpcUrl,
|
|
127
|
-
);
|
|
128
|
-
setXSwapBalance(response);
|
|
129
|
-
} else {
|
|
130
|
-
setXSwapBalance("0");
|
|
131
|
-
}
|
|
132
|
-
}, []);
|
|
133
|
-
|
|
134
|
-
useEffect(() => {
|
|
135
|
-
getFinishedQuests();
|
|
136
|
-
}, [getFinishedQuests]);
|
|
137
|
-
|
|
138
|
-
useEffect(() => {
|
|
139
|
-
fetchXPower();
|
|
140
|
-
}, [fetchXPower]);
|
|
141
|
-
|
|
142
|
-
useEffect(() => {
|
|
143
|
-
fetchXSwapBalance();
|
|
144
|
-
}, [fetchXSwapBalance]);
|
|
145
|
-
|
|
146
|
-
return (
|
|
147
|
-
<GlobalDataContext.Provider
|
|
148
|
-
value={{
|
|
149
|
-
rank,
|
|
150
|
-
setRank,
|
|
151
|
-
xPower,
|
|
152
|
-
updateXPower: () => fetchXPower(),
|
|
153
|
-
xSwapBalance,
|
|
154
|
-
updateXSwapBalance: () => fetchXSwapBalance(),
|
|
155
|
-
unfinishedQuestsCount,
|
|
156
|
-
setUnfinishedQuestsCount,
|
|
157
|
-
}}
|
|
158
|
-
>
|
|
159
|
-
{children}
|
|
160
|
-
</GlobalDataContext.Provider>
|
|
161
|
-
);
|
|
162
|
-
};
|
|
163
|
-
|
|
164
|
-
export const useGlobalData = (): GlobalDataState =>
|
|
165
|
-
useContext(GlobalDataContext);
|