@tetsuo-ai/marketplace-react 0.1.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.
Files changed (112) hide show
  1. package/CHANGELOG.md +28 -0
  2. package/LICENSE +21 -0
  3. package/README.md +172 -0
  4. package/dist/chunk-5OTKSRHM.js +128 -0
  5. package/dist/chunk-5OTKSRHM.js.map +1 -0
  6. package/dist/chunk-ABS77JB2.js +94 -0
  7. package/dist/chunk-ABS77JB2.js.map +1 -0
  8. package/dist/chunk-GN5DYVN5.js +35 -0
  9. package/dist/chunk-GN5DYVN5.js.map +1 -0
  10. package/dist/chunk-KJMR6OGC.js +1198 -0
  11. package/dist/chunk-KJMR6OGC.js.map +1 -0
  12. package/dist/chunk-YORZNYZZ.js +107 -0
  13. package/dist/chunk-YORZNYZZ.js.map +1 -0
  14. package/dist/components/agenc-components.css +570 -0
  15. package/dist/components/index.cjs +1335 -0
  16. package/dist/components/index.cjs.map +1 -0
  17. package/dist/components/index.d.cts +5 -0
  18. package/dist/components/index.d.ts +5 -0
  19. package/dist/components/index.js +5 -0
  20. package/dist/components/index.js.map +1 -0
  21. package/dist/hooks/index.cjs +493 -0
  22. package/dist/hooks/index.cjs.map +1 -0
  23. package/dist/hooks/index.d.cts +294 -0
  24. package/dist/hooks/index.d.ts +294 -0
  25. package/dist/hooks/index.js +339 -0
  26. package/dist/hooks/index.js.map +1 -0
  27. package/dist/index-BLrlBVj-.d.cts +1129 -0
  28. package/dist/index-CKTYsNPH.d.ts +1129 -0
  29. package/dist/index.cjs +1690 -0
  30. package/dist/index.cjs.map +1 -0
  31. package/dist/index.d.cts +235 -0
  32. package/dist/index.d.ts +235 -0
  33. package/dist/index.js +127 -0
  34. package/dist/index.js.map +1 -0
  35. package/dist/signers/index.cjs +166 -0
  36. package/dist/signers/index.cjs.map +1 -0
  37. package/dist/signers/index.d.cts +136 -0
  38. package/dist/signers/index.d.ts +136 -0
  39. package/dist/signers/index.js +4 -0
  40. package/dist/signers/index.js.map +1 -0
  41. package/dist/testing/index.cjs +62 -0
  42. package/dist/testing/index.cjs.map +1 -0
  43. package/dist/testing/index.d.cts +71 -0
  44. package/dist/testing/index.d.ts +71 -0
  45. package/dist/testing/index.js +60 -0
  46. package/dist/testing/index.js.map +1 -0
  47. package/dist/theme/agenc-tailwind-preset.cjs +184 -0
  48. package/dist/theme/agenc-tokens.css +132 -0
  49. package/dist/types-jvISR6bc.d.cts +135 -0
  50. package/dist/types-jvISR6bc.d.ts +135 -0
  51. package/dist/useAgentTrackRecord-BLf1nrbu.d.cts +249 -0
  52. package/dist/useAgentTrackRecord-BLf1nrbu.d.ts +249 -0
  53. package/package.json +139 -0
  54. package/src/components/DisputeBanner.stories.tsx +39 -0
  55. package/src/components/DisputeBanner.tsx +110 -0
  56. package/src/components/HireButton.stories.tsx +72 -0
  57. package/src/components/HireButton.tsx +151 -0
  58. package/src/components/HireCheckoutModal.stories.tsx +107 -0
  59. package/src/components/HireCheckoutModal.tsx +284 -0
  60. package/src/components/ListingCard.stories.tsx +55 -0
  61. package/src/components/ListingCard.tsx +148 -0
  62. package/src/components/ListingGrid.stories.tsx +44 -0
  63. package/src/components/ListingGrid.tsx +137 -0
  64. package/src/components/Modal.tsx +121 -0
  65. package/src/components/PoweredByAgenC.tsx +85 -0
  66. package/src/components/ProviderCard.stories.tsx +61 -0
  67. package/src/components/ProviderCard.tsx +154 -0
  68. package/src/components/ReferrerDisclosure.tsx +67 -0
  69. package/src/components/ReviewPanel.stories.tsx +65 -0
  70. package/src/components/ReviewPanel.tsx +141 -0
  71. package/src/components/TaskTimeline.stories.tsx +43 -0
  72. package/src/components/TaskTimeline.tsx +156 -0
  73. package/src/components/__fixtures__/index.tsx +173 -0
  74. package/src/components/agenc-components.css +570 -0
  75. package/src/components/badges.tsx +115 -0
  76. package/src/components/format.ts +150 -0
  77. package/src/components/index.ts +102 -0
  78. package/src/components/primitives.tsx +236 -0
  79. package/src/components/strings.ts +131 -0
  80. package/src/components/useFocusTrap.ts +122 -0
  81. package/src/hooks/index.ts +90 -0
  82. package/src/hooks/internal.ts +70 -0
  83. package/src/hooks/useAgentTrackRecord.ts +166 -0
  84. package/src/hooks/useDispute.ts +130 -0
  85. package/src/hooks/useHire.ts +198 -0
  86. package/src/hooks/useListing.ts +138 -0
  87. package/src/hooks/useListings.ts +133 -0
  88. package/src/hooks/useReferrerEarnings.ts +134 -0
  89. package/src/hooks/useSubmissionReview.ts +179 -0
  90. package/src/hooks/useTaskStatus.ts +192 -0
  91. package/src/hooks/useWalletSigner.ts +99 -0
  92. package/src/index.ts +170 -0
  93. package/src/provider/AgencProvider.tsx +169 -0
  94. package/src/provider/context.ts +35 -0
  95. package/src/provider/index.ts +17 -0
  96. package/src/provider/network.ts +68 -0
  97. package/src/provider/referrer.ts +97 -0
  98. package/src/signers/README.md +130 -0
  99. package/src/signers/embedded-wallet-mock.ts +158 -0
  100. package/src/signers/embedded-wallet.ts +64 -0
  101. package/src/signers/index.ts +48 -0
  102. package/src/signers/strings.ts +39 -0
  103. package/src/signers/types.ts +158 -0
  104. package/src/signers/wallet-account.ts +128 -0
  105. package/src/signers/wallet-adapter.ts +149 -0
  106. package/src/strings/index.ts +119 -0
  107. package/src/testing/index.ts +24 -0
  108. package/src/theme/agenc-tailwind-preset.cjs +184 -0
  109. package/src/theme/agenc-tokens.css +132 -0
  110. package/src/theme/index.ts +94 -0
  111. package/src/transport/index.ts +164 -0
  112. package/src/types.ts +224 -0
