@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,121 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* `<Modal>` — the accessible dialog primitive the checkout flow is built on.
|
|
3
|
+
*
|
|
4
|
+
* Accessibility is STRUCTURAL here (PLAN_2 A3): this is the surface a
|
|
5
|
+
* money-handling modal published to third parties renders into, so it ships
|
|
6
|
+
* with:
|
|
7
|
+
* - `role="dialog"` + `aria-modal="true"` + a labelled title
|
|
8
|
+
* (`aria-labelledby`) and optional description (`aria-describedby`);
|
|
9
|
+
* - a focus trap (initial focus in, Tab cycling, focus restore on close) via
|
|
10
|
+
* {@link useFocusTrap};
|
|
11
|
+
* - Escape-to-close and overlay-click-to-close (both opt-out-able);
|
|
12
|
+
* - a real `<button>` close affordance with an accessible name.
|
|
13
|
+
*
|
|
14
|
+
* SSR-safe: renders nothing while closed; all `document` access is inside the
|
|
15
|
+
* focus-trap effect. No portal is used (a portal needs `document.body`, which
|
|
16
|
+
* SSR lacks) — the dialog renders inline in the React tree behind a fixed
|
|
17
|
+
* overlay, which keeps it hydration-safe. Hosts that need a body portal can
|
|
18
|
+
* wrap it themselves on the client.
|
|
19
|
+
*
|
|
20
|
+
* @module components/Modal
|
|
21
|
+
*/
|
|
22
|
+
import { useId, useRef, type ReactNode } from "react";
|
|
23
|
+
import { tc } from "./format.js";
|
|
24
|
+
import { rootClass, type ThemableProps } from "./primitives.js";
|
|
25
|
+
import { useFocusTrap } from "./useFocusTrap.js";
|
|
26
|
+
|
|
27
|
+
/** Props for {@link Modal}. */
|
|
28
|
+
export interface ModalProps extends ThemableProps {
|
|
29
|
+
/** Whether the dialog is open. Renders nothing when false. */
|
|
30
|
+
open: boolean;
|
|
31
|
+
/** Called to request a close (Escape, overlay click, close button). */
|
|
32
|
+
onClose: () => void;
|
|
33
|
+
/** The dialog title (becomes the `aria-labelledby` target). */
|
|
34
|
+
title: ReactNode;
|
|
35
|
+
/** Dialog body. */
|
|
36
|
+
children: ReactNode;
|
|
37
|
+
/** Optional footer (actions). */
|
|
38
|
+
footer?: ReactNode;
|
|
39
|
+
/** Disable Escape-to-close (e.g. mid-transaction). Default false. */
|
|
40
|
+
disableEscapeClose?: boolean;
|
|
41
|
+
/** Disable overlay-click-to-close. Default false. */
|
|
42
|
+
disableOverlayClose?: boolean;
|
|
43
|
+
/** Hide the close (X) button (e.g. a forced confirmation step). Default false. */
|
|
44
|
+
hideCloseButton?: boolean;
|
|
45
|
+
/** Accessible label for the close button. */
|
|
46
|
+
closeLabel?: string;
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
/**
|
|
50
|
+
* An accessible modal dialog.
|
|
51
|
+
*/
|
|
52
|
+
export function Modal({
|
|
53
|
+
open,
|
|
54
|
+
onClose,
|
|
55
|
+
title,
|
|
56
|
+
children,
|
|
57
|
+
footer,
|
|
58
|
+
disableEscapeClose = false,
|
|
59
|
+
disableOverlayClose = false,
|
|
60
|
+
hideCloseButton = false,
|
|
61
|
+
closeLabel,
|
|
62
|
+
unstyled,
|
|
63
|
+
className,
|
|
64
|
+
}: ModalProps): ReactNode {
|
|
65
|
+
const dialogRef = useRef<HTMLDivElement>(null);
|
|
66
|
+
const titleId = useId();
|
|
67
|
+
const bodyId = useId();
|
|
68
|
+
|
|
69
|
+
useFocusTrap(dialogRef, open, () => {
|
|
70
|
+
if (!disableEscapeClose) onClose();
|
|
71
|
+
});
|
|
72
|
+
|
|
73
|
+
if (!open) return null;
|
|
74
|
+
|
|
75
|
+
const overlayClass = rootClass("agenc-modal", unstyled, className);
|
|
76
|
+
|
|
77
|
+
return (
|
|
78
|
+
<div
|
|
79
|
+
className={overlayClass}
|
|
80
|
+
// The overlay. Clicking it (not the dialog) requests close.
|
|
81
|
+
onMouseDown={(event) => {
|
|
82
|
+
if (disableOverlayClose) return;
|
|
83
|
+
if (event.target === event.currentTarget) onClose();
|
|
84
|
+
}}
|
|
85
|
+
>
|
|
86
|
+
<div
|
|
87
|
+
className={unstyled ? undefined : "agenc-modal__dialog"}
|
|
88
|
+
ref={dialogRef}
|
|
89
|
+
role="dialog"
|
|
90
|
+
aria-modal="true"
|
|
91
|
+
aria-labelledby={titleId}
|
|
92
|
+
aria-describedby={bodyId}
|
|
93
|
+
tabIndex={-1}
|
|
94
|
+
>
|
|
95
|
+
<header className={unstyled ? undefined : "agenc-modal__header"}>
|
|
96
|
+
<h2 id={titleId} className={unstyled ? undefined : "agenc-modal__title"}>
|
|
97
|
+
{title}
|
|
98
|
+
</h2>
|
|
99
|
+
{hideCloseButton ? null : (
|
|
100
|
+
<button
|
|
101
|
+
type="button"
|
|
102
|
+
className={unstyled ? undefined : "agenc-modal__close"}
|
|
103
|
+
aria-label={closeLabel ?? tc("components.common.close")}
|
|
104
|
+
onClick={onClose}
|
|
105
|
+
>
|
|
106
|
+
<span aria-hidden="true">×</span>
|
|
107
|
+
</button>
|
|
108
|
+
)}
|
|
109
|
+
</header>
|
|
110
|
+
<div id={bodyId} className={unstyled ? undefined : "agenc-modal__body"}>
|
|
111
|
+
{children}
|
|
112
|
+
</div>
|
|
113
|
+
{footer ? (
|
|
114
|
+
<footer className={unstyled ? undefined : "agenc-modal__footer"}>
|
|
115
|
+
{footer}
|
|
116
|
+
</footer>
|
|
117
|
+
) : null}
|
|
118
|
+
</div>
|
|
119
|
+
</div>
|
|
120
|
+
);
|
|
121
|
+
}
|
|
@@ -0,0 +1,85 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* `<PoweredByAgenC>` — an optional attribution badge linking a trust page.
|
|
3
|
+
*
|
|
4
|
+
* A small, themable "Powered by AgenC" mark embedders can drop into a
|
|
5
|
+
* storefront footer / checkout to link buyers to an explanation of the escrow +
|
|
6
|
+
* moderation trust stack. Optional and fully white-labelable.
|
|
7
|
+
*
|
|
8
|
+
* SSR-safe; the link is a plain anchor (`rel="noopener noreferrer"` for safety
|
|
9
|
+
* when it opens in a new tab). The `href` is scheme-validated (http/https/
|
|
10
|
+
* mailto only; `javascript:`/`data:` fall back to the default trust href) so an
|
|
11
|
+
* embedder wiring untrusted data into the prop cannot create a click-to-execute
|
|
12
|
+
* XSS on a money surface.
|
|
13
|
+
*
|
|
14
|
+
* @module components/PoweredByAgenC
|
|
15
|
+
*/
|
|
16
|
+
import type { ReactNode } from "react";
|
|
17
|
+
import { tc } from "./format.js";
|
|
18
|
+
import { rootClass, type ThemableProps } from "./primitives.js";
|
|
19
|
+
|
|
20
|
+
/** The default trust page the badge links to. */
|
|
21
|
+
export const DEFAULT_TRUST_HREF = "https://agenc.tech/trust";
|
|
22
|
+
|
|
23
|
+
/** Schemes a trust link may safely use. Anything else (e.g. `javascript:`,
|
|
24
|
+
* `data:`) is rejected and falls back to {@link DEFAULT_TRUST_HREF}. */
|
|
25
|
+
const SAFE_HREF_SCHEMES = new Set(["http:", "https:", "mailto:"]);
|
|
26
|
+
|
|
27
|
+
/**
|
|
28
|
+
* Validate an embedder-supplied href. React does NOT block `javascript:` (or
|
|
29
|
+
* `data:`) in an anchor href, so an embedder wiring untrusted data here would
|
|
30
|
+
* create a click-to-execute XSS. Allow only http/https/mailto; fall back to the
|
|
31
|
+
* safe default trust href otherwise. Scheme-relative (`//host`) and
|
|
32
|
+
* path/relative URLs resolve against a dummy base and keep their (http/https)
|
|
33
|
+
* scheme; anything that fails to parse falls back too.
|
|
34
|
+
*/
|
|
35
|
+
function safeHref(href: string): string {
|
|
36
|
+
try {
|
|
37
|
+
// Resolve against a base so relative/scheme-relative hrefs parse and adopt
|
|
38
|
+
// a concrete (https) scheme rather than being rejected.
|
|
39
|
+
const url = new URL(href, DEFAULT_TRUST_HREF);
|
|
40
|
+
return SAFE_HREF_SCHEMES.has(url.protocol) ? href : DEFAULT_TRUST_HREF;
|
|
41
|
+
} catch {
|
|
42
|
+
return DEFAULT_TRUST_HREF;
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
/** Props for {@link PoweredByAgenC}. */
|
|
47
|
+
export interface PoweredByAgenCProps extends ThemableProps {
|
|
48
|
+
/** Trust-page URL. Defaults to {@link DEFAULT_TRUST_HREF}. */
|
|
49
|
+
href?: string;
|
|
50
|
+
/** Open the link in a new tab. Default true. */
|
|
51
|
+
newTab?: boolean;
|
|
52
|
+
/** Override the visible label. */
|
|
53
|
+
label?: string;
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
/**
|
|
57
|
+
* The "Powered by AgenC" attribution mark.
|
|
58
|
+
*/
|
|
59
|
+
export function PoweredByAgenC({
|
|
60
|
+
href = DEFAULT_TRUST_HREF,
|
|
61
|
+
newTab = true,
|
|
62
|
+
label,
|
|
63
|
+
unstyled,
|
|
64
|
+
className,
|
|
65
|
+
}: PoweredByAgenCProps): ReactNode {
|
|
66
|
+
const linkClass = rootClass("agenc-powered-by", unstyled, className);
|
|
67
|
+
return (
|
|
68
|
+
<a
|
|
69
|
+
className={linkClass}
|
|
70
|
+
href={safeHref(href)}
|
|
71
|
+
target={newTab ? "_blank" : undefined}
|
|
72
|
+
// noopener + noreferrer for new-tab links (defense-in-depth against
|
|
73
|
+
// reverse-tabnabbing; noreferrer implies noopener in modern browsers).
|
|
74
|
+
rel={newTab ? "noopener noreferrer" : undefined}
|
|
75
|
+
// The link's accessible name combines the brand + the trust-link copy.
|
|
76
|
+
aria-label={`${label ?? tc("components.poweredBy.label")} — ${tc(
|
|
77
|
+
"components.poweredBy.trustLink",
|
|
78
|
+
)}`}
|
|
79
|
+
>
|
|
80
|
+
<span className={unstyled ? undefined : "agenc-powered-by__label"}>
|
|
81
|
+
{label ?? tc("components.poweredBy.label")}
|
|
82
|
+
</span>
|
|
83
|
+
</a>
|
|
84
|
+
);
|
|
85
|
+
}
|
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Ladle stories for {@link ProviderCard} — verified / provisional rates /
|
|
3
|
+
* no-data / loading / unsupported-transport error + {@link PoweredByAgenC}.
|
|
4
|
+
*/
|
|
5
|
+
import type { Story } from "@ladle/react";
|
|
6
|
+
import { ProviderCard } from "./ProviderCard.js";
|
|
7
|
+
import { PoweredByAgenC } from "./PoweredByAgenC.js";
|
|
8
|
+
import {
|
|
9
|
+
FIXTURE_AGENT,
|
|
10
|
+
makeTrackRecord,
|
|
11
|
+
} from "./__fixtures__/index.js";
|
|
12
|
+
import { ReadTransportUnsupportedError } from "../transport/index.js";
|
|
13
|
+
|
|
14
|
+
export default {
|
|
15
|
+
title: "Provider / ProviderCard",
|
|
16
|
+
};
|
|
17
|
+
|
|
18
|
+
export const Verified: Story = () => (
|
|
19
|
+
<ProviderCard
|
|
20
|
+
agent={FIXTURE_AGENT}
|
|
21
|
+
trackRecord={makeTrackRecord()}
|
|
22
|
+
verified
|
|
23
|
+
/>
|
|
24
|
+
);
|
|
25
|
+
|
|
26
|
+
export const Unverified: Story = () => (
|
|
27
|
+
<ProviderCard agent={FIXTURE_AGENT} trackRecord={makeTrackRecord()} />
|
|
28
|
+
);
|
|
29
|
+
|
|
30
|
+
export const NullRates: Story = () => (
|
|
31
|
+
<ProviderCard
|
|
32
|
+
agent={FIXTURE_AGENT}
|
|
33
|
+
trackRecord={makeTrackRecord({
|
|
34
|
+
completionRate: null,
|
|
35
|
+
disputeRate: null,
|
|
36
|
+
completions: 0,
|
|
37
|
+
disputesLost: 0,
|
|
38
|
+
})}
|
|
39
|
+
/>
|
|
40
|
+
);
|
|
41
|
+
|
|
42
|
+
export const Loading: Story = () => (
|
|
43
|
+
<ProviderCard agent={FIXTURE_AGENT} trackRecord={null} isLoading />
|
|
44
|
+
);
|
|
45
|
+
|
|
46
|
+
export const NoData: Story = () => (
|
|
47
|
+
<ProviderCard agent={FIXTURE_AGENT} trackRecord={null} />
|
|
48
|
+
);
|
|
49
|
+
|
|
50
|
+
export const Unsupported: Story = () => (
|
|
51
|
+
<ProviderCard
|
|
52
|
+
agent={FIXTURE_AGENT}
|
|
53
|
+
trackRecord={null}
|
|
54
|
+
error={new ReadTransportUnsupportedError("agentTrackRecord")}
|
|
55
|
+
onRetry={() => {}}
|
|
56
|
+
/>
|
|
57
|
+
);
|
|
58
|
+
|
|
59
|
+
export const PoweredBy: Story = () => <PoweredByAgenC />;
|
|
60
|
+
|
|
61
|
+
export const PoweredByUnstyled: Story = () => <PoweredByAgenC unstyled />;
|
|
@@ -0,0 +1,154 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* `<ProviderCard>` — a provider's reputation summary.
|
|
3
|
+
*
|
|
4
|
+
* Renders the agent's track record (completion rate, dispute rate, completions,
|
|
5
|
+
* dispute count, slash history count) plus a verified badge. Presentational: it
|
|
6
|
+
* takes the projected `AgentTrackRecord | null` (from
|
|
7
|
+
* `useAgentTrackRecord().trackRecord`) + loading/error, so it renders under SSR
|
|
8
|
+
* and in Ladle.
|
|
9
|
+
*
|
|
10
|
+
* ## P6.6 honesty
|
|
11
|
+
*
|
|
12
|
+
* Rates are PROVISIONAL until P6.6 supplies true denominators. When the
|
|
13
|
+
* `partial` flag is set the card marks the rates "(provisional)"; a `null` rate
|
|
14
|
+
* renders as "—" (no denominator), never as a fabricated 0% or 100%.
|
|
15
|
+
*
|
|
16
|
+
* @module components/ProviderCard
|
|
17
|
+
*/
|
|
18
|
+
import type { ReactNode } from "react";
|
|
19
|
+
import type { AgentTrackRecord } from "../hooks/useAgentTrackRecord.js";
|
|
20
|
+
import type { Address } from "../types.js";
|
|
21
|
+
import { formatRate, tc, truncateAddress } from "./format.js";
|
|
22
|
+
import { VerifiedBadge } from "./badges.js";
|
|
23
|
+
import { StateMessage, rootClass, type ThemableProps } from "./primitives.js";
|
|
24
|
+
|
|
25
|
+
/** Props for {@link ProviderCard}. */
|
|
26
|
+
export interface ProviderCardProps extends ThemableProps {
|
|
27
|
+
/** The provider's agent PDA (for the heading). */
|
|
28
|
+
agent?: Address | string | null;
|
|
29
|
+
/** The projected track record (from `useAgentTrackRecord().trackRecord`). */
|
|
30
|
+
trackRecord: AgentTrackRecord | null;
|
|
31
|
+
/** Whether the provider is verified (shows the verified badge). */
|
|
32
|
+
verified?: boolean;
|
|
33
|
+
/** True while loading the track record. */
|
|
34
|
+
isLoading?: boolean;
|
|
35
|
+
/**
|
|
36
|
+
* A read error. Under the gPA fallback the track record is unsupported; the
|
|
37
|
+
* card shows the "unavailable on this transport" copy for that case.
|
|
38
|
+
*/
|
|
39
|
+
error?: Error | null;
|
|
40
|
+
/** Retry handler for the error state. */
|
|
41
|
+
onRetry?: () => void;
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
/**
|
|
45
|
+
* Render a provider reputation card.
|
|
46
|
+
*/
|
|
47
|
+
export function ProviderCard({
|
|
48
|
+
agent,
|
|
49
|
+
trackRecord,
|
|
50
|
+
verified = false,
|
|
51
|
+
isLoading = false,
|
|
52
|
+
error = null,
|
|
53
|
+
onRetry,
|
|
54
|
+
unstyled,
|
|
55
|
+
className,
|
|
56
|
+
}: ProviderCardProps): ReactNode {
|
|
57
|
+
const cardClass = rootClass("agenc-provider", unstyled, className);
|
|
58
|
+
|
|
59
|
+
const header = (
|
|
60
|
+
<header className={unstyled ? undefined : "agenc-provider__header"}>
|
|
61
|
+
<div className={unstyled ? undefined : "agenc-provider__id"}>
|
|
62
|
+
<span className={unstyled ? undefined : "agenc-provider__label"}>
|
|
63
|
+
{tc("components.provider.title")}
|
|
64
|
+
</span>
|
|
65
|
+
{agent ? (
|
|
66
|
+
<span className={unstyled ? undefined : "agenc-provider__pda"}>
|
|
67
|
+
{truncateAddress(agent)}
|
|
68
|
+
</span>
|
|
69
|
+
) : null}
|
|
70
|
+
</div>
|
|
71
|
+
<VerifiedBadge verified={verified} unstyled={unstyled} />
|
|
72
|
+
</header>
|
|
73
|
+
);
|
|
74
|
+
|
|
75
|
+
if (error) {
|
|
76
|
+
return (
|
|
77
|
+
<section className={cardClass} aria-label={tc("components.provider.title")}>
|
|
78
|
+
{header}
|
|
79
|
+
<StateMessage
|
|
80
|
+
kind="error"
|
|
81
|
+
message={tc("components.provider.unavailable")}
|
|
82
|
+
onRetry={onRetry}
|
|
83
|
+
unstyled={unstyled}
|
|
84
|
+
/>
|
|
85
|
+
</section>
|
|
86
|
+
);
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
if (isLoading && trackRecord === null) {
|
|
90
|
+
return (
|
|
91
|
+
<section className={cardClass} aria-label={tc("components.provider.title")}>
|
|
92
|
+
{header}
|
|
93
|
+
<StateMessage kind="loading" unstyled={unstyled} />
|
|
94
|
+
</section>
|
|
95
|
+
);
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
if (trackRecord === null) {
|
|
99
|
+
return (
|
|
100
|
+
<section className={cardClass} aria-label={tc("components.provider.title")}>
|
|
101
|
+
{header}
|
|
102
|
+
<StateMessage
|
|
103
|
+
kind="empty"
|
|
104
|
+
message={tc("components.provider.noData")}
|
|
105
|
+
unstyled={unstyled}
|
|
106
|
+
/>
|
|
107
|
+
</section>
|
|
108
|
+
);
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
const provisional = trackRecord.partial;
|
|
112
|
+
|
|
113
|
+
return (
|
|
114
|
+
<section className={cardClass} aria-label={tc("components.provider.title")}>
|
|
115
|
+
{header}
|
|
116
|
+
<dl className={unstyled ? undefined : "agenc-provider__stats"}>
|
|
117
|
+
<div className={unstyled ? undefined : "agenc-provider__stat"}>
|
|
118
|
+
<dt>{tc("components.provider.completionRate")}</dt>
|
|
119
|
+
<dd>
|
|
120
|
+
{formatRate(trackRecord.completionRate)}
|
|
121
|
+
{provisional ? (
|
|
122
|
+
<span className={unstyled ? undefined : "agenc-provider__provisional"}>
|
|
123
|
+
{" "}
|
|
124
|
+
({tc("components.provider.provisional")})
|
|
125
|
+
</span>
|
|
126
|
+
) : null}
|
|
127
|
+
</dd>
|
|
128
|
+
</div>
|
|
129
|
+
<div className={unstyled ? undefined : "agenc-provider__stat"}>
|
|
130
|
+
<dt>{tc("components.provider.disputeRate")}</dt>
|
|
131
|
+
<dd>
|
|
132
|
+
{formatRate(trackRecord.disputeRate)}
|
|
133
|
+
{provisional ? (
|
|
134
|
+
<span className={unstyled ? undefined : "agenc-provider__provisional"}>
|
|
135
|
+
{" "}
|
|
136
|
+
({tc("components.provider.provisional")})
|
|
137
|
+
</span>
|
|
138
|
+
) : null}
|
|
139
|
+
</dd>
|
|
140
|
+
</div>
|
|
141
|
+
<div className={unstyled ? undefined : "agenc-provider__stat"}>
|
|
142
|
+
<dt>{tc("components.provider.completions", {
|
|
143
|
+
count: String(trackRecord.completions),
|
|
144
|
+
})}</dt>
|
|
145
|
+
<dd>
|
|
146
|
+
{tc("components.provider.disputes", {
|
|
147
|
+
count: String(trackRecord.disputesLost),
|
|
148
|
+
})}
|
|
149
|
+
</dd>
|
|
150
|
+
</div>
|
|
151
|
+
</dl>
|
|
152
|
+
</section>
|
|
153
|
+
);
|
|
154
|
+
}
|
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* `<ReferrerDisclosure>` — the "this site earns a referral fee" notice.
|
|
3
|
+
*
|
|
4
|
+
* ## THE P6.2 GATE (PLAN_2 §0 / the §0 referrer gate — read before editing)
|
|
5
|
+
*
|
|
6
|
+
* Disclosure is the ONE referrer surface allowed to render while the on-chain
|
|
7
|
+
* referrer leg is not live. It NEVER asserts that a fee was charged: when
|
|
8
|
+
* `live` is false it shows the "(pending protocol support)" copy. It is purely
|
|
9
|
+
* informational and reads no earnings. The actual injection / earnings remain
|
|
10
|
+
* blocked on P6.2 (handled by the hooks, not here). This component only
|
|
11
|
+
* DISCLOSES the configured intent.
|
|
12
|
+
*
|
|
13
|
+
* Render it only when a referrer is configured on the provider.
|
|
14
|
+
*
|
|
15
|
+
* @module components/ReferrerDisclosure
|
|
16
|
+
*/
|
|
17
|
+
import type { ReactNode } from "react";
|
|
18
|
+
import type { ValidatedReferrerConfig } from "../types.js";
|
|
19
|
+
import { tc } from "./format.js";
|
|
20
|
+
import { cx, type ThemableProps } from "./primitives.js";
|
|
21
|
+
|
|
22
|
+
/** Props for {@link ReferrerDisclosure}. */
|
|
23
|
+
export interface ReferrerDisclosureProps extends ThemableProps {
|
|
24
|
+
/** The validated referrer config (from the provider context). */
|
|
25
|
+
referrer: ValidatedReferrerConfig;
|
|
26
|
+
/**
|
|
27
|
+
* Whether the referral fee is actually live on-chain (the P6.2 capability).
|
|
28
|
+
* ALWAYS false today — when false the copy shows the pending-support note and
|
|
29
|
+
* no fee is implied as charged. Defaults to false.
|
|
30
|
+
*/
|
|
31
|
+
live?: boolean;
|
|
32
|
+
/** Show the configured fee in bps alongside the disclosure. Default true. */
|
|
33
|
+
showFee?: boolean;
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
/**
|
|
37
|
+
* Disclose that the embedding site earns a referral fee. Honors the P6.2 gate:
|
|
38
|
+
* shows the pending-support copy until referral settlement is live.
|
|
39
|
+
*/
|
|
40
|
+
export function ReferrerDisclosure({
|
|
41
|
+
referrer,
|
|
42
|
+
live = false,
|
|
43
|
+
showFee = true,
|
|
44
|
+
unstyled,
|
|
45
|
+
className,
|
|
46
|
+
}: ReferrerDisclosureProps): ReactNode {
|
|
47
|
+
const text = live
|
|
48
|
+
? tc("components.referrer.disclosure")
|
|
49
|
+
: tc("components.referrer.disclosurePending");
|
|
50
|
+
return (
|
|
51
|
+
<p
|
|
52
|
+
className={
|
|
53
|
+
unstyled ? className : cx("agenc-referrer-disclosure", className)
|
|
54
|
+
}
|
|
55
|
+
// Informational, not an alert — a polite, non-interrupting note.
|
|
56
|
+
role="note"
|
|
57
|
+
>
|
|
58
|
+
<span>{text}</span>
|
|
59
|
+
{showFee ? (
|
|
60
|
+
<span className={unstyled ? undefined : "agenc-referrer-disclosure__fee"}>
|
|
61
|
+
{" "}
|
|
62
|
+
{tc("components.referrer.feeBps", { bps: String(referrer.feeBps) })}
|
|
63
|
+
</span>
|
|
64
|
+
) : null}
|
|
65
|
+
</p>
|
|
66
|
+
);
|
|
67
|
+
}
|
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Ladle stories for {@link ReviewPanel} — submission-present / awaiting /
|
|
3
|
+
* pending / success / error.
|
|
4
|
+
*/
|
|
5
|
+
import type { Story } from "@ladle/react";
|
|
6
|
+
import { ReviewPanel } from "./ReviewPanel.js";
|
|
7
|
+
|
|
8
|
+
export default {
|
|
9
|
+
title: "Task / ReviewPanel",
|
|
10
|
+
};
|
|
11
|
+
|
|
12
|
+
export const Default: Story = () => (
|
|
13
|
+
<ReviewPanel
|
|
14
|
+
hasSubmission
|
|
15
|
+
onAccept={() => {}}
|
|
16
|
+
onReject={() => {}}
|
|
17
|
+
onRequestChanges={() => {}}
|
|
18
|
+
/>
|
|
19
|
+
);
|
|
20
|
+
|
|
21
|
+
export const AwaitingSubmission: Story = () => (
|
|
22
|
+
<ReviewPanel hasSubmission={false} />
|
|
23
|
+
);
|
|
24
|
+
|
|
25
|
+
export const Pending: Story = () => (
|
|
26
|
+
<ReviewPanel
|
|
27
|
+
hasSubmission
|
|
28
|
+
status="pending"
|
|
29
|
+
onAccept={() => {}}
|
|
30
|
+
onReject={() => {}}
|
|
31
|
+
onRequestChanges={() => {}}
|
|
32
|
+
/>
|
|
33
|
+
);
|
|
34
|
+
|
|
35
|
+
export const Accepted: Story = () => (
|
|
36
|
+
<ReviewPanel
|
|
37
|
+
hasSubmission
|
|
38
|
+
status="success"
|
|
39
|
+
settledAction="accept"
|
|
40
|
+
onAccept={() => {}}
|
|
41
|
+
onReject={() => {}}
|
|
42
|
+
onRequestChanges={() => {}}
|
|
43
|
+
/>
|
|
44
|
+
);
|
|
45
|
+
|
|
46
|
+
export const ErrorState: Story = () => (
|
|
47
|
+
<ReviewPanel
|
|
48
|
+
hasSubmission
|
|
49
|
+
status="error"
|
|
50
|
+
error={new Error("0x1772: task not pending validation")}
|
|
51
|
+
onAccept={() => {}}
|
|
52
|
+
onReject={() => {}}
|
|
53
|
+
onRequestChanges={() => {}}
|
|
54
|
+
/>
|
|
55
|
+
);
|
|
56
|
+
|
|
57
|
+
export const Unstyled: Story = () => (
|
|
58
|
+
<ReviewPanel
|
|
59
|
+
hasSubmission
|
|
60
|
+
unstyled
|
|
61
|
+
onAccept={() => {}}
|
|
62
|
+
onReject={() => {}}
|
|
63
|
+
onRequestChanges={() => {}}
|
|
64
|
+
/>
|
|
65
|
+
);
|
|
@@ -0,0 +1,141 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* `<ReviewPanel>` — buyer-side settlement actions (accept / reject / request
|
|
3
|
+
* changes) for a submitted task.
|
|
4
|
+
*
|
|
5
|
+
* Presentational: it takes the three action handlers and a status/error (map
|
|
6
|
+
* from `useSubmissionReview()`), plus a `hasSubmission` flag that gates the
|
|
7
|
+
* actions until the worker has submitted. Each action is a real, keyboard-
|
|
8
|
+
* accessible button; the panel announces the settled outcome in a live region.
|
|
9
|
+
*
|
|
10
|
+
* The destructive verbs (reject, request changes) are visually distinguished
|
|
11
|
+
* but never hidden behind a confirm of their own — the host decides whether to
|
|
12
|
+
* wrap them; the panel keeps them clearly labelled and reversible-where-the-
|
|
13
|
+
* protocol-allows (request changes returns the task to the worker).
|
|
14
|
+
*
|
|
15
|
+
* @module components/ReviewPanel
|
|
16
|
+
*/
|
|
17
|
+
import type { ReactNode } from "react";
|
|
18
|
+
import type { ReviewStatus } from "../hooks/useSubmissionReview.js";
|
|
19
|
+
import { tc } from "./format.js";
|
|
20
|
+
import {
|
|
21
|
+
Button,
|
|
22
|
+
StateMessage,
|
|
23
|
+
rootClass,
|
|
24
|
+
type ThemableProps,
|
|
25
|
+
} from "./primitives.js";
|
|
26
|
+
|
|
27
|
+
/** Props for {@link ReviewPanel}. */
|
|
28
|
+
export interface ReviewPanelProps extends ThemableProps {
|
|
29
|
+
/** Whether the worker has submitted a result to review. */
|
|
30
|
+
hasSubmission?: boolean;
|
|
31
|
+
/** Accept handler (`useSubmissionReview().accept`-bound by the host). */
|
|
32
|
+
onAccept?: () => void;
|
|
33
|
+
/** Reject handler. */
|
|
34
|
+
onReject?: () => void;
|
|
35
|
+
/** Request-changes handler. */
|
|
36
|
+
onRequestChanges?: () => void;
|
|
37
|
+
/** Current action status (from `useSubmissionReview().status`). */
|
|
38
|
+
status?: ReviewStatus;
|
|
39
|
+
/** The action error to surface. */
|
|
40
|
+
error?: Error | null;
|
|
41
|
+
/**
|
|
42
|
+
* Which verb most recently settled, for the success copy. Optional; when
|
|
43
|
+
* given and `status === "success"` the matching message renders.
|
|
44
|
+
*/
|
|
45
|
+
settledAction?: "accept" | "reject" | "requestChanges";
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
const SUCCESS_STRING: Record<
|
|
49
|
+
NonNullable<ReviewPanelProps["settledAction"]>,
|
|
50
|
+
string
|
|
51
|
+
> = {
|
|
52
|
+
accept: "components.review.accepted",
|
|
53
|
+
reject: "components.review.rejected",
|
|
54
|
+
requestChanges: "components.review.changesRequested",
|
|
55
|
+
};
|
|
56
|
+
|
|
57
|
+
/**
|
|
58
|
+
* The accept / reject / request-changes review panel.
|
|
59
|
+
*/
|
|
60
|
+
export function ReviewPanel({
|
|
61
|
+
hasSubmission = false,
|
|
62
|
+
onAccept,
|
|
63
|
+
onReject,
|
|
64
|
+
onRequestChanges,
|
|
65
|
+
status = "idle",
|
|
66
|
+
error = null,
|
|
67
|
+
settledAction,
|
|
68
|
+
unstyled,
|
|
69
|
+
className,
|
|
70
|
+
}: ReviewPanelProps): ReactNode {
|
|
71
|
+
const panelClass = rootClass("agenc-review", unstyled, className);
|
|
72
|
+
const pending = status === "pending";
|
|
73
|
+
const success = status === "success";
|
|
74
|
+
|
|
75
|
+
return (
|
|
76
|
+
<section
|
|
77
|
+
className={panelClass}
|
|
78
|
+
aria-label={tc("components.review.title")}
|
|
79
|
+
>
|
|
80
|
+
<h3 className={unstyled ? undefined : "agenc-review__title"}>
|
|
81
|
+
{tc("components.review.title")}
|
|
82
|
+
</h3>
|
|
83
|
+
|
|
84
|
+
{!hasSubmission ? (
|
|
85
|
+
<StateMessage
|
|
86
|
+
kind="empty"
|
|
87
|
+
message={tc("components.review.noSubmission")}
|
|
88
|
+
unstyled={unstyled}
|
|
89
|
+
/>
|
|
90
|
+
) : (
|
|
91
|
+
<div className={unstyled ? undefined : "agenc-review__actions"}>
|
|
92
|
+
<Button
|
|
93
|
+
unstyled={unstyled}
|
|
94
|
+
variant="primary"
|
|
95
|
+
loading={pending}
|
|
96
|
+
disabled={pending || !onAccept}
|
|
97
|
+
onClick={onAccept}
|
|
98
|
+
>
|
|
99
|
+
{tc("components.review.accept")}
|
|
100
|
+
</Button>
|
|
101
|
+
<Button
|
|
102
|
+
unstyled={unstyled}
|
|
103
|
+
variant="secondary"
|
|
104
|
+
disabled={pending || !onRequestChanges}
|
|
105
|
+
onClick={onRequestChanges}
|
|
106
|
+
>
|
|
107
|
+
{tc("components.review.requestChanges")}
|
|
108
|
+
</Button>
|
|
109
|
+
<Button
|
|
110
|
+
unstyled={unstyled}
|
|
111
|
+
variant="danger"
|
|
112
|
+
disabled={pending || !onReject}
|
|
113
|
+
onClick={onReject}
|
|
114
|
+
>
|
|
115
|
+
{tc("components.review.reject")}
|
|
116
|
+
</Button>
|
|
117
|
+
</div>
|
|
118
|
+
)}
|
|
119
|
+
|
|
120
|
+
<div
|
|
121
|
+
className={unstyled ? undefined : "agenc-review__status"}
|
|
122
|
+
role="status"
|
|
123
|
+
aria-live="polite"
|
|
124
|
+
>
|
|
125
|
+
{pending ? tc("components.review.pending") : null}
|
|
126
|
+
{success && settledAction ? tc(SUCCESS_STRING[settledAction]) : null}
|
|
127
|
+
</div>
|
|
128
|
+
|
|
129
|
+
{error ? (
|
|
130
|
+
<div
|
|
131
|
+
className={unstyled ? undefined : "agenc-review__error"}
|
|
132
|
+
role="alert"
|
|
133
|
+
aria-live="assertive"
|
|
134
|
+
>
|
|
135
|
+
<strong>{tc("components.review.errorTitle")}</strong>
|
|
136
|
+
<span>{error.message}</span>
|
|
137
|
+
</div>
|
|
138
|
+
) : null}
|
|
139
|
+
</section>
|
|
140
|
+
);
|
|
141
|
+
}
|