@xswap-link/sdk 0.9.10 → 0.10.1

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.9.10",
3
+ "version": "0.10.1",
4
4
  "description": "JavaScript SDK for XSwap platform",
5
5
  "homepage": "https://github.com/xswap-link/xswap-sdk",
6
6
  "repository": {
@@ -236,21 +236,21 @@ export const TokenPicker = ({
236
236
  // Create groups based on chain and wallet connection status
237
237
  const groups = chain
238
238
  ? [
239
- ...(!!address && ownedFilteredTokens.length && type === "source"
239
+ ...(!!address && ownedFilteredTokens.length
240
240
  ? [ownedFilteredTokens]
241
241
  : []),
242
242
  currentChainTokens,
243
243
  otherChainTokens,
244
244
  ]
245
245
  : [
246
- ...(!!address && ownedFilteredTokens.length && type === "source"
246
+ ...(!!address && ownedFilteredTokens.length
247
247
  ? [ownedFilteredTokens]
248
248
  : []),
249
249
  [...currentChainTokens, ...otherChainTokens],
250
250
  ];
251
251
 
252
252
  return groups.flat();
253
- }, [filteredTokens, otherFilteredTokens, chain, address, type, tokenPrices]);
253
+ }, [filteredTokens, otherFilteredTokens, chain, address, tokenPrices]);
254
254
 
255
255
  const ownedTokens = useMemo(
256
256
  () => allTokens.filter((token) => token.balance?.gt(0)),
@@ -260,19 +260,15 @@ export const TokenPicker = ({
260
260
  const tokenGroups = useMemo(() => {
261
261
  return chain
262
262
  ? [
263
- ...(type === "source" && !!address && ownedTokens.length
264
- ? [ownedTokens]
265
- : []),
263
+ ...(!!address && ownedTokens.length ? [ownedTokens] : []),
266
264
  filteredTokens,
267
265
  otherFilteredTokens,
268
266
  ]
269
267
  : [
270
- ...(type === "source" && !!address && ownedTokens.length
271
- ? [ownedTokens]
272
- : []),
268
+ ...(!!address && ownedTokens.length ? [ownedTokens] : []),
273
269
  otherFilteredTokens,
274
270
  ];
275
- }, [chain, type, address, ownedTokens, filteredTokens, otherFilteredTokens]);
271
+ }, [chain, address, ownedTokens, filteredTokens, otherFilteredTokens]);
276
272
 
277
273
  return showImportWarning ? (
278
274
  <>
@@ -465,7 +461,7 @@ export const TokenPicker = ({
465
461
  if (!address) {
466
462
  return `${chain.displayName} network`;
467
463
  }
468
- return ownedTokens.length && type === "source"
464
+ return ownedTokens.length
469
465
  ? "My tokens"
470
466
  : `${chain.displayName} network`;
471
467
  }
@@ -489,7 +485,7 @@ export const TokenPicker = ({
489
485
  if (!address) {
490
486
  return "All networks";
491
487
  }
492
- return ownedTokens.length && type === "source"
488
+ return ownedTokens.length
493
489
  ? "My tokens"
494
490
  : "All networks";
495
491
  }
@@ -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
  );
@@ -1,4 +1,3 @@
1
- export * from "./GlobalDataProvider";
2
1
  export * from "./HistoryProvider";
3
2
  export * from "./SwapProvider";
4
3
  export * from "./TransactionProvider";
@@ -21,4 +21,6 @@ export type GetRoutePayload = {
21
21
  collectFees?: CollectFees;
22
22
  fallbackAddresses?: CoinTypeAddress[];
23
23
  infiniteApproval: boolean;
24
+ integratorFee?: number;
25
+ integratorFeeReceiverAddress?: string;
24
26
  };
@@ -67,4 +67,6 @@ export type ModalIntegrationPayload = {
67
67
  override?: {
68
68
  apiUrl?: string;
69
69
  };
70
+ integratorFee?: number;
71
+ integratorFeeReceiverAddress?: string;
70
72
  };
@@ -30,4 +30,6 @@ export type WidgetIntegrationPayload = {
30
30
  override?: {
31
31
  apiUrl?: string;
32
32
  };
33
+ integratorFee?: number;
34
+ integratorFeeReceiverAddress?: string;
33
35
  };
@@ -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);