@zkp2p/cash 0.1.2 → 0.1.4
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/AGENTS.md +92 -28
- package/README.md +69 -25
- package/dist/chunk-P3KYZ2FX.js +373 -0
- package/dist/{createCashClient-iHuGgjH_.d.cts → createCashClient-BbkfxILl.d.cts} +37 -8
- package/dist/{createCashClient-iHuGgjH_.d.ts → createCashClient-BbkfxILl.d.ts} +37 -8
- package/dist/index.cjs +1099 -254
- package/dist/index.d.cts +1554 -74
- package/dist/index.d.ts +1554 -74
- package/dist/index.js +886 -248
- package/dist/react.cjs +239 -59
- package/dist/react.d.cts +6 -4
- package/dist/react.d.ts +6 -4
- package/dist/react.js +236 -59
- package/dist/tools.cjs +36 -36
- package/dist/tools.d.cts +282 -3
- package/dist/tools.d.ts +282 -3
- package/dist/tools.js +36 -36
- package/docs/lifecycle-and-recovery.md +278 -0
- package/examples/agent-tool-use.ts +122 -0
- package/examples/node-cashout.ts +79 -0
- package/llms.txt +23 -5
- package/package.json +51 -21
- package/skills/peer-cash-integration/SKILL.md +82 -19
- package/dist/chunk-FKVPZVFH.js +0 -188
- package/dist/chunk-FKVPZVFH.js.map +0 -1
- package/dist/index.cjs.map +0 -1
- package/dist/index.js.map +0 -1
- package/dist/react.cjs.map +0 -1
- package/dist/react.js.map +0 -1
- package/dist/tools.cjs.map +0 -1
- package/dist/tools.js.map +0 -1
package/dist/react.cjs
CHANGED
|
@@ -15,14 +15,32 @@ function useEstimate({
|
|
|
15
15
|
const [isLoading, setIsLoading] = react.useState(false);
|
|
16
16
|
const [error, setError] = react.useState(null);
|
|
17
17
|
const mountedRef = react.useRef(true);
|
|
18
|
+
const latestRequestRef = react.useRef(0);
|
|
18
19
|
const timerRef = react.useRef(null);
|
|
20
|
+
const estimateIdentityRef = react.useRef(null);
|
|
21
|
+
const loadingIdentityRef = react.useRef(null);
|
|
22
|
+
const errorIdentityRef = react.useRef(null);
|
|
19
23
|
const refresh = react.useCallback(async () => {
|
|
24
|
+
const requestId = ++latestRequestRef.current;
|
|
25
|
+
const isCurrent = () => mountedRef.current && requestId === latestRequestRef.current;
|
|
20
26
|
if (!client || !currency || !amount || amount <= 0n) {
|
|
21
|
-
if (
|
|
27
|
+
if (isCurrent()) {
|
|
28
|
+
estimateIdentityRef.current = null;
|
|
29
|
+
loadingIdentityRef.current = null;
|
|
30
|
+
errorIdentityRef.current = null;
|
|
31
|
+
setEstimate(null);
|
|
32
|
+
setIsLoading(false);
|
|
33
|
+
setError(null);
|
|
34
|
+
}
|
|
22
35
|
return;
|
|
23
36
|
}
|
|
24
|
-
|
|
25
|
-
|
|
37
|
+
const identity = { client, amount, currency, platform, source };
|
|
38
|
+
if (isCurrent()) {
|
|
39
|
+
loadingIdentityRef.current = identity;
|
|
40
|
+
errorIdentityRef.current = null;
|
|
41
|
+
setIsLoading(true);
|
|
42
|
+
setError(null);
|
|
43
|
+
}
|
|
26
44
|
try {
|
|
27
45
|
const result = await client.estimate({
|
|
28
46
|
amount,
|
|
@@ -30,17 +48,31 @@ function useEstimate({
|
|
|
30
48
|
...platform ? { platform } : {},
|
|
31
49
|
...source ? { source } : {}
|
|
32
50
|
});
|
|
33
|
-
if (
|
|
51
|
+
if (isCurrent()) {
|
|
52
|
+
estimateIdentityRef.current = identity;
|
|
53
|
+
setEstimate(result);
|
|
54
|
+
}
|
|
34
55
|
} catch (err) {
|
|
35
56
|
const e = err instanceof Error ? err : new Error(String(err));
|
|
36
|
-
if (
|
|
57
|
+
if (isCurrent()) {
|
|
58
|
+
estimateIdentityRef.current = null;
|
|
59
|
+
errorIdentityRef.current = identity;
|
|
37
60
|
setEstimate(null);
|
|
38
61
|
setError(e);
|
|
39
62
|
}
|
|
40
63
|
} finally {
|
|
41
|
-
if (
|
|
64
|
+
if (isCurrent()) setIsLoading(false);
|
|
42
65
|
}
|
|
43
66
|
}, [client, currency, amount, platform, source]);
|
|
67
|
+
react.useEffect(() => {
|
|
68
|
+
latestRequestRef.current += 1;
|
|
69
|
+
estimateIdentityRef.current = null;
|
|
70
|
+
loadingIdentityRef.current = null;
|
|
71
|
+
errorIdentityRef.current = null;
|
|
72
|
+
setEstimate(null);
|
|
73
|
+
setIsLoading(false);
|
|
74
|
+
setError(null);
|
|
75
|
+
}, [client, amount, currency, platform, source]);
|
|
44
76
|
react.useEffect(() => {
|
|
45
77
|
mountedRef.current = true;
|
|
46
78
|
void refresh();
|
|
@@ -49,10 +81,38 @@ function useEstimate({
|
|
|
49
81
|
}
|
|
50
82
|
return () => {
|
|
51
83
|
mountedRef.current = false;
|
|
84
|
+
latestRequestRef.current += 1;
|
|
52
85
|
if (timerRef.current) clearInterval(timerRef.current);
|
|
53
86
|
};
|
|
54
87
|
}, [refresh, refreshIntervalMs]);
|
|
55
|
-
|
|
88
|
+
const matchesCurrentIdentity = (identity) => identity?.client === client && identity.amount === amount && identity.currency === currency && identity.platform === platform && identity.source === source;
|
|
89
|
+
return {
|
|
90
|
+
estimate: matchesCurrentIdentity(estimateIdentityRef.current) ? estimate : null,
|
|
91
|
+
isLoading: matchesCurrentIdentity(loadingIdentityRef.current) ? isLoading : false,
|
|
92
|
+
error: matchesCurrentIdentity(errorIdentityRef.current) ? error : null,
|
|
93
|
+
refresh
|
|
94
|
+
};
|
|
95
|
+
}
|
|
96
|
+
function useMountedRef() {
|
|
97
|
+
const mounted = react.useRef(true);
|
|
98
|
+
react.useEffect(() => {
|
|
99
|
+
mounted.current = true;
|
|
100
|
+
return () => {
|
|
101
|
+
mounted.current = false;
|
|
102
|
+
};
|
|
103
|
+
}, []);
|
|
104
|
+
return mounted;
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
// src/react/useCashout.ts
|
|
108
|
+
function matchesIdentity(identity, client, signer, sourceSigner) {
|
|
109
|
+
return identity?.client === client && identity.signer === signer && identity.sourceSigner === sourceSigner;
|
|
110
|
+
}
|
|
111
|
+
function notifyObserver(observer, value) {
|
|
112
|
+
try {
|
|
113
|
+
observer?.(value);
|
|
114
|
+
} catch {
|
|
115
|
+
}
|
|
56
116
|
}
|
|
57
117
|
function useCashout({
|
|
58
118
|
client,
|
|
@@ -63,16 +123,35 @@ function useCashout({
|
|
|
63
123
|
onError
|
|
64
124
|
}) {
|
|
65
125
|
const [pending, setPending] = react.useState(null);
|
|
126
|
+
const pendingRef = react.useRef(null);
|
|
66
127
|
const [result, setResult] = react.useState(null);
|
|
67
128
|
const [error, setError] = react.useState(null);
|
|
129
|
+
const resultIdentityRef = react.useRef(null);
|
|
130
|
+
const errorIdentityRef = react.useRef(null);
|
|
131
|
+
const mounted = useMountedRef();
|
|
132
|
+
react.useEffect(() => {
|
|
133
|
+
pendingRef.current = null;
|
|
134
|
+
resultIdentityRef.current = null;
|
|
135
|
+
errorIdentityRef.current = null;
|
|
136
|
+
setPending(null);
|
|
137
|
+
setResult(null);
|
|
138
|
+
setError(null);
|
|
139
|
+
}, [client, signer, sourceSigner]);
|
|
68
140
|
const cashout = react.useCallback(
|
|
69
141
|
async (input) => {
|
|
142
|
+
const identity = { client, signer, sourceSigner };
|
|
70
143
|
if (!client || !signer) {
|
|
71
144
|
const err = new Error("Cash client or signer is not ready");
|
|
72
|
-
|
|
73
|
-
|
|
145
|
+
if (mounted.current) {
|
|
146
|
+
errorIdentityRef.current = identity;
|
|
147
|
+
setError(err);
|
|
148
|
+
}
|
|
149
|
+
notifyObserver(onError, err);
|
|
74
150
|
return null;
|
|
75
151
|
}
|
|
152
|
+
if (matchesIdentity(pendingRef.current, client, signer, sourceSigner)) return null;
|
|
153
|
+
const active = { ...identity, kind: "cashout" };
|
|
154
|
+
pendingRef.current = active;
|
|
76
155
|
setPending("cashout");
|
|
77
156
|
setError(null);
|
|
78
157
|
setResult(null);
|
|
@@ -82,28 +161,44 @@ function useCashout({
|
|
|
82
161
|
...sourceSigner ? { sourceSigner } : {},
|
|
83
162
|
...onSourceProgress ? { onSourceProgress } : {}
|
|
84
163
|
});
|
|
85
|
-
|
|
86
|
-
|
|
164
|
+
if (mounted.current && pendingRef.current === active) {
|
|
165
|
+
resultIdentityRef.current = identity;
|
|
166
|
+
setResult(cashoutResult);
|
|
167
|
+
}
|
|
168
|
+
notifyObserver(onCashout, cashoutResult);
|
|
87
169
|
return cashoutResult;
|
|
88
170
|
} catch (err) {
|
|
89
171
|
const e = err instanceof Error ? err : new Error(String(err));
|
|
90
|
-
|
|
91
|
-
|
|
172
|
+
if (mounted.current && pendingRef.current === active) {
|
|
173
|
+
errorIdentityRef.current = identity;
|
|
174
|
+
setError(e);
|
|
175
|
+
}
|
|
176
|
+
notifyObserver(onError, e);
|
|
92
177
|
return null;
|
|
93
178
|
} finally {
|
|
94
|
-
|
|
179
|
+
if (mounted.current && pendingRef.current === active) {
|
|
180
|
+
pendingRef.current = null;
|
|
181
|
+
setPending(null);
|
|
182
|
+
}
|
|
95
183
|
}
|
|
96
184
|
},
|
|
97
185
|
[client, signer, sourceSigner, onSourceProgress, onCashout, onError]
|
|
98
186
|
);
|
|
99
187
|
const withdraw = react.useCallback(
|
|
100
188
|
async (depositId, amount) => {
|
|
189
|
+
const identity = { client, signer, sourceSigner };
|
|
101
190
|
if (!client || !signer) {
|
|
102
191
|
const err = new Error("Cash client or signer is not ready");
|
|
103
|
-
|
|
104
|
-
|
|
192
|
+
if (mounted.current) {
|
|
193
|
+
errorIdentityRef.current = identity;
|
|
194
|
+
setError(err);
|
|
195
|
+
}
|
|
196
|
+
notifyObserver(onError, err);
|
|
105
197
|
return null;
|
|
106
198
|
}
|
|
199
|
+
if (matchesIdentity(pendingRef.current, client, signer, sourceSigner)) return null;
|
|
200
|
+
const active = { ...identity, kind: "withdraw" };
|
|
201
|
+
pendingRef.current = active;
|
|
107
202
|
setPending("withdraw");
|
|
108
203
|
setError(null);
|
|
109
204
|
try {
|
|
@@ -113,41 +208,70 @@ function useCashout({
|
|
|
113
208
|
});
|
|
114
209
|
} catch (err) {
|
|
115
210
|
const e = err instanceof Error ? err : new Error(String(err));
|
|
116
|
-
|
|
117
|
-
|
|
211
|
+
if (mounted.current && pendingRef.current === active) {
|
|
212
|
+
errorIdentityRef.current = identity;
|
|
213
|
+
setError(e);
|
|
214
|
+
}
|
|
215
|
+
notifyObserver(onError, e);
|
|
118
216
|
return null;
|
|
119
217
|
} finally {
|
|
120
|
-
|
|
218
|
+
if (mounted.current && pendingRef.current === active) {
|
|
219
|
+
pendingRef.current = null;
|
|
220
|
+
setPending(null);
|
|
221
|
+
}
|
|
121
222
|
}
|
|
122
223
|
},
|
|
123
|
-
[client, signer, onError]
|
|
224
|
+
[client, signer, sourceSigner, onError]
|
|
124
225
|
);
|
|
125
226
|
const topUp = react.useCallback(
|
|
126
227
|
async (depositId, amount) => {
|
|
228
|
+
const identity = { client, signer, sourceSigner };
|
|
127
229
|
if (!client || !signer) {
|
|
128
230
|
const err = new Error("Cash client or signer is not ready");
|
|
129
|
-
|
|
130
|
-
|
|
231
|
+
if (mounted.current) {
|
|
232
|
+
errorIdentityRef.current = identity;
|
|
233
|
+
setError(err);
|
|
234
|
+
}
|
|
235
|
+
notifyObserver(onError, err);
|
|
131
236
|
return null;
|
|
132
237
|
}
|
|
238
|
+
if (matchesIdentity(pendingRef.current, client, signer, sourceSigner)) return null;
|
|
239
|
+
const active = { ...identity, kind: "topUp" };
|
|
240
|
+
pendingRef.current = active;
|
|
133
241
|
setPending("topUp");
|
|
134
242
|
setError(null);
|
|
135
243
|
try {
|
|
136
244
|
return await client.topUp(depositId, amount, { signer });
|
|
137
245
|
} catch (err) {
|
|
138
246
|
const e = err instanceof Error ? err : new Error(String(err));
|
|
139
|
-
|
|
140
|
-
|
|
247
|
+
if (mounted.current && pendingRef.current === active) {
|
|
248
|
+
errorIdentityRef.current = identity;
|
|
249
|
+
setError(e);
|
|
250
|
+
}
|
|
251
|
+
notifyObserver(onError, e);
|
|
141
252
|
return null;
|
|
142
253
|
} finally {
|
|
143
|
-
|
|
254
|
+
if (mounted.current && pendingRef.current === active) {
|
|
255
|
+
pendingRef.current = null;
|
|
256
|
+
setPending(null);
|
|
257
|
+
}
|
|
144
258
|
}
|
|
145
259
|
},
|
|
146
|
-
[client, signer, onError]
|
|
260
|
+
[client, signer, sourceSigner, onError]
|
|
147
261
|
);
|
|
262
|
+
const visiblePending = matchesIdentity(pendingRef.current, client, signer, sourceSigner) ? pending : null;
|
|
263
|
+
const visibleResult = matchesIdentity(resultIdentityRef.current, client, signer, sourceSigner) ? result : null;
|
|
264
|
+
const visibleError = matchesIdentity(errorIdentityRef.current, client, signer, sourceSigner) ? error : null;
|
|
148
265
|
return react.useMemo(
|
|
149
|
-
() => ({
|
|
150
|
-
|
|
266
|
+
() => ({
|
|
267
|
+
cashout,
|
|
268
|
+
topUp,
|
|
269
|
+
withdraw,
|
|
270
|
+
pending: visiblePending,
|
|
271
|
+
result: visibleResult,
|
|
272
|
+
error: visibleError
|
|
273
|
+
}),
|
|
274
|
+
[cashout, topUp, withdraw, visiblePending, visibleResult, visibleError]
|
|
151
275
|
);
|
|
152
276
|
}
|
|
153
277
|
|
|
@@ -159,12 +283,14 @@ var CashError = class extends Error {
|
|
|
159
283
|
code;
|
|
160
284
|
retryable;
|
|
161
285
|
remediation;
|
|
286
|
+
recovery;
|
|
162
287
|
constructor(shape, options) {
|
|
163
288
|
super(shape.message, options);
|
|
164
289
|
this.name = "CashError";
|
|
165
290
|
this.code = shape.code;
|
|
166
291
|
this.retryable = shape.retryable;
|
|
167
292
|
this.remediation = shape.remediation;
|
|
293
|
+
if (shape.recovery) this.recovery = shape.recovery;
|
|
168
294
|
}
|
|
169
295
|
/** Serializable view (for tool results and logs). */
|
|
170
296
|
toJSON() {
|
|
@@ -172,7 +298,8 @@ var CashError = class extends Error {
|
|
|
172
298
|
code: this.code,
|
|
173
299
|
message: this.message,
|
|
174
300
|
retryable: this.retryable,
|
|
175
|
-
remediation: this.remediation
|
|
301
|
+
remediation: this.remediation,
|
|
302
|
+
...this.recovery ? { recovery: this.recovery } : {}
|
|
176
303
|
};
|
|
177
304
|
}
|
|
178
305
|
};
|
|
@@ -197,16 +324,6 @@ function usePoll(enabled, intervalMs, tick) {
|
|
|
197
324
|
};
|
|
198
325
|
}, [enabled, intervalMs, tick]);
|
|
199
326
|
}
|
|
200
|
-
function useMountedRef() {
|
|
201
|
-
const mounted = react.useRef(true);
|
|
202
|
-
react.useEffect(() => {
|
|
203
|
-
mounted.current = true;
|
|
204
|
-
return () => {
|
|
205
|
-
mounted.current = false;
|
|
206
|
-
};
|
|
207
|
-
}, []);
|
|
208
|
-
return mounted;
|
|
209
|
-
}
|
|
210
327
|
|
|
211
328
|
// src/react/useOrder.ts
|
|
212
329
|
function useOrder({
|
|
@@ -219,27 +336,52 @@ function useOrder({
|
|
|
219
336
|
const [isLoading, setIsLoading] = react.useState(false);
|
|
220
337
|
const [error, setError] = react.useState(null);
|
|
221
338
|
const mounted = useMountedRef();
|
|
339
|
+
const latestRequest = react.useRef(0);
|
|
340
|
+
const orderIdentity = react.useRef(null);
|
|
341
|
+
const loadingIdentity = react.useRef(null);
|
|
342
|
+
const errorIdentity = react.useRef(null);
|
|
343
|
+
react.useEffect(() => {
|
|
344
|
+
latestRequest.current += 1;
|
|
345
|
+
orderIdentity.current = null;
|
|
346
|
+
loadingIdentity.current = null;
|
|
347
|
+
errorIdentity.current = null;
|
|
348
|
+
setOrder(null);
|
|
349
|
+
setIsLoading(false);
|
|
350
|
+
setError(null);
|
|
351
|
+
}, [client, depositId]);
|
|
222
352
|
const fetchOrder = react.useCallback(
|
|
223
353
|
async (isActive = () => true) => {
|
|
224
354
|
if (!client || !depositId) return null;
|
|
225
|
-
|
|
226
|
-
|
|
355
|
+
const requestId = ++latestRequest.current;
|
|
356
|
+
const identity = { client, depositId };
|
|
357
|
+
const isCurrent = () => mounted.current && isActive() && requestId === latestRequest.current;
|
|
358
|
+
if (isCurrent()) {
|
|
359
|
+
loadingIdentity.current = identity;
|
|
360
|
+
errorIdentity.current = null;
|
|
361
|
+
setIsLoading(true);
|
|
362
|
+
setError(null);
|
|
363
|
+
}
|
|
227
364
|
try {
|
|
228
365
|
const derived = await client.order(depositId);
|
|
229
|
-
if (
|
|
366
|
+
if (!isCurrent()) return null;
|
|
367
|
+
orderIdentity.current = identity;
|
|
368
|
+
setOrder(derived);
|
|
230
369
|
return derived;
|
|
231
370
|
} catch (err) {
|
|
232
371
|
if (isCashError(err) && err.code === "ORDER_NOT_FOUND") {
|
|
233
372
|
return null;
|
|
234
373
|
}
|
|
235
374
|
const e = err instanceof Error ? err : new Error(String(err));
|
|
236
|
-
if (
|
|
375
|
+
if (isCurrent()) {
|
|
376
|
+
errorIdentity.current = identity;
|
|
377
|
+
setError(e);
|
|
378
|
+
}
|
|
237
379
|
return null;
|
|
238
380
|
} finally {
|
|
239
|
-
if (
|
|
381
|
+
if (isCurrent()) setIsLoading(false);
|
|
240
382
|
}
|
|
241
383
|
},
|
|
242
|
-
[client, depositId]
|
|
384
|
+
[client, depositId, mounted]
|
|
243
385
|
);
|
|
244
386
|
usePoll(
|
|
245
387
|
Boolean(client && depositId && !paused),
|
|
@@ -253,7 +395,13 @@ function useOrder({
|
|
|
253
395
|
)
|
|
254
396
|
);
|
|
255
397
|
const refresh = react.useCallback(() => fetchOrder(() => mounted.current), [fetchOrder, mounted]);
|
|
256
|
-
|
|
398
|
+
const matchesCurrentIdentity = (identity) => identity?.client === client && identity.depositId === depositId;
|
|
399
|
+
return {
|
|
400
|
+
order: matchesCurrentIdentity(orderIdentity.current) ? order : null,
|
|
401
|
+
isLoading: matchesCurrentIdentity(loadingIdentity.current) ? isLoading : false,
|
|
402
|
+
error: matchesCurrentIdentity(errorIdentity.current) ? error : null,
|
|
403
|
+
refresh
|
|
404
|
+
};
|
|
257
405
|
}
|
|
258
406
|
function useOrders({
|
|
259
407
|
client,
|
|
@@ -266,45 +414,77 @@ function useOrders({
|
|
|
266
414
|
const [isLoading, setIsLoading] = react.useState(false);
|
|
267
415
|
const [error, setError] = react.useState(null);
|
|
268
416
|
const mounted = useMountedRef();
|
|
417
|
+
const latestRequest = react.useRef(0);
|
|
418
|
+
const ordersIdentity = react.useRef(null);
|
|
419
|
+
const loadingIdentity = react.useRef(null);
|
|
420
|
+
const errorIdentity = react.useRef(null);
|
|
421
|
+
react.useEffect(() => {
|
|
422
|
+
latestRequest.current += 1;
|
|
423
|
+
ordersIdentity.current = null;
|
|
424
|
+
loadingIdentity.current = null;
|
|
425
|
+
errorIdentity.current = null;
|
|
426
|
+
setOrders([]);
|
|
427
|
+
setIsLoading(false);
|
|
428
|
+
setError(null);
|
|
429
|
+
}, [client, owner, limit]);
|
|
269
430
|
const fetchOrders = react.useCallback(
|
|
270
431
|
async (isActive = () => true) => {
|
|
271
432
|
if (!client || !owner) return [];
|
|
272
|
-
|
|
273
|
-
|
|
433
|
+
const requestId = ++latestRequest.current;
|
|
434
|
+
const identity = { client, owner, limit };
|
|
435
|
+
const isCurrent = () => mounted.current && isActive() && requestId === latestRequest.current;
|
|
436
|
+
if (isCurrent()) {
|
|
437
|
+
loadingIdentity.current = identity;
|
|
438
|
+
errorIdentity.current = null;
|
|
439
|
+
setIsLoading(true);
|
|
440
|
+
setError(null);
|
|
441
|
+
}
|
|
274
442
|
try {
|
|
275
443
|
const derived = await client.orders(owner, { limit });
|
|
276
|
-
if (
|
|
444
|
+
if (!isCurrent()) return [];
|
|
445
|
+
ordersIdentity.current = identity;
|
|
446
|
+
setOrders(derived);
|
|
277
447
|
return derived;
|
|
278
448
|
} catch (err) {
|
|
279
449
|
const e = err instanceof Error ? err : new Error(String(err));
|
|
280
|
-
if (
|
|
450
|
+
if (isCurrent()) {
|
|
451
|
+
errorIdentity.current = identity;
|
|
452
|
+
setError(e);
|
|
453
|
+
}
|
|
281
454
|
return [];
|
|
282
455
|
} finally {
|
|
283
|
-
if (
|
|
456
|
+
if (isCurrent()) setIsLoading(false);
|
|
284
457
|
}
|
|
285
458
|
},
|
|
286
|
-
[client, owner, limit]
|
|
459
|
+
[client, owner, limit, mounted]
|
|
287
460
|
);
|
|
288
461
|
usePoll(
|
|
289
462
|
Boolean(client && owner && !paused),
|
|
290
463
|
pollIntervalMs,
|
|
291
464
|
react.useCallback(
|
|
292
465
|
async (isActive) => {
|
|
293
|
-
|
|
294
|
-
return
|
|
466
|
+
await fetchOrders(isActive);
|
|
467
|
+
return true;
|
|
295
468
|
},
|
|
296
469
|
[fetchOrders]
|
|
297
470
|
)
|
|
298
471
|
);
|
|
299
472
|
const refresh = react.useCallback(() => fetchOrders(() => mounted.current), [fetchOrders, mounted]);
|
|
300
|
-
const
|
|
301
|
-
const
|
|
302
|
-
|
|
473
|
+
const matchesCurrentIdentity = (identity) => identity?.client === client && identity.owner === owner && identity.limit === limit;
|
|
474
|
+
const visibleOrders = matchesCurrentIdentity(ordersIdentity.current) ? orders : [];
|
|
475
|
+
const inFlightCount = visibleOrders.filter((o) => o.isInFlight).length;
|
|
476
|
+
const totalCashedOut = visibleOrders.reduce((sum, o) => sum + o.filledAmount, 0n);
|
|
477
|
+
return {
|
|
478
|
+
orders: visibleOrders,
|
|
479
|
+
inFlightCount,
|
|
480
|
+
totalCashedOut,
|
|
481
|
+
isLoading: matchesCurrentIdentity(loadingIdentity.current) ? isLoading : false,
|
|
482
|
+
error: matchesCurrentIdentity(errorIdentity.current) ? error : null,
|
|
483
|
+
refresh
|
|
484
|
+
};
|
|
303
485
|
}
|
|
304
486
|
|
|
305
487
|
exports.useCashout = useCashout;
|
|
306
488
|
exports.useEstimate = useEstimate;
|
|
307
489
|
exports.useOrder = useOrder;
|
|
308
490
|
exports.useOrders = useOrders;
|
|
309
|
-
//# sourceMappingURL=react.cjs.map
|
|
310
|
-
//# sourceMappingURL=react.cjs.map
|
package/dist/react.d.cts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { CurrencyType } from '@zkp2p/sdk';
|
|
2
|
-
import {
|
|
2
|
+
import { q as CashClient, E as EstimateInput, i as CashEstimate, B as CashoutOptions, h as CashoutResult, A as CashoutInput, T as TopUpResult, W as WithdrawResult, e as CashOrder } from './createCashClient-BbkfxILl.cjs';
|
|
3
3
|
import { WalletClient } from 'viem';
|
|
4
4
|
import '@relayprotocol/relay-sdk';
|
|
5
5
|
|
|
@@ -27,6 +27,7 @@ declare function useEstimate({ client, amount, currency, platform, source, refre
|
|
|
27
27
|
refresh: () => Promise<void>;
|
|
28
28
|
};
|
|
29
29
|
|
|
30
|
+
type PendingMutation = 'cashout' | 'withdraw' | 'topUp';
|
|
30
31
|
interface UseCashoutOptions {
|
|
31
32
|
client: CashClient | null;
|
|
32
33
|
/** A viem WalletClient with an account, on Base. */
|
|
@@ -49,7 +50,7 @@ declare function useCashout({ client, signer, sourceSigner, onSourceProgress, on
|
|
|
49
50
|
cashout: (input: CashoutInput) => Promise<CashoutResult | null>;
|
|
50
51
|
topUp: (depositId: string, amount: bigint) => Promise<TopUpResult | null>;
|
|
51
52
|
withdraw: (depositId: string, amount?: bigint) => Promise<WithdrawResult | null>;
|
|
52
|
-
pending:
|
|
53
|
+
pending: PendingMutation | null;
|
|
53
54
|
result: CashoutResult | null;
|
|
54
55
|
error: Error | null;
|
|
55
56
|
};
|
|
@@ -84,14 +85,15 @@ interface UseOrdersOptions {
|
|
|
84
85
|
owner: string | null | undefined;
|
|
85
86
|
/** Max deposits to scan. */
|
|
86
87
|
limit?: number;
|
|
87
|
-
/** Poll cadence (ms) while
|
|
88
|
+
/** Poll cadence (ms) while the feed is enabled. */
|
|
88
89
|
pollIntervalMs?: number;
|
|
89
90
|
paused?: boolean;
|
|
90
91
|
}
|
|
91
92
|
/**
|
|
92
93
|
* List the user's cash-out orders (the Transactions-feed pattern). Reads
|
|
93
94
|
* deposits by depositor and derives real amounts + states from the indexer
|
|
94
|
-
* aggregates. Polls while
|
|
95
|
+
* aggregates. Polls while enabled so an empty or terminal feed can still
|
|
96
|
+
* discover a newly indexed cash-out without a remount.
|
|
95
97
|
*/
|
|
96
98
|
declare function useOrders({ client, owner, limit, pollIntervalMs, paused, }: UseOrdersOptions): {
|
|
97
99
|
orders: CashOrder[];
|
package/dist/react.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { CurrencyType } from '@zkp2p/sdk';
|
|
2
|
-
import {
|
|
2
|
+
import { q as CashClient, E as EstimateInput, i as CashEstimate, B as CashoutOptions, h as CashoutResult, A as CashoutInput, T as TopUpResult, W as WithdrawResult, e as CashOrder } from './createCashClient-BbkfxILl.js';
|
|
3
3
|
import { WalletClient } from 'viem';
|
|
4
4
|
import '@relayprotocol/relay-sdk';
|
|
5
5
|
|
|
@@ -27,6 +27,7 @@ declare function useEstimate({ client, amount, currency, platform, source, refre
|
|
|
27
27
|
refresh: () => Promise<void>;
|
|
28
28
|
};
|
|
29
29
|
|
|
30
|
+
type PendingMutation = 'cashout' | 'withdraw' | 'topUp';
|
|
30
31
|
interface UseCashoutOptions {
|
|
31
32
|
client: CashClient | null;
|
|
32
33
|
/** A viem WalletClient with an account, on Base. */
|
|
@@ -49,7 +50,7 @@ declare function useCashout({ client, signer, sourceSigner, onSourceProgress, on
|
|
|
49
50
|
cashout: (input: CashoutInput) => Promise<CashoutResult | null>;
|
|
50
51
|
topUp: (depositId: string, amount: bigint) => Promise<TopUpResult | null>;
|
|
51
52
|
withdraw: (depositId: string, amount?: bigint) => Promise<WithdrawResult | null>;
|
|
52
|
-
pending:
|
|
53
|
+
pending: PendingMutation | null;
|
|
53
54
|
result: CashoutResult | null;
|
|
54
55
|
error: Error | null;
|
|
55
56
|
};
|
|
@@ -84,14 +85,15 @@ interface UseOrdersOptions {
|
|
|
84
85
|
owner: string | null | undefined;
|
|
85
86
|
/** Max deposits to scan. */
|
|
86
87
|
limit?: number;
|
|
87
|
-
/** Poll cadence (ms) while
|
|
88
|
+
/** Poll cadence (ms) while the feed is enabled. */
|
|
88
89
|
pollIntervalMs?: number;
|
|
89
90
|
paused?: boolean;
|
|
90
91
|
}
|
|
91
92
|
/**
|
|
92
93
|
* List the user's cash-out orders (the Transactions-feed pattern). Reads
|
|
93
94
|
* deposits by depositor and derives real amounts + states from the indexer
|
|
94
|
-
* aggregates. Polls while
|
|
95
|
+
* aggregates. Polls while enabled so an empty or terminal feed can still
|
|
96
|
+
* discover a newly indexed cash-out without a remount.
|
|
95
97
|
*/
|
|
96
98
|
declare function useOrders({ client, owner, limit, pollIntervalMs, paused, }: UseOrdersOptions): {
|
|
97
99
|
orders: CashOrder[];
|