@zkp2p/sdk 0.0.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/react.cjs ADDED
@@ -0,0 +1,798 @@
1
+ 'use strict';
2
+
3
+ var react = require('react');
4
+ var viem = require('viem');
5
+
6
+ // src/react/hooks/useCreateDeposit.ts
7
+ function useCreateDeposit({ client, onSuccess, onError }) {
8
+ const [isLoading, setIsLoading] = react.useState(false);
9
+ const [error, setError] = react.useState(null);
10
+ const [txHash, setTxHash] = react.useState(null);
11
+ const [depositDetails, setDepositDetails] = react.useState(null);
12
+ const createDeposit = react.useCallback(
13
+ async (params) => {
14
+ if (!client) {
15
+ const err = new Error("Zkp2pClient is not initialized");
16
+ setError(err);
17
+ onError?.(err);
18
+ return null;
19
+ }
20
+ setIsLoading(true);
21
+ setError(null);
22
+ setTxHash(null);
23
+ setDepositDetails(null);
24
+ try {
25
+ const result = await client.createDeposit(params);
26
+ setTxHash(result.hash);
27
+ setDepositDetails(result.depositDetails);
28
+ onSuccess?.(result);
29
+ return result;
30
+ } catch (err) {
31
+ const e = err instanceof Error ? err : new Error(String(err));
32
+ setError(e);
33
+ onError?.(e);
34
+ return null;
35
+ } finally {
36
+ setIsLoading(false);
37
+ }
38
+ },
39
+ [client, onSuccess, onError]
40
+ );
41
+ return react.useMemo(() => ({ createDeposit, isLoading, error, txHash, depositDetails }), [createDeposit, isLoading, error, txHash, depositDetails]);
42
+ }
43
+ function useSignalIntent({ client, onSuccess, onError }) {
44
+ const [isLoading, setIsLoading] = react.useState(false);
45
+ const [error, setError] = react.useState(null);
46
+ const [txHash, setTxHash] = react.useState(null);
47
+ const signalIntent = react.useCallback(
48
+ async (params) => {
49
+ if (!client) {
50
+ const err = new Error("Zkp2pClient is not initialized");
51
+ setError(err);
52
+ onError?.(err);
53
+ return null;
54
+ }
55
+ setIsLoading(true);
56
+ setError(null);
57
+ setTxHash(null);
58
+ try {
59
+ const hash = await client.signalIntent(params);
60
+ setTxHash(hash);
61
+ onSuccess?.(hash);
62
+ return hash;
63
+ } catch (err) {
64
+ const e = err instanceof Error ? err : new Error(String(err));
65
+ setError(e);
66
+ onError?.(e);
67
+ return null;
68
+ } finally {
69
+ setIsLoading(false);
70
+ }
71
+ },
72
+ [client, onSuccess, onError]
73
+ );
74
+ return react.useMemo(() => ({ signalIntent, isLoading, error, txHash }), [signalIntent, isLoading, error, txHash]);
75
+ }
76
+ function useGetTakerTier({
77
+ client,
78
+ owner,
79
+ chainId,
80
+ autoFetch = true,
81
+ onSuccess,
82
+ onError
83
+ }) {
84
+ const [isLoading, setIsLoading] = react.useState(false);
85
+ const [error, setError] = react.useState(null);
86
+ const [takerTier, setTakerTier] = react.useState(null);
87
+ const getTakerTier = react.useCallback(
88
+ async (params) => {
89
+ if (!client) {
90
+ const err = new Error("Zkp2pClient is not initialized");
91
+ setError(err);
92
+ onError?.(err);
93
+ return null;
94
+ }
95
+ const request = params ?? (owner && chainId ? { owner, chainId } : null);
96
+ if (!request) {
97
+ const err = new Error("Owner address and chainId are required");
98
+ setError(err);
99
+ onError?.(err);
100
+ return null;
101
+ }
102
+ setIsLoading(true);
103
+ setError(null);
104
+ setTakerTier(null);
105
+ try {
106
+ const response = await client.getTakerTier(request);
107
+ setTakerTier(response.responseObject);
108
+ onSuccess?.(response.responseObject);
109
+ return response;
110
+ } catch (err) {
111
+ const e = err instanceof Error ? err : new Error(String(err));
112
+ setError(e);
113
+ onError?.(e);
114
+ return null;
115
+ } finally {
116
+ setIsLoading(false);
117
+ }
118
+ },
119
+ [client, owner, chainId, onSuccess, onError]
120
+ );
121
+ react.useEffect(() => {
122
+ if (!autoFetch || !owner || !chainId) return;
123
+ void getTakerTier({ owner, chainId });
124
+ }, [autoFetch, owner, chainId, getTakerTier]);
125
+ return react.useMemo(
126
+ () => ({ getTakerTier, takerTier, isLoading, error }),
127
+ [getTakerTier, takerTier, isLoading, error]
128
+ );
129
+ }
130
+ var TIER_CAPS = {
131
+ PEASANT: 100,
132
+ PEER: 500,
133
+ PLUS: 5e3,
134
+ PRO: 1e4,
135
+ PLATINUM: 25e3
136
+ };
137
+ function getNextTierCap(currentTier) {
138
+ if (!currentTier) return null;
139
+ const tierOrder = ["PEASANT", "PEER", "PLUS", "PRO", "PLATINUM"];
140
+ const currentIndex = tierOrder.indexOf(currentTier);
141
+ if (currentIndex === -1 || currentIndex >= tierOrder.length - 1) {
142
+ return null;
143
+ }
144
+ const nextTier = tierOrder[currentIndex + 1];
145
+ const nextCap = TIER_CAPS[nextTier];
146
+ return nextCap ? `$${nextCap.toLocaleString()}` : null;
147
+ }
148
+ function formatCapFromBaseUnits(baseUnits) {
149
+ if (!baseUnits || baseUnits === "") return "$0";
150
+ const value = Number(viem.formatUnits(BigInt(baseUnits), 6));
151
+ return `$${value.toLocaleString()}`;
152
+ }
153
+ function getTierDisplayInfo(tier) {
154
+ if (!tier) {
155
+ return {
156
+ tierLabel: "Loading...",
157
+ capDisplay: "...",
158
+ isNewUser: false,
159
+ showScore: false
160
+ };
161
+ }
162
+ const isNewUser = tier.source === "fallback";
163
+ const isZeroFulfills = tier.stats?.lifetimeFulfilledCount === 0;
164
+ const tierLabels = {
165
+ PEASANT: "Peer Peasant",
166
+ PEER: "Peer",
167
+ PLUS: "Peer Plus",
168
+ PRO: "Peer Pro",
169
+ PLATINUM: "Peer Platinum"
170
+ };
171
+ const capDisplay = formatCapFromBaseUnits(tier.perIntentCapBaseUnits);
172
+ return {
173
+ tierLabel: tierLabels[tier.tier] || tier.tier,
174
+ capDisplay,
175
+ isNewUser: isNewUser || isZeroFulfills,
176
+ showScore: !isNewUser && !!tier.stats && tier.stats.lockScoreDiluted !== "0"
177
+ };
178
+ }
179
+ function useFulfillIntent({ client, onSuccess, onError }) {
180
+ const [isLoading, setIsLoading] = react.useState(false);
181
+ const [error, setError] = react.useState(null);
182
+ const [txHash, setTxHash] = react.useState(null);
183
+ const fulfillIntent = react.useCallback(
184
+ async (params) => {
185
+ if (!client) {
186
+ const err = new Error("Zkp2pClient is not initialized");
187
+ setError(err);
188
+ onError?.(err);
189
+ return null;
190
+ }
191
+ setIsLoading(true);
192
+ setError(null);
193
+ setTxHash(null);
194
+ try {
195
+ const hash = await client.fulfillIntent(params);
196
+ setTxHash(hash);
197
+ onSuccess?.(hash);
198
+ return hash;
199
+ } catch (err) {
200
+ const e = err instanceof Error ? err : new Error(String(err));
201
+ setError(e);
202
+ onError?.(e);
203
+ return null;
204
+ } finally {
205
+ setIsLoading(false);
206
+ }
207
+ },
208
+ [client, onSuccess, onError]
209
+ );
210
+ return react.useMemo(() => ({ fulfillIntent, isLoading, error, txHash }), [fulfillIntent, isLoading, error, txHash]);
211
+ }
212
+ function useReleaseFundsToPayer({ client, onSuccess, onError }) {
213
+ const [isLoading, setIsLoading] = react.useState(false);
214
+ const [error, setError] = react.useState(null);
215
+ const [txHash, setTxHash] = react.useState(null);
216
+ const releaseFundsToPayer = react.useCallback(
217
+ async (params) => {
218
+ if (!client) {
219
+ const err = new Error("Zkp2pClient is not initialized");
220
+ setError(err);
221
+ onError?.(err);
222
+ return null;
223
+ }
224
+ setIsLoading(true);
225
+ setError(null);
226
+ setTxHash(null);
227
+ try {
228
+ const hash = await client.releaseFundsToPayer(params);
229
+ setTxHash(hash);
230
+ onSuccess?.(hash);
231
+ return hash;
232
+ } catch (err) {
233
+ const e = err instanceof Error ? err : new Error(String(err));
234
+ setError(e);
235
+ onError?.(e);
236
+ return null;
237
+ } finally {
238
+ setIsLoading(false);
239
+ }
240
+ },
241
+ [client, onSuccess, onError]
242
+ );
243
+ return react.useMemo(() => ({ releaseFundsToPayer, isLoading, error, txHash }), [releaseFundsToPayer, isLoading, error, txHash]);
244
+ }
245
+ function useSetAcceptingIntents({ client, onSuccess, onError }) {
246
+ const [isLoading, setIsLoading] = react.useState(false);
247
+ const [error, setError] = react.useState(null);
248
+ const [txHash, setTxHash] = react.useState(null);
249
+ const setAcceptingIntents = react.useCallback(
250
+ async (params) => {
251
+ if (!client) {
252
+ const err = new Error("Zkp2pClient is not initialized");
253
+ setError(err);
254
+ onError?.(err);
255
+ return null;
256
+ }
257
+ setIsLoading(true);
258
+ setError(null);
259
+ setTxHash(null);
260
+ try {
261
+ const hash = await client.setAcceptingIntents(params);
262
+ setTxHash(hash);
263
+ onSuccess?.(hash);
264
+ return hash;
265
+ } catch (err) {
266
+ const e = err instanceof Error ? err : new Error(String(err));
267
+ setError(e);
268
+ onError?.(e);
269
+ return null;
270
+ } finally {
271
+ setIsLoading(false);
272
+ }
273
+ },
274
+ [client, onSuccess, onError]
275
+ );
276
+ return react.useMemo(() => ({ setAcceptingIntents, isLoading, error, txHash }), [setAcceptingIntents, isLoading, error, txHash]);
277
+ }
278
+ function useSetIntentRange({ client, onSuccess, onError }) {
279
+ const [isLoading, setIsLoading] = react.useState(false);
280
+ const [error, setError] = react.useState(null);
281
+ const [txHash, setTxHash] = react.useState(null);
282
+ const setIntentRange = react.useCallback(
283
+ async (params) => {
284
+ if (!client) {
285
+ const err = new Error("Zkp2pClient is not initialized");
286
+ setError(err);
287
+ onError?.(err);
288
+ return null;
289
+ }
290
+ setIsLoading(true);
291
+ setError(null);
292
+ setTxHash(null);
293
+ try {
294
+ const hash = await client.setIntentRange(params);
295
+ setTxHash(hash);
296
+ onSuccess?.(hash);
297
+ return hash;
298
+ } catch (err) {
299
+ const e = err instanceof Error ? err : new Error(String(err));
300
+ setError(e);
301
+ onError?.(e);
302
+ return null;
303
+ } finally {
304
+ setIsLoading(false);
305
+ }
306
+ },
307
+ [client, onSuccess, onError]
308
+ );
309
+ return react.useMemo(() => ({ setIntentRange, isLoading, error, txHash }), [setIntentRange, isLoading, error, txHash]);
310
+ }
311
+ function useSetCurrencyMinRate({ client, onSuccess, onError }) {
312
+ const [isLoading, setIsLoading] = react.useState(false);
313
+ const [error, setError] = react.useState(null);
314
+ const [txHash, setTxHash] = react.useState(null);
315
+ const setCurrencyMinRate = react.useCallback(
316
+ async (params) => {
317
+ if (!client) {
318
+ const err = new Error("Zkp2pClient is not initialized");
319
+ setError(err);
320
+ onError?.(err);
321
+ return null;
322
+ }
323
+ setIsLoading(true);
324
+ setError(null);
325
+ setTxHash(null);
326
+ try {
327
+ const hash = await client.setCurrencyMinRate(params);
328
+ setTxHash(hash);
329
+ onSuccess?.(hash);
330
+ return hash;
331
+ } catch (err) {
332
+ const e = err instanceof Error ? err : new Error(String(err));
333
+ setError(e);
334
+ onError?.(e);
335
+ return null;
336
+ } finally {
337
+ setIsLoading(false);
338
+ }
339
+ },
340
+ [client, onSuccess, onError]
341
+ );
342
+ return react.useMemo(() => ({ setCurrencyMinRate, isLoading, error, txHash }), [setCurrencyMinRate, isLoading, error, txHash]);
343
+ }
344
+ function useAddFunds({ client, onSuccess, onError }) {
345
+ const [isLoading, setIsLoading] = react.useState(false);
346
+ const [error, setError] = react.useState(null);
347
+ const [txHash, setTxHash] = react.useState(null);
348
+ const addFunds = react.useCallback(
349
+ async (params) => {
350
+ if (!client) {
351
+ const err = new Error("Zkp2pClient is not initialized");
352
+ setError(err);
353
+ onError?.(err);
354
+ return null;
355
+ }
356
+ setIsLoading(true);
357
+ setError(null);
358
+ setTxHash(null);
359
+ try {
360
+ const hash = await client.addFunds(params);
361
+ setTxHash(hash);
362
+ onSuccess?.(hash);
363
+ return hash;
364
+ } catch (err) {
365
+ const e = err instanceof Error ? err : new Error(String(err));
366
+ setError(e);
367
+ onError?.(e);
368
+ return null;
369
+ } finally {
370
+ setIsLoading(false);
371
+ }
372
+ },
373
+ [client, onSuccess, onError]
374
+ );
375
+ return react.useMemo(() => ({ addFunds, isLoading, error, txHash }), [addFunds, isLoading, error, txHash]);
376
+ }
377
+ function useRemoveFunds({ client, onSuccess, onError }) {
378
+ const [isLoading, setIsLoading] = react.useState(false);
379
+ const [error, setError] = react.useState(null);
380
+ const [txHash, setTxHash] = react.useState(null);
381
+ const removeFunds = react.useCallback(
382
+ async (params) => {
383
+ if (!client) {
384
+ const err = new Error("Zkp2pClient is not initialized");
385
+ setError(err);
386
+ onError?.(err);
387
+ return null;
388
+ }
389
+ setIsLoading(true);
390
+ setError(null);
391
+ setTxHash(null);
392
+ try {
393
+ const hash = await client.removeFunds(params);
394
+ setTxHash(hash);
395
+ onSuccess?.(hash);
396
+ return hash;
397
+ } catch (err) {
398
+ const e = err instanceof Error ? err : new Error(String(err));
399
+ setError(e);
400
+ onError?.(e);
401
+ return null;
402
+ } finally {
403
+ setIsLoading(false);
404
+ }
405
+ },
406
+ [client, onSuccess, onError]
407
+ );
408
+ return react.useMemo(() => ({ removeFunds, isLoading, error, txHash }), [removeFunds, isLoading, error, txHash]);
409
+ }
410
+ function useWithdrawDeposit({ client, onSuccess, onError }) {
411
+ const [isLoading, setIsLoading] = react.useState(false);
412
+ const [error, setError] = react.useState(null);
413
+ const [txHash, setTxHash] = react.useState(null);
414
+ const withdrawDeposit = react.useCallback(
415
+ async (params) => {
416
+ if (!client) {
417
+ const err = new Error("Zkp2pClient is not initialized");
418
+ setError(err);
419
+ onError?.(err);
420
+ return null;
421
+ }
422
+ setIsLoading(true);
423
+ setError(null);
424
+ setTxHash(null);
425
+ try {
426
+ const hash = await client.withdrawDeposit(params);
427
+ setTxHash(hash);
428
+ onSuccess?.(hash);
429
+ return hash;
430
+ } catch (err) {
431
+ const e = err instanceof Error ? err : new Error(String(err));
432
+ setError(e);
433
+ onError?.(e);
434
+ return null;
435
+ } finally {
436
+ setIsLoading(false);
437
+ }
438
+ },
439
+ [client, onSuccess, onError]
440
+ );
441
+ return react.useMemo(() => ({ withdrawDeposit, isLoading, error, txHash }), [withdrawDeposit, isLoading, error, txHash]);
442
+ }
443
+ function useSetRetainOnEmpty({ client, onSuccess, onError }) {
444
+ const [isLoading, setIsLoading] = react.useState(false);
445
+ const [error, setError] = react.useState(null);
446
+ const [txHash, setTxHash] = react.useState(null);
447
+ const setRetainOnEmpty = react.useCallback(
448
+ async (params) => {
449
+ if (!client) {
450
+ const err = new Error("Zkp2pClient is not initialized");
451
+ setError(err);
452
+ onError?.(err);
453
+ return null;
454
+ }
455
+ setIsLoading(true);
456
+ setError(null);
457
+ setTxHash(null);
458
+ try {
459
+ const hash = await client.setRetainOnEmpty(params);
460
+ setTxHash(hash);
461
+ onSuccess?.(hash);
462
+ return hash;
463
+ } catch (err) {
464
+ const e = err instanceof Error ? err : new Error(String(err));
465
+ setError(e);
466
+ onError?.(e);
467
+ return null;
468
+ } finally {
469
+ setIsLoading(false);
470
+ }
471
+ },
472
+ [client, onSuccess, onError]
473
+ );
474
+ return react.useMemo(() => ({ setRetainOnEmpty, isLoading, error, txHash }), [setRetainOnEmpty, isLoading, error, txHash]);
475
+ }
476
+ function useSetDelegate({ client, onSuccess, onError }) {
477
+ const [isLoading, setIsLoading] = react.useState(false);
478
+ const [error, setError] = react.useState(null);
479
+ const [txHash, setTxHash] = react.useState(null);
480
+ const setDelegate = react.useCallback(
481
+ async (params) => {
482
+ if (!client) {
483
+ const err = new Error("Zkp2pClient is not initialized");
484
+ setError(err);
485
+ onError?.(err);
486
+ return null;
487
+ }
488
+ setIsLoading(true);
489
+ setError(null);
490
+ setTxHash(null);
491
+ try {
492
+ const hash = await client.setDelegate(params);
493
+ setTxHash(hash);
494
+ onSuccess?.(hash);
495
+ return hash;
496
+ } catch (err) {
497
+ const e = err instanceof Error ? err : new Error(String(err));
498
+ setError(e);
499
+ onError?.(e);
500
+ return null;
501
+ } finally {
502
+ setIsLoading(false);
503
+ }
504
+ },
505
+ [client, onSuccess, onError]
506
+ );
507
+ return react.useMemo(() => ({ setDelegate, isLoading, error, txHash }), [setDelegate, isLoading, error, txHash]);
508
+ }
509
+ function useRemoveDelegate({ client, onSuccess, onError }) {
510
+ const [isLoading, setIsLoading] = react.useState(false);
511
+ const [error, setError] = react.useState(null);
512
+ const [txHash, setTxHash] = react.useState(null);
513
+ const removeDelegate = react.useCallback(
514
+ async (params) => {
515
+ if (!client) {
516
+ const err = new Error("Zkp2pClient is not initialized");
517
+ setError(err);
518
+ onError?.(err);
519
+ return null;
520
+ }
521
+ setIsLoading(true);
522
+ setError(null);
523
+ setTxHash(null);
524
+ try {
525
+ const hash = await client.removeDelegate(params);
526
+ setTxHash(hash);
527
+ onSuccess?.(hash);
528
+ return hash;
529
+ } catch (err) {
530
+ const e = err instanceof Error ? err : new Error(String(err));
531
+ setError(e);
532
+ onError?.(e);
533
+ return null;
534
+ } finally {
535
+ setIsLoading(false);
536
+ }
537
+ },
538
+ [client, onSuccess, onError]
539
+ );
540
+ return react.useMemo(() => ({ removeDelegate, isLoading, error, txHash }), [removeDelegate, isLoading, error, txHash]);
541
+ }
542
+ function useAddPaymentMethods({ client, onSuccess, onError }) {
543
+ const [isLoading, setIsLoading] = react.useState(false);
544
+ const [error, setError] = react.useState(null);
545
+ const [txHash, setTxHash] = react.useState(null);
546
+ const addPaymentMethods = react.useCallback(
547
+ async (params) => {
548
+ if (!client) {
549
+ const err = new Error("Zkp2pClient is not initialized");
550
+ setError(err);
551
+ onError?.(err);
552
+ return null;
553
+ }
554
+ setIsLoading(true);
555
+ setError(null);
556
+ setTxHash(null);
557
+ try {
558
+ const hash = await client.addPaymentMethods(params);
559
+ setTxHash(hash);
560
+ onSuccess?.(hash);
561
+ return hash;
562
+ } catch (err) {
563
+ const e = err instanceof Error ? err : new Error(String(err));
564
+ setError(e);
565
+ onError?.(e);
566
+ return null;
567
+ } finally {
568
+ setIsLoading(false);
569
+ }
570
+ },
571
+ [client, onSuccess, onError]
572
+ );
573
+ return react.useMemo(() => ({ addPaymentMethods, isLoading, error, txHash }), [addPaymentMethods, isLoading, error, txHash]);
574
+ }
575
+ function useSetPaymentMethodActive({ client, onSuccess, onError }) {
576
+ const [isLoading, setIsLoading] = react.useState(false);
577
+ const [error, setError] = react.useState(null);
578
+ const [txHash, setTxHash] = react.useState(null);
579
+ const setPaymentMethodActive = react.useCallback(
580
+ async (params) => {
581
+ if (!client) {
582
+ const err = new Error("Zkp2pClient is not initialized");
583
+ setError(err);
584
+ onError?.(err);
585
+ return null;
586
+ }
587
+ setIsLoading(true);
588
+ setError(null);
589
+ setTxHash(null);
590
+ try {
591
+ const hash = await client.setPaymentMethodActive(params);
592
+ setTxHash(hash);
593
+ onSuccess?.(hash);
594
+ return hash;
595
+ } catch (err) {
596
+ const e = err instanceof Error ? err : new Error(String(err));
597
+ setError(e);
598
+ onError?.(e);
599
+ return null;
600
+ } finally {
601
+ setIsLoading(false);
602
+ }
603
+ },
604
+ [client, onSuccess, onError]
605
+ );
606
+ return react.useMemo(() => ({ setPaymentMethodActive, isLoading, error, txHash }), [setPaymentMethodActive, isLoading, error, txHash]);
607
+ }
608
+ function useRemovePaymentMethod({ client, onSuccess, onError }) {
609
+ const [isLoading, setIsLoading] = react.useState(false);
610
+ const [error, setError] = react.useState(null);
611
+ const [txHash, setTxHash] = react.useState(null);
612
+ const removePaymentMethod = react.useCallback(
613
+ async (params) => {
614
+ if (!client) {
615
+ const err = new Error("Zkp2pClient is not initialized");
616
+ setError(err);
617
+ onError?.(err);
618
+ return null;
619
+ }
620
+ setIsLoading(true);
621
+ setError(null);
622
+ setTxHash(null);
623
+ try {
624
+ const hash = await client.removePaymentMethod(params);
625
+ setTxHash(hash);
626
+ onSuccess?.(hash);
627
+ return hash;
628
+ } catch (err) {
629
+ const e = err instanceof Error ? err : new Error(String(err));
630
+ setError(e);
631
+ onError?.(e);
632
+ return null;
633
+ } finally {
634
+ setIsLoading(false);
635
+ }
636
+ },
637
+ [client, onSuccess, onError]
638
+ );
639
+ return react.useMemo(() => ({ removePaymentMethod, isLoading, error, txHash }), [removePaymentMethod, isLoading, error, txHash]);
640
+ }
641
+ function useAddCurrencies({ client, onSuccess, onError }) {
642
+ const [isLoading, setIsLoading] = react.useState(false);
643
+ const [error, setError] = react.useState(null);
644
+ const [txHash, setTxHash] = react.useState(null);
645
+ const addCurrencies = react.useCallback(
646
+ async (params) => {
647
+ if (!client) {
648
+ const err = new Error("Zkp2pClient is not initialized");
649
+ setError(err);
650
+ onError?.(err);
651
+ return null;
652
+ }
653
+ setIsLoading(true);
654
+ setError(null);
655
+ setTxHash(null);
656
+ try {
657
+ const hash = await client.addCurrencies(params);
658
+ setTxHash(hash);
659
+ onSuccess?.(hash);
660
+ return hash;
661
+ } catch (err) {
662
+ const e = err instanceof Error ? err : new Error(String(err));
663
+ setError(e);
664
+ onError?.(e);
665
+ return null;
666
+ } finally {
667
+ setIsLoading(false);
668
+ }
669
+ },
670
+ [client, onSuccess, onError]
671
+ );
672
+ return react.useMemo(() => ({ addCurrencies, isLoading, error, txHash }), [addCurrencies, isLoading, error, txHash]);
673
+ }
674
+ function useDeactivateCurrency({ client, onSuccess, onError }) {
675
+ const [isLoading, setIsLoading] = react.useState(false);
676
+ const [error, setError] = react.useState(null);
677
+ const [txHash, setTxHash] = react.useState(null);
678
+ const deactivateCurrency = react.useCallback(
679
+ async (params) => {
680
+ if (!client) {
681
+ const err = new Error("Zkp2pClient is not initialized");
682
+ setError(err);
683
+ onError?.(err);
684
+ return null;
685
+ }
686
+ setIsLoading(true);
687
+ setError(null);
688
+ setTxHash(null);
689
+ try {
690
+ const hash = await client.deactivateCurrency(params);
691
+ setTxHash(hash);
692
+ onSuccess?.(hash);
693
+ return hash;
694
+ } catch (err) {
695
+ const e = err instanceof Error ? err : new Error(String(err));
696
+ setError(e);
697
+ onError?.(e);
698
+ return null;
699
+ } finally {
700
+ setIsLoading(false);
701
+ }
702
+ },
703
+ [client, onSuccess, onError]
704
+ );
705
+ return react.useMemo(() => ({ deactivateCurrency, isLoading, error, txHash }), [deactivateCurrency, isLoading, error, txHash]);
706
+ }
707
+ function useRemoveCurrency({ client, onSuccess, onError }) {
708
+ const [isLoading, setIsLoading] = react.useState(false);
709
+ const [error, setError] = react.useState(null);
710
+ const [txHash, setTxHash] = react.useState(null);
711
+ const removeCurrency = react.useCallback(
712
+ async (params) => {
713
+ if (!client) {
714
+ const err = new Error("Zkp2pClient is not initialized");
715
+ setError(err);
716
+ onError?.(err);
717
+ return null;
718
+ }
719
+ setIsLoading(true);
720
+ setError(null);
721
+ setTxHash(null);
722
+ try {
723
+ const hash = await client.removeCurrency(params);
724
+ setTxHash(hash);
725
+ onSuccess?.(hash);
726
+ return hash;
727
+ } catch (err) {
728
+ const e = err instanceof Error ? err : new Error(String(err));
729
+ setError(e);
730
+ onError?.(e);
731
+ return null;
732
+ } finally {
733
+ setIsLoading(false);
734
+ }
735
+ },
736
+ [client, onSuccess, onError]
737
+ );
738
+ return react.useMemo(() => ({ removeCurrency, isLoading, error, txHash }), [removeCurrency, isLoading, error, txHash]);
739
+ }
740
+ function usePruneExpiredIntents({ client, onSuccess, onError }) {
741
+ const [isLoading, setIsLoading] = react.useState(false);
742
+ const [error, setError] = react.useState(null);
743
+ const [txHash, setTxHash] = react.useState(null);
744
+ const pruneExpiredIntents = react.useCallback(
745
+ async (params) => {
746
+ if (!client) {
747
+ const err = new Error("Zkp2pClient is not initialized");
748
+ setError(err);
749
+ onError?.(err);
750
+ return null;
751
+ }
752
+ setIsLoading(true);
753
+ setError(null);
754
+ setTxHash(null);
755
+ try {
756
+ const hash = await client.pruneExpiredIntents(params);
757
+ setTxHash(hash);
758
+ onSuccess?.(hash);
759
+ return hash;
760
+ } catch (err) {
761
+ const e = err instanceof Error ? err : new Error(String(err));
762
+ setError(e);
763
+ onError?.(e);
764
+ return null;
765
+ } finally {
766
+ setIsLoading(false);
767
+ }
768
+ },
769
+ [client, onSuccess, onError]
770
+ );
771
+ return react.useMemo(() => ({ pruneExpiredIntents, isLoading, error, txHash }), [pruneExpiredIntents, isLoading, error, txHash]);
772
+ }
773
+
774
+ exports.getNextTierCap = getNextTierCap;
775
+ exports.getTierDisplayInfo = getTierDisplayInfo;
776
+ exports.useAddCurrencies = useAddCurrencies;
777
+ exports.useAddFunds = useAddFunds;
778
+ exports.useAddPaymentMethods = useAddPaymentMethods;
779
+ exports.useCreateDeposit = useCreateDeposit;
780
+ exports.useDeactivateCurrency = useDeactivateCurrency;
781
+ exports.useFulfillIntent = useFulfillIntent;
782
+ exports.useGetTakerTier = useGetTakerTier;
783
+ exports.usePruneExpiredIntents = usePruneExpiredIntents;
784
+ exports.useReleaseFundsToPayer = useReleaseFundsToPayer;
785
+ exports.useRemoveCurrency = useRemoveCurrency;
786
+ exports.useRemoveDelegate = useRemoveDelegate;
787
+ exports.useRemoveFunds = useRemoveFunds;
788
+ exports.useRemovePaymentMethod = useRemovePaymentMethod;
789
+ exports.useSetAcceptingIntents = useSetAcceptingIntents;
790
+ exports.useSetCurrencyMinRate = useSetCurrencyMinRate;
791
+ exports.useSetDelegate = useSetDelegate;
792
+ exports.useSetIntentRange = useSetIntentRange;
793
+ exports.useSetPaymentMethodActive = useSetPaymentMethodActive;
794
+ exports.useSetRetainOnEmpty = useSetRetainOnEmpty;
795
+ exports.useSignalIntent = useSignalIntent;
796
+ exports.useWithdrawDeposit = useWithdrawDeposit;
797
+ //# sourceMappingURL=react.cjs.map
798
+ //# sourceMappingURL=react.cjs.map