@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.
- package/CHANGELOG.md +28 -0
- package/LICENSE +21 -0
- package/README.md +172 -0
- package/dist/chunk-5OTKSRHM.js +128 -0
- package/dist/chunk-5OTKSRHM.js.map +1 -0
- package/dist/chunk-ABS77JB2.js +94 -0
- package/dist/chunk-ABS77JB2.js.map +1 -0
- package/dist/chunk-GN5DYVN5.js +35 -0
- package/dist/chunk-GN5DYVN5.js.map +1 -0
- package/dist/chunk-KJMR6OGC.js +1198 -0
- package/dist/chunk-KJMR6OGC.js.map +1 -0
- package/dist/chunk-YORZNYZZ.js +107 -0
- package/dist/chunk-YORZNYZZ.js.map +1 -0
- package/dist/components/agenc-components.css +570 -0
- package/dist/components/index.cjs +1335 -0
- package/dist/components/index.cjs.map +1 -0
- package/dist/components/index.d.cts +5 -0
- package/dist/components/index.d.ts +5 -0
- package/dist/components/index.js +5 -0
- package/dist/components/index.js.map +1 -0
- package/dist/hooks/index.cjs +493 -0
- package/dist/hooks/index.cjs.map +1 -0
- package/dist/hooks/index.d.cts +294 -0
- package/dist/hooks/index.d.ts +294 -0
- package/dist/hooks/index.js +339 -0
- package/dist/hooks/index.js.map +1 -0
- package/dist/index-BLrlBVj-.d.cts +1129 -0
- package/dist/index-CKTYsNPH.d.ts +1129 -0
- package/dist/index.cjs +1690 -0
- package/dist/index.cjs.map +1 -0
- package/dist/index.d.cts +235 -0
- package/dist/index.d.ts +235 -0
- package/dist/index.js +127 -0
- package/dist/index.js.map +1 -0
- package/dist/signers/index.cjs +166 -0
- package/dist/signers/index.cjs.map +1 -0
- package/dist/signers/index.d.cts +136 -0
- package/dist/signers/index.d.ts +136 -0
- package/dist/signers/index.js +4 -0
- package/dist/signers/index.js.map +1 -0
- package/dist/testing/index.cjs +62 -0
- package/dist/testing/index.cjs.map +1 -0
- package/dist/testing/index.d.cts +71 -0
- package/dist/testing/index.d.ts +71 -0
- package/dist/testing/index.js +60 -0
- package/dist/testing/index.js.map +1 -0
- package/dist/theme/agenc-tailwind-preset.cjs +184 -0
- package/dist/theme/agenc-tokens.css +132 -0
- package/dist/types-jvISR6bc.d.cts +135 -0
- package/dist/types-jvISR6bc.d.ts +135 -0
- package/dist/useAgentTrackRecord-BLf1nrbu.d.cts +249 -0
- package/dist/useAgentTrackRecord-BLf1nrbu.d.ts +249 -0
- package/package.json +139 -0
- package/src/components/DisputeBanner.stories.tsx +39 -0
- package/src/components/DisputeBanner.tsx +110 -0
- package/src/components/HireButton.stories.tsx +72 -0
- package/src/components/HireButton.tsx +151 -0
- package/src/components/HireCheckoutModal.stories.tsx +107 -0
- package/src/components/HireCheckoutModal.tsx +284 -0
- package/src/components/ListingCard.stories.tsx +55 -0
- package/src/components/ListingCard.tsx +148 -0
- package/src/components/ListingGrid.stories.tsx +44 -0
- package/src/components/ListingGrid.tsx +137 -0
- package/src/components/Modal.tsx +121 -0
- package/src/components/PoweredByAgenC.tsx +85 -0
- package/src/components/ProviderCard.stories.tsx +61 -0
- package/src/components/ProviderCard.tsx +154 -0
- package/src/components/ReferrerDisclosure.tsx +67 -0
- package/src/components/ReviewPanel.stories.tsx +65 -0
- package/src/components/ReviewPanel.tsx +141 -0
- package/src/components/TaskTimeline.stories.tsx +43 -0
- package/src/components/TaskTimeline.tsx +156 -0
- package/src/components/__fixtures__/index.tsx +173 -0
- package/src/components/agenc-components.css +570 -0
- package/src/components/badges.tsx +115 -0
- package/src/components/format.ts +150 -0
- package/src/components/index.ts +102 -0
- package/src/components/primitives.tsx +236 -0
- package/src/components/strings.ts +131 -0
- package/src/components/useFocusTrap.ts +122 -0
- package/src/hooks/index.ts +90 -0
- package/src/hooks/internal.ts +70 -0
- package/src/hooks/useAgentTrackRecord.ts +166 -0
- package/src/hooks/useDispute.ts +130 -0
- package/src/hooks/useHire.ts +198 -0
- package/src/hooks/useListing.ts +138 -0
- package/src/hooks/useListings.ts +133 -0
- package/src/hooks/useReferrerEarnings.ts +134 -0
- package/src/hooks/useSubmissionReview.ts +179 -0
- package/src/hooks/useTaskStatus.ts +192 -0
- package/src/hooks/useWalletSigner.ts +99 -0
- package/src/index.ts +170 -0
- package/src/provider/AgencProvider.tsx +169 -0
- package/src/provider/context.ts +35 -0
- package/src/provider/index.ts +17 -0
- package/src/provider/network.ts +68 -0
- package/src/provider/referrer.ts +97 -0
- package/src/signers/README.md +130 -0
- package/src/signers/embedded-wallet-mock.ts +158 -0
- package/src/signers/embedded-wallet.ts +64 -0
- package/src/signers/index.ts +48 -0
- package/src/signers/strings.ts +39 -0
- package/src/signers/types.ts +158 -0
- package/src/signers/wallet-account.ts +128 -0
- package/src/signers/wallet-adapter.ts +149 -0
- package/src/strings/index.ts +119 -0
- package/src/testing/index.ts +24 -0
- package/src/theme/agenc-tailwind-preset.cjs +184 -0
- package/src/theme/agenc-tokens.css +132 -0
- package/src/theme/index.ts +94 -0
- package/src/transport/index.ts +164 -0
- package/src/types.ts +224 -0
|
@@ -0,0 +1,284 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* `<HireCheckoutModal>` — the embeddable money path (PLAN_2 A3).
|
|
3
|
+
*
|
|
4
|
+
* The accessible, themable checkout dialog: it shows the price, the moderation
|
|
5
|
+
* attestation badge, the escrow-funding explanation, the referrer disclosure
|
|
6
|
+
* (P6.2-gated), and walks the buyer through idle → confirming → funded /
|
|
7
|
+
* error confirmation states.
|
|
8
|
+
*
|
|
9
|
+
* ## Accessibility (STRUCTURAL — this is published to third parties)
|
|
10
|
+
*
|
|
11
|
+
* Built on the accessible {@link Modal}: focus trap, Escape/overlay close
|
|
12
|
+
* (auto-disabled while a hire is in flight so the buyer can't dismiss a pending
|
|
13
|
+
* transaction), ARIA dialog roles, and live-region status announcements for
|
|
14
|
+
* the confirming/funded/error transitions.
|
|
15
|
+
*
|
|
16
|
+
* ## The P6.2 referrer gate
|
|
17
|
+
*
|
|
18
|
+
* The disclosure renders when a `referrer` is configured, with the pending-
|
|
19
|
+
* support copy until `referrerLive` is true (always false today). The modal
|
|
20
|
+
* NEVER computes or claims a fee was charged — it discloses configured intent
|
|
21
|
+
* only. Injection/earnings stay in the hooks, blocked on P6.2.
|
|
22
|
+
*
|
|
23
|
+
* ## Wiring
|
|
24
|
+
*
|
|
25
|
+
* Presentational by design: a host maps `useHire()` onto the props
|
|
26
|
+
* (`status`/`error`/`taskPda`/`onConfirm`). The connected
|
|
27
|
+
* {@link HireButton} shows the canonical wiring.
|
|
28
|
+
*
|
|
29
|
+
* @module components/HireCheckoutModal
|
|
30
|
+
*/
|
|
31
|
+
import { useCallback, useEffect, useRef, useState, type ReactNode } from "react";
|
|
32
|
+
import type {
|
|
33
|
+
Address,
|
|
34
|
+
IndexerListing,
|
|
35
|
+
ServiceListing,
|
|
36
|
+
ValidatedReferrerConfig,
|
|
37
|
+
} from "../types.js";
|
|
38
|
+
import type { HireStatus } from "../hooks/useHire.js";
|
|
39
|
+
import { formatPriceSol, tc } from "./format.js";
|
|
40
|
+
import { ModerationBadge } from "./badges.js";
|
|
41
|
+
import { Modal } from "./Modal.js";
|
|
42
|
+
import { ReferrerDisclosure } from "./ReferrerDisclosure.js";
|
|
43
|
+
import { Button } from "./primitives.js";
|
|
44
|
+
|
|
45
|
+
/** The listing being hired (decoded account + address). */
|
|
46
|
+
export interface HireCheckoutListing {
|
|
47
|
+
/** The listing PDA. */
|
|
48
|
+
address: Address;
|
|
49
|
+
/** The decoded on-chain account (for price + name). */
|
|
50
|
+
account: ServiceListing;
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
/** Props for {@link HireCheckoutModal}. */
|
|
54
|
+
export interface HireCheckoutModalProps {
|
|
55
|
+
/** Whether the modal is open. */
|
|
56
|
+
open: boolean;
|
|
57
|
+
/** Close request handler. */
|
|
58
|
+
onClose: () => void;
|
|
59
|
+
/** The listing under checkout. */
|
|
60
|
+
listing: HireCheckoutListing;
|
|
61
|
+
/**
|
|
62
|
+
* Confirm handler — runs the actual hire (e.g. `() => hire({...})`). Resolves
|
|
63
|
+
* when the hire settles; rejects with the typed `AgencError` to surface.
|
|
64
|
+
*/
|
|
65
|
+
onConfirm: () => void | Promise<void>;
|
|
66
|
+
/** Current hire status (map from `useHire().status`). Default "idle". */
|
|
67
|
+
status?: HireStatus;
|
|
68
|
+
/** The hire error to surface (map from `useHire().error`). */
|
|
69
|
+
error?: Error | null;
|
|
70
|
+
/** The minted Task PDA on success (map from `useHire().taskPda`). */
|
|
71
|
+
taskPda?: Address | null;
|
|
72
|
+
/** Optional handler when the buyer clicks "View task" after success. */
|
|
73
|
+
onViewTask?: (taskPda: Address) => void;
|
|
74
|
+
/** Indexer projection for the moderation badge. */
|
|
75
|
+
moderation?: IndexerListing | null;
|
|
76
|
+
/**
|
|
77
|
+
* Configured referrer (from provider context). When present the disclosure
|
|
78
|
+
* renders. Pass `null`/omit when no referrer is configured.
|
|
79
|
+
*/
|
|
80
|
+
referrer?: ValidatedReferrerConfig | null;
|
|
81
|
+
/**
|
|
82
|
+
* Whether referral settlement is live (P6.2). Always false today. Drives the
|
|
83
|
+
* disclosure copy only; never implies a fee was charged.
|
|
84
|
+
*/
|
|
85
|
+
referrerLive?: boolean;
|
|
86
|
+
/** Whether a signer/wallet is connected (gates the confirm button). */
|
|
87
|
+
connected?: boolean;
|
|
88
|
+
/** White-label mode. */
|
|
89
|
+
unstyled?: boolean;
|
|
90
|
+
/** Extra root class. */
|
|
91
|
+
className?: string;
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
/**
|
|
95
|
+
* The hire checkout dialog.
|
|
96
|
+
*/
|
|
97
|
+
export function HireCheckoutModal({
|
|
98
|
+
open,
|
|
99
|
+
onClose,
|
|
100
|
+
listing,
|
|
101
|
+
onConfirm,
|
|
102
|
+
status = "idle",
|
|
103
|
+
error = null,
|
|
104
|
+
taskPda = null,
|
|
105
|
+
onViewTask,
|
|
106
|
+
moderation,
|
|
107
|
+
referrer,
|
|
108
|
+
referrerLive = false,
|
|
109
|
+
connected = true,
|
|
110
|
+
unstyled,
|
|
111
|
+
className,
|
|
112
|
+
}: HireCheckoutModalProps): ReactNode {
|
|
113
|
+
const pending = status === "pending";
|
|
114
|
+
const success = status === "success";
|
|
115
|
+
const price = formatPriceSol(listing.account.price);
|
|
116
|
+
|
|
117
|
+
// SYNCHRONOUS double-submit guard. The parent-controlled `status` prop does
|
|
118
|
+
// NOT flip to "pending" within the same tick as the click, so two fast
|
|
119
|
+
// clicks would otherwise fire `onConfirm` (a funded hire) twice. We latch
|
|
120
|
+
// locally the instant the button is clicked — before awaiting — and clear it
|
|
121
|
+
// only when the hire settles (resolve/reject), the modal closes, or the
|
|
122
|
+
// parent reaches a terminal status. This is independent of `status` so the
|
|
123
|
+
// first click immediately disables the button.
|
|
124
|
+
const [submitting, setSubmitting] = useState(false);
|
|
125
|
+
// A ref mirror so the click handler reads/sets the latch synchronously
|
|
126
|
+
// (state updates are async; a second click in the same tick must see it set).
|
|
127
|
+
const submittingRef = useRef(false);
|
|
128
|
+
|
|
129
|
+
// Clear the latch when the modal closes so a re-open starts clean, and when
|
|
130
|
+
// the parent settles to a terminal status (success/error/idle, i.e. not
|
|
131
|
+
// pending) so a retry after an error is allowed. The local latch (set
|
|
132
|
+
// synchronously on click) only needs to outlive the gap before the parent's
|
|
133
|
+
// `status` flips to pending; once it has settled the parent drives the gate.
|
|
134
|
+
useEffect(() => {
|
|
135
|
+
if (!open || !pending) {
|
|
136
|
+
submittingRef.current = false;
|
|
137
|
+
setSubmitting(false);
|
|
138
|
+
}
|
|
139
|
+
}, [open, pending]);
|
|
140
|
+
|
|
141
|
+
const handleConfirm = useCallback(() => {
|
|
142
|
+
// Already in flight (sync ref check) — drop the duplicate click.
|
|
143
|
+
if (submittingRef.current) return;
|
|
144
|
+
submittingRef.current = true;
|
|
145
|
+
setSubmitting(true);
|
|
146
|
+
let result: void | Promise<void>;
|
|
147
|
+
try {
|
|
148
|
+
result = onConfirm();
|
|
149
|
+
} catch {
|
|
150
|
+
// Synchronous throw: release the latch so the buyer can retry.
|
|
151
|
+
submittingRef.current = false;
|
|
152
|
+
setSubmitting(false);
|
|
153
|
+
return;
|
|
154
|
+
}
|
|
155
|
+
if (result && typeof (result as Promise<void>).then === "function") {
|
|
156
|
+
void (result as Promise<void>).finally(() => {
|
|
157
|
+
submittingRef.current = false;
|
|
158
|
+
setSubmitting(false);
|
|
159
|
+
});
|
|
160
|
+
}
|
|
161
|
+
// For a synchronous (void) onConfirm the parent drives `status`; the effect
|
|
162
|
+
// above clears the latch when it reaches a terminal/closed state.
|
|
163
|
+
}, [onConfirm]);
|
|
164
|
+
|
|
165
|
+
// The button is disabled the instant a submit is in flight (local latch) OR
|
|
166
|
+
// the parent reports pending — whichever fires first.
|
|
167
|
+
const confirmDisabled = !connected || pending || submitting;
|
|
168
|
+
|
|
169
|
+
// While a hire is in flight, lock the dialog so the buyer cannot dismiss a
|
|
170
|
+
// pending on-chain transaction by mistake.
|
|
171
|
+
const lockClose = pending || submitting;
|
|
172
|
+
|
|
173
|
+
const footer = success ? (
|
|
174
|
+
<>
|
|
175
|
+
{taskPda && onViewTask ? (
|
|
176
|
+
<Button
|
|
177
|
+
unstyled={unstyled}
|
|
178
|
+
variant="primary"
|
|
179
|
+
onClick={() => onViewTask(taskPda)}
|
|
180
|
+
>
|
|
181
|
+
{tc("components.hire.viewTask")}
|
|
182
|
+
</Button>
|
|
183
|
+
) : null}
|
|
184
|
+
<Button unstyled={unstyled} variant="secondary" onClick={onClose}>
|
|
185
|
+
{tc("components.common.close")}
|
|
186
|
+
</Button>
|
|
187
|
+
</>
|
|
188
|
+
) : (
|
|
189
|
+
<>
|
|
190
|
+
<Button
|
|
191
|
+
unstyled={unstyled}
|
|
192
|
+
variant="secondary"
|
|
193
|
+
onClick={onClose}
|
|
194
|
+
disabled={pending || submitting}
|
|
195
|
+
>
|
|
196
|
+
{tc("components.hire.cancel")}
|
|
197
|
+
</Button>
|
|
198
|
+
<Button
|
|
199
|
+
unstyled={unstyled}
|
|
200
|
+
variant="primary"
|
|
201
|
+
loading={pending || submitting}
|
|
202
|
+
disabled={confirmDisabled}
|
|
203
|
+
onClick={handleConfirm}
|
|
204
|
+
>
|
|
205
|
+
{pending || submitting
|
|
206
|
+
? tc("components.hire.pending")
|
|
207
|
+
: tc("components.hire.confirm")}
|
|
208
|
+
</Button>
|
|
209
|
+
</>
|
|
210
|
+
);
|
|
211
|
+
|
|
212
|
+
return (
|
|
213
|
+
<Modal
|
|
214
|
+
open={open}
|
|
215
|
+
onClose={onClose}
|
|
216
|
+
title={tc("components.hire.checkoutTitle")}
|
|
217
|
+
footer={footer}
|
|
218
|
+
disableEscapeClose={lockClose}
|
|
219
|
+
disableOverlayClose={lockClose}
|
|
220
|
+
hideCloseButton={lockClose}
|
|
221
|
+
unstyled={unstyled}
|
|
222
|
+
className={className}
|
|
223
|
+
>
|
|
224
|
+
<div className={unstyled ? undefined : "agenc-checkout"}>
|
|
225
|
+
<div className={unstyled ? undefined : "agenc-checkout__row"}>
|
|
226
|
+
<span className={unstyled ? undefined : "agenc-checkout__price-label"}>
|
|
227
|
+
{tc("components.hire.priceLabel")}
|
|
228
|
+
</span>
|
|
229
|
+
<span className={unstyled ? undefined : "agenc-checkout__price"}>
|
|
230
|
+
{price}
|
|
231
|
+
</span>
|
|
232
|
+
</div>
|
|
233
|
+
|
|
234
|
+
<div className={unstyled ? undefined : "agenc-checkout__moderation"}>
|
|
235
|
+
<ModerationBadge moderation={moderation} unstyled={unstyled} />
|
|
236
|
+
</div>
|
|
237
|
+
|
|
238
|
+
<p className={unstyled ? undefined : "agenc-checkout__escrow-note"}>
|
|
239
|
+
{tc("components.hire.escrowNote")}
|
|
240
|
+
</p>
|
|
241
|
+
|
|
242
|
+
{referrer ? (
|
|
243
|
+
<ReferrerDisclosure
|
|
244
|
+
referrer={referrer}
|
|
245
|
+
live={referrerLive}
|
|
246
|
+
unstyled={unstyled}
|
|
247
|
+
/>
|
|
248
|
+
) : null}
|
|
249
|
+
|
|
250
|
+
{/* Live-region status: announces confirming / funded / error. */}
|
|
251
|
+
<div
|
|
252
|
+
className={unstyled ? undefined : "agenc-checkout__status"}
|
|
253
|
+
role="status"
|
|
254
|
+
aria-live="polite"
|
|
255
|
+
>
|
|
256
|
+
{pending ? tc("components.hire.pending") : null}
|
|
257
|
+
{success ? (
|
|
258
|
+
<>
|
|
259
|
+
<strong>{tc("components.hire.success")}</strong>{" "}
|
|
260
|
+
{tc("components.hire.successDetail")}
|
|
261
|
+
</>
|
|
262
|
+
) : null}
|
|
263
|
+
</div>
|
|
264
|
+
|
|
265
|
+
{error ? (
|
|
266
|
+
<div
|
|
267
|
+
className={unstyled ? undefined : "agenc-checkout__error"}
|
|
268
|
+
role="alert"
|
|
269
|
+
aria-live="assertive"
|
|
270
|
+
>
|
|
271
|
+
<strong>{tc("components.hire.errorTitle")}</strong>
|
|
272
|
+
<span>{error.message}</span>
|
|
273
|
+
</div>
|
|
274
|
+
) : null}
|
|
275
|
+
|
|
276
|
+
{!connected && !success ? (
|
|
277
|
+
<p className={unstyled ? undefined : "agenc-checkout__hint"}>
|
|
278
|
+
{tc("components.hire.notConnected")}
|
|
279
|
+
</p>
|
|
280
|
+
) : null}
|
|
281
|
+
</div>
|
|
282
|
+
</Modal>
|
|
283
|
+
);
|
|
284
|
+
}
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Ladle stories for {@link ListingCard}.
|
|
3
|
+
*/
|
|
4
|
+
import type { Story } from "@ladle/react";
|
|
5
|
+
import { ListingCard } from "./ListingCard.js";
|
|
6
|
+
import {
|
|
7
|
+
makeIndexerListing,
|
|
8
|
+
makeListingRow,
|
|
9
|
+
} from "./__fixtures__/index.js";
|
|
10
|
+
|
|
11
|
+
export default {
|
|
12
|
+
title: "Listings / ListingCard",
|
|
13
|
+
};
|
|
14
|
+
|
|
15
|
+
const row = makeListingRow();
|
|
16
|
+
|
|
17
|
+
export const Default: Story = () => (
|
|
18
|
+
<ListingCard
|
|
19
|
+
listing={row}
|
|
20
|
+
moderation={makeIndexerListing()}
|
|
21
|
+
onHire={() => {}}
|
|
22
|
+
/>
|
|
23
|
+
);
|
|
24
|
+
|
|
25
|
+
export const Pending: Story = () => (
|
|
26
|
+
<ListingCard listing={row} moderation={null} onHire={() => {}} />
|
|
27
|
+
);
|
|
28
|
+
|
|
29
|
+
export const WithIssues: Story = () => (
|
|
30
|
+
<ListingCard
|
|
31
|
+
listing={row}
|
|
32
|
+
moderation={makeIndexerListing({
|
|
33
|
+
metadataValid: false,
|
|
34
|
+
metadataIssues: ["name exceeds 32 bytes"],
|
|
35
|
+
})}
|
|
36
|
+
onHire={() => {}}
|
|
37
|
+
/>
|
|
38
|
+
);
|
|
39
|
+
|
|
40
|
+
export const Selectable: Story = () => (
|
|
41
|
+
<ListingCard listing={row} onSelect={() => {}} onHire={() => {}} />
|
|
42
|
+
);
|
|
43
|
+
|
|
44
|
+
export const DisplayOnly: Story = () => (
|
|
45
|
+
<ListingCard listing={row} moderation={makeIndexerListing()} />
|
|
46
|
+
);
|
|
47
|
+
|
|
48
|
+
export const Unstyled: Story = () => (
|
|
49
|
+
<ListingCard
|
|
50
|
+
listing={row}
|
|
51
|
+
moderation={makeIndexerListing()}
|
|
52
|
+
onHire={() => {}}
|
|
53
|
+
unstyled
|
|
54
|
+
/>
|
|
55
|
+
);
|
|
@@ -0,0 +1,148 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* `<ListingCard>` — a single service-listing card.
|
|
3
|
+
*
|
|
4
|
+
* Renders the decoded on-chain `ServiceListing` (name, category, price,
|
|
5
|
+
* provider, lifetime hires) plus the moderation attestation badge. It is a
|
|
6
|
+
* PRESENTATIONAL component: it takes already-fetched data (a `ListingRow` from
|
|
7
|
+
* `useListings`, or a `ServiceListing` + address) so it can be used inside a
|
|
8
|
+
* grid, a detail page, or SSR without owning a query.
|
|
9
|
+
*
|
|
10
|
+
* Themable via `--agenc-*`; `unstyled` strips the default classes. Every
|
|
11
|
+
* literal routes through the component catalog.
|
|
12
|
+
*
|
|
13
|
+
* @module components/ListingCard
|
|
14
|
+
*/
|
|
15
|
+
import type { ReactNode } from "react";
|
|
16
|
+
import type { Address, IndexerListing, ServiceListing } from "../types.js";
|
|
17
|
+
import {
|
|
18
|
+
decodeListingCategory,
|
|
19
|
+
decodeListingName,
|
|
20
|
+
formatPriceSol,
|
|
21
|
+
tc,
|
|
22
|
+
truncateAddress,
|
|
23
|
+
} from "./format.js";
|
|
24
|
+
import { ModerationBadge } from "./badges.js";
|
|
25
|
+
import { Badge, Button, rootClass, type ThemableProps } from "./primitives.js";
|
|
26
|
+
|
|
27
|
+
/** A decoded listing the card can render (matches `useListings`' `ListingRow`). */
|
|
28
|
+
export interface ListingCardData {
|
|
29
|
+
/** The listing PDA. */
|
|
30
|
+
address: Address;
|
|
31
|
+
/** The decoded on-chain account. */
|
|
32
|
+
account: ServiceListing;
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
/** Props for {@link ListingCard}. */
|
|
36
|
+
export interface ListingCardProps extends ThemableProps {
|
|
37
|
+
/** The decoded listing to render. */
|
|
38
|
+
listing: ListingCardData;
|
|
39
|
+
/**
|
|
40
|
+
* Optional indexer projection for the moderation badge. When absent the badge
|
|
41
|
+
* shows the honest "pending" state (never asserts attestation).
|
|
42
|
+
*/
|
|
43
|
+
moderation?: IndexerListing | null;
|
|
44
|
+
/**
|
|
45
|
+
* Click/hire handler. When provided the card renders a hire CTA (use
|
|
46
|
+
* {@link HireButton} for the full flow); when absent the card is display-only.
|
|
47
|
+
*/
|
|
48
|
+
onHire?: (listing: ListingCardData) => void;
|
|
49
|
+
/** Optional select handler (e.g. open a detail view) on the card body. */
|
|
50
|
+
onSelect?: (listing: ListingCardData) => void;
|
|
51
|
+
/** Hide the price row (e.g. a teaser card). Default false. */
|
|
52
|
+
hidePrice?: boolean;
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
/**
|
|
56
|
+
* Render one service listing as a card.
|
|
57
|
+
*
|
|
58
|
+
* @example
|
|
59
|
+
* ```tsx
|
|
60
|
+
* <ListingCard listing={row} moderation={detail.moderation} onHire={open} />
|
|
61
|
+
* ```
|
|
62
|
+
*/
|
|
63
|
+
export function ListingCard({
|
|
64
|
+
listing,
|
|
65
|
+
moderation,
|
|
66
|
+
onHire,
|
|
67
|
+
onSelect,
|
|
68
|
+
hidePrice = false,
|
|
69
|
+
unstyled,
|
|
70
|
+
className,
|
|
71
|
+
}: ListingCardProps): ReactNode {
|
|
72
|
+
const { account } = listing;
|
|
73
|
+
const name = decodeListingName(account) || tc("components.listingCard.untitled");
|
|
74
|
+
const category = decodeListingCategory(account);
|
|
75
|
+
const price = formatPriceSol(account.price);
|
|
76
|
+
const provider = truncateAddress(account.providerAgent);
|
|
77
|
+
const hires = account.totalHires;
|
|
78
|
+
|
|
79
|
+
const cardClass = rootClass("agenc-listing-card", unstyled, className);
|
|
80
|
+
|
|
81
|
+
const selectable = Boolean(onSelect);
|
|
82
|
+
const heading = (
|
|
83
|
+
<h3 className={unstyled ? undefined : "agenc-listing-card__title"}>{name}</h3>
|
|
84
|
+
);
|
|
85
|
+
|
|
86
|
+
return (
|
|
87
|
+
<article
|
|
88
|
+
className={cardClass}
|
|
89
|
+
aria-label={name}
|
|
90
|
+
>
|
|
91
|
+
<header className={unstyled ? undefined : "agenc-listing-card__header"}>
|
|
92
|
+
{selectable ? (
|
|
93
|
+
<button
|
|
94
|
+
type="button"
|
|
95
|
+
className={
|
|
96
|
+
unstyled ? undefined : "agenc-listing-card__title-button"
|
|
97
|
+
}
|
|
98
|
+
onClick={() => onSelect?.(listing)}
|
|
99
|
+
>
|
|
100
|
+
{heading}
|
|
101
|
+
</button>
|
|
102
|
+
) : (
|
|
103
|
+
heading
|
|
104
|
+
)}
|
|
105
|
+
<ModerationBadge moderation={moderation} unstyled={unstyled} />
|
|
106
|
+
</header>
|
|
107
|
+
|
|
108
|
+
<dl className={unstyled ? undefined : "agenc-listing-card__meta"}>
|
|
109
|
+
{category ? (
|
|
110
|
+
<div className={unstyled ? undefined : "agenc-listing-card__meta-row"}>
|
|
111
|
+
<dt>{tc("components.listingCard.category")}</dt>
|
|
112
|
+
<dd>
|
|
113
|
+
<Badge tone="info" unstyled={unstyled}>
|
|
114
|
+
{category}
|
|
115
|
+
</Badge>
|
|
116
|
+
</dd>
|
|
117
|
+
</div>
|
|
118
|
+
) : null}
|
|
119
|
+
<div className={unstyled ? undefined : "agenc-listing-card__meta-row"}>
|
|
120
|
+
<dt>{tc("components.listingCard.byProvider", { provider })}</dt>
|
|
121
|
+
<dd>{tc("components.listingCard.hires", { count: String(hires) })}</dd>
|
|
122
|
+
</div>
|
|
123
|
+
</dl>
|
|
124
|
+
|
|
125
|
+
<footer className={unstyled ? undefined : "agenc-listing-card__footer"}>
|
|
126
|
+
{hidePrice ? null : (
|
|
127
|
+
<p className={unstyled ? undefined : "agenc-listing-card__price"}>
|
|
128
|
+
<span className={unstyled ? undefined : "agenc-listing-card__price-label"}>
|
|
129
|
+
{tc("components.listingCard.priceLabel")}
|
|
130
|
+
</span>{" "}
|
|
131
|
+
<span className={unstyled ? undefined : "agenc-listing-card__price-value"}>
|
|
132
|
+
{price}
|
|
133
|
+
</span>
|
|
134
|
+
</p>
|
|
135
|
+
)}
|
|
136
|
+
{onHire ? (
|
|
137
|
+
<Button
|
|
138
|
+
unstyled={unstyled}
|
|
139
|
+
variant="primary"
|
|
140
|
+
onClick={() => onHire(listing)}
|
|
141
|
+
>
|
|
142
|
+
{tc("components.hire.cta")}
|
|
143
|
+
</Button>
|
|
144
|
+
) : null}
|
|
145
|
+
</footer>
|
|
146
|
+
</article>
|
|
147
|
+
);
|
|
148
|
+
}
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Ladle stories for {@link ListingGrid} — covers default / loading / empty /
|
|
3
|
+
* error / load-more.
|
|
4
|
+
*/
|
|
5
|
+
import type { Story } from "@ladle/react";
|
|
6
|
+
import { ListingGrid } from "./ListingGrid.js";
|
|
7
|
+
import { makeListingRows } from "./__fixtures__/index.js";
|
|
8
|
+
|
|
9
|
+
export default {
|
|
10
|
+
title: "Listings / ListingGrid",
|
|
11
|
+
};
|
|
12
|
+
|
|
13
|
+
const rows = makeListingRows(6);
|
|
14
|
+
|
|
15
|
+
export const Default: Story = () => (
|
|
16
|
+
<ListingGrid listings={rows} onHire={() => {}} onSelect={() => {}} />
|
|
17
|
+
);
|
|
18
|
+
|
|
19
|
+
export const Loading: Story = () => (
|
|
20
|
+
<ListingGrid listings={[]} isLoading />
|
|
21
|
+
);
|
|
22
|
+
|
|
23
|
+
export const Empty: Story = () => <ListingGrid listings={[]} />;
|
|
24
|
+
|
|
25
|
+
export const ErrorState: Story = () => (
|
|
26
|
+
<ListingGrid
|
|
27
|
+
listings={[]}
|
|
28
|
+
error={new Error("RPC unavailable")}
|
|
29
|
+
onRetry={() => {}}
|
|
30
|
+
/>
|
|
31
|
+
);
|
|
32
|
+
|
|
33
|
+
export const HasMore: Story = () => (
|
|
34
|
+
<ListingGrid
|
|
35
|
+
listings={rows.slice(0, 3)}
|
|
36
|
+
hasMore
|
|
37
|
+
onLoadMore={() => {}}
|
|
38
|
+
onHire={() => {}}
|
|
39
|
+
/>
|
|
40
|
+
);
|
|
41
|
+
|
|
42
|
+
export const Unstyled: Story = () => (
|
|
43
|
+
<ListingGrid listings={rows} onHire={() => {}} unstyled />
|
|
44
|
+
);
|
|
@@ -0,0 +1,137 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* `<ListingGrid>` — a responsive grid of {@link ListingCard}s with the
|
|
3
|
+
* canonical loading / empty / error states.
|
|
4
|
+
*
|
|
5
|
+
* Presentational by design: it takes the `useListings` result fields
|
|
6
|
+
* (`listings`, `isLoading`, `error`, `hasMore`, `fetchMore`) rather than
|
|
7
|
+
* calling the hook itself, so it renders identically under SSR, in Ladle, and
|
|
8
|
+
* against the live transport. A host wires it to `useListings` in one line:
|
|
9
|
+
*
|
|
10
|
+
* ```tsx
|
|
11
|
+
* const q = useListings(filter);
|
|
12
|
+
* <ListingGrid {...q} onLoadMore={q.fetchMore} onHire={open} />
|
|
13
|
+
* ```
|
|
14
|
+
*
|
|
15
|
+
* @module components/ListingGrid
|
|
16
|
+
*/
|
|
17
|
+
import type { ReactNode } from "react";
|
|
18
|
+
import type { IndexerListing } from "../types.js";
|
|
19
|
+
import { tc } from "./format.js";
|
|
20
|
+
import { ListingCard, type ListingCardData } from "./ListingCard.js";
|
|
21
|
+
import { StateMessage, rootClass, type ThemableProps } from "./primitives.js";
|
|
22
|
+
|
|
23
|
+
/** Props for {@link ListingGrid}. */
|
|
24
|
+
export interface ListingGridProps extends ThemableProps {
|
|
25
|
+
/** The listings to render (typically `useListings().listings`). */
|
|
26
|
+
listings: ListingCardData[];
|
|
27
|
+
/** True while the first load is in flight. Shows the loading state. */
|
|
28
|
+
isLoading?: boolean;
|
|
29
|
+
/** A load error. Shows the error state (with retry when `onRetry` given). */
|
|
30
|
+
error?: Error | null;
|
|
31
|
+
/** Whether more rows can be revealed (shows the "Load more" control). */
|
|
32
|
+
hasMore?: boolean;
|
|
33
|
+
/** Reveal the next page (typically `useListings().fetchMore`). */
|
|
34
|
+
onLoadMore?: () => void;
|
|
35
|
+
/** Retry handler for the error state. */
|
|
36
|
+
onRetry?: () => void;
|
|
37
|
+
/** Hire handler forwarded to each card. */
|
|
38
|
+
onHire?: (listing: ListingCardData) => void;
|
|
39
|
+
/** Select handler forwarded to each card. */
|
|
40
|
+
onSelect?: (listing: ListingCardData) => void;
|
|
41
|
+
/**
|
|
42
|
+
* Optional per-listing moderation projections, keyed by listing PDA string,
|
|
43
|
+
* for the moderation badge. Absent entries render the honest "pending" badge.
|
|
44
|
+
*/
|
|
45
|
+
moderationByPda?: Record<string, IndexerListing | null>;
|
|
46
|
+
/** Override the empty-state message. */
|
|
47
|
+
emptyMessage?: string;
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
/**
|
|
51
|
+
* A grid of listing cards with loading/empty/error handling.
|
|
52
|
+
*/
|
|
53
|
+
export function ListingGrid({
|
|
54
|
+
listings,
|
|
55
|
+
isLoading = false,
|
|
56
|
+
error = null,
|
|
57
|
+
hasMore = false,
|
|
58
|
+
onLoadMore,
|
|
59
|
+
onRetry,
|
|
60
|
+
onHire,
|
|
61
|
+
onSelect,
|
|
62
|
+
moderationByPda,
|
|
63
|
+
emptyMessage,
|
|
64
|
+
unstyled,
|
|
65
|
+
className,
|
|
66
|
+
}: ListingGridProps): ReactNode {
|
|
67
|
+
const gridClass = rootClass("agenc-listing-grid", unstyled, className);
|
|
68
|
+
|
|
69
|
+
// Error wins over loading/empty so a failed refetch is never masked.
|
|
70
|
+
if (error) {
|
|
71
|
+
return (
|
|
72
|
+
<div className={gridClass}>
|
|
73
|
+
<StateMessage
|
|
74
|
+
kind="error"
|
|
75
|
+
message={tc("components.listingGrid.error")}
|
|
76
|
+
onRetry={onRetry}
|
|
77
|
+
unstyled={unstyled}
|
|
78
|
+
/>
|
|
79
|
+
</div>
|
|
80
|
+
);
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
if (isLoading && listings.length === 0) {
|
|
84
|
+
return (
|
|
85
|
+
<div className={gridClass}>
|
|
86
|
+
<StateMessage kind="loading" unstyled={unstyled} />
|
|
87
|
+
</div>
|
|
88
|
+
);
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
if (listings.length === 0) {
|
|
92
|
+
return (
|
|
93
|
+
<div className={gridClass}>
|
|
94
|
+
<StateMessage
|
|
95
|
+
kind="empty"
|
|
96
|
+
message={emptyMessage ?? tc("components.listingGrid.empty")}
|
|
97
|
+
unstyled={unstyled}
|
|
98
|
+
/>
|
|
99
|
+
</div>
|
|
100
|
+
);
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
return (
|
|
104
|
+
<div className={gridClass}>
|
|
105
|
+
<ul
|
|
106
|
+
className={unstyled ? undefined : "agenc-listing-grid__list"}
|
|
107
|
+
// The list is a semantic list of cards; each item is a listitem.
|
|
108
|
+
>
|
|
109
|
+
{listings.map((listing) => (
|
|
110
|
+
<li
|
|
111
|
+
key={String(listing.address)}
|
|
112
|
+
className={unstyled ? undefined : "agenc-listing-grid__item"}
|
|
113
|
+
>
|
|
114
|
+
<ListingCard
|
|
115
|
+
listing={listing}
|
|
116
|
+
moderation={moderationByPda?.[String(listing.address)] ?? null}
|
|
117
|
+
onHire={onHire}
|
|
118
|
+
onSelect={onSelect}
|
|
119
|
+
unstyled={unstyled}
|
|
120
|
+
/>
|
|
121
|
+
</li>
|
|
122
|
+
))}
|
|
123
|
+
</ul>
|
|
124
|
+
{hasMore && onLoadMore ? (
|
|
125
|
+
<div className={unstyled ? undefined : "agenc-listing-grid__more"}>
|
|
126
|
+
<button
|
|
127
|
+
type="button"
|
|
128
|
+
className={unstyled ? undefined : "agenc-button agenc-button--secondary"}
|
|
129
|
+
onClick={onLoadMore}
|
|
130
|
+
>
|
|
131
|
+
{tc("components.listingGrid.loadMore")}
|
|
132
|
+
</button>
|
|
133
|
+
</div>
|
|
134
|
+
) : null}
|
|
135
|
+
</div>
|
|
136
|
+
);
|
|
137
|
+
}
|