@tetsuo-ai/marketplace-react 0.4.1 → 0.5.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/CHANGELOG.md +56 -0
- package/README.md +93 -47
- package/dist/chunk-7NKRSPPN.js +227 -0
- package/dist/chunk-7NKRSPPN.js.map +1 -0
- package/dist/{chunk-JVXGNW3Q.js → chunk-CDDHUFMG.js} +6 -5
- package/dist/chunk-CDDHUFMG.js.map +1 -0
- package/dist/chunk-FIDFPM5A.cjs +40 -0
- package/dist/chunk-FIDFPM5A.cjs.map +1 -0
- package/dist/chunk-IJKWKY4H.cjs +1370 -0
- package/dist/chunk-IJKWKY4H.cjs.map +1 -0
- package/dist/chunk-JTSG5FGC.cjs +397 -0
- package/dist/chunk-JTSG5FGC.cjs.map +1 -0
- package/dist/chunk-ONC6L3IX.cjs +97 -0
- package/dist/chunk-ONC6L3IX.cjs.map +1 -0
- package/dist/chunk-R76EUYDI.cjs +233 -0
- package/dist/chunk-R76EUYDI.cjs.map +1 -0
- package/dist/{chunk-XLA7DARS.js → chunk-RG5JZ6JL.js} +159 -36
- package/dist/chunk-RG5JZ6JL.js.map +1 -0
- package/dist/components/index.cjs +158 -1594
- package/dist/components/index.cjs.map +1 -1
- package/dist/components/index.d.cts +2 -2
- package/dist/components/index.d.ts +2 -2
- package/dist/components/index.js +2 -2
- package/dist/hooks/index.cjs +656 -509
- package/dist/hooks/index.cjs.map +1 -1
- package/dist/hooks/index.d.cts +63 -29
- package/dist/hooks/index.d.ts +63 -29
- package/dist/hooks/index.js +619 -196
- package/dist/hooks/index.js.map +1 -1
- package/dist/{index-CmVz0OOm.d.ts → index-BAyr1ODZ.d.ts} +28 -3
- package/dist/{index-DAZzhuO4.d.cts → index-C20NVU7_.d.cts} +28 -3
- package/dist/index.cjs +284 -1833
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +7 -8
- package/dist/index.d.ts +7 -8
- package/dist/index.js +64 -4
- package/dist/index.js.map +1 -1
- package/dist/signers/index.cjs +22 -161
- package/dist/signers/index.cjs.map +1 -1
- package/dist/signers/index.d.cts +16 -11
- package/dist/signers/index.d.ts +16 -11
- package/dist/signers/index.js +1 -1
- package/dist/testing/index.d.cts +1 -1
- package/dist/testing/index.d.ts +1 -1
- package/dist/theme/agenc-tailwind-preset.cjs +134 -108
- package/dist/{types-jvISR6bc.d.cts → types-B10rndEI.d.cts} +16 -7
- package/dist/{types-jvISR6bc.d.ts → types-B10rndEI.d.ts} +16 -7
- package/dist/{useAgentTrackRecord-DPt3SfYz.d.cts → useAgentTrackRecord-Ch7gHTFj.d.cts} +1 -1
- package/dist/{useAgentTrackRecord-DPt3SfYz.d.ts → useAgentTrackRecord-Ch7gHTFj.d.ts} +1 -1
- package/package.json +6 -3
- package/src/components/HireCheckoutModal.tsx +5 -2
- package/src/hooks/index.ts +1 -0
- package/src/hooks/internal.ts +178 -24
- package/src/hooks/useAgentTrackRecord.ts +5 -2
- package/src/hooks/useCompletionBond.ts +56 -21
- package/src/hooks/useDispute.ts +46 -9
- package/src/hooks/useHire.ts +113 -23
- package/src/hooks/useHumanlessHireFlow.ts +335 -115
- package/src/hooks/useListing.ts +2 -2
- package/src/hooks/useListings.ts +2 -2
- package/src/hooks/useRateHire.ts +32 -5
- package/src/hooks/useReferrerEarnings.ts +4 -1
- package/src/hooks/useSubmissionReview.ts +95 -32
- package/src/hooks/useTaskActivation.ts +51 -9
- package/src/hooks/useTaskGuarantee.ts +4 -1
- package/src/hooks/useTaskLifecycle.ts +104 -24
- package/src/hooks/useTaskStatus.ts +121 -26
- package/src/hooks/useTaskWork.ts +76 -12
- package/src/hooks/useWalletSigner.ts +11 -16
- package/src/index.ts +3 -0
- package/src/provider/AgencProvider.tsx +95 -3
- package/src/provider/referrer.ts +1 -1
- package/src/signers/README.md +13 -7
- package/src/signers/index.ts +6 -1
- package/src/signers/strings.ts +13 -1
- package/src/signers/types.ts +16 -5
- package/src/signers/wallet-account.ts +115 -29
- package/src/signers/wallet-adapter.ts +38 -4
- package/src/theme/agenc-tailwind-preset.cjs +134 -108
- package/src/types.ts +27 -1
- package/dist/chunk-JVXGNW3Q.js.map +0 -1
- package/dist/chunk-ON6XR4XO.js +0 -128
- package/dist/chunk-ON6XR4XO.js.map +0 -1
- package/dist/chunk-XLA7DARS.js.map +0 -1
package/src/hooks/internal.ts
CHANGED
|
@@ -11,6 +11,7 @@
|
|
|
11
11
|
*
|
|
12
12
|
* @module hooks/internal
|
|
13
13
|
*/
|
|
14
|
+
import { stabilizeTransactionSigner } from "@tetsuo-ai/marketplace-sdk";
|
|
14
15
|
import { t } from "../strings/index.js";
|
|
15
16
|
import type {
|
|
16
17
|
Address,
|
|
@@ -22,10 +23,18 @@ import type {
|
|
|
22
23
|
/** Root namespace for every cache key this package writes. */
|
|
23
24
|
export const QUERY_KEY_ROOT = "agenc" as const;
|
|
24
25
|
|
|
26
|
+
/** Namespace used only by direct callers that omit deployment identity. */
|
|
27
|
+
export const DEFAULT_QUERY_CACHE_NAMESPACE = "default" as const;
|
|
28
|
+
|
|
29
|
+
function queryRoot(cacheNamespace: string) {
|
|
30
|
+
return [QUERY_KEY_ROOT, cacheNamespace] as const;
|
|
31
|
+
}
|
|
32
|
+
|
|
25
33
|
/**
|
|
26
34
|
* Stable, hierarchical TanStack Query keys. Hooks build their keys ONLY through
|
|
27
|
-
* this factory so a consumer (or a hook) can invalidate a
|
|
28
|
-
* (`["agenc", "listings"]`) or one entity
|
|
35
|
+
* this factory so a consumer (or a hook) can invalidate a deployment sub-tree
|
|
36
|
+
* (`["agenc", namespace, "listings"]`) or one entity
|
|
37
|
+
* (`["agenc", namespace, "listing", pda]`).
|
|
29
38
|
*
|
|
30
39
|
* `JSON.stringify` is intentionally NOT used — TanStack compares keys
|
|
31
40
|
* structurally, so passing the raw filter object keeps equality correct for
|
|
@@ -33,24 +42,40 @@ export const QUERY_KEY_ROOT = "agenc" as const;
|
|
|
33
42
|
*/
|
|
34
43
|
export const queryKeys = {
|
|
35
44
|
/** All listings list queries (with their filter object as the leaf). */
|
|
36
|
-
listings: (
|
|
37
|
-
|
|
45
|
+
listings: (
|
|
46
|
+
filter?: unknown,
|
|
47
|
+
cacheNamespace: string = DEFAULT_QUERY_CACHE_NAMESPACE,
|
|
48
|
+
) => [...queryRoot(cacheNamespace), "listings", filter ?? null] as const,
|
|
38
49
|
/** One listing + its joined provider/track-record/moderation. */
|
|
39
|
-
listing: (
|
|
50
|
+
listing: (
|
|
51
|
+
pda: string,
|
|
52
|
+
cacheNamespace: string = DEFAULT_QUERY_CACHE_NAMESPACE,
|
|
53
|
+
) => [...queryRoot(cacheNamespace), "listing", pda] as const,
|
|
40
54
|
/** One agent's indexer track record. */
|
|
41
|
-
agentTrackRecord: (
|
|
42
|
-
|
|
55
|
+
agentTrackRecord: (
|
|
56
|
+
agentPda: string,
|
|
57
|
+
cacheNamespace: string = DEFAULT_QUERY_CACHE_NAMESPACE,
|
|
58
|
+
) => [...queryRoot(cacheNamespace), "agentTrackRecord", agentPda] as const,
|
|
43
59
|
/** One task's status (read via transport / svm decode). */
|
|
44
|
-
taskStatus: (
|
|
45
|
-
|
|
60
|
+
taskStatus: (
|
|
61
|
+
taskPda: string,
|
|
62
|
+
cacheNamespace: string = DEFAULT_QUERY_CACHE_NAMESPACE,
|
|
63
|
+
) => [...queryRoot(cacheNamespace), "taskStatus", taskPda] as const,
|
|
46
64
|
/** One task's dispute record. */
|
|
47
|
-
dispute: (
|
|
65
|
+
dispute: (
|
|
66
|
+
taskPda: string,
|
|
67
|
+
cacheNamespace: string = DEFAULT_QUERY_CACHE_NAMESPACE,
|
|
68
|
+
) => [...queryRoot(cacheNamespace), "dispute", taskPda] as const,
|
|
48
69
|
/** One task's completion-bond ("Guaranteed Hire") state. */
|
|
49
|
-
taskGuarantee: (
|
|
50
|
-
|
|
70
|
+
taskGuarantee: (
|
|
71
|
+
taskPda: string,
|
|
72
|
+
cacheNamespace: string = DEFAULT_QUERY_CACHE_NAMESPACE,
|
|
73
|
+
) => [...queryRoot(cacheNamespace), "taskGuarantee", taskPda] as const,
|
|
51
74
|
/** One referrer wallet's earnings (indexer-gated; see useReferrerEarnings). */
|
|
52
|
-
referrerEarnings: (
|
|
53
|
-
|
|
75
|
+
referrerEarnings: (
|
|
76
|
+
wallet: string,
|
|
77
|
+
cacheNamespace: string = DEFAULT_QUERY_CACHE_NAMESPACE,
|
|
78
|
+
) => [...queryRoot(cacheNamespace), "referrerEarnings", wallet] as const,
|
|
54
79
|
} as const;
|
|
55
80
|
|
|
56
81
|
/**
|
|
@@ -116,21 +141,150 @@ export function resolveReferrerArgs(
|
|
|
116
141
|
};
|
|
117
142
|
}
|
|
118
143
|
|
|
119
|
-
|
|
144
|
+
/**
|
|
145
|
+
* Detach one on-chain fixed-byte value from caller-owned mutable storage.
|
|
146
|
+
* Validation happens synchronously at the hook's public enqueue boundary so a
|
|
147
|
+
* later TanStack/SDK await can never observe a different byte sequence.
|
|
148
|
+
*/
|
|
149
|
+
export function snapshotFixedBytes32(
|
|
150
|
+
value: unknown,
|
|
151
|
+
label: string,
|
|
152
|
+
): Uint8Array {
|
|
153
|
+
return snapshotFixedBytes(value, 32, label);
|
|
154
|
+
}
|
|
155
|
+
|
|
156
|
+
function snapshotFixedBytes(
|
|
157
|
+
value: unknown,
|
|
158
|
+
byteLength: number,
|
|
159
|
+
label: string,
|
|
160
|
+
): Uint8Array {
|
|
161
|
+
if (
|
|
162
|
+
!isExactUint8Array(value) ||
|
|
163
|
+
typedArrayByteLengthGetter?.call(value) !== byteLength ||
|
|
164
|
+
!hasOrdinaryArrayBuffer(value)
|
|
165
|
+
) {
|
|
166
|
+
throw new TypeError(`${label} must be exactly ${byteLength} bytes`);
|
|
167
|
+
}
|
|
168
|
+
return new Uint8Array(value);
|
|
169
|
+
}
|
|
170
|
+
|
|
171
|
+
const typedArrayPrototype = Object.getPrototypeOf(Uint8Array.prototype);
|
|
172
|
+
const typedArrayTagGetter = Object.getOwnPropertyDescriptor(
|
|
173
|
+
typedArrayPrototype,
|
|
174
|
+
Symbol.toStringTag,
|
|
175
|
+
)?.get;
|
|
176
|
+
const typedArrayByteLengthGetter = Object.getOwnPropertyDescriptor(
|
|
177
|
+
typedArrayPrototype,
|
|
178
|
+
"byteLength",
|
|
179
|
+
)?.get;
|
|
180
|
+
const typedArrayBufferGetter = Object.getOwnPropertyDescriptor(
|
|
181
|
+
typedArrayPrototype,
|
|
182
|
+
"buffer",
|
|
183
|
+
)?.get;
|
|
184
|
+
const arrayBufferByteLengthGetter = Object.getOwnPropertyDescriptor(
|
|
185
|
+
ArrayBuffer.prototype,
|
|
186
|
+
"byteLength",
|
|
187
|
+
)?.get;
|
|
188
|
+
|
|
189
|
+
/**
|
|
190
|
+
* Recognize the SDK's exact byte-view contract across browser/worker realms.
|
|
191
|
+
* `instanceof` is realm-local and `Object#toString` honors a spoofable own
|
|
192
|
+
* `Symbol.toStringTag`. Calling the shared `%TypedArray%` intrinsic getter
|
|
193
|
+
* directly performs the unforgeable typed-array-kind check across realms.
|
|
194
|
+
*/
|
|
195
|
+
function isExactUint8Array(value: unknown): value is Uint8Array {
|
|
196
|
+
return (
|
|
197
|
+
ArrayBuffer.isView(value) &&
|
|
198
|
+
typedArrayTagGetter?.call(value) === "Uint8Array"
|
|
199
|
+
);
|
|
200
|
+
}
|
|
201
|
+
|
|
202
|
+
/** Shared backing can change concurrently and cannot yield one coherent hash. */
|
|
203
|
+
function hasOrdinaryArrayBuffer(value: Uint8Array): boolean {
|
|
204
|
+
try {
|
|
205
|
+
const buffer = typedArrayBufferGetter?.call(value);
|
|
206
|
+
return (
|
|
207
|
+
buffer !== undefined &&
|
|
208
|
+
typeof arrayBufferByteLengthGetter?.call(buffer) === "number"
|
|
209
|
+
);
|
|
210
|
+
} catch {
|
|
211
|
+
// `%ArrayBuffer%.byteLength` rejects SharedArrayBuffer and foreign brands.
|
|
212
|
+
return false;
|
|
213
|
+
}
|
|
214
|
+
}
|
|
215
|
+
|
|
216
|
+
/**
|
|
217
|
+
* Detach a nullable Solana `OptionOrNullable<ReadonlyUint8Array>` while
|
|
218
|
+
* preserving its public representation. Both the convenient nullable form and
|
|
219
|
+
* Kit's explicit `Some`/`None` objects are accepted by generated encoders.
|
|
220
|
+
*/
|
|
221
|
+
export function snapshotOptionalFixedBytes<T>(
|
|
222
|
+
value: T,
|
|
223
|
+
byteLength: number,
|
|
224
|
+
label: string,
|
|
225
|
+
): T {
|
|
226
|
+
if (value === undefined || value === null) return value;
|
|
227
|
+
if (isExactUint8Array(value)) {
|
|
228
|
+
return snapshotFixedBytes(value, byteLength, label) as T;
|
|
229
|
+
}
|
|
230
|
+
if (typeof value !== "object") {
|
|
231
|
+
throw new TypeError(`${label} must be exactly ${byteLength} bytes or None`);
|
|
232
|
+
}
|
|
120
233
|
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
234
|
+
const option = value as {
|
|
235
|
+
readonly __option?: unknown;
|
|
236
|
+
readonly value?: unknown;
|
|
237
|
+
};
|
|
238
|
+
const tag = option.__option;
|
|
239
|
+
if (tag === "None") {
|
|
240
|
+
return Object.freeze({ __option: "None" }) as T;
|
|
124
241
|
}
|
|
242
|
+
if (tag === "Some") {
|
|
243
|
+
const bytes = snapshotFixedBytes(option.value, byteLength, label);
|
|
244
|
+
return Object.freeze({ __option: "Some", value: bytes }) as T;
|
|
245
|
+
}
|
|
246
|
+
throw new TypeError(`${label} must be exactly ${byteLength} bytes or None`);
|
|
247
|
+
}
|
|
248
|
+
|
|
249
|
+
/**
|
|
250
|
+
* Copy and freeze one caller-owned record. Callers with nested mutable values
|
|
251
|
+
* must replace those values with their own snapshots before enqueueing.
|
|
252
|
+
*/
|
|
253
|
+
export function snapshotRecord<T extends object>(value: T): T {
|
|
254
|
+
return Object.freeze({ ...value }) as T;
|
|
255
|
+
}
|
|
256
|
+
|
|
257
|
+
/** Copy a caller-owned account collection and every known-flat entry. */
|
|
258
|
+
export function snapshotRecordArray<T extends object>(
|
|
259
|
+
value: readonly T[],
|
|
260
|
+
): readonly T[] {
|
|
261
|
+
return Object.freeze(value.map((entry) => snapshotRecord(entry)));
|
|
262
|
+
}
|
|
263
|
+
|
|
264
|
+
/**
|
|
265
|
+
* Stabilize the fee-payer signer and the exact optional instruction override at
|
|
266
|
+
* the synchronous hook boundary. An override for the fee-payer's canonical
|
|
267
|
+
* address resolves to the fee-payer object because Solana Kit rejects distinct
|
|
268
|
+
* signer implementations for one address. A different-address override keeps
|
|
269
|
+
* its own identity after the SDK guard permanently locks its address. Other
|
|
270
|
+
* stateful wallet/session fields remain usable.
|
|
271
|
+
*/
|
|
272
|
+
export function stabilizeSelectedTransactionSigner(
|
|
273
|
+
clientSigner: TransactionSigner,
|
|
274
|
+
override?: TransactionSigner,
|
|
275
|
+
): TransactionSigner {
|
|
276
|
+
const stableClientSigner = stabilizeTransactionSigner(clientSigner);
|
|
125
277
|
if (
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
typeof signerOrAddress.address === "string"
|
|
278
|
+
override === undefined ||
|
|
279
|
+
override === stableClientSigner ||
|
|
280
|
+
override.address === stableClientSigner.address
|
|
130
281
|
) {
|
|
131
|
-
return
|
|
282
|
+
return stableClientSigner;
|
|
132
283
|
}
|
|
133
|
-
|
|
284
|
+
const stableOverride = stabilizeTransactionSigner(override);
|
|
285
|
+
return stableOverride.address === stableClientSigner.address
|
|
286
|
+
? stableClientSigner
|
|
287
|
+
: stableOverride;
|
|
134
288
|
}
|
|
135
289
|
|
|
136
290
|
export function withoutReferrerArgs<T extends object>(
|
|
@@ -140,11 +140,14 @@ export function useAgentTrackRecord(
|
|
|
140
140
|
agentPda: Address | string | undefined | null,
|
|
141
141
|
options?: UseAgentTrackRecordOptions,
|
|
142
142
|
): UseAgentTrackRecordResult {
|
|
143
|
-
const { read } = useAgencContext();
|
|
143
|
+
const { read, cacheNamespace } = useAgencContext();
|
|
144
144
|
const enabled = (options?.enabled ?? true) && Boolean(agentPda);
|
|
145
145
|
|
|
146
146
|
const query = useQuery<AgentTrackRecord, Error>({
|
|
147
|
-
queryKey: queryKeys.agentTrackRecord(
|
|
147
|
+
queryKey: queryKeys.agentTrackRecord(
|
|
148
|
+
agentPda ? pdaKey(agentPda) : "",
|
|
149
|
+
cacheNamespace,
|
|
150
|
+
),
|
|
148
151
|
enabled,
|
|
149
152
|
queryFn: async () => {
|
|
150
153
|
const raw = await read.agentTrackRecord(agentPda as Address | string);
|
|
@@ -22,14 +22,17 @@
|
|
|
22
22
|
* @module hooks/useCompletionBond
|
|
23
23
|
*/
|
|
24
24
|
import { useMutation, useQueryClient } from "@tanstack/react-query";
|
|
25
|
-
import { useCallback } from "react";
|
|
25
|
+
import { useCallback, useRef } from "react";
|
|
26
26
|
import type { facade as facadeNs } from "@tetsuo-ai/marketplace-sdk";
|
|
27
27
|
import { useAgencContext } from "../provider/context.js";
|
|
28
|
+
import type { MarketplaceClient } from "../types.js";
|
|
28
29
|
import {
|
|
29
30
|
mutationStatusOf,
|
|
30
31
|
pdaKey,
|
|
31
32
|
queryKeys,
|
|
32
33
|
requireClient,
|
|
34
|
+
snapshotRecord,
|
|
35
|
+
stabilizeSelectedTransactionSigner,
|
|
33
36
|
type MutationStatus,
|
|
34
37
|
} from "./internal.js";
|
|
35
38
|
|
|
@@ -62,6 +65,11 @@ export type ReclaimCompletionBondInput = Omit<
|
|
|
62
65
|
/** Lifecycle status of a bond verb. */
|
|
63
66
|
export type CompletionBondStatus = MutationStatus;
|
|
64
67
|
|
|
68
|
+
interface QueuedCompletionBondInput<TInput> {
|
|
69
|
+
readonly client: MarketplaceClient;
|
|
70
|
+
readonly input: TInput;
|
|
71
|
+
}
|
|
72
|
+
|
|
65
73
|
/** Return value of {@link useCompletionBond}. */
|
|
66
74
|
export interface UseCompletionBondResult {
|
|
67
75
|
/** Post a bond. Resolves to the tx signature; rejects with `AgencError`. */
|
|
@@ -91,33 +99,38 @@ export function useCompletionBond(
|
|
|
91
99
|
): UseCompletionBondResult {
|
|
92
100
|
const ctx = useAgencContext();
|
|
93
101
|
const queryClient = useQueryClient();
|
|
102
|
+
const lastAction = useRef<"post" | "reclaim" | null>(null);
|
|
94
103
|
|
|
95
104
|
const invalidateGuarantee = useCallback(() => {
|
|
96
105
|
void queryClient.invalidateQueries({
|
|
97
|
-
queryKey: queryKeys.taskGuarantee(pdaKey(taskPda)),
|
|
106
|
+
queryKey: queryKeys.taskGuarantee(pdaKey(taskPda), ctx.cacheNamespace),
|
|
98
107
|
});
|
|
99
|
-
}, [queryClient, taskPda]);
|
|
108
|
+
}, [ctx.cacheNamespace, queryClient, taskPda]);
|
|
100
109
|
|
|
101
|
-
const postMut = useMutation<
|
|
102
|
-
|
|
103
|
-
|
|
110
|
+
const postMut = useMutation<
|
|
111
|
+
string,
|
|
112
|
+
Error,
|
|
113
|
+
QueuedCompletionBondInput<PostCompletionBondInput>
|
|
114
|
+
>({
|
|
115
|
+
mutationFn: async ({ client, input }) => {
|
|
104
116
|
const { signature } = await client.postCompletionBond({
|
|
105
117
|
...input,
|
|
106
118
|
task: taskPda,
|
|
107
|
-
authority: input.authority ?? client.signer,
|
|
108
119
|
} as Parameters<typeof facadeNs.postCompletionBond>[0]);
|
|
109
120
|
invalidateGuarantee();
|
|
110
121
|
return signature;
|
|
111
122
|
},
|
|
112
123
|
});
|
|
113
124
|
|
|
114
|
-
const reclaimMut = useMutation<
|
|
115
|
-
|
|
116
|
-
|
|
125
|
+
const reclaimMut = useMutation<
|
|
126
|
+
string,
|
|
127
|
+
Error,
|
|
128
|
+
QueuedCompletionBondInput<ReclaimCompletionBondInput>
|
|
129
|
+
>({
|
|
130
|
+
mutationFn: async ({ client, input }) => {
|
|
117
131
|
const { signature } = await client.reclaimCompletionBond({
|
|
118
132
|
...input,
|
|
119
133
|
task: taskPda,
|
|
120
|
-
party: input.party ?? client.signer.address,
|
|
121
134
|
} as Parameters<typeof facadeNs.reclaimCompletionBond>[0]);
|
|
122
135
|
invalidateGuarantee();
|
|
123
136
|
return signature;
|
|
@@ -125,30 +138,52 @@ export function useCompletionBond(
|
|
|
125
138
|
});
|
|
126
139
|
|
|
127
140
|
const post = useCallback(
|
|
128
|
-
(input: PostCompletionBondInput) =>
|
|
129
|
-
|
|
141
|
+
async (input: PostCompletionBondInput) => {
|
|
142
|
+
const client = requireClient(ctx.client);
|
|
143
|
+
const detachedInput = snapshotRecord(input);
|
|
144
|
+
const authority = stabilizeSelectedTransactionSigner(
|
|
145
|
+
client.signer,
|
|
146
|
+
detachedInput.authority,
|
|
147
|
+
);
|
|
148
|
+
const snapshottedInput = snapshotRecord({
|
|
149
|
+
...detachedInput,
|
|
150
|
+
authority,
|
|
151
|
+
}) as PostCompletionBondInput;
|
|
152
|
+
lastAction.current = "post";
|
|
153
|
+
return postMut.mutateAsync({ client, input: snapshottedInput });
|
|
154
|
+
},
|
|
155
|
+
[ctx.client, postMut],
|
|
130
156
|
);
|
|
131
157
|
const reclaim = useCallback(
|
|
132
|
-
(input: ReclaimCompletionBondInput) =>
|
|
133
|
-
|
|
158
|
+
async (input: ReclaimCompletionBondInput) => {
|
|
159
|
+
const client = requireClient(ctx.client);
|
|
160
|
+
const detachedInput = snapshotRecord(input);
|
|
161
|
+
const feePayer = stabilizeSelectedTransactionSigner(client.signer);
|
|
162
|
+
const snapshottedInput = snapshotRecord({
|
|
163
|
+
...detachedInput,
|
|
164
|
+
party: detachedInput.party ?? feePayer.address,
|
|
165
|
+
}) as ReclaimCompletionBondInput;
|
|
166
|
+
lastAction.current = "reclaim";
|
|
167
|
+
return reclaimMut.mutateAsync({ client, input: snapshottedInput });
|
|
168
|
+
},
|
|
169
|
+
[ctx.client, reclaimMut],
|
|
134
170
|
);
|
|
135
171
|
|
|
136
172
|
const isPending = postMut.isPending || reclaimMut.isPending;
|
|
173
|
+
const latest = lastAction.current === "reclaim" ? reclaimMut : postMut;
|
|
137
174
|
const status: CompletionBondStatus = isPending
|
|
138
175
|
? "pending"
|
|
139
|
-
: mutationStatusOf(
|
|
140
|
-
// Surface the most recently-touched verb's terminal state.
|
|
141
|
-
[postMut, reclaimMut].find((m) => m.isError || m.isSuccess) ?? postMut,
|
|
142
|
-
);
|
|
176
|
+
: mutationStatusOf(latest);
|
|
143
177
|
|
|
144
178
|
return {
|
|
145
179
|
post,
|
|
146
180
|
reclaim,
|
|
147
181
|
status,
|
|
148
|
-
error:
|
|
149
|
-
signature:
|
|
182
|
+
error: latest.error ?? null,
|
|
183
|
+
signature: latest.data ?? null,
|
|
150
184
|
isPending,
|
|
151
185
|
reset: () => {
|
|
186
|
+
lastAction.current = null;
|
|
152
187
|
postMut.reset();
|
|
153
188
|
reclaimMut.reset();
|
|
154
189
|
},
|
package/src/hooks/useDispute.ts
CHANGED
|
@@ -16,8 +16,15 @@ import {
|
|
|
16
16
|
type facade as facadeNs,
|
|
17
17
|
} from "@tetsuo-ai/marketplace-sdk";
|
|
18
18
|
import { useAgencContext } from "../provider/context.js";
|
|
19
|
-
import type { Address } from "../types.js";
|
|
20
|
-
import {
|
|
19
|
+
import type { Address, MarketplaceClient } from "../types.js";
|
|
20
|
+
import {
|
|
21
|
+
pdaKey,
|
|
22
|
+
queryKeys,
|
|
23
|
+
requireClient,
|
|
24
|
+
snapshotFixedBytes32,
|
|
25
|
+
snapshotRecord,
|
|
26
|
+
stabilizeSelectedTransactionSigner,
|
|
27
|
+
} from "./internal.js";
|
|
21
28
|
|
|
22
29
|
/** Reads a Dispute account for a task, returning the decoded value or null. */
|
|
23
30
|
export type DisputeReader = (
|
|
@@ -40,6 +47,11 @@ export type InitiateDisputeInput = Omit<
|
|
|
40
47
|
/** Lifecycle status of the initiate mutation. */
|
|
41
48
|
export type DisputeStatus = "idle" | "pending" | "success" | "error";
|
|
42
49
|
|
|
50
|
+
interface QueuedDisputeInput {
|
|
51
|
+
readonly client: MarketplaceClient;
|
|
52
|
+
readonly input: InitiateDisputeInput;
|
|
53
|
+
}
|
|
54
|
+
|
|
43
55
|
/** Options for {@link useDispute}. */
|
|
44
56
|
export interface UseDisputeOptions {
|
|
45
57
|
/** How to read the Dispute account. Without it the read stays idle. */
|
|
@@ -85,18 +97,19 @@ export function useDispute(
|
|
|
85
97
|
(options?.enabled ?? true) && Boolean(taskPda) && Boolean(reader);
|
|
86
98
|
|
|
87
99
|
const read = useQuery<Dispute | null, Error>({
|
|
88
|
-
queryKey: queryKeys.dispute(
|
|
100
|
+
queryKey: queryKeys.dispute(
|
|
101
|
+
taskPda ? pdaKey(taskPda) : "",
|
|
102
|
+
ctx.cacheNamespace,
|
|
103
|
+
),
|
|
89
104
|
enabled,
|
|
90
105
|
queryFn: () => reader!(taskPda as Address | string),
|
|
91
106
|
});
|
|
92
107
|
|
|
93
|
-
const mutation = useMutation<string, Error,
|
|
94
|
-
mutationFn: async (input) => {
|
|
95
|
-
const client = requireClient(ctx.client);
|
|
108
|
+
const mutation = useMutation<string, Error, QueuedDisputeInput>({
|
|
109
|
+
mutationFn: async ({ client, input }) => {
|
|
96
110
|
const { signature } = await client.initiateDispute({
|
|
97
111
|
...input,
|
|
98
112
|
task: taskPda as Address,
|
|
99
|
-
authority: input.authority ?? client.signer,
|
|
100
113
|
} as Parameters<typeof facadeNs.initiateDispute>[0]);
|
|
101
114
|
// A new dispute exists — refresh the read.
|
|
102
115
|
void read.refetch();
|
|
@@ -105,8 +118,32 @@ export function useDispute(
|
|
|
105
118
|
});
|
|
106
119
|
|
|
107
120
|
const initiate = useCallback(
|
|
108
|
-
(input: InitiateDisputeInput) =>
|
|
109
|
-
|
|
121
|
+
async (input: InitiateDisputeInput) => {
|
|
122
|
+
const client = requireClient(ctx.client);
|
|
123
|
+
const detachedInput = snapshotRecord(input);
|
|
124
|
+
const authority = stabilizeSelectedTransactionSigner(
|
|
125
|
+
client.signer,
|
|
126
|
+
detachedInput.authority,
|
|
127
|
+
);
|
|
128
|
+
const snapshottedInput = snapshotRecord({
|
|
129
|
+
...detachedInput,
|
|
130
|
+
authority,
|
|
131
|
+
disputeId: snapshotFixedBytes32(
|
|
132
|
+
detachedInput.disputeId,
|
|
133
|
+
"useDispute.initiate: disputeId",
|
|
134
|
+
),
|
|
135
|
+
taskId: snapshotFixedBytes32(
|
|
136
|
+
detachedInput.taskId,
|
|
137
|
+
"useDispute.initiate: taskId",
|
|
138
|
+
),
|
|
139
|
+
evidenceHash: snapshotFixedBytes32(
|
|
140
|
+
detachedInput.evidenceHash,
|
|
141
|
+
"useDispute.initiate: evidenceHash",
|
|
142
|
+
),
|
|
143
|
+
}) as InitiateDisputeInput;
|
|
144
|
+
return mutation.mutateAsync({ client, input: snapshottedInput });
|
|
145
|
+
},
|
|
146
|
+
[ctx.client, mutation],
|
|
110
147
|
);
|
|
111
148
|
|
|
112
149
|
const status: DisputeStatus = mutation.isPending
|