@@ -0,0 +1,179 @@
1
+ /**
2
+ * `useSubmissionReview(taskPda)` — buyer-side settlement actions.
3
+ *
4
+ * Exposes the three creator review verbs for a task in `PendingValidation`:
5
+ * - `accept(...)` — accept the result and settle the escrow to the worker
6
+ * (`client.acceptTaskResult`, a named client convenience);
7
+ * - `reject(...)` — reject the result with a rejection hash
8
+ * (`facade.rejectTaskResult` -> `client.send`);
9
+ * - `requestChanges(...)` — return the task to the worker with a changes hash
10
+ * (`facade.requestChanges` -> `client.send`).
11
+ *
12
+ * Each verb is its own mutation so a UI can show independent
13
+ * pending/error/success per button. Typed `AgencError`s surface UNTOUCHED.
14
+ *
15
+ * The `task` PDA is bound at hook construction; callers pass only the per-call
16
+ * settlement parties (worker / treasury / hashes) the SDK cannot derive.
17
+ *
18
+ * @module hooks/useSubmissionReview
19
+ */
20
+ import { useMutation } from "@tanstack/react-query";
21
+ import { useCallback } from "react";
22
+ import { facade, type facade as facadeNs } from "@tetsuo-ai/marketplace-sdk";
23
+ import { useAgencContext } from "../provider/context.js";
24
+ import { requireClient } from "./internal.js";
25
+
26
+ /** Per-call input for `accept` (task auto-bound; signer defaults to the client). */
27
+ export type AcceptInput = Omit<
28
+ Parameters<typeof facadeNs.acceptTaskResult>[0],
29
+ "task" | "creator"
30
+ > & {
31
+ creator?: Parameters<typeof facadeNs.acceptTaskResult>[0]["creator"];
32
+ };
33
+
34
+ /** Per-call input for `reject`. */
35
+ export type RejectInput = Omit<
36
+ Parameters<typeof facadeNs.rejectTaskResult>[0],
37
+ "task" | "creator"
38
+ > & {
39
+ creator?: Parameters<typeof facadeNs.rejectTaskResult>[0]["creator"];
40
+ };
41
+
42
+ /** Per-call input for `requestChanges`. */
43
+ export type RequestChangesInput = Omit<
44
+ Parameters<typeof facadeNs.requestChanges>[0],
45
+ "task" | "creator"
46
+ > & {
47
+ creator?: Parameters<typeof facadeNs.requestChanges>[0]["creator"];
48
+ };
49
+
50
+ /** Lifecycle status of a review verb. */
51
+ export type ReviewStatus = "idle" | "pending" | "success" | "error";
52
+
53
+ /** A single review verb's surface. */
54
+ export interface ReviewAction<TInput> {
55
+ /** Run the action. Resolves to the tx signature; rejects with `AgencError`. */
56
+ (input: TInput): Promise<string>;
57
+ }
58
+
59
+ /** Return value of {@link useSubmissionReview}. */
60
+ export interface UseSubmissionReviewResult {
61
+ /** Accept the result and settle to the worker. */
62
+ accept: ReviewAction<AcceptInput>;
63
+ /** Reject the result (with a rejection hash). */
64
+ reject: ReviewAction<RejectInput>;
65
+ /** Request changes (with a changes hash), returning the task to the worker. */
66
+ requestChanges: ReviewAction<RequestChangesInput>;
67
+ /** Aggregate status: `pending` if any verb is in flight, else last settled. */
68
+ status: ReviewStatus;
69
+ /** The most recent error across the three verbs, or null. */
70
+ error: Error | null;
71
+ /** Signature of the last successful action, or null. */
72
+ signature: string | null;
73
+ /** Reset all three mutations to idle. */
74
+ reset: () => void;
75
+ }
76
+
77
+ function statusOf(m: {
78
+ isPending: boolean;
79
+ isError: boolean;
80
+ isSuccess: boolean;
81
+ }): ReviewStatus {
82
+ if (m.isPending) return "pending";
83
+ if (m.isError) return "error";
84
+ if (m.isSuccess) return "success";
85
+ return "idle";
86
+ }
87
+
88
+ /**
89
+ * Buyer-side review actions for one task.
90
+ *
91
+ * @param taskPda - The Task PDA under review (bound to every verb).
92
+ * @returns {@link UseSubmissionReviewResult}.
93
+ */
94
+ export function useSubmissionReview(
95
+ taskPda: Parameters<typeof facadeNs.acceptTaskResult>[0]["task"],
96
+ ): UseSubmissionReviewResult {
97
+ const ctx = useAgencContext();
98
+
99
+ const acceptMut = useMutation<string, Error, AcceptInput>({
100
+ mutationFn: async (input) => {
101
+ const client = requireClient(ctx.client);
102
+ const { signature } = await client.acceptTaskResult({
103
+ ...input,
104
+ task: taskPda,
105
+ creator: input.creator ?? client.signer,
106
+ } as Parameters<typeof facadeNs.acceptTaskResult>[0]);
107
+ return signature;
108
+ },
109
+ });
110
+
111
+ const rejectMut = useMutation<string, Error, RejectInput>({
112
+ mutationFn: async (input) => {
113
+ const client = requireClient(ctx.client);
114
+ const ix = await facade.rejectTaskResult({
115
+ ...input,
116
+ task: taskPda,
117
+ creator: input.creator ?? client.signer,
118
+ } as Parameters<typeof facadeNs.rejectTaskResult>[0]);
119
+ const { signature } = await client.send([ix]);
120
+ return signature;
121
+ },
122
+ });
123
+
124
+ const requestChangesMut = useMutation<string, Error, RequestChangesInput>({
125
+ mutationFn: async (input) => {
126
+ const client = requireClient(ctx.client);
127
+ const ix = await facade.requestChanges({
128
+ ...input,
129
+ task: taskPda,
130
+ creator: input.creator ?? client.signer,
131
+ } as Parameters<typeof facadeNs.requestChanges>[0]);
132
+ const { signature } = await client.send([ix]);
133
+ return signature;
134
+ },
135
+ });
136
+
137
+ const accept = useCallback<ReviewAction<AcceptInput>>(
138
+ (input) => acceptMut.mutateAsync(input),
139
+ [acceptMut],
140
+ );
141
+ const reject = useCallback<ReviewAction<RejectInput>>(
142
+ (input) => rejectMut.mutateAsync(input),
143
+ [rejectMut],
144
+ );
145
+ const requestChanges = useCallback<ReviewAction<RequestChangesInput>>(
146
+ (input) => requestChangesMut.mutateAsync(input),
147
+ [requestChangesMut],
148
+ );
149
+
150
+ const anyPending =
151
+ acceptMut.isPending || rejectMut.isPending || requestChangesMut.isPending;
152
+ const status: ReviewStatus = anyPending
153
+ ? "pending"
154
+ : statusOf(
155
+ // Surface the most recently-touched verb's terminal state.
156
+ [acceptMut, rejectMut, requestChangesMut].find(
157
+ (m) => m.isError || m.isSuccess,
158
+ ) ?? acceptMut,
159
+ );
160
+
161
+ const error =
162
+ acceptMut.error ?? rejectMut.error ?? requestChangesMut.error ?? null;
163
+ const signature =
164
+ acceptMut.data ?? rejectMut.data ?? requestChangesMut.data ?? null;
165
+
166
+ return {
167
+ accept,
168
+ reject,
169
+ requestChanges,
170
+ status,
171
+ error,
172
+ signature,
173
+ reset: () => {
174
+ acceptMut.reset();
175
+ rejectMut.reset();
176
+ requestChangesMut.reset();
177
+ },
178
+ };
179
+ }
@@ -0,0 +1,192 @@
1
+ /**
2
+ * `useTaskStatus(taskPda)` — live task status with a poll fallback.
3
+ *
4
+ * Tracks a Task account's {@link TaskStatus} (and optionally its submission and
5
+ * the coordination events seen for it) after a hire. It is built to satisfy the
6
+ * PLAN_2 A2 contract `{ task, status, submission, events }` while staying SSR-
7
+ * and transport-agnostic.
8
+ *
9
+ * ## How it reads (the seam)
10
+ *
11
+ * The unified read transport intentionally has NO raw account fetch, and the
12
+ * litesvm e2e harness has no RPC — so a task read cannot be assumed from
13
+ * context. `useTaskStatus` therefore takes a **`taskReader`**: an async
14
+ * `(pda) => Promise<Task | null>`. Callers wire it from whatever they have:
15
+ * - a kit RPC: `(pda) => getTaskDecoder().decode(...)` over `getAccountInfo`
16
+ * (the SDK's `waitForTaskStatus` uses exactly this `getAccountInfo` shape);
17
+ * - litesvm e2e: `(pda) => decode(svm.getAccount(pda))`.
18
+ * A reader-less call returns the idle state (and a clear `error` if `poll` was
19
+ * requested) rather than guessing a transport.
20
+ *
21
+ * ## Polling vs. subscription (SSR-safe, cleaned up)
22
+ *
23
+ * - Polling: TanStack Query `refetchInterval` re-runs `taskReader` until the
24
+ * task reaches a terminal status (`Completed`/`Cancelled`/`RejectFrozen`) or
25
+ * the optional `targetStatus` — then stops.
26
+ * - Subscription: when an `events` async-iterable is supplied (e.g. from the
27
+ * SDK's `subscribeMarketplaceEvents`), a `useEffect` (browser-only; never runs
28
+ * during SSR) drains it, appends each event to `events`, and triggers a
29
+ * refetch so status stays fresh without tight polling. The effect aborts the
30
+ * iterable and clears state on unmount.
31
+ *
32
+ * @module hooks/useTaskStatus
33
+ */
34
+ import { useQuery } from "@tanstack/react-query";
35
+ import { useEffect, useRef, useState } from "react";
36
+ import { TaskStatus, type Task } from "@tetsuo-ai/marketplace-sdk";
37
+ import { useAgencContext } from "../provider/context.js";
38
+ import type { Address } from "../types.js";
39
+ import { pdaKey, queryKeys } from "./internal.js";
40
+
41
+ /** Reads a Task account, returning the decoded {@link Task} or null if absent. */
42
+ export type TaskReader = (pda: Address | string) => Promise<Task | null>;
43
+
44
+ /**
45
+ * A single coordination event observed for the watched task. Kept loosely typed
46
+ * (the SDK's `AgencEvent` union) so this hook does not pin the event schema.
47
+ */
48
+ export type ObservedEvent = unknown;
49
+
50
+ /**
51
+ * An async source of coordination events for the watched task. Pass the result
52
+ * of the SDK's `subscribeMarketplaceEvents(...)` (already address-filtered) or
53
+ * any async iterable. Optional.
54
+ */
55
+ export type TaskEventsSource = AsyncIterable<ObservedEvent>;
56
+
57
+ /** Options for {@link useTaskStatus}. */
58
+ export interface UseTaskStatusOptions {
59
+ /**
60
+ * How to read the Task account. REQUIRED for any live status — without it the
61
+ * hook stays idle. See the module doc for wiring patterns.
62
+ */
63
+ taskReader?: TaskReader;
64
+ /**
65
+ * Optional event source. When given, observed events are appended to
66
+ * `events` and each triggers a refetch. Drained in a browser-only effect and
67
+ * aborted on unmount.
68
+ */
69
+ events?: TaskEventsSource;
70
+ /**
71
+ * Stop polling once the task reaches this status (in addition to terminal
72
+ * statuses). Useful to await a specific transition (e.g. `Completed`).
73
+ */
74
+ targetStatus?: TaskStatus;
75
+ /** Poll interval in ms while non-terminal. Default `2000`. */
76
+ pollIntervalMs?: number;
77
+ /** Disable the hook entirely. Default `true` when `taskPda` + reader exist. */
78
+ enabled?: boolean;
79
+ }
80
+
81
+ /** Return value of {@link useTaskStatus}. */
82
+ export interface UseTaskStatusResult {
83
+ /** The decoded Task, or null until first read. */
84
+ task: Task | null;
85
+ /** The task status, or null until first read. */
86
+ status: TaskStatus | null;
87
+ /**
88
+ * The submission projection. v1 surfaces the task's on-chain `result` bytes
89
+ * (the worker's submitted result) once present; a richer submission read
90
+ * lands with the indexer projection. `null` until a result exists.
91
+ */
92
+ submission: Uint8Array | null;
93
+ /** Coordination events observed for this task (chronological). */
94
+ events: ObservedEvent[];
95
+ /** True while the first read is in flight. */
96
+ isLoading: boolean;
97
+ /** The read error, or null. */
98
+ error: Error | null;
99
+ /** Force a refetch. */
100
+ refetch: () => void;
101
+ }
102
+
103
+ /** Statuses after which no further transition is possible (stop polling). */
104
+ const TERMINAL_STATUSES: ReadonlySet<TaskStatus> = new Set([
105
+ TaskStatus.Completed,
106
+ TaskStatus.Cancelled,
107
+ TaskStatus.RejectFrozen,
108
+ ]);
109
+
110
+ /** True when the task's `result` bytes are present and non-empty. */
111
+ function hasResult(task: Task | null): boolean {
112
+ return task !== null && task.result.length > 0 && task.result.some((b) => b !== 0);
113
+ }
114
+
115
+ /**
116
+ * Watch a task's status.
117
+ *
118
+ * @param taskPda - The Task PDA to watch (falsy disables the hook).
119
+ * @param options - Reader, event source, target status, poll interval.
120
+ * @returns {@link UseTaskStatusResult}.
121
+ */
122
+ export function useTaskStatus(
123
+ taskPda: Address | string | undefined | null,
124
+ options?: UseTaskStatusOptions,
125
+ ): UseTaskStatusResult {
126
+ // Touch context so the hook is provider-bound (and throws clearly outside it),
127
+ // matching every other hook's contract even though reads come via the reader.
128
+ useAgencContext();
129
+
130
+ const reader = options?.taskReader;
131
+ const enabled =
132
+ (options?.enabled ?? true) && Boolean(taskPda) && Boolean(reader);
133
+ const pollIntervalMs = options?.pollIntervalMs ?? 2000;
134
+
135
+ const [events, setEvents] = useState<ObservedEvent[]>([]);
136
+
137
+ const query = useQuery<Task | null, Error>({
138
+ queryKey: queryKeys.taskStatus(taskPda ? pdaKey(taskPda) : ""),
139
+ enabled,
140
+ queryFn: () => reader!(taskPda as Address | string),
141
+ // Poll until terminal / target reached; then stop (return `false`).
142
+ refetchInterval: (q) => {
143
+ const task = q.state.data ?? null;
144
+ if (task === null) return pollIntervalMs;
145
+ if (TERMINAL_STATUSES.has(task.status)) return false;
146
+ if (
147
+ options?.targetStatus !== undefined &&
148
+ task.status === options.targetStatus
149
+ ) {
150
+ return false;
151
+ }
152
+ return pollIntervalMs;
153
+ },
154
+ });
155
+
156
+ // Drain the optional event source in a browser-only effect (never during SSR;
157
+ // effects don't run on the server). Abort + reset on unmount / source change.
158
+ const refetchRef = useRef(query.refetch);
159
+ refetchRef.current = query.refetch;
160
+ const eventsSource = options?.events;
161
+ useEffect(() => {
162
+ if (!eventsSource) return;
163
+ let cancelled = false;
164
+ (async () => {
165
+ try {
166
+ for await (const ev of eventsSource) {
167
+ if (cancelled) break;
168
+ setEvents((prev) => [...prev, ev]);
169
+ // A status-changing event landed — pull a fresh read.
170
+ void refetchRef.current();
171
+ }
172
+ } catch {
173
+ // A torn-down subscription (unmount) surfaces as an iterator throw;
174
+ // swallow it — the read query owns the surfaced error channel.
175
+ }
176
+ })();
177
+ return () => {
178
+ cancelled = true;
179
+ };
180
+ }, [eventsSource]);
181
+
182
+ const task = query.data ?? null;
183
+ return {
184
+ task,
185
+ status: task?.status ?? null,
186
+ submission: hasResult(task) ? Uint8Array.from(task!.result) : null,
187
+ events,
188
+ isLoading: query.isLoading,
189
+ error: query.error ?? null,
190
+ refetch: () => void query.refetch(),
191
+ };
192
+ }
@@ -0,0 +1,99 @@
1
+ /**
2
+ * `useWalletSigner()` — bridges a browser wallet into the kit `TransactionSigner`
3
+ * the SDK write client expects.
4
+ *
5
+ * ## Adapter seam (the signer-adapters package is not built yet)
6
+ *
7
+ * The dedicated `@tetsuo-ai/signer-adapters` package (the signers agent, PLAN.md
8
+ * P4.1) — which wraps `@solana/react`'s
9
+ * `useWalletAccountTransactionSendingSigner` (Wallet Standard) and the legacy
10
+ * `@solana/wallet-adapter` shim into a kit `TransactionSigner` — does not exist
11
+ * at this hook's build time. So this hook is defined against a **documented
12
+ * adapter interface** ({@link WalletSignerAdapter}) rather than importing that
13
+ * package. A caller passes an adapter (today: a thin wrapper they write, or the
14
+ * signer-adapters hook once it ships) and this hook normalizes it to the
15
+ * `{ signer, connected, connect() }` contract every other hook expects.
16
+ *
17
+ * With NO adapter passed, the hook falls back to the provider's configured
18
+ * `signer` (the `AgencProvider config.signer` slot), so a server-supplied or
19
+ * test signer just works and `connect()` is a no-op.
20
+ *
21
+ * SSR-safe: no `window`/`document`; the adapter (which may touch wallet globals)
22
+ * is the caller's responsibility to gate to the client. This hook only reads
23
+ * what the adapter already resolved.
24
+ *
25
+ * @module hooks/useWalletSigner
26
+ */
27
+ import { useCallback } from "react";
28
+ import { useAgencContext } from "../provider/context.js";
29
+ import type { TransactionSigner } from "../types.js";
30
+
31
+ /**
32
+ * The minimal adapter shape this hook bridges. The forthcoming
33
+ * `@tetsuo-ai/signer-adapters` hook is expected to return exactly this shape
34
+ * (its `signerFromWalletAccount(...)` resolves the `signer`); until it ships,
35
+ * any object matching this interface works.
36
+ */
37
+ export interface WalletSignerAdapter {
38
+ /** The resolved kit signer, or null when no wallet is connected. */
39
+ signer: TransactionSigner | null;
40
+ /** Whether a wallet is currently connected. */
41
+ connected?: boolean;
42
+ /** Trigger the wallet connect flow (browser-only). Optional. */
43
+ connect?: () => void | Promise<void>;
44
+ }
45
+
46
+ /** Options for {@link useWalletSigner}. */
47
+ export interface UseWalletSignerOptions {
48
+ /**
49
+ * A wallet adapter (e.g. the signer-adapters hook's result). When omitted the
50
+ * hook falls back to the provider's `config.signer`.
51
+ */
52
+ adapter?: WalletSignerAdapter;
53
+ }
54
+
55
+ /** Return value of {@link useWalletSigner}. */
56
+ export interface UseWalletSignerResult {
57
+ /** The resolved kit `TransactionSigner`, or null. */
58
+ signer: TransactionSigner | null;
59
+ /** Whether a signer is available (adapter-connected or provider-configured). */
60
+ connected: boolean;
61
+ /** Trigger the wallet connect flow. No-op when no adapter `connect` exists. */
62
+ connect: () => void | Promise<void>;
63
+ }
64
+
65
+ /**
66
+ * Resolve the active signer for write operations.
67
+ *
68
+ * @param options - Optional wallet adapter; falls back to the provider signer.
69
+ * @returns {@link UseWalletSignerResult}.
70
+ *
71
+ * @example
72
+ * ```tsx
73
+ * // Once @tetsuo-ai/signer-adapters ships:
74
+ * const adapter = useWalletStandardSigner(); // returns WalletSignerAdapter
75
+ * const { signer, connected, connect } = useWalletSigner({ adapter });
76
+ * ```
77
+ */
78
+ export function useWalletSigner(
79
+ options?: UseWalletSignerOptions,
80
+ ): UseWalletSignerResult {
81
+ const ctx = useAgencContext();
82
+ const adapter = options?.adapter;
83
+
84
+ // Adapter wins when present; otherwise the provider's configured signer.
85
+ const signer: TransactionSigner | null =
86
+ adapter?.signer ?? ctx.signer ?? null;
87
+ const connected =
88
+ adapter !== undefined
89
+ ? (adapter.connected ?? adapter.signer !== null)
90
+ : ctx.signer !== null;
91
+
92
+ const connect = useCallback(() => {
93
+ // No adapter (or no connect on it) => provider-supplied signer is already
94
+ // "connected"; connecting is a no-op rather than an error.
95
+ return adapter?.connect ? adapter.connect() : undefined;
96
+ }, [adapter]);
97
+
98
+ return { signer, connected, connect };
99
+ }
package/src/index.ts ADDED
@@ -0,0 +1,170 @@
1
+ /**
2
+ * `@tetsuo-ai/marketplace-react` — headless React hooks + themable components
3
+ * for the AgenC marketplace.
4
+ *
5
+ * This barrel exposes the FOUNDATION layer (PLAN.md P4.2 / PLAN_2 Part A):
6
+ * - `<AgencProvider>` + `useAgencContext()` — the one context wiring reads,
7
+ * writes, and the (P6.2-gated) referrer config;
8
+ * - `createReadTransport()` — indexer-first read transport with gPA fallback;
9
+ * - the referrer validation + capability gate (`resolveReferrerCapability()`,
10
+ * not-live today per PLAN_2 §0);
11
+ * - the `--agenc-*` theme contract helpers + the English string catalog.
12
+ *
13
+ * Hooks (`useListings`, `useHire`, ...) and components (`ListingCard`, ...) bind
14
+ * to the context value and transport exposed here.
15
+ *
16
+ * SSR-safe, tree-shakeable, zero required CSS imports for headless use.
17
+ *
18
+ * @packageDocumentation
19
+ */
20
+
21
+ // Provider + context (the foundation hooks/components bind to).
22
+ export {
23
+ AgencContext,
24
+ AgencProvider,
25
+ useAgencContext,
26
+ type AgencProviderProps,
27
+ } from "./provider/index.js";
28
+ export {
29
+ REFERRER_FEE_BPS_MAX,
30
+ REFERRER_FEE_BPS_MIN,
31
+ resolveReferrerCapability,
32
+ validateReferrerConfig,
33
+ } from "./provider/referrer.js";
34
+ export {
35
+ deriveSubscriptionsUrl,
36
+ resolveEndpoints,
37
+ type ResolvedEndpoints,
38
+ } from "./provider/network.js";
39
+
40
+ // Read transport.
41
+ export {
42
+ createReadTransport,
43
+ ReadTransportUnsupportedError,
44
+ } from "./transport/index.js";
45
+
46
+ // Theme contract (CSS is shipped separately via the "./theme.css" export).
47
+ export {
48
+ AGENC_THEME_CLASS,
49
+ AGENC_TOKENS_CSS_PATH,
50
+ agencThemeStyleTag,
51
+ resolveThemeClassName,
52
+ } from "./theme/index.js";
53
+
54
+ // String catalog.
55
+ export {
56
+ EN_STRINGS,
57
+ t,
58
+ type StringCatalog,
59
+ type StringId,
60
+ type StringVars,
61
+ type TranslateOptions,
62
+ } from "./strings/index.js";
63
+
64
+ // Browser-wallet → kit `TransactionSigner` bridges (P4.1 / PLAN_2 D-1). Also
65
+ // available tree-shaken via the "./signers" subpath. The test-only MOCK
66
+ // embedded wallet is deliberately NOT re-exported here — it lives behind the
67
+ // "./testing" subpath so it can never reach a production bundle by accident.
68
+ export {
69
+ EN_SIGNER_STRINGS,
70
+ signerFromEmbeddedWallet,
71
+ signerFromWalletAccount,
72
+ signerFromWalletAdapter,
73
+ type EmbeddedWalletConnection,
74
+ type EmbeddedWalletProvider,
75
+ type SignerFromWalletAccountOptions,
76
+ type SignerFromWalletAdapterOptions,
77
+ type SignerStringId,
78
+ type VersionedTransactionCtor,
79
+ type VersionedTransactionLike,
80
+ type WalletAdapterLike,
81
+ type WalletStandardAccountLike,
82
+ type WalletStandardSignTransaction,
83
+ } from "./signers/index.js";
84
+
85
+ // Prebuilt themable components (PLAN_2 A3). Also tree-shaken via "./components".
86
+ export {
87
+ Badge,
88
+ Button,
89
+ DEFAULT_TRUST_HREF,
90
+ DisputeBanner,
91
+ HireButton,
92
+ HireCheckoutModal,
93
+ ListingCard,
94
+ ListingGrid,
95
+ Modal,
96
+ ModerationBadge,
97
+ PoweredByAgenC,
98
+ ProviderCard,
99
+ ReferrerDisclosure,
100
+ ReviewPanel,
101
+ Spinner,
102
+ StateMessage,
103
+ TaskTimeline,
104
+ VerifiedBadge,
105
+ COMPONENT_CATALOG,
106
+ EN_COMPONENT_STRINGS,
107
+ cx,
108
+ decodeListingCategory,
109
+ decodeListingName,
110
+ decodeListingTags,
111
+ elementClass,
112
+ formatPriceSol,
113
+ formatRate,
114
+ formatSol,
115
+ moderationStateOf,
116
+ rootClass,
117
+ tc,
118
+ toHex,
119
+ truncateAddress,
120
+ useFocusTrap,
121
+ type BadgeProps,
122
+ type BadgeTone,
123
+ type ButtonProps,
124
+ type ButtonVariant,
125
+ type ComponentStringId,
126
+ type DisputeBannerProps,
127
+ type HireButtonProps,
128
+ type HireCheckoutListing,
129
+ type HireCheckoutModalProps,
130
+ type ListingCardData,
131
+ type ListingCardProps,
132
+ type ListingGridProps,
133
+ type ModalProps,
134
+ type ModerationBadgeProps,
135
+ type ModerationState,
136
+ type PoweredByAgenCProps,
137
+ type ProviderCardProps,
138
+ type ReferrerDisclosureProps,
139
+ type ReviewPanelProps,
140
+ type SpinnerProps,
141
+ type StateKind,
142
+ type StateMessageProps,
143
+ type TaskTimelineProps,
144
+ type ThemableProps,
145
+ type VerifiedBadgeProps,
146
+ } from "./components/index.js";
147
+
148
+ // Shared types (the public contract for the hooks/components agents).
149
+ export type {
150
+ Address,
151
+ AgencContextValue,
152
+ AgencNetwork,
153
+ AgencProviderConfig,
154
+ CreateReadTransportConfig,
155
+ DecodedProgramAccount,
156
+ GpaReadSource,
157
+ IndexerAgentTrackRecord,
158
+ IndexerConfig,
159
+ IndexerHire,
160
+ IndexerListing,
161
+ ListActiveListingsOptions,
162
+ MarketplaceClient,
163
+ ReadListingResult,
164
+ ReadTransport,
165
+ ReferrerCapability,
166
+ ReferrerConfig,
167
+ ServiceListing,
168
+ TransactionSigner,
169
+ ValidatedReferrerConfig,
170
+ } from "./types.js";