@liberfi.io/hooks 0.1.6 → 0.1.8

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