@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,150 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Pure presentation helpers for the prebuilt components.
|
|
3
|
+
*
|
|
4
|
+
* Everything here is a deterministic, SSR-safe pure function — no React, no
|
|
5
|
+
* `window`/`document`, no `Intl` at module scope. They turn the SDK's raw
|
|
6
|
+
* on-chain shapes (NUL-padded byte fields, lamport `bigint`s, base58
|
|
7
|
+
* `Address`es) into display strings, and centralize the component string
|
|
8
|
+
* resolver so callers don't thread the component catalog by hand.
|
|
9
|
+
*
|
|
10
|
+
* @module components/format
|
|
11
|
+
*/
|
|
12
|
+
import { values } from "@tetsuo-ai/marketplace-sdk";
|
|
13
|
+
import type { ServiceListing } from "../types.js";
|
|
14
|
+
import { t, type StringVars, type TranslateOptions } from "../strings/index.js";
|
|
15
|
+
import { COMPONENT_CATALOG, type ComponentStringId } from "./strings.js";
|
|
16
|
+
|
|
17
|
+
/**
|
|
18
|
+
* Resolve a component string id against the merged component catalog by
|
|
19
|
+
* default. A per-call `options.catalog` (e.g. a future locale) still wins.
|
|
20
|
+
*
|
|
21
|
+
* This is the only resolver components call so every literal is overridable in
|
|
22
|
+
* one place.
|
|
23
|
+
*/
|
|
24
|
+
export function tc(
|
|
25
|
+
id: ComponentStringId | (string & {}),
|
|
26
|
+
vars?: StringVars,
|
|
27
|
+
options?: TranslateOptions,
|
|
28
|
+
): string {
|
|
29
|
+
return t(id, vars, { catalog: COMPONENT_CATALOG, ...options });
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
/** Lamports per SOL. */
|
|
33
|
+
const LAMPORTS_PER_SOL = 1_000_000_000n;
|
|
34
|
+
|
|
35
|
+
/**
|
|
36
|
+
* Format a lamports `bigint` as a human SOL string with up to 9 decimal places,
|
|
37
|
+
* trailing zeros trimmed. Pure bigint math — no float rounding, no `Intl`.
|
|
38
|
+
*
|
|
39
|
+
* @example formatSol(1_500_000_000n) // "1.5"
|
|
40
|
+
* @example formatSol(1_000_000n) // "0.001"
|
|
41
|
+
* @example formatSol(0n) // "0"
|
|
42
|
+
*/
|
|
43
|
+
export function formatSol(lamports: bigint): string {
|
|
44
|
+
const negative = lamports < 0n;
|
|
45
|
+
const abs = negative ? -lamports : lamports;
|
|
46
|
+
const whole = abs / LAMPORTS_PER_SOL;
|
|
47
|
+
const frac = abs % LAMPORTS_PER_SOL;
|
|
48
|
+
let out: string;
|
|
49
|
+
if (frac === 0n) {
|
|
50
|
+
out = whole.toString();
|
|
51
|
+
} else {
|
|
52
|
+
// Zero-pad the fractional part to 9 digits, then trim trailing zeros.
|
|
53
|
+
const fracStr = frac.toString().padStart(9, "0").replace(/0+$/, "");
|
|
54
|
+
out = `${whole.toString()}.${fracStr}`;
|
|
55
|
+
}
|
|
56
|
+
return negative ? `-${out}` : out;
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
/**
|
|
60
|
+
* A price label like `"1.5 SOL"` (SOL leg) — the only denomination the v1
|
|
61
|
+
* components render (SPL-priced listings surface the raw lamport-equivalent
|
|
62
|
+
* with the configured unit label by the caller; v1 assumes SOL).
|
|
63
|
+
*/
|
|
64
|
+
export function formatPriceSol(
|
|
65
|
+
lamports: bigint,
|
|
66
|
+
options?: TranslateOptions,
|
|
67
|
+
): string {
|
|
68
|
+
return `${formatSol(lamports)} ${t("components.common.sol", undefined, {
|
|
69
|
+
catalog: COMPONENT_CATALOG,
|
|
70
|
+
...options,
|
|
71
|
+
})}`;
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
/**
|
|
75
|
+
* Truncate a base58 address/string to `head…tail` for compact display.
|
|
76
|
+
*
|
|
77
|
+
* @example truncateAddress("So11111111111111111111111111111111111111112")
|
|
78
|
+
* // "So1111…1112"
|
|
79
|
+
*/
|
|
80
|
+
export function truncateAddress(
|
|
81
|
+
value: string | { toString(): string } | null | undefined,
|
|
82
|
+
head = 4,
|
|
83
|
+
tail = 4,
|
|
84
|
+
): string {
|
|
85
|
+
if (value === null || value === undefined) return "";
|
|
86
|
+
const s = String(value);
|
|
87
|
+
if (s.length <= head + tail + 1) return s;
|
|
88
|
+
return `${s.slice(0, head)}…${s.slice(-tail)}`;
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
/**
|
|
92
|
+
* Decode a listing's NUL-padded `name` byte field to a display string using the
|
|
93
|
+
* SDK's canonical decoder, falling back to an empty string on any decode error
|
|
94
|
+
* (a malformed on-chain name must never crash a card).
|
|
95
|
+
*/
|
|
96
|
+
export function decodeListingName(listing: Pick<ServiceListing, "name">): string {
|
|
97
|
+
try {
|
|
98
|
+
return values.decodeListingName(Uint8Array.from(listing.name));
|
|
99
|
+
} catch {
|
|
100
|
+
return "";
|
|
101
|
+
}
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
/**
|
|
105
|
+
* Decode a listing's `category` byte field, tolerant of malformed bytes.
|
|
106
|
+
*/
|
|
107
|
+
export function decodeListingCategory(
|
|
108
|
+
listing: Pick<ServiceListing, "category">,
|
|
109
|
+
): string {
|
|
110
|
+
try {
|
|
111
|
+
return values.decodeListingCategory(Uint8Array.from(listing.category));
|
|
112
|
+
} catch {
|
|
113
|
+
return "";
|
|
114
|
+
}
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
/**
|
|
118
|
+
* Decode a listing's `tags` byte field to a string array, tolerant of malformed
|
|
119
|
+
* bytes (returns `[]` on error).
|
|
120
|
+
*/
|
|
121
|
+
export function decodeListingTags(
|
|
122
|
+
listing: Pick<ServiceListing, "tags">,
|
|
123
|
+
): string[] {
|
|
124
|
+
try {
|
|
125
|
+
return values.decodeListingTags(Uint8Array.from(listing.tags));
|
|
126
|
+
} catch {
|
|
127
|
+
return [];
|
|
128
|
+
}
|
|
129
|
+
}
|
|
130
|
+
|
|
131
|
+
/**
|
|
132
|
+
* Lowercase-hex a byte field (e.g. a spec hash) for display / comparison.
|
|
133
|
+
*/
|
|
134
|
+
export function toHex(bytes: ArrayLike<number>): string {
|
|
135
|
+
let out = "";
|
|
136
|
+
for (let i = 0; i < bytes.length; i++) {
|
|
137
|
+
out += bytes[i]!.toString(16).padStart(2, "0");
|
|
138
|
+
}
|
|
139
|
+
return out;
|
|
140
|
+
}
|
|
141
|
+
|
|
142
|
+
/**
|
|
143
|
+
* Format a `[0,1]` rate as an integer percentage string, or a fallback when the
|
|
144
|
+
* rate is `null` (no denominator — the P6.6 provisional state).
|
|
145
|
+
*/
|
|
146
|
+
export function formatRate(rate: number | null, fallback = "—"): string {
|
|
147
|
+
if (rate === null || Number.isNaN(rate)) return fallback;
|
|
148
|
+
const pct = Math.round(rate * 100);
|
|
149
|
+
return `${pct}%`;
|
|
150
|
+
}
|
|
@@ -0,0 +1,102 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Prebuilt, themable components for `@tetsuo-ai/marketplace-react` (PLAN_2 A3).
|
|
3
|
+
*
|
|
4
|
+
* Every component:
|
|
5
|
+
* - is built over the A2 headless hooks (the connected `HireButton`) or takes
|
|
6
|
+
* their result fields (the presentational read/review/dispute components);
|
|
7
|
+
* - themes via `--agenc-*` CSS custom properties and accepts `unstyled` for
|
|
8
|
+
* full white-label — NO CSS-in-JS runtime;
|
|
9
|
+
* - routes every user-facing string through the component string catalog;
|
|
10
|
+
* - is SSR-safe (no `window`/`document` at module scope).
|
|
11
|
+
*
|
|
12
|
+
* The default theme CSS is OPTIONAL and shipped separately — import
|
|
13
|
+
* `@tetsuo-ai/marketplace-react/theme.css` (foundation tokens) +
|
|
14
|
+
* `@tetsuo-ai/marketplace-react/components.css` (component recipes) for the
|
|
15
|
+
* styled look, or pass `unstyled` and bring your own.
|
|
16
|
+
*
|
|
17
|
+
* @module components
|
|
18
|
+
*/
|
|
19
|
+
|
|
20
|
+
// Shared primitives + theming helpers.
|
|
21
|
+
export {
|
|
22
|
+
Badge,
|
|
23
|
+
Button,
|
|
24
|
+
Spinner,
|
|
25
|
+
StateMessage,
|
|
26
|
+
cx,
|
|
27
|
+
elementClass,
|
|
28
|
+
rootClass,
|
|
29
|
+
type BadgeProps,
|
|
30
|
+
type BadgeTone,
|
|
31
|
+
type ButtonProps,
|
|
32
|
+
type ButtonVariant,
|
|
33
|
+
type SpinnerProps,
|
|
34
|
+
type StateKind,
|
|
35
|
+
type StateMessageProps,
|
|
36
|
+
type ThemableProps,
|
|
37
|
+
} from "./primitives.js";
|
|
38
|
+
|
|
39
|
+
// Shared badges.
|
|
40
|
+
export {
|
|
41
|
+
ModerationBadge,
|
|
42
|
+
VerifiedBadge,
|
|
43
|
+
moderationStateOf,
|
|
44
|
+
type ModerationBadgeProps,
|
|
45
|
+
type ModerationState,
|
|
46
|
+
type VerifiedBadgeProps,
|
|
47
|
+
} from "./badges.js";
|
|
48
|
+
|
|
49
|
+
// Presentational formatting helpers + the component string resolver.
|
|
50
|
+
export {
|
|
51
|
+
decodeListingCategory,
|
|
52
|
+
decodeListingName,
|
|
53
|
+
decodeListingTags,
|
|
54
|
+
formatPriceSol,
|
|
55
|
+
formatRate,
|
|
56
|
+
formatSol,
|
|
57
|
+
tc,
|
|
58
|
+
toHex,
|
|
59
|
+
truncateAddress,
|
|
60
|
+
} from "./format.js";
|
|
61
|
+
export {
|
|
62
|
+
COMPONENT_CATALOG,
|
|
63
|
+
EN_COMPONENT_STRINGS,
|
|
64
|
+
type ComponentStringId,
|
|
65
|
+
} from "./strings.js";
|
|
66
|
+
|
|
67
|
+
// Accessible modal primitive + focus trap.
|
|
68
|
+
export { Modal, type ModalProps } from "./Modal.js";
|
|
69
|
+
export { useFocusTrap } from "./useFocusTrap.js";
|
|
70
|
+
|
|
71
|
+
// Listing components.
|
|
72
|
+
export {
|
|
73
|
+
ListingCard,
|
|
74
|
+
type ListingCardData,
|
|
75
|
+
type ListingCardProps,
|
|
76
|
+
} from "./ListingCard.js";
|
|
77
|
+
export { ListingGrid, type ListingGridProps } from "./ListingGrid.js";
|
|
78
|
+
|
|
79
|
+
// Hire / checkout (the money path).
|
|
80
|
+
export { HireButton, type HireButtonProps } from "./HireButton.js";
|
|
81
|
+
export {
|
|
82
|
+
HireCheckoutModal,
|
|
83
|
+
type HireCheckoutListing,
|
|
84
|
+
type HireCheckoutModalProps,
|
|
85
|
+
} from "./HireCheckoutModal.js";
|
|
86
|
+
export {
|
|
87
|
+
ReferrerDisclosure,
|
|
88
|
+
type ReferrerDisclosureProps,
|
|
89
|
+
} from "./ReferrerDisclosure.js";
|
|
90
|
+
|
|
91
|
+
// Task lifecycle + settlement.
|
|
92
|
+
export { TaskTimeline, type TaskTimelineProps } from "./TaskTimeline.js";
|
|
93
|
+
export { ReviewPanel, type ReviewPanelProps } from "./ReviewPanel.js";
|
|
94
|
+
export { DisputeBanner, type DisputeBannerProps } from "./DisputeBanner.js";
|
|
95
|
+
|
|
96
|
+
// Reputation + attribution.
|
|
97
|
+
export { ProviderCard, type ProviderCardProps } from "./ProviderCard.js";
|
|
98
|
+
export {
|
|
99
|
+
PoweredByAgenC,
|
|
100
|
+
DEFAULT_TRUST_HREF,
|
|
101
|
+
type PoweredByAgenCProps,
|
|
102
|
+
} from "./PoweredByAgenC.js";
|
|
@@ -0,0 +1,236 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Shared presentational primitives for the prebuilt components.
|
|
3
|
+
*
|
|
4
|
+
* These are the small, themable building blocks every higher-level component
|
|
5
|
+
* (ListingCard, HireCheckoutModal, ...) composes: a class-name joiner, a
|
|
6
|
+
* loading spinner, the canonical loading/empty/error state block, a status
|
|
7
|
+
* badge, and a button. They emit ONLY `--agenc-*`-driven class names (no
|
|
8
|
+
* CSS-in-JS), honor the `unstyled` white-label contract, and route every
|
|
9
|
+
* literal through {@link tc}.
|
|
10
|
+
*
|
|
11
|
+
* SSR-safe: pure render functions, no `window`/`document` at module scope.
|
|
12
|
+
*
|
|
13
|
+
* @module components/primitives
|
|
14
|
+
*/
|
|
15
|
+
import type {
|
|
16
|
+
ButtonHTMLAttributes,
|
|
17
|
+
HTMLAttributes,
|
|
18
|
+
ReactNode,
|
|
19
|
+
} from "react";
|
|
20
|
+
import { AGENC_THEME_CLASS } from "../theme/index.js";
|
|
21
|
+
import { tc } from "./format.js";
|
|
22
|
+
|
|
23
|
+
/** Join truthy class names with a single space. */
|
|
24
|
+
export function cx(...parts: Array<string | false | null | undefined>): string {
|
|
25
|
+
return parts.filter((p): p is string => Boolean(p)).join(" ");
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
/**
|
|
29
|
+
* Resolve the className a styled element should carry: when `unstyled`, only
|
|
30
|
+
* the caller's `extra` survives (white-label); otherwise the base `agenc-*`
|
|
31
|
+
* class plus `extra`.
|
|
32
|
+
*/
|
|
33
|
+
export function elementClass(
|
|
34
|
+
base: string,
|
|
35
|
+
unstyled: boolean | undefined,
|
|
36
|
+
extra?: string,
|
|
37
|
+
): string | undefined {
|
|
38
|
+
if (unstyled) return extra && extra.trim() !== "" ? extra : undefined;
|
|
39
|
+
return cx(base, extra) || undefined;
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
/**
|
|
43
|
+
* Resolve a COMPONENT ROOT className. Like {@link elementClass} but, when
|
|
44
|
+
* styled, ALSO prepends the {@link AGENC_THEME_CLASS} scope (`"agenc"`) so the
|
|
45
|
+
* `--agenc-*` tokens resolve even when the token sheet is scoped rather than
|
|
46
|
+
* global. When `unstyled`, ONLY the caller's `extra` survives — neither the
|
|
47
|
+
* scope class nor the component base class is emitted (true white-label).
|
|
48
|
+
*
|
|
49
|
+
* Use this for the outermost element of every prebuilt component; use
|
|
50
|
+
* {@link elementClass} for inner elements (which inherit the scope from the
|
|
51
|
+
* root and so don't repeat it).
|
|
52
|
+
*/
|
|
53
|
+
export function rootClass(
|
|
54
|
+
base: string,
|
|
55
|
+
unstyled: boolean | undefined,
|
|
56
|
+
extra?: string,
|
|
57
|
+
): string | undefined {
|
|
58
|
+
if (unstyled) return extra && extra.trim() !== "" ? extra : undefined;
|
|
59
|
+
return cx(AGENC_THEME_CLASS, base, extra) || undefined;
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
/** Common props every prebuilt component accepts. */
|
|
63
|
+
export interface ThemableProps {
|
|
64
|
+
/** White-label mode: emit semantic markup + ARIA but no default theme class. */
|
|
65
|
+
unstyled?: boolean;
|
|
66
|
+
/** Extra class name appended to the component root. */
|
|
67
|
+
className?: string;
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
/** Variants the loading/empty/error block renders. */
|
|
71
|
+
export type StateKind = "loading" | "empty" | "error";
|
|
72
|
+
|
|
73
|
+
/** Props for {@link StateMessage}. */
|
|
74
|
+
export interface StateMessageProps extends ThemableProps {
|
|
75
|
+
/** Which state to render. */
|
|
76
|
+
kind: StateKind;
|
|
77
|
+
/** Override message (defaults to the catalog string for `kind`). */
|
|
78
|
+
message?: string;
|
|
79
|
+
/** Optional retry handler (renders a Retry button for `error`/`empty`). */
|
|
80
|
+
onRetry?: () => void;
|
|
81
|
+
/** Accessible role override. Defaults: `status` (loading) / `alert` (error). */
|
|
82
|
+
role?: HTMLAttributes<HTMLDivElement>["role"];
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
const STATE_STRING: Record<StateKind, string> = {
|
|
86
|
+
loading: "components.common.loading",
|
|
87
|
+
empty: "components.common.empty",
|
|
88
|
+
error: "components.common.error",
|
|
89
|
+
};
|
|
90
|
+
|
|
91
|
+
/**
|
|
92
|
+
* The canonical loading / empty / error block. Every read component renders
|
|
93
|
+
* this for its non-data states so screen readers get a consistent, polite
|
|
94
|
+
* announcement (`role="status"` for loading, `role="alert"` for error).
|
|
95
|
+
*/
|
|
96
|
+
export function StateMessage({
|
|
97
|
+
kind,
|
|
98
|
+
message,
|
|
99
|
+
onRetry,
|
|
100
|
+
role,
|
|
101
|
+
unstyled,
|
|
102
|
+
className,
|
|
103
|
+
}: StateMessageProps): ReactNode {
|
|
104
|
+
const text = message ?? tc(STATE_STRING[kind]);
|
|
105
|
+
const resolvedRole = role ?? (kind === "error" ? "alert" : "status");
|
|
106
|
+
return (
|
|
107
|
+
<div
|
|
108
|
+
className={elementClass(`agenc-state agenc-state--${kind}`, unstyled, className)}
|
|
109
|
+
role={resolvedRole}
|
|
110
|
+
aria-live={kind === "error" ? "assertive" : "polite"}
|
|
111
|
+
aria-busy={kind === "loading" ? true : undefined}
|
|
112
|
+
>
|
|
113
|
+
{kind === "loading" ? <Spinner unstyled={unstyled} /> : null}
|
|
114
|
+
<span className={unstyled ? undefined : "agenc-state__text"}>{text}</span>
|
|
115
|
+
{onRetry && kind !== "loading" ? (
|
|
116
|
+
<Button unstyled={unstyled} variant="ghost" onClick={onRetry}>
|
|
117
|
+
{tc("components.common.retry")}
|
|
118
|
+
</Button>
|
|
119
|
+
) : null}
|
|
120
|
+
</div>
|
|
121
|
+
);
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
/** Props for {@link Spinner}. */
|
|
125
|
+
export interface SpinnerProps extends ThemableProps {
|
|
126
|
+
/** Accessible label (default "Loading…"). */
|
|
127
|
+
label?: string;
|
|
128
|
+
}
|
|
129
|
+
|
|
130
|
+
/**
|
|
131
|
+
* An accessible, CSS-animated spinner. `role="status"` + visually-hidden label
|
|
132
|
+
* so a screen reader announces the loading state with no visible text.
|
|
133
|
+
*/
|
|
134
|
+
export function Spinner({ label, unstyled, className }: SpinnerProps): ReactNode {
|
|
135
|
+
return (
|
|
136
|
+
<span
|
|
137
|
+
className={elementClass("agenc-spinner", unstyled, className)}
|
|
138
|
+
role="status"
|
|
139
|
+
aria-live="polite"
|
|
140
|
+
>
|
|
141
|
+
<span className={unstyled ? undefined : "agenc-visually-hidden"}>
|
|
142
|
+
{label ?? tc("components.common.loading")}
|
|
143
|
+
</span>
|
|
144
|
+
</span>
|
|
145
|
+
);
|
|
146
|
+
}
|
|
147
|
+
|
|
148
|
+
/** Visual intent of a {@link Badge}. */
|
|
149
|
+
export type BadgeTone = "neutral" | "success" | "warning" | "danger" | "info";
|
|
150
|
+
|
|
151
|
+
/** Props for {@link Badge}. */
|
|
152
|
+
export interface BadgeProps extends ThemableProps {
|
|
153
|
+
/** Color intent. */
|
|
154
|
+
tone?: BadgeTone;
|
|
155
|
+
/** Badge content. */
|
|
156
|
+
children: ReactNode;
|
|
157
|
+
/**
|
|
158
|
+
* Optional `title`/`aria-label` for an icon-only or abbreviated badge so it
|
|
159
|
+
* carries an accessible name.
|
|
160
|
+
*/
|
|
161
|
+
label?: string;
|
|
162
|
+
}
|
|
163
|
+
|
|
164
|
+
/**
|
|
165
|
+
* A small status pill (verified / moderation / state). Themable via
|
|
166
|
+
* `--agenc-*`; tone maps to a semantic color token.
|
|
167
|
+
*/
|
|
168
|
+
export function Badge({
|
|
169
|
+
tone = "neutral",
|
|
170
|
+
children,
|
|
171
|
+
label,
|
|
172
|
+
unstyled,
|
|
173
|
+
className,
|
|
174
|
+
}: BadgeProps): ReactNode {
|
|
175
|
+
return (
|
|
176
|
+
<span
|
|
177
|
+
className={elementClass(
|
|
178
|
+
`agenc-badge agenc-badge--${tone}`,
|
|
179
|
+
unstyled,
|
|
180
|
+
className,
|
|
181
|
+
)}
|
|
182
|
+
title={label}
|
|
183
|
+
aria-label={label}
|
|
184
|
+
>
|
|
185
|
+
{children}
|
|
186
|
+
</span>
|
|
187
|
+
);
|
|
188
|
+
}
|
|
189
|
+
|
|
190
|
+
/** Visual variant of a {@link Button}. */
|
|
191
|
+
export type ButtonVariant = "primary" | "secondary" | "ghost" | "danger";
|
|
192
|
+
|
|
193
|
+
/** Props for {@link Button}. */
|
|
194
|
+
export interface ButtonProps
|
|
195
|
+
extends ButtonHTMLAttributes<HTMLButtonElement>,
|
|
196
|
+
ThemableProps {
|
|
197
|
+
/** Visual variant. */
|
|
198
|
+
variant?: ButtonVariant;
|
|
199
|
+
/** Show a spinner + disable while a related action is in flight. */
|
|
200
|
+
loading?: boolean;
|
|
201
|
+
}
|
|
202
|
+
|
|
203
|
+
/**
|
|
204
|
+
* A themable, accessible button. Always a real `<button type="button">` (the
|
|
205
|
+
* default) so keyboard + screen-reader semantics are correct; `loading`
|
|
206
|
+
* disables it and shows an inline spinner with an accessible busy state.
|
|
207
|
+
*/
|
|
208
|
+
export function Button({
|
|
209
|
+
variant = "primary",
|
|
210
|
+
loading = false,
|
|
211
|
+
unstyled,
|
|
212
|
+
className,
|
|
213
|
+
children,
|
|
214
|
+
disabled,
|
|
215
|
+
type,
|
|
216
|
+
...rest
|
|
217
|
+
}: ButtonProps): ReactNode {
|
|
218
|
+
return (
|
|
219
|
+
<button
|
|
220
|
+
type={type ?? "button"}
|
|
221
|
+
className={elementClass(
|
|
222
|
+
`agenc-button agenc-button--${variant}`,
|
|
223
|
+
unstyled,
|
|
224
|
+
className,
|
|
225
|
+
)}
|
|
226
|
+
disabled={disabled || loading}
|
|
227
|
+
aria-busy={loading || undefined}
|
|
228
|
+
{...rest}
|
|
229
|
+
>
|
|
230
|
+
{loading ? <Spinner unstyled={unstyled} /> : null}
|
|
231
|
+
<span className={unstyled ? undefined : "agenc-button__label"}>
|
|
232
|
+
{children}
|
|
233
|
+
</span>
|
|
234
|
+
</button>
|
|
235
|
+
);
|
|
236
|
+
}
|
|
@@ -0,0 +1,131 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Component-layer string catalog (PLAN_2 A3).
|
|
3
|
+
*
|
|
4
|
+
* Every user-facing literal a prebuilt component renders routes through the
|
|
5
|
+
* shared {@link t} resolver and is keyed HERE, namespaced under
|
|
6
|
+
* `components.*` so it never collides with the foundation catalog
|
|
7
|
+
* (`provider.*`, `referrer.*`, `transport.*`, `state.*`, `hire.*`). A future
|
|
8
|
+
* locale extends this object — no component code changes.
|
|
9
|
+
*
|
|
10
|
+
* These are MERGED over `EN_STRINGS` at module load (see `mergedCatalog`) so a
|
|
11
|
+
* component calling `t("components.listingCard.priceLabel")` resolves without
|
|
12
|
+
* the caller threading a catalog. SSR-safe: a plain object literal, no globals.
|
|
13
|
+
*
|
|
14
|
+
* @module components/strings
|
|
15
|
+
*/
|
|
16
|
+
import { EN_STRINGS, type StringCatalog } from "../strings/index.js";
|
|
17
|
+
|
|
18
|
+
/**
|
|
19
|
+
* The component-surface English strings. Keys are namespaced by component
|
|
20
|
+
* (`components.<component>.<key>`) plus a few shared `components.common.*`.
|
|
21
|
+
*/
|
|
22
|
+
export const EN_COMPONENT_STRINGS = {
|
|
23
|
+
// Shared / cross-component.
|
|
24
|
+
"components.common.loading": "Loading…",
|
|
25
|
+
"components.common.empty": "Nothing to show yet.",
|
|
26
|
+
"components.common.error": "Something went wrong.",
|
|
27
|
+
"components.common.retry": "Retry",
|
|
28
|
+
"components.common.close": "Close",
|
|
29
|
+
"components.common.verified": "Verified",
|
|
30
|
+
"components.common.unverified": "Unverified",
|
|
31
|
+
"components.common.sol": "SOL",
|
|
32
|
+
"components.common.lamports": "lamports",
|
|
33
|
+
|
|
34
|
+
// ListingCard.
|
|
35
|
+
"components.listingCard.priceLabel": "Price",
|
|
36
|
+
"components.listingCard.byProvider": "by {provider}",
|
|
37
|
+
"components.listingCard.untitled": "Untitled service",
|
|
38
|
+
"components.listingCard.hires": "{count} hires",
|
|
39
|
+
"components.listingCard.category": "Category",
|
|
40
|
+
|
|
41
|
+
// ListingGrid.
|
|
42
|
+
"components.listingGrid.empty": "No listings match your filters yet.",
|
|
43
|
+
"components.listingGrid.loadMore": "Load more",
|
|
44
|
+
"components.listingGrid.error": "Could not load listings.",
|
|
45
|
+
|
|
46
|
+
// HireButton / Checkout.
|
|
47
|
+
"components.hire.cta": "Hire",
|
|
48
|
+
"components.hire.ctaPrice": "Hire — {price}",
|
|
49
|
+
"components.hire.checkoutTitle": "Confirm hire",
|
|
50
|
+
"components.hire.priceLabel": "You pay",
|
|
51
|
+
"components.hire.escrowNote":
|
|
52
|
+
"Funds are held in protocol escrow and released to the provider only when you accept the result.",
|
|
53
|
+
"components.hire.confirm": "Confirm and fund escrow",
|
|
54
|
+
"components.hire.cancel": "Cancel",
|
|
55
|
+
"components.hire.pending": "Confirming…",
|
|
56
|
+
"components.hire.success": "Escrow funded.",
|
|
57
|
+
"components.hire.successDetail": "Your task is created. Track it below.",
|
|
58
|
+
"components.hire.viewTask": "View task",
|
|
59
|
+
"components.hire.errorTitle": "Hire failed",
|
|
60
|
+
"components.hire.moderationAttested": "Moderation attested",
|
|
61
|
+
"components.hire.moderationPending": "Moderation pending",
|
|
62
|
+
"components.hire.moderationIssues": "Moderation issues found",
|
|
63
|
+
"components.hire.notConnected": "Connect a wallet to hire.",
|
|
64
|
+
|
|
65
|
+
// Referrer disclosure (P6.2 gate — never claims a live fee).
|
|
66
|
+
"components.referrer.disclosure": "This site earns a referral fee.",
|
|
67
|
+
"components.referrer.disclosurePending":
|
|
68
|
+
"This site earns a referral fee (pending protocol support).",
|
|
69
|
+
"components.referrer.feeBps": "{bps} bps",
|
|
70
|
+
|
|
71
|
+
// TaskTimeline.
|
|
72
|
+
"components.taskTimeline.title": "Task progress",
|
|
73
|
+
"components.taskTimeline.empty": "No task to track yet.",
|
|
74
|
+
"components.taskTimeline.status.Open": "Open",
|
|
75
|
+
"components.taskTimeline.status.InProgress": "In progress",
|
|
76
|
+
"components.taskTimeline.status.PendingValidation": "Pending review",
|
|
77
|
+
"components.taskTimeline.status.Completed": "Completed",
|
|
78
|
+
"components.taskTimeline.status.Cancelled": "Cancelled",
|
|
79
|
+
"components.taskTimeline.status.Disputed": "Disputed",
|
|
80
|
+
"components.taskTimeline.status.RejectFrozen": "Rejected (frozen)",
|
|
81
|
+
|
|
82
|
+
// ReviewPanel.
|
|
83
|
+
"components.review.title": "Review submission",
|
|
84
|
+
"components.review.noSubmission": "Awaiting the worker's submission.",
|
|
85
|
+
"components.review.accept": "Accept and release escrow",
|
|
86
|
+
"components.review.reject": "Reject",
|
|
87
|
+
"components.review.requestChanges": "Request changes",
|
|
88
|
+
"components.review.accepted": "Result accepted. Escrow released.",
|
|
89
|
+
"components.review.rejected": "Result rejected.",
|
|
90
|
+
"components.review.changesRequested": "Changes requested.",
|
|
91
|
+
"components.review.pending": "Submitting…",
|
|
92
|
+
"components.review.errorTitle": "Review action failed",
|
|
93
|
+
|
|
94
|
+
// DisputeBanner.
|
|
95
|
+
"components.dispute.title": "This task is in dispute.",
|
|
96
|
+
"components.dispute.body":
|
|
97
|
+
"A dispute has been opened. A protocol resolver decides the outcome; funds stay in escrow until then.",
|
|
98
|
+
"components.dispute.initiate": "Open a dispute",
|
|
99
|
+
"components.dispute.pending": "Opening dispute…",
|
|
100
|
+
"components.dispute.opened": "Dispute opened.",
|
|
101
|
+
"components.dispute.none": "No open dispute.",
|
|
102
|
+
"components.dispute.errorTitle": "Could not open dispute",
|
|
103
|
+
|
|
104
|
+
// ProviderCard.
|
|
105
|
+
"components.provider.title": "Provider",
|
|
106
|
+
"components.provider.completionRate": "Completion rate",
|
|
107
|
+
"components.provider.disputeRate": "Dispute rate",
|
|
108
|
+
"components.provider.completions": "{count} completed",
|
|
109
|
+
"components.provider.disputes": "{count} disputes",
|
|
110
|
+
"components.provider.provisional": "provisional",
|
|
111
|
+
"components.provider.noData": "No track record yet.",
|
|
112
|
+
"components.provider.unavailable":
|
|
113
|
+
"Track record is unavailable on this read transport.",
|
|
114
|
+
|
|
115
|
+
// PoweredByAgenC.
|
|
116
|
+
"components.poweredBy.label": "Powered by AgenC",
|
|
117
|
+
"components.poweredBy.trustLink": "Learn how this works",
|
|
118
|
+
} as const satisfies StringCatalog;
|
|
119
|
+
|
|
120
|
+
/** A component-surface message id. */
|
|
121
|
+
export type ComponentStringId = keyof typeof EN_COMPONENT_STRINGS;
|
|
122
|
+
|
|
123
|
+
/**
|
|
124
|
+
* The default catalog every component resolves against: the foundation
|
|
125
|
+
* `EN_STRINGS` merged with {@link EN_COMPONENT_STRINGS}. A host-supplied catalog
|
|
126
|
+
* (`t(id, vars, { catalog })`) still wins per-call.
|
|
127
|
+
*/
|
|
128
|
+
export const COMPONENT_CATALOG: StringCatalog = {
|
|
129
|
+
...EN_STRINGS,
|
|
130
|
+
...EN_COMPONENT_STRINGS,
|
|
131
|
+
};
|