@tetsuo-ai/marketplace-react 0.3.0 → 0.3.2
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 +29 -0
- package/dist/{chunk-FAIRTAIB.js → chunk-2Y6JN2VZ.js} +3 -3
- package/dist/{chunk-FAIRTAIB.js.map → chunk-2Y6JN2VZ.js.map} +1 -1
- package/dist/{chunk-D2TDU3TJ.js → chunk-AKPPKMQ2.js} +3 -3
- package/dist/{chunk-D2TDU3TJ.js.map → chunk-AKPPKMQ2.js.map} +1 -1
- package/dist/{chunk-ECU7HGO3.js → chunk-H6PJIDQR.js} +4 -3
- package/dist/chunk-H6PJIDQR.js.map +1 -0
- package/dist/{chunk-MNJ2EQDJ.js → chunk-ON6XR4XO.js} +3 -3
- package/dist/{chunk-MNJ2EQDJ.js.map → chunk-ON6XR4XO.js.map} +1 -1
- package/dist/{chunk-WJUVTFJ7.js → chunk-ZAMIL27X.js} +4 -4
- package/dist/{chunk-WJUVTFJ7.js.map → chunk-ZAMIL27X.js.map} +1 -1
- package/dist/components/index.cjs +2 -1
- package/dist/components/index.cjs.map +1 -1
- package/dist/components/index.d.cts +1 -1
- package/dist/components/index.d.ts +1 -1
- package/dist/components/index.js +3 -3
- package/dist/hooks/index.cjs +86 -9
- package/dist/hooks/index.cjs.map +1 -1
- package/dist/hooks/index.d.cts +6 -8
- package/dist/hooks/index.d.ts +6 -8
- package/dist/hooks/index.js +89 -12
- package/dist/hooks/index.js.map +1 -1
- package/dist/{index-C9R3B80j.d.ts → index-DQ3Xovkq.d.ts} +15 -1
- package/dist/{index-CTTh1ZPg.d.cts → index-UxuvIlmD.d.cts} +15 -1
- package/dist/index.cjs +9 -1
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +2 -2
- package/dist/index.d.ts +2 -2
- package/dist/index.js +15 -8
- package/dist/index.js.map +1 -1
- package/dist/signers/index.cjs +2 -1
- package/dist/signers/index.cjs.map +1 -1
- package/dist/signers/index.js +2 -2
- package/package.json +1 -1
- package/src/hooks/moderation-attestor.ts +98 -0
- package/src/hooks/useHumanlessHireFlow.ts +12 -0
- package/src/hooks/useReferrerEarnings.ts +73 -38
- package/src/hooks/useTaskActivation.ts +13 -0
- package/src/provider/AgencProvider.tsx +12 -0
- package/src/strings/index.ts +3 -1
- package/src/types.ts +13 -0
- package/dist/chunk-ECU7HGO3.js.map +0 -1
package/dist/hooks/index.d.cts
CHANGED
|
@@ -364,7 +364,7 @@ interface UseWalletSignerResult {
|
|
|
364
364
|
*/
|
|
365
365
|
declare function useWalletSigner(options?: UseWalletSignerOptions): UseWalletSignerResult;
|
|
366
366
|
|
|
367
|
-
/** A single referral-earning hire
|
|
367
|
+
/** A single referral-earning hire. */
|
|
368
368
|
interface ReferrerHire {
|
|
369
369
|
/** The minted Task PDA of the referred hire. */
|
|
370
370
|
taskPda: string;
|
|
@@ -372,7 +372,7 @@ interface ReferrerHire {
|
|
|
372
372
|
hireRecordPda: string;
|
|
373
373
|
/** Referral fee earned on this hire, in lamports. */
|
|
374
374
|
feeLamports: bigint;
|
|
375
|
-
/** Transaction signature of the hire. */
|
|
375
|
+
/** Transaction signature of the hire (empty until event indexing lands). */
|
|
376
376
|
signature: string;
|
|
377
377
|
}
|
|
378
378
|
/** Return value of {@link useReferrerEarnings}. */
|
|
@@ -387,7 +387,7 @@ interface UseReferrerEarningsResult {
|
|
|
387
387
|
totalLamports: bigint;
|
|
388
388
|
/** Per-hire earnings. `[]` while not live. */
|
|
389
389
|
hires: ReferrerHire[];
|
|
390
|
-
/** True while a fetch is in flight.
|
|
390
|
+
/** True while a fetch is in flight. */
|
|
391
391
|
isLoading: boolean;
|
|
392
392
|
/** The fetch error, or null. */
|
|
393
393
|
error: Error | null;
|
|
@@ -400,17 +400,15 @@ interface UseReferrerEarningsResult {
|
|
|
400
400
|
refetch: () => void;
|
|
401
401
|
}
|
|
402
402
|
/**
|
|
403
|
-
* Read a referrer wallet's earnings.
|
|
403
|
+
* Read a referrer wallet's aggregated earnings from the hosted explorer.
|
|
404
404
|
*
|
|
405
405
|
* @param wallet - The referrer wallet (base58 / Address). Falsy disables the
|
|
406
|
-
*
|
|
407
|
-
|
|
408
|
-
* the earnings indexer ships.
|
|
406
|
+
* fetch; the not-live state is still returned.
|
|
407
|
+
* @returns {@link UseReferrerEarningsResult}
|
|
409
408
|
*
|
|
410
409
|
* @example
|
|
411
410
|
* ```tsx
|
|
412
411
|
* const { live, totalLamports, hires, reason } = useReferrerEarnings(myWallet);
|
|
413
|
-
* // until the earnings indexer ships: live === false, totalLamports === 0n, hires === []
|
|
414
412
|
* ```
|
|
415
413
|
*/
|
|
416
414
|
declare function useReferrerEarnings(wallet: Address | string | undefined | null): UseReferrerEarningsResult;
|
package/dist/hooks/index.d.ts
CHANGED
|
@@ -364,7 +364,7 @@ interface UseWalletSignerResult {
|
|
|
364
364
|
*/
|
|
365
365
|
declare function useWalletSigner(options?: UseWalletSignerOptions): UseWalletSignerResult;
|
|
366
366
|
|
|
367
|
-
/** A single referral-earning hire
|
|
367
|
+
/** A single referral-earning hire. */
|
|
368
368
|
interface ReferrerHire {
|
|
369
369
|
/** The minted Task PDA of the referred hire. */
|
|
370
370
|
taskPda: string;
|
|
@@ -372,7 +372,7 @@ interface ReferrerHire {
|
|
|
372
372
|
hireRecordPda: string;
|
|
373
373
|
/** Referral fee earned on this hire, in lamports. */
|
|
374
374
|
feeLamports: bigint;
|
|
375
|
-
/** Transaction signature of the hire. */
|
|
375
|
+
/** Transaction signature of the hire (empty until event indexing lands). */
|
|
376
376
|
signature: string;
|
|
377
377
|
}
|
|
378
378
|
/** Return value of {@link useReferrerEarnings}. */
|
|
@@ -387,7 +387,7 @@ interface UseReferrerEarningsResult {
|
|
|
387
387
|
totalLamports: bigint;
|
|
388
388
|
/** Per-hire earnings. `[]` while not live. */
|
|
389
389
|
hires: ReferrerHire[];
|
|
390
|
-
/** True while a fetch is in flight.
|
|
390
|
+
/** True while a fetch is in flight. */
|
|
391
391
|
isLoading: boolean;
|
|
392
392
|
/** The fetch error, or null. */
|
|
393
393
|
error: Error | null;
|
|
@@ -400,17 +400,15 @@ interface UseReferrerEarningsResult {
|
|
|
400
400
|
refetch: () => void;
|
|
401
401
|
}
|
|
402
402
|
/**
|
|
403
|
-
* Read a referrer wallet's earnings.
|
|
403
|
+
* Read a referrer wallet's aggregated earnings from the hosted explorer.
|
|
404
404
|
*
|
|
405
405
|
* @param wallet - The referrer wallet (base58 / Address). Falsy disables the
|
|
406
|
-
*
|
|
407
|
-
|
|
408
|
-
* the earnings indexer ships.
|
|
406
|
+
* fetch; the not-live state is still returned.
|
|
407
|
+
* @returns {@link UseReferrerEarningsResult}
|
|
409
408
|
*
|
|
410
409
|
* @example
|
|
411
410
|
* ```tsx
|
|
412
411
|
* const { live, totalLamports, hires, reason } = useReferrerEarnings(myWallet);
|
|
413
|
-
* // until the earnings indexer ships: live === false, totalLamports === 0n, hires === []
|
|
414
412
|
* ```
|
|
415
413
|
*/
|
|
416
414
|
declare function useReferrerEarnings(wallet: Address | string | undefined | null): UseReferrerEarningsResult;
|
package/dist/hooks/index.js
CHANGED
|
@@ -1,10 +1,11 @@
|
|
|
1
|
-
import { ReadTransportUnsupportedError } from '../chunk-
|
|
2
|
-
import { useAgencContext, queryKeys, pdaKey, requireClient, mutationStatusOf, resolveReferrerArgs, withoutReferrerArgs, signerAddress } from '../chunk-
|
|
3
|
-
export { QUERY_KEY_ROOT, queryKeys, useHire, useWalletSigner } from '../chunk-
|
|
4
|
-
import { t } from '../chunk-
|
|
1
|
+
import { ReadTransportUnsupportedError } from '../chunk-AKPPKMQ2.js';
|
|
2
|
+
import { useAgencContext, queryKeys, pdaKey, requireClient, mutationStatusOf, resolveReferrerArgs, withoutReferrerArgs, signerAddress } from '../chunk-2Y6JN2VZ.js';
|
|
3
|
+
export { QUERY_KEY_ROOT, queryKeys, useHire, useWalletSigner } from '../chunk-2Y6JN2VZ.js';
|
|
4
|
+
import { t } from '../chunk-H6PJIDQR.js';
|
|
5
5
|
import { useQuery, useMutation } from '@tanstack/react-query';
|
|
6
6
|
import { useState, useMemo, useCallback, useRef, useEffect } from 'react';
|
|
7
|
-
import { TaskStatus, facade, findTaskPda } from '@tetsuo-ai/marketplace-sdk';
|
|
7
|
+
import { TaskStatus, facade, findTaskPda, findTaskModerationPda, fetchMaybeTaskModeration, findModerationConfigPda, fetchMaybeModerationConfig, findModerationAttestorPda } from '@tetsuo-ai/marketplace-sdk';
|
|
8
|
+
import { createSolanaRpc } from '@solana/kit';
|
|
8
9
|
|
|
9
10
|
var DEFAULT_PAGE_SIZE = 12;
|
|
10
11
|
function useListings(filter, options) {
|
|
@@ -260,13 +261,50 @@ function useSubmissionReview(taskPda) {
|
|
|
260
261
|
}
|
|
261
262
|
};
|
|
262
263
|
}
|
|
264
|
+
async function resolveActivationModerationAttestor(input) {
|
|
265
|
+
try {
|
|
266
|
+
const rpc = input.rpc ?? (input.rpcUrl ? createSolanaRpc(input.rpcUrl) : null);
|
|
267
|
+
if (!rpc) return void 0;
|
|
268
|
+
const [taskModerationPda] = await findTaskModerationPda({
|
|
269
|
+
task: input.task,
|
|
270
|
+
jobSpecHash: input.jobSpecHash
|
|
271
|
+
});
|
|
272
|
+
const taskModeration = await fetchMaybeTaskModeration(
|
|
273
|
+
rpc,
|
|
274
|
+
taskModerationPda
|
|
275
|
+
);
|
|
276
|
+
if (!taskModeration.exists) return void 0;
|
|
277
|
+
const [moderationConfigPda] = await findModerationConfigPda();
|
|
278
|
+
const moderationConfig = await fetchMaybeModerationConfig(
|
|
279
|
+
rpc,
|
|
280
|
+
moderationConfigPda
|
|
281
|
+
);
|
|
282
|
+
if (moderationConfig.exists && taskModeration.data.moderator === moderationConfig.data.moderationAuthority) {
|
|
283
|
+
return void 0;
|
|
284
|
+
}
|
|
285
|
+
const [rosterPda] = await findModerationAttestorPda({
|
|
286
|
+
attestor: taskModeration.data.moderator
|
|
287
|
+
});
|
|
288
|
+
return rosterPda;
|
|
289
|
+
} catch {
|
|
290
|
+
return void 0;
|
|
291
|
+
}
|
|
292
|
+
}
|
|
293
|
+
|
|
294
|
+
// src/hooks/useTaskActivation.ts
|
|
263
295
|
function useTaskActivation(taskPda) {
|
|
264
296
|
const ctx = useAgencContext();
|
|
265
297
|
const mutation = useMutation({
|
|
266
298
|
mutationFn: async (input) => {
|
|
267
299
|
const client = requireClient(ctx.client);
|
|
300
|
+
const moderationAttestor = input.moderationAttestor ?? await resolveActivationModerationAttestor({
|
|
301
|
+
rpcUrl: ctx.rpcUrl,
|
|
302
|
+
task: taskPda,
|
|
303
|
+
jobSpecHash: input.jobSpecHash
|
|
304
|
+
});
|
|
268
305
|
const { signature } = await client.setTaskJobSpec({
|
|
269
306
|
...input,
|
|
307
|
+
...moderationAttestor !== void 0 ? { moderationAttestor } : {},
|
|
270
308
|
task: taskPda,
|
|
271
309
|
creator: input.creator ?? client.signer
|
|
272
310
|
});
|
|
@@ -360,8 +398,14 @@ function useHumanlessHireFlow() {
|
|
|
360
398
|
jobSpecUri
|
|
361
399
|
}));
|
|
362
400
|
setPhase("activating");
|
|
401
|
+
const moderationAttestor = input.activation?.moderationAttestor ?? await resolveActivationModerationAttestor({
|
|
402
|
+
rpcUrl: ctx.rpcUrl,
|
|
403
|
+
task: taskPda,
|
|
404
|
+
jobSpecHash
|
|
405
|
+
});
|
|
363
406
|
const activationResult = await client.setTaskJobSpec({
|
|
364
407
|
...input.activation ?? {},
|
|
408
|
+
...moderationAttestor !== void 0 ? { moderationAttestor } : {},
|
|
365
409
|
task: taskPda,
|
|
366
410
|
creator,
|
|
367
411
|
jobSpecHash,
|
|
@@ -584,23 +628,48 @@ function useDispute(taskPda, options) {
|
|
|
584
628
|
reset: mutation.reset
|
|
585
629
|
};
|
|
586
630
|
}
|
|
587
|
-
var
|
|
631
|
+
var EARNINGS_INDEXER_DEFAULTS = {
|
|
632
|
+
mainnet: "https://api.agenc.ag"
|
|
633
|
+
};
|
|
634
|
+
function resolveEarningsBaseUrl(ctx) {
|
|
635
|
+
return ctx.indexerBaseUrl ?? EARNINGS_INDEXER_DEFAULTS[ctx.network] ?? null;
|
|
636
|
+
}
|
|
588
637
|
function useReferrerEarnings(wallet) {
|
|
589
638
|
const ctx = useAgencContext();
|
|
590
639
|
const capability = ctx.resolveReferrerCapability();
|
|
591
|
-
const
|
|
592
|
-
|
|
640
|
+
const earningsBase = resolveEarningsBaseUrl(ctx);
|
|
641
|
+
const enabled = capability.live && earningsBase !== null && Boolean(wallet);
|
|
642
|
+
const query = useQuery(
|
|
593
643
|
{
|
|
594
644
|
queryKey: queryKeys.referrerEarnings(wallet ? pdaKey(wallet) : ""),
|
|
595
645
|
enabled,
|
|
596
646
|
queryFn: async () => {
|
|
597
|
-
|
|
598
|
-
|
|
599
|
-
)
|
|
647
|
+
const url = `${earningsBase}/api/explorer/referrers/${encodeURIComponent(
|
|
648
|
+
String(wallet)
|
|
649
|
+
)}/hires`;
|
|
650
|
+
const response = await fetch(url, {
|
|
651
|
+
headers: { accept: "application/json" }
|
|
652
|
+
});
|
|
653
|
+
if (!response.ok) {
|
|
654
|
+
throw new Error(
|
|
655
|
+
t("referrer.earningsFetchFailed") + ` (HTTP ${response.status})`
|
|
656
|
+
);
|
|
657
|
+
}
|
|
658
|
+
const body = await response.json();
|
|
659
|
+
const hires = (body.hires ?? []).map((h) => ({
|
|
660
|
+
taskPda: String(h.taskPda ?? ""),
|
|
661
|
+
hireRecordPda: String(h.hireRecordPda ?? ""),
|
|
662
|
+
feeLamports: BigInt(h.feeLamports ?? "0"),
|
|
663
|
+
signature: String(h.signature ?? "")
|
|
664
|
+
}));
|
|
665
|
+
return {
|
|
666
|
+
totalLamports: BigInt(body.totalLamports ?? "0"),
|
|
667
|
+
hires
|
|
668
|
+
};
|
|
600
669
|
}
|
|
601
670
|
}
|
|
602
671
|
);
|
|
603
|
-
if (!
|
|
672
|
+
if (!enabled) {
|
|
604
673
|
return {
|
|
605
674
|
live: false,
|
|
606
675
|
totalLamports: 0n,
|
|
@@ -612,6 +681,14 @@ function useReferrerEarnings(wallet) {
|
|
|
612
681
|
}
|
|
613
682
|
};
|
|
614
683
|
}
|
|
684
|
+
return {
|
|
685
|
+
live: true,
|
|
686
|
+
totalLamports: query.data?.totalLamports ?? 0n,
|
|
687
|
+
hires: query.data?.hires ?? [],
|
|
688
|
+
isLoading: query.isLoading,
|
|
689
|
+
error: query.error ?? null,
|
|
690
|
+
refetch: () => void query.refetch()
|
|
691
|
+
};
|
|
615
692
|
}
|
|
616
693
|
|
|
617
694
|
export { projectTrackRecord, useAgentTrackRecord, useDispute, useHumanlessHireFlow, useListing, useListings, useRateHire, useReferrerEarnings, useSubmissionReview, useTaskActivation, useTaskLifecycle, useTaskStatus, useTaskWork };
|