@chipi-stack/chipi-react 11.3.0 → 11.4.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/dist/hooks.d.mts +351 -10
- package/dist/hooks.d.ts +351 -10
- package/dist/hooks.js +50 -30
- package/dist/hooks.js.map +1 -1
- package/dist/hooks.mjs +51 -32
- package/dist/hooks.mjs.map +1 -1
- package/dist/index.d.mts +2 -1
- package/dist/index.d.ts +2 -1
- package/dist/index.js +50 -30
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +51 -32
- package/dist/index.mjs.map +1 -1
- package/package.json +4 -4
package/dist/hooks.d.ts
CHANGED
|
@@ -1,4 +1,6 @@
|
|
|
1
|
-
import { CreateWalletParams, CreateWalletResponse, GetWalletParams, WalletData, TransferParams, ApproveParams, StakeVesuUsdcParams, WithdrawVesuUsdcParams, CallAnyContractParams, RecordSendTransactionParams, Transaction } from '@chipi-stack/types';
|
|
1
|
+
import { CreateWalletParams, CreateWalletResponse, GetWalletParams, WalletData, TransferParams, ApproveParams, StakeVesuUsdcParams, WithdrawVesuUsdcParams, CallAnyContractParams, RecordSendTransactionParams, Transaction, GetTokenBalanceParams, GetTokenBalanceResponse } from '@chipi-stack/types';
|
|
2
|
+
import * as _tanstack_react_query from '@tanstack/react-query';
|
|
3
|
+
import { UseQueryOptions } from '@tanstack/react-query';
|
|
2
4
|
|
|
3
5
|
type CreateWalletInput = {
|
|
4
6
|
params: CreateWalletParams;
|
|
@@ -18,15 +20,179 @@ declare function useCreateWallet(): {
|
|
|
18
20
|
reset: () => void;
|
|
19
21
|
};
|
|
20
22
|
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
23
|
+
type GetWalletInput = {
|
|
24
|
+
params?: GetWalletParams;
|
|
25
|
+
getBearerToken?: () => Promise<string | null | undefined>;
|
|
26
|
+
queryOptions?: Omit<UseQueryOptions<WalletData, Error>, 'queryKey' | 'queryFn'>;
|
|
27
|
+
};
|
|
28
|
+
declare function useGetWallet(input?: GetWalletInput): {
|
|
29
|
+
fetchWallet: (newInput: GetWalletInput) => Promise<WalletData>;
|
|
30
|
+
data: WalletData;
|
|
31
|
+
error: Error;
|
|
32
|
+
isError: true;
|
|
33
|
+
isPending: false;
|
|
34
|
+
isLoading: false;
|
|
35
|
+
isLoadingError: false;
|
|
36
|
+
isRefetchError: true;
|
|
37
|
+
isSuccess: false;
|
|
38
|
+
isPlaceholderData: false;
|
|
39
|
+
status: "error";
|
|
40
|
+
dataUpdatedAt: number;
|
|
41
|
+
errorUpdatedAt: number;
|
|
42
|
+
failureCount: number;
|
|
43
|
+
failureReason: Error | null;
|
|
44
|
+
errorUpdateCount: number;
|
|
45
|
+
isFetched: boolean;
|
|
46
|
+
isFetchedAfterMount: boolean;
|
|
47
|
+
isFetching: boolean;
|
|
48
|
+
isInitialLoading: boolean;
|
|
49
|
+
isPaused: boolean;
|
|
50
|
+
isRefetching: boolean;
|
|
51
|
+
isStale: boolean;
|
|
52
|
+
isEnabled: boolean;
|
|
53
|
+
refetch: (options?: _tanstack_react_query.RefetchOptions) => Promise<_tanstack_react_query.QueryObserverResult<WalletData, Error>>;
|
|
54
|
+
fetchStatus: _tanstack_react_query.FetchStatus;
|
|
55
|
+
promise: Promise<WalletData>;
|
|
56
|
+
} | {
|
|
57
|
+
fetchWallet: (newInput: GetWalletInput) => Promise<WalletData>;
|
|
58
|
+
data: WalletData;
|
|
59
|
+
error: null;
|
|
60
|
+
isError: false;
|
|
61
|
+
isPending: false;
|
|
62
|
+
isLoading: false;
|
|
63
|
+
isLoadingError: false;
|
|
64
|
+
isRefetchError: false;
|
|
65
|
+
isSuccess: true;
|
|
66
|
+
isPlaceholderData: false;
|
|
67
|
+
status: "success";
|
|
68
|
+
dataUpdatedAt: number;
|
|
69
|
+
errorUpdatedAt: number;
|
|
70
|
+
failureCount: number;
|
|
71
|
+
failureReason: Error | null;
|
|
72
|
+
errorUpdateCount: number;
|
|
73
|
+
isFetched: boolean;
|
|
74
|
+
isFetchedAfterMount: boolean;
|
|
75
|
+
isFetching: boolean;
|
|
76
|
+
isInitialLoading: boolean;
|
|
77
|
+
isPaused: boolean;
|
|
78
|
+
isRefetching: boolean;
|
|
79
|
+
isStale: boolean;
|
|
80
|
+
isEnabled: boolean;
|
|
81
|
+
refetch: (options?: _tanstack_react_query.RefetchOptions) => Promise<_tanstack_react_query.QueryObserverResult<WalletData, Error>>;
|
|
82
|
+
fetchStatus: _tanstack_react_query.FetchStatus;
|
|
83
|
+
promise: Promise<WalletData>;
|
|
84
|
+
} | {
|
|
85
|
+
fetchWallet: (newInput: GetWalletInput) => Promise<WalletData>;
|
|
86
|
+
data: undefined;
|
|
87
|
+
error: Error;
|
|
88
|
+
isError: true;
|
|
89
|
+
isPending: false;
|
|
90
|
+
isLoading: false;
|
|
91
|
+
isLoadingError: true;
|
|
92
|
+
isRefetchError: false;
|
|
93
|
+
isSuccess: false;
|
|
94
|
+
isPlaceholderData: false;
|
|
95
|
+
status: "error";
|
|
96
|
+
dataUpdatedAt: number;
|
|
97
|
+
errorUpdatedAt: number;
|
|
98
|
+
failureCount: number;
|
|
99
|
+
failureReason: Error | null;
|
|
100
|
+
errorUpdateCount: number;
|
|
101
|
+
isFetched: boolean;
|
|
102
|
+
isFetchedAfterMount: boolean;
|
|
103
|
+
isFetching: boolean;
|
|
104
|
+
isInitialLoading: boolean;
|
|
105
|
+
isPaused: boolean;
|
|
106
|
+
isRefetching: boolean;
|
|
107
|
+
isStale: boolean;
|
|
108
|
+
isEnabled: boolean;
|
|
109
|
+
refetch: (options?: _tanstack_react_query.RefetchOptions) => Promise<_tanstack_react_query.QueryObserverResult<WalletData, Error>>;
|
|
110
|
+
fetchStatus: _tanstack_react_query.FetchStatus;
|
|
111
|
+
promise: Promise<WalletData>;
|
|
112
|
+
} | {
|
|
113
|
+
fetchWallet: (newInput: GetWalletInput) => Promise<WalletData>;
|
|
114
|
+
data: undefined;
|
|
115
|
+
error: null;
|
|
116
|
+
isError: false;
|
|
117
|
+
isPending: true;
|
|
118
|
+
isLoading: true;
|
|
119
|
+
isLoadingError: false;
|
|
120
|
+
isRefetchError: false;
|
|
121
|
+
isSuccess: false;
|
|
122
|
+
isPlaceholderData: false;
|
|
123
|
+
status: "pending";
|
|
124
|
+
dataUpdatedAt: number;
|
|
125
|
+
errorUpdatedAt: number;
|
|
126
|
+
failureCount: number;
|
|
127
|
+
failureReason: Error | null;
|
|
128
|
+
errorUpdateCount: number;
|
|
129
|
+
isFetched: boolean;
|
|
130
|
+
isFetchedAfterMount: boolean;
|
|
131
|
+
isFetching: boolean;
|
|
132
|
+
isInitialLoading: boolean;
|
|
133
|
+
isPaused: boolean;
|
|
134
|
+
isRefetching: boolean;
|
|
135
|
+
isStale: boolean;
|
|
136
|
+
isEnabled: boolean;
|
|
137
|
+
refetch: (options?: _tanstack_react_query.RefetchOptions) => Promise<_tanstack_react_query.QueryObserverResult<WalletData, Error>>;
|
|
138
|
+
fetchStatus: _tanstack_react_query.FetchStatus;
|
|
139
|
+
promise: Promise<WalletData>;
|
|
140
|
+
} | {
|
|
141
|
+
fetchWallet: (newInput: GetWalletInput) => Promise<WalletData>;
|
|
142
|
+
data: undefined;
|
|
143
|
+
error: null;
|
|
144
|
+
isError: false;
|
|
145
|
+
isPending: true;
|
|
146
|
+
isLoadingError: false;
|
|
147
|
+
isRefetchError: false;
|
|
148
|
+
isSuccess: false;
|
|
149
|
+
isPlaceholderData: false;
|
|
150
|
+
status: "pending";
|
|
151
|
+
dataUpdatedAt: number;
|
|
152
|
+
errorUpdatedAt: number;
|
|
153
|
+
failureCount: number;
|
|
154
|
+
failureReason: Error | null;
|
|
155
|
+
errorUpdateCount: number;
|
|
156
|
+
isFetched: boolean;
|
|
157
|
+
isFetchedAfterMount: boolean;
|
|
158
|
+
isFetching: boolean;
|
|
25
159
|
isLoading: boolean;
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
160
|
+
isInitialLoading: boolean;
|
|
161
|
+
isPaused: boolean;
|
|
162
|
+
isRefetching: boolean;
|
|
163
|
+
isStale: boolean;
|
|
164
|
+
isEnabled: boolean;
|
|
165
|
+
refetch: (options?: _tanstack_react_query.RefetchOptions) => Promise<_tanstack_react_query.QueryObserverResult<WalletData, Error>>;
|
|
166
|
+
fetchStatus: _tanstack_react_query.FetchStatus;
|
|
167
|
+
promise: Promise<WalletData>;
|
|
168
|
+
} | {
|
|
169
|
+
fetchWallet: (newInput: GetWalletInput) => Promise<WalletData>;
|
|
170
|
+
data: WalletData;
|
|
171
|
+
isError: false;
|
|
172
|
+
error: null;
|
|
173
|
+
isPending: false;
|
|
174
|
+
isLoading: false;
|
|
175
|
+
isLoadingError: false;
|
|
176
|
+
isRefetchError: false;
|
|
177
|
+
isSuccess: true;
|
|
178
|
+
isPlaceholderData: true;
|
|
179
|
+
status: "success";
|
|
180
|
+
dataUpdatedAt: number;
|
|
181
|
+
errorUpdatedAt: number;
|
|
182
|
+
failureCount: number;
|
|
183
|
+
failureReason: Error | null;
|
|
184
|
+
errorUpdateCount: number;
|
|
185
|
+
isFetched: boolean;
|
|
186
|
+
isFetchedAfterMount: boolean;
|
|
187
|
+
isFetching: boolean;
|
|
188
|
+
isInitialLoading: boolean;
|
|
189
|
+
isPaused: boolean;
|
|
190
|
+
isRefetching: boolean;
|
|
191
|
+
isStale: boolean;
|
|
192
|
+
isEnabled: boolean;
|
|
193
|
+
refetch: (options?: _tanstack_react_query.RefetchOptions) => Promise<_tanstack_react_query.QueryObserverResult<WalletData, Error>>;
|
|
194
|
+
fetchStatus: _tanstack_react_query.FetchStatus;
|
|
195
|
+
promise: Promise<WalletData>;
|
|
30
196
|
};
|
|
31
197
|
|
|
32
198
|
type TransferInput = {
|
|
@@ -134,4 +300,179 @@ declare function useRecordSendTransaction(): {
|
|
|
134
300
|
reset: () => void;
|
|
135
301
|
};
|
|
136
302
|
|
|
137
|
-
|
|
303
|
+
type GetTokenBalanceInput = {
|
|
304
|
+
params?: GetTokenBalanceParams;
|
|
305
|
+
getBearerToken?: () => Promise<string | null | undefined>;
|
|
306
|
+
queryOptions?: Omit<UseQueryOptions<GetTokenBalanceResponse, Error>, 'queryKey' | 'queryFn'>;
|
|
307
|
+
};
|
|
308
|
+
declare function useGetTokenBalance(input?: GetTokenBalanceInput): {
|
|
309
|
+
fetchTokenBalance: (newInput: GetTokenBalanceInput) => Promise<GetTokenBalanceResponse>;
|
|
310
|
+
data: GetTokenBalanceResponse;
|
|
311
|
+
error: Error;
|
|
312
|
+
isError: true;
|
|
313
|
+
isPending: false;
|
|
314
|
+
isLoading: false;
|
|
315
|
+
isLoadingError: false;
|
|
316
|
+
isRefetchError: true;
|
|
317
|
+
isSuccess: false;
|
|
318
|
+
isPlaceholderData: false;
|
|
319
|
+
status: "error";
|
|
320
|
+
dataUpdatedAt: number;
|
|
321
|
+
errorUpdatedAt: number;
|
|
322
|
+
failureCount: number;
|
|
323
|
+
failureReason: Error | null;
|
|
324
|
+
errorUpdateCount: number;
|
|
325
|
+
isFetched: boolean;
|
|
326
|
+
isFetchedAfterMount: boolean;
|
|
327
|
+
isFetching: boolean;
|
|
328
|
+
isInitialLoading: boolean;
|
|
329
|
+
isPaused: boolean;
|
|
330
|
+
isRefetching: boolean;
|
|
331
|
+
isStale: boolean;
|
|
332
|
+
isEnabled: boolean;
|
|
333
|
+
refetch: (options?: _tanstack_react_query.RefetchOptions) => Promise<_tanstack_react_query.QueryObserverResult<GetTokenBalanceResponse, Error>>;
|
|
334
|
+
fetchStatus: _tanstack_react_query.FetchStatus;
|
|
335
|
+
promise: Promise<GetTokenBalanceResponse>;
|
|
336
|
+
} | {
|
|
337
|
+
fetchTokenBalance: (newInput: GetTokenBalanceInput) => Promise<GetTokenBalanceResponse>;
|
|
338
|
+
data: GetTokenBalanceResponse;
|
|
339
|
+
error: null;
|
|
340
|
+
isError: false;
|
|
341
|
+
isPending: false;
|
|
342
|
+
isLoading: false;
|
|
343
|
+
isLoadingError: false;
|
|
344
|
+
isRefetchError: false;
|
|
345
|
+
isSuccess: true;
|
|
346
|
+
isPlaceholderData: false;
|
|
347
|
+
status: "success";
|
|
348
|
+
dataUpdatedAt: number;
|
|
349
|
+
errorUpdatedAt: number;
|
|
350
|
+
failureCount: number;
|
|
351
|
+
failureReason: Error | null;
|
|
352
|
+
errorUpdateCount: number;
|
|
353
|
+
isFetched: boolean;
|
|
354
|
+
isFetchedAfterMount: boolean;
|
|
355
|
+
isFetching: boolean;
|
|
356
|
+
isInitialLoading: boolean;
|
|
357
|
+
isPaused: boolean;
|
|
358
|
+
isRefetching: boolean;
|
|
359
|
+
isStale: boolean;
|
|
360
|
+
isEnabled: boolean;
|
|
361
|
+
refetch: (options?: _tanstack_react_query.RefetchOptions) => Promise<_tanstack_react_query.QueryObserverResult<GetTokenBalanceResponse, Error>>;
|
|
362
|
+
fetchStatus: _tanstack_react_query.FetchStatus;
|
|
363
|
+
promise: Promise<GetTokenBalanceResponse>;
|
|
364
|
+
} | {
|
|
365
|
+
fetchTokenBalance: (newInput: GetTokenBalanceInput) => Promise<GetTokenBalanceResponse>;
|
|
366
|
+
data: undefined;
|
|
367
|
+
error: Error;
|
|
368
|
+
isError: true;
|
|
369
|
+
isPending: false;
|
|
370
|
+
isLoading: false;
|
|
371
|
+
isLoadingError: true;
|
|
372
|
+
isRefetchError: false;
|
|
373
|
+
isSuccess: false;
|
|
374
|
+
isPlaceholderData: false;
|
|
375
|
+
status: "error";
|
|
376
|
+
dataUpdatedAt: number;
|
|
377
|
+
errorUpdatedAt: number;
|
|
378
|
+
failureCount: number;
|
|
379
|
+
failureReason: Error | null;
|
|
380
|
+
errorUpdateCount: number;
|
|
381
|
+
isFetched: boolean;
|
|
382
|
+
isFetchedAfterMount: boolean;
|
|
383
|
+
isFetching: boolean;
|
|
384
|
+
isInitialLoading: boolean;
|
|
385
|
+
isPaused: boolean;
|
|
386
|
+
isRefetching: boolean;
|
|
387
|
+
isStale: boolean;
|
|
388
|
+
isEnabled: boolean;
|
|
389
|
+
refetch: (options?: _tanstack_react_query.RefetchOptions) => Promise<_tanstack_react_query.QueryObserverResult<GetTokenBalanceResponse, Error>>;
|
|
390
|
+
fetchStatus: _tanstack_react_query.FetchStatus;
|
|
391
|
+
promise: Promise<GetTokenBalanceResponse>;
|
|
392
|
+
} | {
|
|
393
|
+
fetchTokenBalance: (newInput: GetTokenBalanceInput) => Promise<GetTokenBalanceResponse>;
|
|
394
|
+
data: undefined;
|
|
395
|
+
error: null;
|
|
396
|
+
isError: false;
|
|
397
|
+
isPending: true;
|
|
398
|
+
isLoading: true;
|
|
399
|
+
isLoadingError: false;
|
|
400
|
+
isRefetchError: false;
|
|
401
|
+
isSuccess: false;
|
|
402
|
+
isPlaceholderData: false;
|
|
403
|
+
status: "pending";
|
|
404
|
+
dataUpdatedAt: number;
|
|
405
|
+
errorUpdatedAt: number;
|
|
406
|
+
failureCount: number;
|
|
407
|
+
failureReason: Error | null;
|
|
408
|
+
errorUpdateCount: number;
|
|
409
|
+
isFetched: boolean;
|
|
410
|
+
isFetchedAfterMount: boolean;
|
|
411
|
+
isFetching: boolean;
|
|
412
|
+
isInitialLoading: boolean;
|
|
413
|
+
isPaused: boolean;
|
|
414
|
+
isRefetching: boolean;
|
|
415
|
+
isStale: boolean;
|
|
416
|
+
isEnabled: boolean;
|
|
417
|
+
refetch: (options?: _tanstack_react_query.RefetchOptions) => Promise<_tanstack_react_query.QueryObserverResult<GetTokenBalanceResponse, Error>>;
|
|
418
|
+
fetchStatus: _tanstack_react_query.FetchStatus;
|
|
419
|
+
promise: Promise<GetTokenBalanceResponse>;
|
|
420
|
+
} | {
|
|
421
|
+
fetchTokenBalance: (newInput: GetTokenBalanceInput) => Promise<GetTokenBalanceResponse>;
|
|
422
|
+
data: undefined;
|
|
423
|
+
error: null;
|
|
424
|
+
isError: false;
|
|
425
|
+
isPending: true;
|
|
426
|
+
isLoadingError: false;
|
|
427
|
+
isRefetchError: false;
|
|
428
|
+
isSuccess: false;
|
|
429
|
+
isPlaceholderData: false;
|
|
430
|
+
status: "pending";
|
|
431
|
+
dataUpdatedAt: number;
|
|
432
|
+
errorUpdatedAt: number;
|
|
433
|
+
failureCount: number;
|
|
434
|
+
failureReason: Error | null;
|
|
435
|
+
errorUpdateCount: number;
|
|
436
|
+
isFetched: boolean;
|
|
437
|
+
isFetchedAfterMount: boolean;
|
|
438
|
+
isFetching: boolean;
|
|
439
|
+
isLoading: boolean;
|
|
440
|
+
isInitialLoading: boolean;
|
|
441
|
+
isPaused: boolean;
|
|
442
|
+
isRefetching: boolean;
|
|
443
|
+
isStale: boolean;
|
|
444
|
+
isEnabled: boolean;
|
|
445
|
+
refetch: (options?: _tanstack_react_query.RefetchOptions) => Promise<_tanstack_react_query.QueryObserverResult<GetTokenBalanceResponse, Error>>;
|
|
446
|
+
fetchStatus: _tanstack_react_query.FetchStatus;
|
|
447
|
+
promise: Promise<GetTokenBalanceResponse>;
|
|
448
|
+
} | {
|
|
449
|
+
fetchTokenBalance: (newInput: GetTokenBalanceInput) => Promise<GetTokenBalanceResponse>;
|
|
450
|
+
data: GetTokenBalanceResponse;
|
|
451
|
+
isError: false;
|
|
452
|
+
error: null;
|
|
453
|
+
isPending: false;
|
|
454
|
+
isLoading: false;
|
|
455
|
+
isLoadingError: false;
|
|
456
|
+
isRefetchError: false;
|
|
457
|
+
isSuccess: true;
|
|
458
|
+
isPlaceholderData: true;
|
|
459
|
+
status: "success";
|
|
460
|
+
dataUpdatedAt: number;
|
|
461
|
+
errorUpdatedAt: number;
|
|
462
|
+
failureCount: number;
|
|
463
|
+
failureReason: Error | null;
|
|
464
|
+
errorUpdateCount: number;
|
|
465
|
+
isFetched: boolean;
|
|
466
|
+
isFetchedAfterMount: boolean;
|
|
467
|
+
isFetching: boolean;
|
|
468
|
+
isInitialLoading: boolean;
|
|
469
|
+
isPaused: boolean;
|
|
470
|
+
isRefetching: boolean;
|
|
471
|
+
isStale: boolean;
|
|
472
|
+
isEnabled: boolean;
|
|
473
|
+
refetch: (options?: _tanstack_react_query.RefetchOptions) => Promise<_tanstack_react_query.QueryObserverResult<GetTokenBalanceResponse, Error>>;
|
|
474
|
+
fetchStatus: _tanstack_react_query.FetchStatus;
|
|
475
|
+
promise: Promise<GetTokenBalanceResponse>;
|
|
476
|
+
};
|
|
477
|
+
|
|
478
|
+
export { useApprove, useCallAnyContract, useCreateWallet, useGetTokenBalance, useGetWallet, useRecordSendTransaction, useStakeVesuUsdc, useTransfer, useWithdrawVesuUsdc };
|
package/dist/hooks.js
CHANGED
|
@@ -35,45 +35,34 @@ function useCreateWallet() {
|
|
|
35
35
|
reset: mutation.reset
|
|
36
36
|
};
|
|
37
37
|
}
|
|
38
|
-
|
|
39
|
-
function useGetWallet() {
|
|
38
|
+
function useGetWallet(input) {
|
|
40
39
|
const { chipiSDK } = useChipiContext();
|
|
41
40
|
const queryClient = reactQuery.useQueryClient();
|
|
42
|
-
const [params, setParams] = react.useState(null);
|
|
43
41
|
const query = reactQuery.useQuery({
|
|
44
|
-
queryKey:
|
|
45
|
-
queryFn: () => {
|
|
46
|
-
if (!params) throw new Error("
|
|
47
|
-
|
|
42
|
+
queryKey: ["wallet", input?.params?.externalUserId],
|
|
43
|
+
queryFn: async () => {
|
|
44
|
+
if (!input || !input.params || !input.getBearerToken) throw new Error("Input is required");
|
|
45
|
+
const bearerToken = await input.getBearerToken();
|
|
46
|
+
if (!bearerToken) throw new Error("Bearer token is required");
|
|
47
|
+
return chipiSDK.getWallet(input.params, bearerToken);
|
|
48
48
|
},
|
|
49
|
-
enabled:
|
|
50
|
-
|
|
51
|
-
gcTime: Infinity,
|
|
52
|
-
refetchOnWindowFocus: false,
|
|
53
|
-
refetchOnMount: false
|
|
49
|
+
enabled: Boolean(input?.params && input?.getBearerToken),
|
|
50
|
+
...input?.queryOptions
|
|
54
51
|
});
|
|
55
|
-
const
|
|
56
|
-
setParams(walletParams);
|
|
57
|
-
};
|
|
58
|
-
const getWalletAsync = (walletParams) => {
|
|
52
|
+
const fetchWallet = async (newInput) => {
|
|
59
53
|
return queryClient.fetchQuery({
|
|
60
|
-
queryKey:
|
|
61
|
-
queryFn: () =>
|
|
62
|
-
|
|
63
|
-
|
|
54
|
+
queryKey: ["wallet", newInput?.params?.externalUserId],
|
|
55
|
+
queryFn: async () => {
|
|
56
|
+
if (!newInput || !newInput.getBearerToken || !newInput.params) throw new Error("Input is required");
|
|
57
|
+
const bearerToken = await newInput.getBearerToken();
|
|
58
|
+
if (!bearerToken) throw new Error("Bearer token is required");
|
|
59
|
+
return chipiSDK.getWallet(newInput.params, bearerToken);
|
|
60
|
+
}
|
|
64
61
|
});
|
|
65
62
|
};
|
|
66
63
|
return {
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
data: query.data,
|
|
70
|
-
isLoading: query.isLoading,
|
|
71
|
-
isError: query.isError,
|
|
72
|
-
error: query.error ?? null,
|
|
73
|
-
isSuccess: query.isSuccess,
|
|
74
|
-
refetch: () => {
|
|
75
|
-
if (params) void query.refetch();
|
|
76
|
-
}
|
|
64
|
+
...query,
|
|
65
|
+
fetchWallet
|
|
77
66
|
};
|
|
78
67
|
}
|
|
79
68
|
function useTransfer() {
|
|
@@ -180,10 +169,41 @@ function useRecordSendTransaction() {
|
|
|
180
169
|
reset: mutation.reset
|
|
181
170
|
};
|
|
182
171
|
}
|
|
172
|
+
function useGetTokenBalance(input) {
|
|
173
|
+
const { chipiSDK } = useChipiContext();
|
|
174
|
+
const queryClient = reactQuery.useQueryClient();
|
|
175
|
+
const query = reactQuery.useQuery({
|
|
176
|
+
queryKey: ["chain-token-balance", input?.params?.chainToken, input?.params?.chain, input?.params?.walletPublicKey, input?.params?.externalUserId],
|
|
177
|
+
queryFn: async () => {
|
|
178
|
+
if (!input || !input.params || !input.getBearerToken) throw new Error("Input is required");
|
|
179
|
+
const bearerToken = await input.getBearerToken();
|
|
180
|
+
if (!bearerToken) throw new Error("Bearer token is required");
|
|
181
|
+
return chipiSDK.getTokenBalance(input.params, bearerToken);
|
|
182
|
+
},
|
|
183
|
+
enabled: Boolean(input?.params && input?.getBearerToken),
|
|
184
|
+
...input?.queryOptions
|
|
185
|
+
});
|
|
186
|
+
const fetchTokenBalance = async (newInput) => {
|
|
187
|
+
return queryClient.fetchQuery({
|
|
188
|
+
queryKey: ["chain-token-balance", newInput?.params?.chainToken, newInput?.params?.chain, newInput?.params?.walletPublicKey, newInput?.params?.externalUserId],
|
|
189
|
+
queryFn: async () => {
|
|
190
|
+
if (!newInput || !newInput.getBearerToken || !newInput.params) throw new Error("Input is required");
|
|
191
|
+
const bearerToken = await newInput.getBearerToken();
|
|
192
|
+
if (!bearerToken) throw new Error("Bearer token is required");
|
|
193
|
+
return chipiSDK.getTokenBalance(newInput.params, bearerToken);
|
|
194
|
+
}
|
|
195
|
+
});
|
|
196
|
+
};
|
|
197
|
+
return {
|
|
198
|
+
...query,
|
|
199
|
+
fetchTokenBalance
|
|
200
|
+
};
|
|
201
|
+
}
|
|
183
202
|
|
|
184
203
|
exports.useApprove = useApprove;
|
|
185
204
|
exports.useCallAnyContract = useCallAnyContract;
|
|
186
205
|
exports.useCreateWallet = useCreateWallet;
|
|
206
|
+
exports.useGetTokenBalance = useGetTokenBalance;
|
|
187
207
|
exports.useGetWallet = useGetWallet;
|
|
188
208
|
exports.useRecordSendTransaction = useRecordSendTransaction;
|
|
189
209
|
exports.useStakeVesuUsdc = useStakeVesuUsdc;
|
package/dist/hooks.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/context/ChipiProvider.tsx","../src/hooks/useCreateWallet.ts","../src/hooks/useGetWallet.ts","../src/hooks/useTransfer.ts","../src/hooks/useApprove.ts","../src/hooks/useStakeVesuUsdc.ts","../src/hooks/useWithdrawVesuUsdc.ts","../src/hooks/useCallAnyContract.ts","../src/hooks/useRecordSendTransaction.ts"],"names":["createContext","useContext","useMutation","useQueryClient","useState","useQuery"],"mappings":";;;;;;;;AAUA,IAAM,YAAA,GAAeA,oBAAwC,IAAI,CAA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,OAAO,QAAA,CAAS;AAAA,GAClB;AACF;AC5BO,SAAS,wBAAA,GAWd;AACA,EAAA,MAAM,EAAE,QAAA,EAAS,GAAI,eAAA,EAAgB;AAErC,EAAA,MAAM,WAIFA,sBAAAA,CAAY;AAAA,IACd,UAAA,EAAY,CAAC,KAAA,KACX,QAAA,CAAS,qBAAA,CAAsB;AAAA,MAC7B,QAAQ,KAAA,CAAM,MAAA;AAAA,MACd,aAAa,KAAA,CAAM;AAAA,KACpB;AAAA,GACJ,CAAA;AAED,EAAA,OAAO;AAAA,IACL,uBAAuB,QAAA,CAAS,MAAA;AAAA,IAChC,4BAA4B,QAAA,CAAS,WAAA;AAAA,IACrC,MAAM,QAAA,CAAS,IAAA;AAAA,IACf,WAAW,QAAA,CAAS,SAAA;AAAA,IACpB,SAAS,QAAA,CAAS,OAAA;AAAA,IAClB,OAAO,QAAA,CAAS,KAAA;AAAA,IAChB,WAAW,QAAA,CAAS,SAAA;AAAA,IACpB,OAAO,QAAA,CAAS;AAAA,GAClB;AACF","file":"hooks.js","sourcesContent":["import React, { createContext, useContext, ReactNode } from \"react\";\nimport { QueryClient, QueryClientProvider } from \"@tanstack/react-query\";\nimport { ChipiSDK } from \"@chipi-stack/backend\";\nimport type { ChipiSDKConfig } from \"@chipi-stack/types\";\n\ninterface ChipiContextValue {\n chipiSDK: ChipiSDK;\n config: ChipiSDKConfig;\n}\n\nconst ChipiContext = createContext<ChipiContextValue | null>(null);\n\ninterface ChipiProviderProps {\n children: ReactNode;\n config: ChipiSDKConfig;\n}\n\n// Default QueryClient configuration\nconst createDefaultQueryClient = () =>\n new QueryClient({\n defaultOptions: {\n queries: {\n staleTime: 60 * 1000, // 1 minute\n gcTime: 10 * 60 * 1000, // 10 minutes (formerly cacheTime)\n retry: (failureCount, error: any) => {\n // Don't retry on 4xx errors\n if (error?.status >= 400 && error?.status < 500) {\n return false;\n }\n return failureCount < 3;\n },\n },\n mutations: {\n retry: false,\n },\n },\n });\n\n/**\n * Provider component that wraps your app and provides Chipi SDK context with QueryClient\n */\nexport function ChipiProvider({ children, config }: ChipiProviderProps) {\n // Create QueryClient\n const queryClient = React.useMemo(() => createDefaultQueryClient(), []);\n\n const chipiSDK = React.useMemo(() => new ChipiSDK(config), [config]);\n\n const value = React.useMemo(\n () => ({\n chipiSDK,\n config,\n }),\n [chipiSDK, config]\n );\n\n return (\n <QueryClientProvider client={queryClient}>\n <ChipiContext.Provider value={value}>{children}</ChipiContext.Provider>\n </QueryClientProvider>\n );\n}\n\n/**\n * Hook to access Chipi SDK context\n */\nexport function useChipiContext(): ChipiContextValue {\n const context = useContext(ChipiContext);\n\n if (!context) {\n throw new Error(\"useChipiContext must be used within a ChipiProvider\");\n }\n\n return context;\n}\n","import { useMutation, type UseMutationResult } from \"@tanstack/react-query\";\nimport { useChipiContext } from \"../context\";\nimport type {\n CreateWalletParams,\n CreateWalletResponse,\n} from \"@chipi-stack/types\";\n\ntype CreateWalletInput = {\n params: CreateWalletParams;\n bearerToken: string;\n};\n\n/**\n * Hook for creating a new wallet\n */\nexport function useCreateWallet(): {\n createWallet: (input: CreateWalletInput) => void;\n createWalletAsync: (\n input: CreateWalletInput\n ) => Promise<CreateWalletResponse>;\n data: CreateWalletResponse | undefined;\n isLoading: boolean;\n isError: boolean;\n error: Error | null;\n isSuccess: boolean;\n reset: () => void;\n} {\n const { chipiSDK } = useChipiContext();\n\n const mutation: UseMutationResult<\n CreateWalletResponse,\n Error,\n CreateWalletInput\n > = useMutation({\n mutationFn: (input: CreateWalletInput) =>\n chipiSDK.createWallet({\n params: input.params,\n bearerToken: input.bearerToken,\n }),\n });\n\n return {\n createWallet: mutation.mutate,\n createWalletAsync: mutation.mutateAsync,\n data: mutation.data,\n isLoading: mutation.isPending,\n isError: mutation.isError,\n error: mutation.error,\n isSuccess: mutation.isSuccess,\n reset: mutation.reset,\n };\n}\n","\"use client\";\n\nimport { useState } from \"react\";\nimport {\n useQuery,\n useQueryClient,\n type UseQueryResult,\n} from \"@tanstack/react-query\";\nimport { GetWalletParams, WalletData } from \"@chipi-stack/types\";\nimport { useChipiContext } from \"../context\";\n\nconst walletKey = (externalUserId: string) =>\n [\"wallet\", externalUserId] as const;\n\nexport function useGetWallet(): {\n getWallet: (params: GetWalletParams) => void;\n getWalletAsync: (params: GetWalletParams) => Promise<WalletData>;\n data: WalletData | undefined;\n isLoading: boolean;\n isError: boolean;\n error: Error | null;\n isSuccess: boolean;\n refetch: () => void;\n} {\n const { chipiSDK } = useChipiContext();\n const queryClient = useQueryClient();\n\n const [params, setParams] = useState<GetWalletParams | null>(null);\n\n const query: UseQueryResult<WalletData, Error> = useQuery({\n queryKey: walletKey(params?.externalUserId || \"\"),\n queryFn: () => {\n if (!params) throw new Error(\"No wallet params provided\");\n return chipiSDK.getWallet(params);\n },\n enabled: !!params,\n staleTime: Infinity,\n gcTime: Infinity,\n refetchOnWindowFocus: false,\n refetchOnMount: false,\n });\n\n const getWallet = (walletParams: GetWalletParams) => {\n setParams(walletParams);\n };\n\n const getWalletAsync = (\n walletParams: GetWalletParams\n ): Promise<WalletData> => {\n return queryClient.fetchQuery({\n queryKey: walletKey(walletParams.externalUserId),\n queryFn: () => chipiSDK.getWallet(walletParams),\n staleTime: Infinity,\n gcTime: Infinity,\n });\n };\n\n return {\n getWallet,\n getWalletAsync,\n data: query.data,\n isLoading: query.isLoading,\n isError: query.isError,\n error: query.error ?? null,\n isSuccess: query.isSuccess,\n refetch: () => {\n if (params) void query.refetch();\n },\n };\n}\n","import { useMutation, type UseMutationResult } from \"@tanstack/react-query\";\nimport { useChipiContext } from \"../context\";\nimport type { TransferParams } from \"@chipi-stack/types\";\n\ntype TransferInput = { params: TransferParams; bearerToken: string };\n\n/**\n * Hook for transferring tokens\n */\nexport function useTransfer(): {\n transfer: (input: TransferInput) => void;\n transferAsync: (input: TransferInput) => Promise<string>;\n data: string | undefined;\n isLoading: boolean;\n isError: boolean;\n error: Error | null;\n isSuccess: boolean;\n reset: () => void;\n} {\n const { chipiSDK } = useChipiContext();\n\n const mutation: UseMutationResult<string, Error, TransferInput> = useMutation(\n {\n mutationFn: (input: TransferInput) =>\n chipiSDK.transfer({\n params: input.params,\n bearerToken: input.bearerToken,\n }),\n }\n );\n\n return {\n transfer: mutation.mutate,\n transferAsync: mutation.mutateAsync,\n data: mutation.data,\n isLoading: mutation.isPending,\n isError: mutation.isError,\n error: mutation.error,\n isSuccess: mutation.isSuccess,\n reset: mutation.reset,\n };\n}\n","import { useMutation, type UseMutationResult } from \"@tanstack/react-query\";\nimport { useChipiContext } from \"../context\";\nimport type { ApproveParams } from \"@chipi-stack/types\";\n\ntype ApproveInput = {\n params: ApproveParams;\n bearerToken: string;\n};\n\n/**\n * Hook for approving token spending\n */\nexport function useApprove(): {\n approve: (params: ApproveInput) => void;\n approveAsync: (params: ApproveInput) => Promise<string>;\n data: string | undefined;\n isLoading: boolean;\n isError: boolean;\n error: Error | null;\n isSuccess: boolean;\n reset: () => void;\n} {\n const { chipiSDK } = useChipiContext();\n\n const mutation: UseMutationResult<string, Error, ApproveInput> = useMutation({\n mutationFn: (params: ApproveInput) => chipiSDK.approve(params),\n });\n\n return {\n approve: mutation.mutate,\n approveAsync: mutation.mutateAsync,\n data: mutation.data,\n isLoading: mutation.isPending,\n isError: mutation.isError,\n error: mutation.error,\n isSuccess: mutation.isSuccess,\n reset: mutation.reset,\n };\n}\n","import { useMutation, type UseMutationResult } from \"@tanstack/react-query\";\nimport { useChipiContext } from \"../context\";\nimport type { StakeVesuUsdcParams } from \"@chipi-stack/types\";\n\ntype StakeVesuUsdcInput = {\n params: StakeVesuUsdcParams;\n bearerToken: string;\n};\n\n/**\n * Hook for staking USDC in Vesu protocol\n */\nexport function useStakeVesuUsdc(): {\n stakeVesuUsdc: (params: StakeVesuUsdcInput) => void;\n stakeVesuUsdcAsync: (params: StakeVesuUsdcInput) => Promise<string>;\n data: string | undefined;\n isLoading: boolean;\n isError: boolean;\n error: Error | null;\n isSuccess: boolean;\n reset: () => void;\n} {\n const { chipiSDK } = useChipiContext();\n\n const mutation: UseMutationResult<string, Error, StakeVesuUsdcInput> =\n useMutation({\n mutationFn: (params: StakeVesuUsdcInput) =>\n chipiSDK.stakeVesuUsdc(params),\n });\n\n return {\n stakeVesuUsdc: mutation.mutate,\n stakeVesuUsdcAsync: mutation.mutateAsync,\n data: mutation.data,\n isLoading: mutation.isPending,\n isError: mutation.isError,\n error: mutation.error,\n isSuccess: mutation.isSuccess,\n reset: mutation.reset,\n };\n}\n","import { useMutation, type UseMutationResult } from \"@tanstack/react-query\";\nimport { useChipiContext } from \"../context\";\nimport type { WithdrawVesuUsdcParams } from \"@chipi-stack/types\";\n\ntype WithdrawVesuUsdcInput = {\n params: WithdrawVesuUsdcParams;\n bearerToken: string;\n};\n\n/**\n * Hook for withdrawing USDC from Vesu protocol\n */\nexport function useWithdrawVesuUsdc(): {\n withdrawVesuUsdc: (params: WithdrawVesuUsdcInput) => void;\n withdrawVesuUsdcAsync: (params: WithdrawVesuUsdcInput) => Promise<string>;\n data: string | undefined;\n isLoading: boolean;\n isError: boolean;\n error: Error | null;\n isSuccess: boolean;\n reset: () => void;\n} {\n const { chipiSDK } = useChipiContext();\n\n const mutation: UseMutationResult<string, Error, WithdrawVesuUsdcInput> =\n useMutation({\n mutationFn: (params: WithdrawVesuUsdcInput) =>\n chipiSDK.withdrawVesuUsdc(params),\n });\n\n return {\n withdrawVesuUsdc: mutation.mutate,\n withdrawVesuUsdcAsync: mutation.mutateAsync,\n data: mutation.data,\n isLoading: mutation.isPending,\n isError: mutation.isError,\n error: mutation.error,\n isSuccess: mutation.isSuccess,\n reset: mutation.reset,\n };\n}\n","import { useMutation, type UseMutationResult } from \"@tanstack/react-query\";\nimport { useChipiContext } from \"../context\";\nimport type { CallAnyContractParams } from \"@chipi-stack/types\";\n\ntype CallAnyContractInput = {\n params: CallAnyContractParams;\n bearerToken: string;\n};\n\n/**\n * Hook for calling any contract method\n */\nexport function useCallAnyContract(): {\n callAnyContract: (params: CallAnyContractInput) => void;\n callAnyContractAsync: (params: CallAnyContractInput) => Promise<string>;\n data: string | undefined;\n isLoading: boolean;\n isError: boolean;\n error: Error | null;\n isSuccess: boolean;\n reset: () => void;\n} {\n const { chipiSDK } = useChipiContext();\n\n const mutation: UseMutationResult<string, Error, CallAnyContractInput> =\n useMutation({\n mutationFn: (params: CallAnyContractInput) =>\n chipiSDK.callAnyContract(params),\n });\n\n return {\n callAnyContract: mutation.mutate,\n callAnyContractAsync: mutation.mutateAsync,\n data: mutation.data,\n isLoading: mutation.isPending,\n isError: mutation.isError,\n error: mutation.error,\n isSuccess: mutation.isSuccess,\n reset: mutation.reset,\n };\n}\n","import { useMutation, type UseMutationResult } from \"@tanstack/react-query\";\nimport { useChipiContext } from \"../context\";\nimport type {\n RecordSendTransactionParams,\n Transaction,\n} from \"@chipi-stack/types\";\n\ntype RecordSendTransactionInput = {\n params: RecordSendTransactionParams;\n bearerToken: string;\n};\n\nexport function useRecordSendTransaction(): {\n recordSendTransaction: (input: RecordSendTransactionInput) => void;\n recordSendTransactionAsync: (\n input: RecordSendTransactionInput\n ) => Promise<Transaction>;\n data: Transaction | undefined;\n isLoading: boolean;\n isError: boolean;\n error: Error | null;\n isSuccess: boolean;\n reset: () => void;\n} {\n const { chipiSDK } = useChipiContext();\n\n const mutation: UseMutationResult<\n Transaction,\n Error,\n RecordSendTransactionInput\n > = useMutation({\n mutationFn: (input: RecordSendTransactionInput) =>\n chipiSDK.recordSendTransaction({\n params: input.params,\n bearerToken: input.bearerToken,\n }),\n });\n\n return {\n recordSendTransaction: mutation.mutate,\n recordSendTransactionAsync: mutation.mutateAsync,\n data: mutation.data,\n isLoading: mutation.isPending,\n isError: mutation.isError,\n error: mutation.error,\n isSuccess: mutation.isSuccess,\n reset: mutation.reset,\n };\n}\n"]}
|
|
1
|
+
{"version":3,"sources":["../src/context/ChipiProvider.tsx","../src/hooks/useCreateWallet.ts","../src/hooks/useGetWallet.ts","../src/hooks/useTransfer.ts","../src/hooks/useApprove.ts","../src/hooks/useStakeVesuUsdc.ts","../src/hooks/useWithdrawVesuUsdc.ts","../src/hooks/useCallAnyContract.ts","../src/hooks/useRecordSendTransaction.ts","../src/hooks/useGetTokenBalance.ts"],"names":["createContext","useContext","useMutation","useQueryClient","useQuery"],"mappings":";;;;;;;;AAUA,IAAM,YAAA,GAAeA,oBAAwC,IAAI,CAAA;AAuD1D,SAAS,eAAA,GAAqC;AACnD,EAAA,MAAM,OAAA,GAAUC,iBAAW,YAAY,CAAA;AAEvC,EAAA,IAAI,CAAC,OAAA,EAAS;AACZ,IAAA,MAAM,IAAI,MAAM,qDAAqD,CAAA;AAAA,EACvE;AAEA,EAAA,OAAO,OAAA;AACT;;;AC1DO,SAAS,eAAA,GAWd;AACA,EAAA,MAAM,EAAE,QAAA,EAAS,GAAI,eAAA,EAAgB;AAErC,EAAA,MAAM,WAIFC,sBAAA,CAAY;AAAA,IACd,UAAA,EAAY,CAAC,KAAA,KACX,QAAA,CAAS,YAAA,CAAa;AAAA,MACpB,QAAQ,KAAA,CAAM,MAAA;AAAA,MACd,aAAa,KAAA,CAAM;AAAA,KACpB;AAAA,GACJ,CAAA;AAED,EAAA,OAAO;AAAA,IACL,cAAc,QAAA,CAAS,MAAA;AAAA,IACvB,mBAAmB,QAAA,CAAS,WAAA;AAAA,IAC5B,MAAM,QAAA,CAAS,IAAA;AAAA,IACf,WAAW,QAAA,CAAS,SAAA;AAAA,IACpB,SAAS,QAAA,CAAS,OAAA;AAAA,IAClB,OAAO,QAAA,CAAS,KAAA;AAAA,IAChB,WAAW,QAAA,CAAS,SAAA;AAAA,IACpB,OAAO,QAAA,CAAS;AAAA,GAClB;AACF;ACvCO,SAAS,aAAa,KAAA,EAAwB;AACnD,EAAA,MAAM,EAAE,QAAA,EAAS,GAAI,eAAA,EAAgB;AACrC,EAAA,MAAM,cAAcC,yBAAA,EAAe;AAEnC,EAAA,MAAM,QAAQC,mBAAA,CAA4B;AAAA,IACxC,QAAA,EAAU,CAAC,QAAA,EAAU,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react\";\nimport { QueryClient, QueryClientProvider } from \"@tanstack/react-query\";\nimport { ChipiSDK } from \"@chipi-stack/backend\";\nimport type { ChipiSDKConfig } from \"@chipi-stack/types\";\n\ninterface ChipiContextValue {\n chipiSDK: ChipiSDK;\n config: ChipiSDKConfig;\n}\n\nconst ChipiContext = createContext<ChipiContextValue | null>(null);\n\ninterface ChipiProviderProps {\n children: ReactNode;\n config: ChipiSDKConfig;\n}\n\n// Default QueryClient configuration\nconst createDefaultQueryClient = () =>\n new QueryClient({\n defaultOptions: {\n queries: {\n staleTime: 60 * 1000, // 1 minute\n gcTime: 10 * 60 * 1000, // 10 minutes (formerly cacheTime)\n retry: (failureCount, error: any) => {\n // Don't retry on 4xx errors\n if (error?.status >= 400 && error?.status < 500) {\n return false;\n }\n return failureCount < 3;\n },\n },\n mutations: {\n retry: false,\n },\n },\n });\n\n/**\n * Provider component that wraps your app and provides Chipi SDK context with QueryClient\n */\nexport function ChipiProvider({ children, config }: ChipiProviderProps) {\n // Create QueryClient\n const queryClient = React.useMemo(() => createDefaultQueryClient(), []);\n\n const chipiSDK = React.useMemo(() => new ChipiSDK(config), [config]);\n\n const value = React.useMemo(\n () => ({\n chipiSDK,\n config,\n }),\n [chipiSDK, config]\n );\n\n return (\n <QueryClientProvider client={queryClient}>\n <ChipiContext.Provider value={value}>{children}</ChipiContext.Provider>\n </QueryClientProvider>\n );\n}\n\n/**\n * Hook to access Chipi SDK context\n */\nexport function useChipiContext(): ChipiContextValue {\n const context = useContext(ChipiContext);\n\n if (!context) {\n throw new Error(\"useChipiContext must be used within a ChipiProvider\");\n }\n\n return context;\n}\n","import { useMutation, type UseMutationResult } from \"@tanstack/react-query\";\nimport { useChipiContext } from \"../context\";\nimport type {\n CreateWalletParams,\n CreateWalletResponse,\n} from \"@chipi-stack/types\";\n\ntype CreateWalletInput = {\n params: CreateWalletParams;\n bearerToken: string;\n};\n\n/**\n * Hook for creating a new wallet\n */\nexport function useCreateWallet(): {\n createWallet: (input: CreateWalletInput) => void;\n createWalletAsync: (\n input: CreateWalletInput\n ) => Promise<CreateWalletResponse>;\n data: CreateWalletResponse | undefined;\n isLoading: boolean;\n isError: boolean;\n error: Error | null;\n isSuccess: boolean;\n reset: () => void;\n} {\n const { chipiSDK } = useChipiContext();\n\n const mutation: UseMutationResult<\n CreateWalletResponse,\n Error,\n CreateWalletInput\n > = useMutation({\n mutationFn: (input: CreateWalletInput) =>\n chipiSDK.createWallet({\n params: input.params,\n bearerToken: input.bearerToken,\n }),\n });\n\n return {\n createWallet: mutation.mutate,\n createWalletAsync: mutation.mutateAsync,\n data: mutation.data,\n isLoading: mutation.isPending,\n isError: mutation.isError,\n error: mutation.error,\n isSuccess: mutation.isSuccess,\n reset: mutation.reset,\n };\n}\n","\"use client\";\n\nimport { useQuery, useQueryClient, type UseQueryOptions } from \"@tanstack/react-query\";\nimport { GetWalletParams, WalletData } from \"@chipi-stack/types\";\nimport { useChipiContext } from \"../context\";\n\ntype GetWalletInput = {\n params?: GetWalletParams;\n getBearerToken?: () => Promise<string | null | undefined>;\n queryOptions?: Omit<UseQueryOptions<WalletData, Error>, 'queryKey' | 'queryFn'>;\n};\n\nexport function useGetWallet(input?: GetWalletInput) {\n const { chipiSDK } = useChipiContext();\n const queryClient = useQueryClient();\n \n const query = useQuery<WalletData, Error>({\n queryKey: [\"wallet\", input?.params?.externalUserId],\n queryFn: async () => {\n if (!input || !input.params || !input.getBearerToken) throw new Error(\"Input is required\");\n const bearerToken = await input.getBearerToken();\n if (!bearerToken) throw new Error(\"Bearer token is required\");\n return chipiSDK.getWallet(input.params, bearerToken);\n },\n enabled: Boolean(input?.params && input?.getBearerToken),\n ...input?.queryOptions\n });\n\n const fetchWallet = async (newInput: GetWalletInput) => {\n return queryClient.fetchQuery({\n queryKey: [\"wallet\", newInput?.params?.externalUserId],\n queryFn: async () => {\n if (!newInput || !newInput.getBearerToken || !newInput.params) throw new Error(\"Input is required\");\n const bearerToken = await newInput.getBearerToken();\n if (!bearerToken) throw new Error(\"Bearer token is required\");\n return chipiSDK.getWallet(newInput.params, bearerToken);\n },\n });\n };\n\n return {\n ...query,\n fetchWallet,\n };\n}\n","import { useMutation, type UseMutationResult } from \"@tanstack/react-query\";\nimport { useChipiContext } from \"../context\";\nimport type { TransferParams } from \"@chipi-stack/types\";\n\ntype TransferInput = { params: TransferParams; bearerToken: string };\n\n/**\n * Hook for transferring tokens\n */\nexport function useTransfer(): {\n transfer: (input: TransferInput) => void;\n transferAsync: (input: TransferInput) => Promise<string>;\n data: string | undefined;\n isLoading: boolean;\n isError: boolean;\n error: Error | null;\n isSuccess: boolean;\n reset: () => void;\n} {\n const { chipiSDK } = useChipiContext();\n\n const mutation: UseMutationResult<string, Error, TransferInput> = useMutation(\n {\n mutationFn: (input: TransferInput) =>\n chipiSDK.transfer({\n params: input.params,\n bearerToken: input.bearerToken,\n }),\n }\n );\n\n return {\n transfer: mutation.mutate,\n transferAsync: mutation.mutateAsync,\n data: mutation.data,\n isLoading: mutation.isPending,\n isError: mutation.isError,\n error: mutation.error,\n isSuccess: mutation.isSuccess,\n reset: mutation.reset,\n };\n}\n","import { useMutation, type UseMutationResult } from \"@tanstack/react-query\";\nimport { useChipiContext } from \"../context\";\nimport type { ApproveParams } from \"@chipi-stack/types\";\n\ntype ApproveInput = {\n params: ApproveParams;\n bearerToken: string;\n};\n\n/**\n * Hook for approving token spending\n */\nexport function useApprove(): {\n approve: (params: ApproveInput) => void;\n approveAsync: (params: ApproveInput) => Promise<string>;\n data: string | undefined;\n isLoading: boolean;\n isError: boolean;\n error: Error | null;\n isSuccess: boolean;\n reset: () => void;\n} {\n const { chipiSDK } = useChipiContext();\n\n const mutation: UseMutationResult<string, Error, ApproveInput> = useMutation({\n mutationFn: (params: ApproveInput) => chipiSDK.approve(params),\n });\n\n return {\n approve: mutation.mutate,\n approveAsync: mutation.mutateAsync,\n data: mutation.data,\n isLoading: mutation.isPending,\n isError: mutation.isError,\n error: mutation.error,\n isSuccess: mutation.isSuccess,\n reset: mutation.reset,\n };\n}\n","import { useMutation, type UseMutationResult } from \"@tanstack/react-query\";\nimport { useChipiContext } from \"../context\";\nimport type { StakeVesuUsdcParams } from \"@chipi-stack/types\";\n\ntype StakeVesuUsdcInput = {\n params: StakeVesuUsdcParams;\n bearerToken: string;\n};\n\n/**\n * Hook for staking USDC in Vesu protocol\n */\nexport function useStakeVesuUsdc(): {\n stakeVesuUsdc: (params: StakeVesuUsdcInput) => void;\n stakeVesuUsdcAsync: (params: StakeVesuUsdcInput) => Promise<string>;\n data: string | undefined;\n isLoading: boolean;\n isError: boolean;\n error: Error | null;\n isSuccess: boolean;\n reset: () => void;\n} {\n const { chipiSDK } = useChipiContext();\n\n const mutation: UseMutationResult<string, Error, StakeVesuUsdcInput> =\n useMutation({\n mutationFn: (params: StakeVesuUsdcInput) =>\n chipiSDK.stakeVesuUsdc(params),\n });\n\n return {\n stakeVesuUsdc: mutation.mutate,\n stakeVesuUsdcAsync: mutation.mutateAsync,\n data: mutation.data,\n isLoading: mutation.isPending,\n isError: mutation.isError,\n error: mutation.error,\n isSuccess: mutation.isSuccess,\n reset: mutation.reset,\n };\n}\n","import { useMutation, type UseMutationResult } from \"@tanstack/react-query\";\nimport { useChipiContext } from \"../context\";\nimport type { WithdrawVesuUsdcParams } from \"@chipi-stack/types\";\n\ntype WithdrawVesuUsdcInput = {\n params: WithdrawVesuUsdcParams;\n bearerToken: string;\n};\n\n/**\n * Hook for withdrawing USDC from Vesu protocol\n */\nexport function useWithdrawVesuUsdc(): {\n withdrawVesuUsdc: (params: WithdrawVesuUsdcInput) => void;\n withdrawVesuUsdcAsync: (params: WithdrawVesuUsdcInput) => Promise<string>;\n data: string | undefined;\n isLoading: boolean;\n isError: boolean;\n error: Error | null;\n isSuccess: boolean;\n reset: () => void;\n} {\n const { chipiSDK } = useChipiContext();\n\n const mutation: UseMutationResult<string, Error, WithdrawVesuUsdcInput> =\n useMutation({\n mutationFn: (params: WithdrawVesuUsdcInput) =>\n chipiSDK.withdrawVesuUsdc(params),\n });\n\n return {\n withdrawVesuUsdc: mutation.mutate,\n withdrawVesuUsdcAsync: mutation.mutateAsync,\n data: mutation.data,\n isLoading: mutation.isPending,\n isError: mutation.isError,\n error: mutation.error,\n isSuccess: mutation.isSuccess,\n reset: mutation.reset,\n };\n}\n","import { useMutation, type UseMutationResult } from \"@tanstack/react-query\";\nimport { useChipiContext } from \"../context\";\nimport type { CallAnyContractParams } from \"@chipi-stack/types\";\n\ntype CallAnyContractInput = {\n params: CallAnyContractParams;\n bearerToken: string;\n};\n\n/**\n * Hook for calling any contract method\n */\nexport function useCallAnyContract(): {\n callAnyContract: (params: CallAnyContractInput) => void;\n callAnyContractAsync: (params: CallAnyContractInput) => Promise<string>;\n data: string | undefined;\n isLoading: boolean;\n isError: boolean;\n error: Error | null;\n isSuccess: boolean;\n reset: () => void;\n} {\n const { chipiSDK } = useChipiContext();\n\n const mutation: UseMutationResult<string, Error, CallAnyContractInput> =\n useMutation({\n mutationFn: (params: CallAnyContractInput) =>\n chipiSDK.callAnyContract(params),\n });\n\n return {\n callAnyContract: mutation.mutate,\n callAnyContractAsync: mutation.mutateAsync,\n data: mutation.data,\n isLoading: mutation.isPending,\n isError: mutation.isError,\n error: mutation.error,\n isSuccess: mutation.isSuccess,\n reset: mutation.reset,\n };\n}\n","import { useMutation, type UseMutationResult } from \"@tanstack/react-query\";\nimport { useChipiContext } from \"../context\";\nimport type {\n RecordSendTransactionParams,\n Transaction,\n} from \"@chipi-stack/types\";\n\ntype RecordSendTransactionInput = {\n params: RecordSendTransactionParams;\n bearerToken: string;\n};\n\nexport function useRecordSendTransaction(): {\n recordSendTransaction: (input: RecordSendTransactionInput) => void;\n recordSendTransactionAsync: (\n input: RecordSendTransactionInput\n ) => Promise<Transaction>;\n data: Transaction | undefined;\n isLoading: boolean;\n isError: boolean;\n error: Error | null;\n isSuccess: boolean;\n reset: () => void;\n} {\n const { chipiSDK } = useChipiContext();\n\n const mutation: UseMutationResult<\n Transaction,\n Error,\n RecordSendTransactionInput\n > = useMutation({\n mutationFn: (input: RecordSendTransactionInput) =>\n chipiSDK.recordSendTransaction({\n params: input.params,\n bearerToken: input.bearerToken,\n }),\n });\n\n return {\n recordSendTransaction: mutation.mutate,\n recordSendTransactionAsync: mutation.mutateAsync,\n data: mutation.data,\n isLoading: mutation.isPending,\n isError: mutation.isError,\n error: mutation.error,\n isSuccess: mutation.isSuccess,\n reset: mutation.reset,\n };\n}\n","\"use client\";\n\nimport { useQuery, useQueryClient, type UseQueryOptions } from \"@tanstack/react-query\";\nimport {\n GetTokenBalanceParams,\n GetTokenBalanceResponse,\n} from \"@chipi-stack/types\";\nimport { useChipiContext } from \"../context\";\n\ntype GetTokenBalanceInput = {\n params?: GetTokenBalanceParams;\n getBearerToken?: () => Promise<string | null | undefined>;\n queryOptions?: Omit<UseQueryOptions<GetTokenBalanceResponse, Error>, 'queryKey' | 'queryFn'>;\n};\n\nexport function useGetTokenBalance(input?: GetTokenBalanceInput) {\n const { chipiSDK } = useChipiContext();\n const queryClient = useQueryClient();\n \n const query = useQuery<GetTokenBalanceResponse, Error>({\n queryKey: [\"chain-token-balance\", input?.params?.chainToken, input?.params?.chain, input?.params?.walletPublicKey, input?.params?.externalUserId],\n queryFn: async () => {\n if (!input || !input.params || !input.getBearerToken) throw new Error(\"Input is required\");\n const bearerToken = await input.getBearerToken();\n if (!bearerToken) throw new Error(\"Bearer token is required\");\n return chipiSDK.getTokenBalance(input.params, bearerToken);\n },\n enabled: Boolean(input?.params && input?.getBearerToken),\n ...input?.queryOptions\n });\n\n const fetchTokenBalance = async (newInput: GetTokenBalanceInput) => {\n return queryClient.fetchQuery({\n queryKey: [\"chain-token-balance\", newInput?.params?.chainToken, newInput?.params?.chain, newInput?.params?.walletPublicKey, newInput?.params?.externalUserId],\n queryFn: async () => {\n if (!newInput || !newInput.getBearerToken || !newInput.params) throw new Error(\"Input is required\");\n const bearerToken = await newInput.getBearerToken();\n if (!bearerToken) throw new Error(\"Bearer token is required\");\n return chipiSDK.getTokenBalance(newInput.params, bearerToken);\n },\n });\n };\n\n return {\n ...query,\n fetchTokenBalance,\n };\n}\n"]}
|