@liberfi.io/hooks 0.1.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/dist/index.js ADDED
@@ -0,0 +1,885 @@
1
+ 'use strict';
2
+
3
+ var React = require('react');
4
+ var jsxRuntime = require('react/jsx-runtime');
5
+ var reactQuery = require('@tanstack/react-query');
6
+ var useConstant = require('use-constant');
7
+ var core = require('@liberfi.io/core');
8
+ var useDebounce = require('use-debounce');
9
+
10
+ function _interopDefault (e) { return e && e.__esModule ? e : { default: e }; }
11
+
12
+ var React__default = /*#__PURE__*/_interopDefault(React);
13
+ var useConstant__default = /*#__PURE__*/_interopDefault(useConstant);
14
+
15
+ var __defProp = Object.defineProperty;
16
+ var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
17
+ var __publicField = (obj, key, value) => __defNormalProp(obj, typeof key !== "symbol" ? key + "" : key, value);
18
+
19
+ // src/version.ts
20
+ if (typeof window !== "undefined") {
21
+ window.__LIBERFI_VERSION__ = window.__LIBERFI_VERSION__ || {};
22
+ window.__LIBERFI_VERSION__["@liberfi.io/hooks"] = "0.1.0";
23
+ }
24
+ var version_default = "0.1.0";
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
+ var useBoolean = (initialValue = false) => {
446
+ const [value, setValue] = React.useState(initialValue);
447
+ const setTrue = React.useCallback(() => setValue(true), []);
448
+ const setFalse = React.useCallback(() => setValue(false), []);
449
+ const toggle = React.useCallback(() => setValue((v) => !v), []);
450
+ return [value, { setTrue, setFalse, toggle }];
451
+ };
452
+ var useSafeLayoutEffect = globalThis?.document ? React.useLayoutEffect : React.useEffect;
453
+
454
+ // src/useCallbackRef.ts
455
+ function useCallbackRef(fn, deps = []) {
456
+ const ref = React.useRef(fn);
457
+ useSafeLayoutEffect(() => {
458
+ ref.current = fn;
459
+ });
460
+ return React.useCallback(((...args) => ref.current?.(...args)), deps);
461
+ }
462
+ function useIsMounted() {
463
+ const isMounted = React.useRef(false);
464
+ React.useEffect(() => {
465
+ isMounted.current = true;
466
+ return () => {
467
+ isMounted.current = false;
468
+ };
469
+ }, []);
470
+ return React.useCallback(() => isMounted.current, []);
471
+ }
472
+ var initialSize = {
473
+ width: void 0,
474
+ height: void 0
475
+ };
476
+ function useResizeObserver(options) {
477
+ const { ref, box = "content-box" } = options;
478
+ const [{ width, height }, setSize] = React.useState(initialSize);
479
+ const isMounted = useIsMounted();
480
+ const previousSize = React.useRef({ ...initialSize });
481
+ const onResize = React.useRef(void 0);
482
+ onResize.current = options.onResize;
483
+ React.useEffect(() => {
484
+ if (!ref.current) return;
485
+ if (typeof window === "undefined" || !("ResizeObserver" in window)) return;
486
+ const observer = new ResizeObserver(([entry]) => {
487
+ const boxProp = box === "border-box" ? "borderBoxSize" : box === "device-pixel-content-box" ? "devicePixelContentBoxSize" : "contentBoxSize";
488
+ const newWidth = extractSize(entry, boxProp, "inlineSize");
489
+ const newHeight = extractSize(entry, boxProp, "blockSize");
490
+ const hasChanged = previousSize.current.width !== newWidth || previousSize.current.height !== newHeight;
491
+ if (hasChanged) {
492
+ const newSize = { width: newWidth, height: newHeight };
493
+ previousSize.current.width = newWidth;
494
+ previousSize.current.height = newHeight;
495
+ if (onResize.current) {
496
+ onResize.current(newSize);
497
+ } else {
498
+ if (isMounted()) {
499
+ setSize(newSize);
500
+ }
501
+ }
502
+ }
503
+ });
504
+ observer.observe(ref.current, { box });
505
+ return () => {
506
+ observer.disconnect();
507
+ };
508
+ }, [box, ref, isMounted]);
509
+ return { width, height };
510
+ }
511
+ function extractSize(entry, box, sizeType) {
512
+ if (!entry[box]) {
513
+ if (box === "contentBoxSize") {
514
+ return entry.contentRect[sizeType === "inlineSize" ? "width" : "height"];
515
+ }
516
+ return void 0;
517
+ }
518
+ const boxSize = Array.isArray(entry[box]) ? entry[box][0] : entry[box];
519
+ return boxSize[sizeType];
520
+ }
521
+ var _GlobalTimer = class _GlobalTimer {
522
+ constructor() {
523
+ /** setTimeout id */
524
+ __publicField(this, "timeoutId", null);
525
+ /** subscription map */
526
+ __publicField(this, "subscribers", /* @__PURE__ */ new Map());
527
+ /** is timer running */
528
+ __publicField(this, "isRunning", false);
529
+ /** internal update interval for smoothness */
530
+ __publicField(this, "internalInterval", 200);
531
+ }
532
+ /**
533
+ * Get the singleton instance of the timer
534
+ * @returns Timer instance
535
+ */
536
+ static getInstance() {
537
+ if (!_GlobalTimer.instance) {
538
+ _GlobalTimer.instance = new _GlobalTimer();
539
+ }
540
+ return _GlobalTimer.instance;
541
+ }
542
+ /**
543
+ * Subscribe to the timer
544
+ * @param callback tick callback
545
+ * @param interval interval in milliseconds to execute the callback
546
+ * @returns unsubscribe function
547
+ */
548
+ subscribe(callback, interval = 1e3) {
549
+ this.subscribers.set(callback, {
550
+ interval,
551
+ lastExecuted: Date.now()
552
+ });
553
+ if (!this.isRunning) {
554
+ this.start();
555
+ }
556
+ return () => {
557
+ this.subscribers.delete(callback);
558
+ if (this.subscribers.size === 0) {
559
+ this.stop();
560
+ }
561
+ };
562
+ }
563
+ start() {
564
+ if (this.isRunning) return;
565
+ this.isRunning = true;
566
+ this.scheduleNext();
567
+ }
568
+ scheduleNext() {
569
+ this.timeoutId = setTimeout(() => {
570
+ const now = Date.now();
571
+ this.subscribers.forEach((config, callback) => {
572
+ if (now - config.lastExecuted >= config.interval) {
573
+ callback({ delta: now - config.lastExecuted, now });
574
+ config.lastExecuted = now;
575
+ }
576
+ });
577
+ if (this.isRunning) {
578
+ this.scheduleNext();
579
+ }
580
+ }, this.internalInterval);
581
+ }
582
+ stop() {
583
+ this.isRunning = false;
584
+ if (this.timeoutId) {
585
+ clearTimeout(this.timeoutId);
586
+ this.timeoutId = null;
587
+ }
588
+ }
589
+ };
590
+ /** singleton instance */
591
+ __publicField(_GlobalTimer, "instance");
592
+ var GlobalTimer = _GlobalTimer;
593
+ function useTick(callback, interval = 1e3) {
594
+ const callbackRef = useCallbackRef(callback);
595
+ React.useEffect(
596
+ () => GlobalTimer.getInstance().subscribe(callbackRef, interval),
597
+ [interval]
598
+ );
599
+ }
600
+ function useTickAge(birthday = Date.now(), interval = 1e3) {
601
+ const birthdayRef = React.useRef(
602
+ birthday instanceof Date ? birthday.getTime() : birthday
603
+ );
604
+ birthdayRef.current = birthday instanceof Date ? birthday.getTime() : birthday;
605
+ const [age, setAge] = React.useState(Math.max(0, Date.now() - birthdayRef.current));
606
+ const tickAge = React.useCallback(
607
+ ({ now }) => setAge(Math.max(0, now - birthdayRef.current)),
608
+ []
609
+ );
610
+ useTick(tickAge, interval);
611
+ return age;
612
+ }
613
+ var useUpdatedRef = (val) => {
614
+ const latestRef = React.useRef(val);
615
+ latestRef.current = val;
616
+ return latestRef;
617
+ };
618
+ var useMemoizedFn = (fn) => {
619
+ const fnRef = React.useRef(fn);
620
+ fnRef.current = React.useMemo(() => fn, [fn]);
621
+ const memoizedFn = React.useRef(void 0);
622
+ if (!memoizedFn.current) {
623
+ memoizedFn.current = function(...args) {
624
+ return fnRef.current.apply(this, args);
625
+ };
626
+ }
627
+ return memoizedFn.current;
628
+ };
629
+ var useAudioPlayer = (src, options = {}) => {
630
+ const { volume = 1, loop, autoPlay } = options;
631
+ const audioRef = React.useRef(null);
632
+ const [status, setStatus] = React.useState("idle");
633
+ const onPlay = () => {
634
+ setStatus("play");
635
+ };
636
+ const onPlaying = () => {
637
+ setStatus("playing");
638
+ };
639
+ const onPause = () => {
640
+ setStatus("paused");
641
+ };
642
+ const onEnded = () => {
643
+ setStatus("ended");
644
+ };
645
+ const onError = () => {
646
+ setStatus("error");
647
+ };
648
+ const element = React.useMemo(() => {
649
+ return React__default.default.createElement("audio", {
650
+ controls: false,
651
+ ref: audioRef,
652
+ autoPlay,
653
+ src,
654
+ style: { display: "none" },
655
+ onPlay,
656
+ onPlaying,
657
+ onPause,
658
+ onEnded,
659
+ onError
660
+ });
661
+ }, [autoPlay, src, onPlay, onPlaying, onPause, onEnded, onError]);
662
+ React.useEffect(() => {
663
+ const el = audioRef.current;
664
+ if (!el) {
665
+ return;
666
+ }
667
+ el.loop = loop ?? false;
668
+ el.volume = Math.max(0, Math.min(1, volume));
669
+ return () => {
670
+ audioRef.current?.pause();
671
+ audioRef.current = null;
672
+ };
673
+ }, [loop, volume]);
674
+ return [element, audioRef, status];
675
+ };
676
+ var useEventEmitter = () => {
677
+ return useConstant__default.default(() => {
678
+ let ee = core.SimpleDI.get("EE");
679
+ if (!ee) {
680
+ ee = new core.EventEmitter();
681
+ core.SimpleDI.registerByName("EE", ee);
682
+ }
683
+ return ee;
684
+ });
685
+ };
686
+
687
+ // src/utils/json.ts
688
+ function parseJSON(value) {
689
+ try {
690
+ return value === "undefined" ? void 0 : JSON.parse(value ?? "");
691
+ } catch {
692
+ return void 0;
693
+ }
694
+ }
695
+
696
+ // src/useSessionStorage.ts
697
+ function useSessionStorage(key, initialValue) {
698
+ const readValue = React.useCallback(() => {
699
+ if (typeof window === "undefined") {
700
+ return initialValue;
701
+ }
702
+ try {
703
+ const item = window.sessionStorage.getItem(key);
704
+ return item ? parseJSON(item) : initialValue;
705
+ } catch (error) {
706
+ return initialValue;
707
+ }
708
+ }, [initialValue, key]);
709
+ const [storedValue, setStoredValue] = React.useState(readValue);
710
+ const setValue = (value) => {
711
+ try {
712
+ const newValue = value instanceof Function ? value(storedValue) : value;
713
+ window.sessionStorage.setItem(key, JSON.stringify(newValue));
714
+ setStoredValue(newValue);
715
+ } catch (error) {
716
+ }
717
+ };
718
+ React.useEffect(() => {
719
+ setStoredValue(readValue());
720
+ }, []);
721
+ React.useEffect(() => {
722
+ if (typeof window == "undefined") {
723
+ return;
724
+ }
725
+ window.addEventListener?.("storage", handleStorageChange);
726
+ return () => {
727
+ window.removeEventListener?.("storage", handleStorageChange);
728
+ };
729
+ });
730
+ const handleStorageChange = React.useCallback(
731
+ (event) => {
732
+ if (event?.key && event.key !== key) {
733
+ return;
734
+ }
735
+ setStoredValue(readValue());
736
+ },
737
+ [key, readValue]
738
+ );
739
+ return [storedValue, setValue];
740
+ }
741
+ function useLocalStorage(key, initialValue, options = {
742
+ parseJSON
743
+ }) {
744
+ const readValue = React.useCallback(() => {
745
+ if (typeof window === "undefined") {
746
+ return initialValue;
747
+ }
748
+ try {
749
+ const item = window.localStorage.getItem(key);
750
+ return item ? options.parseJSON(item) : initialValue;
751
+ } catch (error) {
752
+ return initialValue;
753
+ }
754
+ }, [initialValue, key]);
755
+ const [storedValue, setStoredValue] = React.useState(readValue);
756
+ const setValue = React.useCallback(
757
+ (value) => {
758
+ try {
759
+ const newValue = value instanceof Function ? value(storedValue) : value;
760
+ window.localStorage.setItem(key, JSON.stringify(newValue));
761
+ window.dispatchEvent(new Event("storage"));
762
+ setStoredValue(() => newValue);
763
+ } catch (error) {
764
+ }
765
+ },
766
+ [storedValue]
767
+ );
768
+ React.useEffect(() => {
769
+ setStoredValue(readValue());
770
+ }, []);
771
+ React.useEffect(() => {
772
+ const handleStorageChange = (event) => {
773
+ if (event?.key && event.key !== key) {
774
+ return;
775
+ }
776
+ setStoredValue(readValue());
777
+ };
778
+ window?.addEventListener?.("storage", handleStorageChange);
779
+ return () => {
780
+ window?.removeEventListener?.("storage", handleStorageChange);
781
+ };
782
+ }, [key]);
783
+ return [storedValue, setValue];
784
+ }
785
+ var useSimpleDI = () => {
786
+ return {
787
+ get: core.SimpleDI.get,
788
+ // getOr: SimpleDI.getOr<T>(name, SimpleDI.get<T>(name)),
789
+ register: core.SimpleDI.register
790
+ };
791
+ };
792
+
793
+ Object.defineProperty(exports, "useConstant", {
794
+ enumerable: true,
795
+ get: function () { return useConstant__default.default; }
796
+ });
797
+ exports.APIClientContext = APIClientContext;
798
+ exports.APIClientProvider = APIClientProvider;
799
+ exports.WalletConnectorContext = WalletConnectorContext;
800
+ exports.WalletConnectorProvider = WalletConnectorProvider;
801
+ exports.fetchFinalStretchTokens = fetchFinalStretchTokens;
802
+ exports.fetchMigratedTokens = fetchMigratedTokens;
803
+ exports.fetchNewTokens = fetchNewTokens;
804
+ exports.fetchPresignedUploadUrl = fetchPresignedUploadUrl;
805
+ exports.fetchSearchTokens = fetchSearchTokens;
806
+ exports.fetchStockTokens = fetchStockTokens;
807
+ exports.fetchSwapRoute = fetchSwapRoute;
808
+ exports.fetchToken = fetchToken;
809
+ exports.fetchTokenCandles = fetchTokenCandles;
810
+ exports.fetchTokenHolders = fetchTokenHolders;
811
+ exports.fetchTokenMarketData = fetchTokenMarketData;
812
+ exports.fetchTokenSecurity = fetchTokenSecurity;
813
+ exports.fetchTokenStats = fetchTokenStats;
814
+ exports.fetchTokenTradeActivities = fetchTokenTradeActivities;
815
+ exports.fetchTokens = fetchTokens;
816
+ exports.fetchTrendingTokens = fetchTrendingTokens;
817
+ exports.fetchTxSuccess = fetchTxSuccess;
818
+ exports.fetchWalletPortfolios = fetchWalletPortfolios;
819
+ exports.fetchWalletTradeActivities = fetchWalletTradeActivities;
820
+ exports.finalStretchTokensQueryKey = finalStretchTokensQueryKey;
821
+ exports.migratedTokensQueryKey = migratedTokensQueryKey;
822
+ exports.newTokensQueryKey = newTokensQueryKey;
823
+ exports.parseJSON = parseJSON;
824
+ exports.searchTokensQueryKey = searchTokensQueryKey;
825
+ exports.sendTx = sendTx;
826
+ exports.stockTokensQueryKey = stockTokensQueryKey;
827
+ exports.swapRouteQueryKey = swapRouteQueryKey;
828
+ exports.tokenCandlesQueryKey = tokenCandlesQueryKey;
829
+ exports.tokenHoldersQueryKey = tokenHoldersQueryKey;
830
+ exports.tokenMarketDataQueryKey = tokenMarketDataQueryKey;
831
+ exports.tokenQueryKey = tokenQueryKey;
832
+ exports.tokenSecurityQueryKey = tokenSecurityQueryKey;
833
+ exports.tokenStatsQueryKey = tokenStatsQueryKey;
834
+ exports.tokenTradeActivitiesQueryKey = tokenTradeActivitiesQueryKey;
835
+ exports.tokensQueryKey = tokensQueryKey;
836
+ exports.trendingTokensQueryKey = trendingTokensQueryKey;
837
+ exports.txSuccessQueryKey = txSuccessQueryKey;
838
+ exports.useAPIClient = useAPIClient;
839
+ exports.useAudioPlayer = useAudioPlayer;
840
+ exports.useBoolean = useBoolean;
841
+ exports.useCallbackRef = useCallbackRef;
842
+ exports.useEventEmitter = useEventEmitter;
843
+ exports.useFinalStretchTokensQuery = useFinalStretchTokensQuery;
844
+ exports.useIsMounted = useIsMounted;
845
+ exports.useLocalStorage = useLocalStorage;
846
+ exports.useMemoizedFn = useMemoizedFn;
847
+ exports.useMigratedTokensQuery = useMigratedTokensQuery;
848
+ exports.useNewTokensQuery = useNewTokensQuery;
849
+ exports.usePresignedUploadUrlQuery = usePresignedUploadUrlQuery;
850
+ exports.useResizeObserver = useResizeObserver;
851
+ exports.useSafeLayoutEffect = useSafeLayoutEffect;
852
+ exports.useSearchTokensQuery = useSearchTokensQuery;
853
+ exports.useSendTxMutation = useSendTxMutation;
854
+ exports.useSessionStorage = useSessionStorage;
855
+ exports.useSimpleDI = useSimpleDI;
856
+ exports.useStockTokensQuery = useStockTokensQuery;
857
+ exports.useSwapRouteQuery = useSwapRouteQuery;
858
+ exports.useTick = useTick;
859
+ exports.useTickAge = useTickAge;
860
+ exports.useTokenCandlesQuery = useTokenCandlesQuery;
861
+ exports.useTokenHoldersQuery = useTokenHoldersQuery;
862
+ exports.useTokenMarketDataQuery = useTokenMarketDataQuery;
863
+ exports.useTokenQuery = useTokenQuery;
864
+ exports.useTokenSecurityQuery = useTokenSecurityQuery;
865
+ exports.useTokenStatsQuery = useTokenStatsQuery;
866
+ exports.useTokenTradeActivitiesQuery = useTokenTradeActivitiesQuery;
867
+ exports.useTokensQuery = useTokensQuery;
868
+ exports.useTrendingTokensQuery = useTrendingTokensQuery;
869
+ exports.useTxSuccessQuery = useTxSuccessQuery;
870
+ exports.useUpdatedRef = useUpdatedRef;
871
+ exports.useWalletConnector = useWalletConnector;
872
+ exports.useWalletPortfoliosQuery = useWalletPortfoliosQuery;
873
+ exports.useWalletTradeActivitiesQuery = useWalletTradeActivitiesQuery;
874
+ exports.useWallets = useWallets;
875
+ exports.version = version_default;
876
+ exports.walletPortfoliosQueryKey = walletPortfoliosQueryKey;
877
+ exports.walletTradeActivitiesQueryKey = walletTradeActivitiesQueryKey;
878
+ Object.keys(useDebounce).forEach(function (k) {
879
+ if (k !== 'default' && !Object.prototype.hasOwnProperty.call(exports, k)) Object.defineProperty(exports, k, {
880
+ enumerable: true,
881
+ get: function () { return useDebounce[k]; }
882
+ });
883
+ });
884
+ //# sourceMappingURL=index.js.map
885
+ //# sourceMappingURL=index.js.map