@liberfi.io/hooks 0.1.6 → 0.1.7

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/dist/index.js CHANGED
@@ -1,8 +1,6 @@
1
1
  'use strict';
2
2
 
3
3
  var React = require('react');
4
- var jsxRuntime = require('react/jsx-runtime');
5
- var reactQuery = require('@tanstack/react-query');
6
4
  var useConstant = require('use-constant');
7
5
  var core = require('@liberfi.io/core');
8
6
  var useDebounce = require('use-debounce');
@@ -22,426 +20,6 @@ if (typeof window !== "undefined") {
22
20
  window.__LIBERFI_VERSION__["@liberfi.io/hooks"] = "0.1.6";
23
21
  }
24
22
  var version_default = "0.1.6";
25
- var APIClientContext = React.createContext(
26
- {}
27
- );
28
- function APIClientProvider({
29
- client,
30
- subscribeClient,
31
- children
32
- }) {
33
- return /* @__PURE__ */ jsxRuntime.jsx(APIClientContext.Provider, { value: { client, subscribeClient }, children });
34
- }
35
- function useAPIClient() {
36
- const context = React.useContext(APIClientContext);
37
- if (!context) {
38
- throw new Error("useAPIClient must be used within an APIClientProvider");
39
- }
40
- return context;
41
- }
42
- function finalStretchTokensQueryKey(params) {
43
- return [
44
- "finalStretchTokens",
45
- params.chain,
46
- params.sortBy ?? "",
47
- params.sortDirection ?? "",
48
- JSON.stringify((params.keywords ?? []).sort()),
49
- JSON.stringify((params.excludeKeywords ?? []).sort()),
50
- JSON.stringify(params.filters ?? [])
51
- ];
52
- }
53
- async function fetchFinalStretchTokens(client, { chain, ...options }) {
54
- return await client.getFinalStretchTokens(chain, options);
55
- }
56
- function useFinalStretchTokensQuery(params, options = {}) {
57
- const { client } = useAPIClient();
58
- return reactQuery.useQuery({
59
- queryKey: finalStretchTokensQueryKey(params),
60
- queryFn: async () => fetchFinalStretchTokens(client, params),
61
- ...options
62
- });
63
- }
64
- function migratedTokensQueryKey(params) {
65
- return [
66
- "migratedTokens",
67
- params.chain,
68
- params.sortBy ?? "",
69
- params.sortDirection ?? "",
70
- JSON.stringify((params.keywords ?? []).sort()),
71
- JSON.stringify((params.excludeKeywords ?? []).sort()),
72
- JSON.stringify(params.filters ?? [])
73
- ];
74
- }
75
- async function fetchMigratedTokens(client, { chain, ...options }) {
76
- return await client.getMigratedTokens(chain, options);
77
- }
78
- function useMigratedTokensQuery(params, options = {}) {
79
- const { client } = useAPIClient();
80
- return reactQuery.useQuery({
81
- queryKey: migratedTokensQueryKey(params),
82
- queryFn: async () => fetchMigratedTokens(client, params),
83
- ...options
84
- });
85
- }
86
- function newTokensQueryKey(params) {
87
- return [
88
- "newTokens",
89
- params.chain,
90
- params.sortBy ?? "",
91
- params.sortDirection ?? "",
92
- JSON.stringify((params.keywords ?? []).sort()),
93
- JSON.stringify((params.excludeKeywords ?? []).sort()),
94
- JSON.stringify(params.filters ?? [])
95
- ];
96
- }
97
- async function fetchNewTokens(client, { chain, ...options }) {
98
- return await client.getNewTokens(chain, options);
99
- }
100
- function useNewTokensQuery(params, options = {}) {
101
- const { client } = useAPIClient();
102
- return reactQuery.useQuery({
103
- queryKey: newTokensQueryKey(params),
104
- queryFn: async () => fetchNewTokens(client, params),
105
- ...options
106
- });
107
- }
108
- async function fetchPresignedUploadUrl(client) {
109
- return await client.getPresignedUploadUrl();
110
- }
111
- function usePresignedUploadUrlQuery(options = {}) {
112
- const { client } = useAPIClient();
113
- return reactQuery.useQuery({
114
- queryKey: ["presignedUploadUrl"],
115
- queryFn: async () => fetchPresignedUploadUrl(client),
116
- staleTime: 0,
117
- ...options
118
- });
119
- }
120
- function searchTokensQueryKey(params) {
121
- return [
122
- "searchTokens",
123
- params.cursor ?? "",
124
- params.limit ? `${params.limit}` : "",
125
- params.direction ?? "",
126
- JSON.stringify((params.chains ?? []).sort()),
127
- params.keyword ?? "",
128
- JSON.stringify(params.filters ?? []),
129
- params.sortBy ?? "",
130
- params.sortDirection ?? ""
131
- ];
132
- }
133
- async function fetchSearchTokens(client, params) {
134
- return await client.searchTokens(params);
135
- }
136
- function useSearchTokensQuery(params, options = {}) {
137
- const { client } = useAPIClient();
138
- return reactQuery.useQuery({
139
- queryKey: searchTokensQueryKey(params),
140
- queryFn: async () => fetchSearchTokens(client, params),
141
- ...options
142
- });
143
- }
144
- async function sendTx(client, params) {
145
- return await client.sendTx(params);
146
- }
147
- function useSendTxMutation(options = {}) {
148
- const { client } = useAPIClient();
149
- return reactQuery.useMutation({
150
- mutationFn: async (params) => sendTx(client, params),
151
- ...options
152
- });
153
- }
154
- function stockTokensQueryKey(params) {
155
- return [
156
- "stockTokens",
157
- params.chain,
158
- params.sortBy ?? "",
159
- params.sortDirection ?? "",
160
- JSON.stringify((params.keywords ?? []).sort()),
161
- JSON.stringify((params.excludeKeywords ?? []).sort()),
162
- JSON.stringify(params.filters ?? [])
163
- ];
164
- }
165
- async function fetchStockTokens(client, { chain, ...options }) {
166
- return await client.getStockTokens(chain, options);
167
- }
168
- function useStockTokensQuery(params, options = {}) {
169
- const { client } = useAPIClient();
170
- return reactQuery.useQuery({
171
- queryKey: stockTokensQueryKey(params),
172
- queryFn: async () => fetchStockTokens(client, params),
173
- ...options
174
- });
175
- }
176
- function swapRouteQueryKey(params) {
177
- return [
178
- "swapRoute",
179
- params.chain,
180
- params.userAddress,
181
- params.input,
182
- params.output,
183
- params.mode,
184
- params.amount,
185
- params.slippage ? `${params.slippage}` : "",
186
- params.priorityFee ?? "",
187
- params.tipFee ?? "",
188
- params.isAntiMev !== void 0 ? `${params.isAntiMev}` : ""
189
- ];
190
- }
191
- async function fetchSwapRoute(client, params) {
192
- return await client.swapRoute(params);
193
- }
194
- function useSwapRouteQuery(params, options = {}) {
195
- const { client } = useAPIClient();
196
- return reactQuery.useQuery({
197
- queryKey: swapRouteQueryKey(params),
198
- queryFn: async () => fetchSwapRoute(client, params),
199
- ...options
200
- });
201
- }
202
- function tokenCandlesQueryKey(params) {
203
- return [
204
- "tokenCandles",
205
- params.chain,
206
- params.address,
207
- params.resolution,
208
- params.after?.toString() ?? "",
209
- params.before?.toString() ?? "",
210
- params.limit ? `${params.limit}` : ""
211
- ];
212
- }
213
- async function fetchTokenCandles(client, { chain, address, resolution, ...options }) {
214
- return await client.getTokenCandles(chain, address, resolution, options);
215
- }
216
- function useTokenCandlesQuery(params, options = {}) {
217
- const { client } = useAPIClient();
218
- return reactQuery.useQuery({
219
- queryKey: tokenCandlesQueryKey(params),
220
- queryFn: async () => fetchTokenCandles(client, params),
221
- ...options
222
- });
223
- }
224
- function tokenHoldersQueryKey(params) {
225
- return [
226
- "tokenHolders",
227
- params.chain,
228
- params.address,
229
- params.cursor ?? "",
230
- params.limit ? `${params.limit}` : "",
231
- params.direction ?? ""
232
- ];
233
- }
234
- async function fetchTokenHolders(client, { chain, address, ...options }) {
235
- return await client.getTokenHolders(chain, address, options);
236
- }
237
- function useTokenHoldersQuery(params, options = {}) {
238
- const { client } = useAPIClient();
239
- return reactQuery.useQuery({
240
- queryKey: tokenHoldersQueryKey(params),
241
- queryFn: async () => fetchTokenHolders(client, params),
242
- ...options
243
- });
244
- }
245
- function tokenMarketDataQueryKey(params) {
246
- return ["tokenMarketData", params.chain, params.address];
247
- }
248
- async function fetchTokenMarketData(client, { chain, address }) {
249
- return await client.getTokenMarketData(chain, address);
250
- }
251
- function useTokenMarketDataQuery(params, options = {}) {
252
- const { client } = useAPIClient();
253
- return reactQuery.useQuery({
254
- queryKey: tokenMarketDataQueryKey(params),
255
- queryFn: async () => fetchTokenMarketData(client, params),
256
- ...options
257
- });
258
- }
259
- function tokenQueryKey(params) {
260
- return ["token", params.chain, params.address];
261
- }
262
- async function fetchToken(client, { chain, address }) {
263
- return await client.getToken(chain, address);
264
- }
265
- function useTokenQuery(params, options = {}) {
266
- const { client } = useAPIClient();
267
- return reactQuery.useQuery({
268
- queryKey: tokenQueryKey(params),
269
- queryFn: async () => fetchToken(client, params),
270
- ...options
271
- });
272
- }
273
- function tokenSecurityQueryKey(params) {
274
- return ["tokenSecurity", params.chain, params.address];
275
- }
276
- async function fetchTokenSecurity(client, { chain, address }) {
277
- return await client.getTokenSecurity(chain, address);
278
- }
279
- function useTokenSecurityQuery(params, options = {}) {
280
- const { client } = useAPIClient();
281
- return reactQuery.useQuery({
282
- queryKey: tokenSecurityQueryKey(params),
283
- queryFn: async () => fetchTokenSecurity(client, params),
284
- ...options
285
- });
286
- }
287
- function tokensQueryKey(params) {
288
- return ["tokens", params.chain, params.addresses.sort().join(",")];
289
- }
290
- async function fetchTokens(client, { chain, addresses }) {
291
- return await client.getTokens(chain, addresses);
292
- }
293
- function useTokensQuery(params, options = {}) {
294
- const { client } = useAPIClient();
295
- return reactQuery.useQuery({
296
- queryKey: tokensQueryKey(params),
297
- queryFn: async () => fetchTokens(client, params),
298
- ...options
299
- });
300
- }
301
- function tokenStatsQueryKey(params) {
302
- return ["tokenStats", params.chain, params.address];
303
- }
304
- async function fetchTokenStats(client, { chain, address }) {
305
- return await client.getTokenStats(chain, address);
306
- }
307
- function useTokenStatsQuery(params, options = {}) {
308
- const { client } = useAPIClient();
309
- return reactQuery.useQuery({
310
- queryKey: tokenStatsQueryKey(params),
311
- queryFn: async () => fetchTokenStats(client, params),
312
- ...options
313
- });
314
- }
315
- function tokenTradeActivitiesQueryKey(params) {
316
- return [
317
- "tokenTradeActivities",
318
- params.chain,
319
- params.address,
320
- params.before?.toString() ?? "",
321
- params.after?.toString() ?? "",
322
- params.beforeBlockHeight ? `${params.beforeBlockHeight}` : "",
323
- params.afterBlockHeight ? `${params.afterBlockHeight}` : "",
324
- params.type ?? "",
325
- params.poolAddress ?? ""
326
- ];
327
- }
328
- async function fetchTokenTradeActivities(client, { chain, address, ...options }) {
329
- return await client.getTokenTradeActivities(chain, address, options);
330
- }
331
- function useTokenTradeActivitiesQuery(params, options = {}) {
332
- const { client } = useAPIClient();
333
- return reactQuery.useQuery({
334
- queryKey: tokenTradeActivitiesQueryKey(params),
335
- queryFn: async () => fetchTokenTradeActivities(client, params),
336
- ...options
337
- });
338
- }
339
- function trendingTokensQueryKey(params) {
340
- return [
341
- "trendingTokens",
342
- params.chain,
343
- params.resolution,
344
- params.sortBy ?? "",
345
- params.sortDirection ?? "",
346
- JSON.stringify((params.keywords ?? []).sort()),
347
- JSON.stringify((params.excludeKeywords ?? []).sort()),
348
- JSON.stringify(params.filters ?? [])
349
- ];
350
- }
351
- async function fetchTrendingTokens(client, { chain, resolution, ...options }) {
352
- return await client.getTrendingTokens(chain, resolution, options);
353
- }
354
- function useTrendingTokensQuery(params, options = {}) {
355
- const { client } = useAPIClient();
356
- return reactQuery.useQuery({
357
- queryKey: trendingTokensQueryKey(params),
358
- queryFn: async () => fetchTrendingTokens(client, params),
359
- ...options
360
- });
361
- }
362
- function txSuccessQueryKey(params) {
363
- return [
364
- "txSuccess",
365
- params.chain,
366
- params.txHash,
367
- params.timeout ? `${params.timeout}` : ""
368
- ];
369
- }
370
- async function fetchTxSuccess(client, { chain, txHash, timeout }) {
371
- return await client.checkTxSuccess(chain, txHash, timeout);
372
- }
373
- function useTxSuccessQuery(params, options = {}) {
374
- const { client } = useAPIClient();
375
- return reactQuery.useQuery({
376
- queryKey: txSuccessQueryKey(params),
377
- queryFn: async () => fetchTxSuccess(client, params),
378
- ...options
379
- });
380
- }
381
- function walletPortfoliosQueryKey(params) {
382
- return ["walletPortfolios", params.chain, params.address];
383
- }
384
- async function fetchWalletPortfolios(client, { chain, address }) {
385
- return await client.getWalletPortfolios(chain, address);
386
- }
387
- function useWalletPortfoliosQuery(params, options = {}) {
388
- const { client } = useAPIClient();
389
- return reactQuery.useQuery({
390
- queryKey: walletPortfoliosQueryKey(params),
391
- queryFn: async () => fetchWalletPortfolios(client, params),
392
- ...options
393
- });
394
- }
395
- function walletTradeActivitiesQueryKey(params) {
396
- return [
397
- "walletTradeActivities",
398
- params.chain,
399
- params.address,
400
- params.before?.toString() ?? "",
401
- params.after?.toString() ?? "",
402
- params.beforeBlockHeight ? `${params.beforeBlockHeight}` : "",
403
- params.afterBlockHeight ? `${params.afterBlockHeight}` : "",
404
- params.type ?? "",
405
- params.poolAddress ?? ""
406
- ];
407
- }
408
- async function fetchWalletTradeActivities(client, { chain, address, ...options }) {
409
- return await client.getWalletTradeActivities(chain, address, options);
410
- }
411
- function useWalletTradeActivitiesQuery(params, options = {}) {
412
- const { client } = useAPIClient();
413
- return reactQuery.useQuery({
414
- queryKey: walletTradeActivitiesQueryKey(params),
415
- queryFn: async () => fetchWalletTradeActivities(client, params),
416
- ...options
417
- });
418
- }
419
- var WalletConnectorContext = React.createContext({});
420
-
421
- // src/wallet/useWalletConnector.ts
422
- function useWalletConnector() {
423
- const context = React.useContext(WalletConnectorContext);
424
- if (!context) {
425
- throw new Error(
426
- "useWalletConnector must be used within a WalletConnectorProvider"
427
- );
428
- }
429
- return context;
430
- }
431
- function useWallets() {
432
- const context = React.useContext(WalletConnectorContext);
433
- if (!context) {
434
- throw new Error("useWallets must be used within a WalletConnectorProvider");
435
- }
436
- const { wallets } = context;
437
- return wallets;
438
- }
439
- function WalletConnectorProvider({
440
- children,
441
- ...value
442
- }) {
443
- return /* @__PURE__ */ jsxRuntime.jsx(WalletConnectorContext.Provider, { value, children });
444
- }
445
23
  var useBoolean = (initialValue = false) => {
446
24
  const [value, setValue] = React.useState(initialValue);
447
25
  const setTrue = React.useCallback(() => setValue(true), []);
@@ -799,88 +377,23 @@ Object.defineProperty(exports, "useConstant", {
799
377
  enumerable: true,
800
378
  get: function () { return useConstant__default.default; }
801
379
  });
802
- exports.APIClientContext = APIClientContext;
803
- exports.APIClientProvider = APIClientProvider;
804
- exports.WalletConnectorContext = WalletConnectorContext;
805
- exports.WalletConnectorProvider = WalletConnectorProvider;
806
- exports.fetchFinalStretchTokens = fetchFinalStretchTokens;
807
- exports.fetchMigratedTokens = fetchMigratedTokens;
808
- exports.fetchNewTokens = fetchNewTokens;
809
- exports.fetchPresignedUploadUrl = fetchPresignedUploadUrl;
810
- exports.fetchSearchTokens = fetchSearchTokens;
811
- exports.fetchStockTokens = fetchStockTokens;
812
- exports.fetchSwapRoute = fetchSwapRoute;
813
- exports.fetchToken = fetchToken;
814
- exports.fetchTokenCandles = fetchTokenCandles;
815
- exports.fetchTokenHolders = fetchTokenHolders;
816
- exports.fetchTokenMarketData = fetchTokenMarketData;
817
- exports.fetchTokenSecurity = fetchTokenSecurity;
818
- exports.fetchTokenStats = fetchTokenStats;
819
- exports.fetchTokenTradeActivities = fetchTokenTradeActivities;
820
- exports.fetchTokens = fetchTokens;
821
- exports.fetchTrendingTokens = fetchTrendingTokens;
822
- exports.fetchTxSuccess = fetchTxSuccess;
823
- exports.fetchWalletPortfolios = fetchWalletPortfolios;
824
- exports.fetchWalletTradeActivities = fetchWalletTradeActivities;
825
- exports.finalStretchTokensQueryKey = finalStretchTokensQueryKey;
826
- exports.migratedTokensQueryKey = migratedTokensQueryKey;
827
- exports.newTokensQueryKey = newTokensQueryKey;
828
380
  exports.parseJSON = parseJSON;
829
- exports.searchTokensQueryKey = searchTokensQueryKey;
830
- exports.sendTx = sendTx;
831
- exports.stockTokensQueryKey = stockTokensQueryKey;
832
- exports.swapRouteQueryKey = swapRouteQueryKey;
833
- exports.tokenCandlesQueryKey = tokenCandlesQueryKey;
834
- exports.tokenHoldersQueryKey = tokenHoldersQueryKey;
835
- exports.tokenMarketDataQueryKey = tokenMarketDataQueryKey;
836
- exports.tokenQueryKey = tokenQueryKey;
837
- exports.tokenSecurityQueryKey = tokenSecurityQueryKey;
838
- exports.tokenStatsQueryKey = tokenStatsQueryKey;
839
- exports.tokenTradeActivitiesQueryKey = tokenTradeActivitiesQueryKey;
840
- exports.tokensQueryKey = tokensQueryKey;
841
- exports.trendingTokensQueryKey = trendingTokensQueryKey;
842
- exports.txSuccessQueryKey = txSuccessQueryKey;
843
- exports.useAPIClient = useAPIClient;
844
381
  exports.useAudioPlayer = useAudioPlayer;
845
382
  exports.useBoolean = useBoolean;
846
383
  exports.useCallbackRef = useCallbackRef;
847
384
  exports.useEventEmitter = useEventEmitter;
848
- exports.useFinalStretchTokensQuery = useFinalStretchTokensQuery;
849
385
  exports.useIsMounted = useIsMounted;
850
386
  exports.useLocalStorage = useLocalStorage;
851
387
  exports.useMemoizedFn = useMemoizedFn;
852
- exports.useMigratedTokensQuery = useMigratedTokensQuery;
853
- exports.useNewTokensQuery = useNewTokensQuery;
854
- exports.usePresignedUploadUrlQuery = usePresignedUploadUrlQuery;
855
388
  exports.useResizeObserver = useResizeObserver;
856
389
  exports.useSafeLayoutEffect = useSafeLayoutEffect;
857
- exports.useSearchTokensQuery = useSearchTokensQuery;
858
- exports.useSendTxMutation = useSendTxMutation;
859
390
  exports.useSessionStorage = useSessionStorage;
860
391
  exports.useSimpleDI = useSimpleDI;
861
- exports.useStockTokensQuery = useStockTokensQuery;
862
- exports.useSwapRouteQuery = useSwapRouteQuery;
863
392
  exports.useTick = useTick;
864
393
  exports.useTickAge = useTickAge;
865
- exports.useTokenCandlesQuery = useTokenCandlesQuery;
866
- exports.useTokenHoldersQuery = useTokenHoldersQuery;
867
- exports.useTokenMarketDataQuery = useTokenMarketDataQuery;
868
- exports.useTokenQuery = useTokenQuery;
869
- exports.useTokenSecurityQuery = useTokenSecurityQuery;
870
- exports.useTokenStatsQuery = useTokenStatsQuery;
871
- exports.useTokenTradeActivitiesQuery = useTokenTradeActivitiesQuery;
872
- exports.useTokensQuery = useTokensQuery;
873
- exports.useTrendingTokensQuery = useTrendingTokensQuery;
874
- exports.useTxSuccessQuery = useTxSuccessQuery;
875
394
  exports.useUpdatedRef = useUpdatedRef;
876
395
  exports.useValueRef = useValueRef;
877
- exports.useWalletConnector = useWalletConnector;
878
- exports.useWalletPortfoliosQuery = useWalletPortfoliosQuery;
879
- exports.useWalletTradeActivitiesQuery = useWalletTradeActivitiesQuery;
880
- exports.useWallets = useWallets;
881
396
  exports.version = version_default;
882
- exports.walletPortfoliosQueryKey = walletPortfoliosQueryKey;
883
- exports.walletTradeActivitiesQueryKey = walletTradeActivitiesQueryKey;
884
397
  Object.keys(useDebounce).forEach(function (k) {
885
398
  if (k !== 'default' && !Object.prototype.hasOwnProperty.call(exports, k)) Object.defineProperty(exports, k, {
886
399
  enumerable: true,