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