@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
package/package.json
ADDED
|
@@ -0,0 +1,139 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@tetsuo-ai/marketplace-react",
|
|
3
|
+
"version": "0.1.0",
|
|
4
|
+
"description": "Headless React hooks + themable components for the AgenC marketplace — provider, indexer-first read transport, and the P6.2-gated referrer config",
|
|
5
|
+
"type": "module",
|
|
6
|
+
"main": "./dist/index.cjs",
|
|
7
|
+
"module": "./dist/index.js",
|
|
8
|
+
"types": "./dist/index.d.ts",
|
|
9
|
+
"sideEffects": [
|
|
10
|
+
"./dist/theme/agenc-tokens.css",
|
|
11
|
+
"./src/theme/agenc-tokens.css",
|
|
12
|
+
"./dist/components/agenc-components.css",
|
|
13
|
+
"./src/components/agenc-components.css"
|
|
14
|
+
],
|
|
15
|
+
"exports": {
|
|
16
|
+
".": {
|
|
17
|
+
"import": {
|
|
18
|
+
"types": "./dist/index.d.ts",
|
|
19
|
+
"default": "./dist/index.js"
|
|
20
|
+
},
|
|
21
|
+
"require": {
|
|
22
|
+
"types": "./dist/index.d.cts",
|
|
23
|
+
"default": "./dist/index.cjs"
|
|
24
|
+
}
|
|
25
|
+
},
|
|
26
|
+
"./hooks": {
|
|
27
|
+
"import": {
|
|
28
|
+
"types": "./dist/hooks/index.d.ts",
|
|
29
|
+
"default": "./dist/hooks/index.js"
|
|
30
|
+
},
|
|
31
|
+
"require": {
|
|
32
|
+
"types": "./dist/hooks/index.d.cts",
|
|
33
|
+
"default": "./dist/hooks/index.cjs"
|
|
34
|
+
}
|
|
35
|
+
},
|
|
36
|
+
"./signers": {
|
|
37
|
+
"import": {
|
|
38
|
+
"types": "./dist/signers/index.d.ts",
|
|
39
|
+
"default": "./dist/signers/index.js"
|
|
40
|
+
},
|
|
41
|
+
"require": {
|
|
42
|
+
"types": "./dist/signers/index.d.cts",
|
|
43
|
+
"default": "./dist/signers/index.cjs"
|
|
44
|
+
}
|
|
45
|
+
},
|
|
46
|
+
"./components": {
|
|
47
|
+
"import": {
|
|
48
|
+
"types": "./dist/components/index.d.ts",
|
|
49
|
+
"default": "./dist/components/index.js"
|
|
50
|
+
},
|
|
51
|
+
"require": {
|
|
52
|
+
"types": "./dist/components/index.d.cts",
|
|
53
|
+
"default": "./dist/components/index.cjs"
|
|
54
|
+
}
|
|
55
|
+
},
|
|
56
|
+
"./testing": {
|
|
57
|
+
"import": {
|
|
58
|
+
"types": "./dist/testing/index.d.ts",
|
|
59
|
+
"default": "./dist/testing/index.js"
|
|
60
|
+
},
|
|
61
|
+
"require": {
|
|
62
|
+
"types": "./dist/testing/index.d.cts",
|
|
63
|
+
"default": "./dist/testing/index.cjs"
|
|
64
|
+
}
|
|
65
|
+
},
|
|
66
|
+
"./theme.css": "./dist/theme/agenc-tokens.css",
|
|
67
|
+
"./components.css": "./dist/components/agenc-components.css",
|
|
68
|
+
"./tailwind-preset": "./dist/theme/agenc-tailwind-preset.cjs",
|
|
69
|
+
"./package.json": "./package.json"
|
|
70
|
+
},
|
|
71
|
+
"files": [
|
|
72
|
+
"dist",
|
|
73
|
+
"src",
|
|
74
|
+
"README.md",
|
|
75
|
+
"LICENSE",
|
|
76
|
+
"CHANGELOG.md"
|
|
77
|
+
],
|
|
78
|
+
"scripts": {
|
|
79
|
+
"build": "tsup",
|
|
80
|
+
"typecheck": "tsc --noEmit",
|
|
81
|
+
"test": "vitest run",
|
|
82
|
+
"test:watch": "vitest",
|
|
83
|
+
"ladle": "ladle serve",
|
|
84
|
+
"ladle:build": "ladle build"
|
|
85
|
+
},
|
|
86
|
+
"peerDependencies": {
|
|
87
|
+
"@solana/kit": "^6.9.0",
|
|
88
|
+
"@solana/program-client-core": "^6.4.0",
|
|
89
|
+
"@tetsuo-ai/marketplace-sdk": "^0.4.0",
|
|
90
|
+
"react": ">=18"
|
|
91
|
+
},
|
|
92
|
+
"dependencies": {
|
|
93
|
+
"@tanstack/react-query": "^5.62.0"
|
|
94
|
+
},
|
|
95
|
+
"devDependencies": {
|
|
96
|
+
"@ladle/react": "^5.1.1",
|
|
97
|
+
"@solana/kit": "6.9.0",
|
|
98
|
+
"@solana/program-client-core": "^6.4.0",
|
|
99
|
+
"@solana/react": "6.9.0",
|
|
100
|
+
"@testing-library/react": "^16.1.0",
|
|
101
|
+
"@tetsuo-ai/marketplace-sdk": "file:../sdk-ts",
|
|
102
|
+
"@types/react": "^18.3.12",
|
|
103
|
+
"@types/react-dom": "^18.3.1",
|
|
104
|
+
"axe-core": "^4.12.0",
|
|
105
|
+
"jsdom": "^25.0.1",
|
|
106
|
+
"react": "^18.3.1",
|
|
107
|
+
"react-dom": "^18.3.1",
|
|
108
|
+
"tsup": "8.5.1",
|
|
109
|
+
"typescript": "5.9.3",
|
|
110
|
+
"vitest": "4.1.8",
|
|
111
|
+
"vitest-axe": "^0.1.0"
|
|
112
|
+
},
|
|
113
|
+
"license": "MIT",
|
|
114
|
+
"publishConfig": {
|
|
115
|
+
"access": "public"
|
|
116
|
+
},
|
|
117
|
+
"repository": {
|
|
118
|
+
"type": "git",
|
|
119
|
+
"url": "git+https://github.com/tetsuo-ai/agenc-protocol.git",
|
|
120
|
+
"directory": "packages/marketplace-react"
|
|
121
|
+
},
|
|
122
|
+
"homepage": "https://github.com/tetsuo-ai/agenc-protocol/tree/main/packages/marketplace-react#readme",
|
|
123
|
+
"bugs": {
|
|
124
|
+
"url": "https://github.com/tetsuo-ai/agenc-protocol/issues"
|
|
125
|
+
},
|
|
126
|
+
"keywords": [
|
|
127
|
+
"solana",
|
|
128
|
+
"agenc",
|
|
129
|
+
"marketplace",
|
|
130
|
+
"react",
|
|
131
|
+
"hooks",
|
|
132
|
+
"headless",
|
|
133
|
+
"embeddable"
|
|
134
|
+
],
|
|
135
|
+
"author": "Tetsuo AI",
|
|
136
|
+
"engines": {
|
|
137
|
+
"node": ">=20.18.0"
|
|
138
|
+
}
|
|
139
|
+
}
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Ladle stories for {@link DisputeBanner} — open / none / initiate-able /
|
|
3
|
+
* pending / opened / error.
|
|
4
|
+
*/
|
|
5
|
+
import type { Story } from "@ladle/react";
|
|
6
|
+
import { DisputeBanner } from "./DisputeBanner.js";
|
|
7
|
+
|
|
8
|
+
export default {
|
|
9
|
+
title: "Task / DisputeBanner",
|
|
10
|
+
};
|
|
11
|
+
|
|
12
|
+
export const Open: Story = () => <DisputeBanner disputeOpen />;
|
|
13
|
+
|
|
14
|
+
export const NoneInformational: Story = () => (
|
|
15
|
+
<DisputeBanner disputeOpen={false} />
|
|
16
|
+
);
|
|
17
|
+
|
|
18
|
+
export const NoneInitiatable: Story = () => (
|
|
19
|
+
<DisputeBanner disputeOpen={false} onInitiate={() => {}} />
|
|
20
|
+
);
|
|
21
|
+
|
|
22
|
+
export const Pending: Story = () => (
|
|
23
|
+
<DisputeBanner disputeOpen={false} status="pending" onInitiate={() => {}} />
|
|
24
|
+
);
|
|
25
|
+
|
|
26
|
+
export const Opened: Story = () => (
|
|
27
|
+
<DisputeBanner disputeOpen={false} status="success" onInitiate={() => {}} />
|
|
28
|
+
);
|
|
29
|
+
|
|
30
|
+
export const ErrorState: Story = () => (
|
|
31
|
+
<DisputeBanner
|
|
32
|
+
disputeOpen={false}
|
|
33
|
+
status="error"
|
|
34
|
+
error={new Error("0x1773: task not disputable")}
|
|
35
|
+
onInitiate={() => {}}
|
|
36
|
+
/>
|
|
37
|
+
);
|
|
38
|
+
|
|
39
|
+
export const Unstyled: Story = () => <DisputeBanner disputeOpen unstyled />;
|
|
@@ -0,0 +1,110 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* `<DisputeBanner>` — surfaces a task's dispute state + the entry point to open
|
|
3
|
+
* one.
|
|
4
|
+
*
|
|
5
|
+
* Two modes, driven by `disputeOpen`:
|
|
6
|
+
* - OPEN: a prominent `role="alert"` banner explaining funds stay in escrow
|
|
7
|
+
* until a protocol resolver decides (matches the assignable single-resolver
|
|
8
|
+
* model — no voting copy);
|
|
9
|
+
* - NONE: an optional "Open a dispute" affordance (rendered only when
|
|
10
|
+
* `onInitiate` is provided), with pending/opened/error states.
|
|
11
|
+
*
|
|
12
|
+
* Presentational: it takes `disputeOpen` + the initiate handler/status/error
|
|
13
|
+
* (map from `useDispute()`), so it renders under SSR and in Ladle.
|
|
14
|
+
*
|
|
15
|
+
* @module components/DisputeBanner
|
|
16
|
+
*/
|
|
17
|
+
import type { ReactNode } from "react";
|
|
18
|
+
import type { DisputeStatus } from "../hooks/useDispute.js";
|
|
19
|
+
import { tc } from "./format.js";
|
|
20
|
+
import { Button, cx, rootClass, type ThemableProps } from "./primitives.js";
|
|
21
|
+
|
|
22
|
+
/** Props for {@link DisputeBanner}. */
|
|
23
|
+
export interface DisputeBannerProps extends ThemableProps {
|
|
24
|
+
/** Whether a dispute is currently open on the task. */
|
|
25
|
+
disputeOpen?: boolean;
|
|
26
|
+
/**
|
|
27
|
+
* Open-a-dispute handler (`useDispute().initiate`-bound by the host). When
|
|
28
|
+
* omitted, the no-dispute state renders informationally with no action.
|
|
29
|
+
*/
|
|
30
|
+
onInitiate?: () => void;
|
|
31
|
+
/** Initiate-mutation status (from `useDispute().status`). */
|
|
32
|
+
status?: DisputeStatus;
|
|
33
|
+
/** The initiate error to surface. */
|
|
34
|
+
error?: Error | null;
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
/**
|
|
38
|
+
* The dispute banner / entry point.
|
|
39
|
+
*/
|
|
40
|
+
export function DisputeBanner({
|
|
41
|
+
disputeOpen = false,
|
|
42
|
+
onInitiate,
|
|
43
|
+
status = "idle",
|
|
44
|
+
error = null,
|
|
45
|
+
unstyled,
|
|
46
|
+
className,
|
|
47
|
+
}: DisputeBannerProps): ReactNode {
|
|
48
|
+
const bannerClass = rootClass(
|
|
49
|
+
cx(
|
|
50
|
+
"agenc-dispute",
|
|
51
|
+
disputeOpen ? "agenc-dispute--open" : "agenc-dispute--none",
|
|
52
|
+
),
|
|
53
|
+
unstyled,
|
|
54
|
+
className,
|
|
55
|
+
);
|
|
56
|
+
const pending = status === "pending";
|
|
57
|
+
const opened = status === "success";
|
|
58
|
+
|
|
59
|
+
if (disputeOpen) {
|
|
60
|
+
return (
|
|
61
|
+
<div className={bannerClass} role="alert">
|
|
62
|
+
<strong className={unstyled ? undefined : "agenc-dispute__title"}>
|
|
63
|
+
{tc("components.dispute.title")}
|
|
64
|
+
</strong>
|
|
65
|
+
<p className={unstyled ? undefined : "agenc-dispute__body"}>
|
|
66
|
+
{tc("components.dispute.body")}
|
|
67
|
+
</p>
|
|
68
|
+
</div>
|
|
69
|
+
);
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
// No open dispute. Render the action only when a handler is provided.
|
|
73
|
+
return (
|
|
74
|
+
<div className={bannerClass} role="region" aria-label={tc("components.dispute.none")}>
|
|
75
|
+
<p className={unstyled ? undefined : "agenc-dispute__none"}>
|
|
76
|
+
{tc("components.dispute.none")}
|
|
77
|
+
</p>
|
|
78
|
+
{onInitiate ? (
|
|
79
|
+
<Button
|
|
80
|
+
unstyled={unstyled}
|
|
81
|
+
variant="secondary"
|
|
82
|
+
loading={pending}
|
|
83
|
+
disabled={pending}
|
|
84
|
+
onClick={onInitiate}
|
|
85
|
+
>
|
|
86
|
+
{pending
|
|
87
|
+
? tc("components.dispute.pending")
|
|
88
|
+
: tc("components.dispute.initiate")}
|
|
89
|
+
</Button>
|
|
90
|
+
) : null}
|
|
91
|
+
<div
|
|
92
|
+
className={unstyled ? undefined : "agenc-dispute__status"}
|
|
93
|
+
role="status"
|
|
94
|
+
aria-live="polite"
|
|
95
|
+
>
|
|
96
|
+
{opened ? tc("components.dispute.opened") : null}
|
|
97
|
+
</div>
|
|
98
|
+
{error ? (
|
|
99
|
+
<div
|
|
100
|
+
className={unstyled ? undefined : "agenc-dispute__error"}
|
|
101
|
+
role="alert"
|
|
102
|
+
aria-live="assertive"
|
|
103
|
+
>
|
|
104
|
+
<strong>{tc("components.dispute.errorTitle")}</strong>
|
|
105
|
+
<span>{error.message}</span>
|
|
106
|
+
</div>
|
|
107
|
+
) : null}
|
|
108
|
+
</div>
|
|
109
|
+
);
|
|
110
|
+
}
|
|
@@ -0,0 +1,72 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Ladle stories for the connected {@link HireButton} (wraps the fixture
|
|
3
|
+
* `AgencProvider`) and the standalone {@link ReferrerDisclosure}.
|
|
4
|
+
*/
|
|
5
|
+
import type { Story } from "@ladle/react";
|
|
6
|
+
import { HireButton } from "./HireButton.js";
|
|
7
|
+
import { ReferrerDisclosure } from "./ReferrerDisclosure.js";
|
|
8
|
+
import { address } from "@solana/kit";
|
|
9
|
+
import {
|
|
10
|
+
FIXTURE_AGENT,
|
|
11
|
+
FIXTURE_LISTING,
|
|
12
|
+
FIXTURE_REFERRER,
|
|
13
|
+
FixtureProvider,
|
|
14
|
+
makeListing,
|
|
15
|
+
} from "./__fixtures__/index.js";
|
|
16
|
+
import type { ValidatedReferrerConfig } from "../types.js";
|
|
17
|
+
|
|
18
|
+
export default {
|
|
19
|
+
title: "Hire / HireButton",
|
|
20
|
+
};
|
|
21
|
+
|
|
22
|
+
const listing = { address: FIXTURE_LISTING, account: makeListing() };
|
|
23
|
+
|
|
24
|
+
const buildInput = () =>
|
|
25
|
+
({
|
|
26
|
+
listing: listing.address,
|
|
27
|
+
creatorAgent: FIXTURE_AGENT,
|
|
28
|
+
taskId: new Uint8Array(32).fill(9),
|
|
29
|
+
expectedPrice: listing.account.price,
|
|
30
|
+
expectedVersion: listing.account.version,
|
|
31
|
+
}) as never;
|
|
32
|
+
|
|
33
|
+
export const Default: Story = () => (
|
|
34
|
+
<FixtureProvider>
|
|
35
|
+
<HireButton listing={listing} buildHireInput={buildInput} />
|
|
36
|
+
</FixtureProvider>
|
|
37
|
+
);
|
|
38
|
+
|
|
39
|
+
export const WithReferrer: Story = () => (
|
|
40
|
+
<FixtureProvider referrer={{ wallet: FIXTURE_REFERRER, feeBps: 300 }}>
|
|
41
|
+
<HireButton listing={listing} buildHireInput={buildInput} />
|
|
42
|
+
</FixtureProvider>
|
|
43
|
+
);
|
|
44
|
+
|
|
45
|
+
export const NoWalletConnected: Story = () => (
|
|
46
|
+
<FixtureProvider withClient={false}>
|
|
47
|
+
<HireButton listing={listing} buildHireInput={buildInput} />
|
|
48
|
+
</FixtureProvider>
|
|
49
|
+
);
|
|
50
|
+
|
|
51
|
+
export const PriceHidden: Story = () => (
|
|
52
|
+
<FixtureProvider>
|
|
53
|
+
<HireButton
|
|
54
|
+
listing={listing}
|
|
55
|
+
buildHireInput={buildInput}
|
|
56
|
+
showPriceInLabel={false}
|
|
57
|
+
/>
|
|
58
|
+
</FixtureProvider>
|
|
59
|
+
);
|
|
60
|
+
|
|
61
|
+
const referrer: ValidatedReferrerConfig = {
|
|
62
|
+
wallet: address(FIXTURE_REFERRER),
|
|
63
|
+
feeBps: 250,
|
|
64
|
+
};
|
|
65
|
+
|
|
66
|
+
export const DisclosurePending: Story = () => (
|
|
67
|
+
<ReferrerDisclosure referrer={referrer} live={false} />
|
|
68
|
+
);
|
|
69
|
+
|
|
70
|
+
export const DisclosureLive: Story = () => (
|
|
71
|
+
<ReferrerDisclosure referrer={referrer} live />
|
|
72
|
+
);
|
|
@@ -0,0 +1,151 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* `<HireButton>` — the connected, drop-in hire entry point.
|
|
3
|
+
*
|
|
4
|
+
* This is the one component that binds the hooks directly: it renders a price-
|
|
5
|
+
* aware CTA that opens {@link HireCheckoutModal}, drives the hire through
|
|
6
|
+
* `useHire()`, resolves the signer via `useWalletSigner()`, and threads the
|
|
7
|
+
* provider's configured referrer + the P6.2 capability into the modal's
|
|
8
|
+
* disclosure (never injecting a fee — the gate lives in `useHire`).
|
|
9
|
+
*
|
|
10
|
+
* ## Why the caller supplies the hire input
|
|
11
|
+
*
|
|
12
|
+
* A hire needs caller-specific fields the listing alone can't provide
|
|
13
|
+
* (`creatorAgent` — the BUYER's registered agent PDA, or the humanless flag —
|
|
14
|
+
* and a fresh `taskId`). So `HireButton` takes a `buildHireInput(listing)`
|
|
15
|
+
* factory rather than guessing them. The compare-and-swap guards
|
|
16
|
+
* (`expectedPrice`/`expectedVersion`/`listingSpecHash`) are derived from the
|
|
17
|
+
* decoded listing by default and can be overridden in the returned input.
|
|
18
|
+
*
|
|
19
|
+
* @module components/HireButton
|
|
20
|
+
*/
|
|
21
|
+
import { useCallback, useRef, useState, type ReactNode } from "react";
|
|
22
|
+
import { useAgencContext } from "../provider/context.js";
|
|
23
|
+
import { useHire, type AnyHireInput } from "../hooks/useHire.js";
|
|
24
|
+
import { useWalletSigner } from "../hooks/useWalletSigner.js";
|
|
25
|
+
import type { Address } from "../types.js";
|
|
26
|
+
import { formatPriceSol, tc } from "./format.js";
|
|
27
|
+
import {
|
|
28
|
+
HireCheckoutModal,
|
|
29
|
+
type HireCheckoutListing,
|
|
30
|
+
} from "./HireCheckoutModal.js";
|
|
31
|
+
import { Button, type ThemableProps } from "./primitives.js";
|
|
32
|
+
|
|
33
|
+
/** Props for {@link HireButton}. */
|
|
34
|
+
export interface HireButtonProps extends ThemableProps {
|
|
35
|
+
/** The listing to hire (decoded account + address). */
|
|
36
|
+
listing: HireCheckoutListing;
|
|
37
|
+
/**
|
|
38
|
+
* Build the per-hire input from the listing. Must return at least
|
|
39
|
+
* `creatorAgent` (standard hire) or `{ humanless: true }` plus a fresh
|
|
40
|
+
* `taskId` and the compare-and-swap guards. `listing` and the signer default
|
|
41
|
+
* to context. See `useHire` for the full input shape.
|
|
42
|
+
*/
|
|
43
|
+
buildHireInput: (listing: HireCheckoutListing) => AnyHireInput;
|
|
44
|
+
/** Called after a successful hire with the minted Task PDA. */
|
|
45
|
+
onHired?: (taskPda: Address) => void;
|
|
46
|
+
/** Called when the buyer clicks "View task" on the success screen. */
|
|
47
|
+
onViewTask?: (taskPda: Address) => void;
|
|
48
|
+
/** Show the price in the button label (`Hire — 1.5 SOL`). Default true. */
|
|
49
|
+
showPriceInLabel?: boolean;
|
|
50
|
+
/** Override the button label. */
|
|
51
|
+
label?: string;
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
/**
|
|
55
|
+
* A connected hire button + checkout modal.
|
|
56
|
+
*
|
|
57
|
+
* @example
|
|
58
|
+
* ```tsx
|
|
59
|
+
* <HireButton
|
|
60
|
+
* listing={row}
|
|
61
|
+
* buildHireInput={(l) => ({
|
|
62
|
+
* listing: l.address,
|
|
63
|
+
* creatorAgent: myAgentPda,
|
|
64
|
+
* taskId: randomId32(),
|
|
65
|
+
* expectedPrice: l.account.price,
|
|
66
|
+
* expectedVersion: l.account.version,
|
|
67
|
+
* })}
|
|
68
|
+
* onHired={(task) => router.push(`/tasks/${task}`)}
|
|
69
|
+
* />
|
|
70
|
+
* ```
|
|
71
|
+
*/
|
|
72
|
+
export function HireButton({
|
|
73
|
+
listing,
|
|
74
|
+
buildHireInput,
|
|
75
|
+
onHired,
|
|
76
|
+
onViewTask,
|
|
77
|
+
showPriceInLabel = true,
|
|
78
|
+
label,
|
|
79
|
+
unstyled,
|
|
80
|
+
className,
|
|
81
|
+
}: HireButtonProps): ReactNode {
|
|
82
|
+
const ctx = useAgencContext();
|
|
83
|
+
const { hire, status, error, taskPda, reset } = useHire();
|
|
84
|
+
const { connected } = useWalletSigner();
|
|
85
|
+
const [open, setOpen] = useState(false);
|
|
86
|
+
// SYNCHRONOUS in-flight latch (defense-in-depth alongside the modal's own
|
|
87
|
+
// latch): the `useHire` mutation's `status` does NOT flip to "pending" within
|
|
88
|
+
// the same tick, and `mutateAsync` does NOT dedupe concurrent calls — so a
|
|
89
|
+
// fast double-invoke of `confirm` would fire two funded hires with fresh
|
|
90
|
+
// taskIds (two escrows / double charge). The ref guards against re-entrancy
|
|
91
|
+
// before the first `hire(...)` promise settles.
|
|
92
|
+
const inFlightRef = useRef(false);
|
|
93
|
+
|
|
94
|
+
const capability = ctx.resolveReferrerCapability();
|
|
95
|
+
|
|
96
|
+
const close = useCallback(() => {
|
|
97
|
+
setOpen(false);
|
|
98
|
+
inFlightRef.current = false;
|
|
99
|
+
// Reset the mutation so re-opening starts clean (idle), not stuck on a
|
|
100
|
+
// prior success/error.
|
|
101
|
+
reset();
|
|
102
|
+
}, [reset]);
|
|
103
|
+
|
|
104
|
+
const confirm = useCallback(async () => {
|
|
105
|
+
// Drop a duplicate confirm while the first hire is still in flight.
|
|
106
|
+
if (inFlightRef.current) return;
|
|
107
|
+
inFlightRef.current = true;
|
|
108
|
+
try {
|
|
109
|
+
const input = buildHireInput(listing);
|
|
110
|
+
const result = await hire(input);
|
|
111
|
+
onHired?.(result.taskPda);
|
|
112
|
+
} finally {
|
|
113
|
+
inFlightRef.current = false;
|
|
114
|
+
}
|
|
115
|
+
}, [buildHireInput, hire, listing, onHired]);
|
|
116
|
+
|
|
117
|
+
const buttonLabel =
|
|
118
|
+
label ??
|
|
119
|
+
(showPriceInLabel
|
|
120
|
+
? tc("components.hire.ctaPrice", {
|
|
121
|
+
price: formatPriceSol(listing.account.price),
|
|
122
|
+
})
|
|
123
|
+
: tc("components.hire.cta"));
|
|
124
|
+
|
|
125
|
+
return (
|
|
126
|
+
<>
|
|
127
|
+
<Button
|
|
128
|
+
unstyled={unstyled}
|
|
129
|
+
className={className}
|
|
130
|
+
variant="primary"
|
|
131
|
+
onClick={() => setOpen(true)}
|
|
132
|
+
>
|
|
133
|
+
{buttonLabel}
|
|
134
|
+
</Button>
|
|
135
|
+
<HireCheckoutModal
|
|
136
|
+
open={open}
|
|
137
|
+
onClose={close}
|
|
138
|
+
listing={listing}
|
|
139
|
+
onConfirm={confirm}
|
|
140
|
+
status={status}
|
|
141
|
+
error={error}
|
|
142
|
+
taskPda={taskPda}
|
|
143
|
+
onViewTask={onViewTask}
|
|
144
|
+
referrer={ctx.referrer}
|
|
145
|
+
referrerLive={capability.live}
|
|
146
|
+
connected={connected}
|
|
147
|
+
unstyled={unstyled}
|
|
148
|
+
/>
|
|
149
|
+
</>
|
|
150
|
+
);
|
|
151
|
+
}
|
|
@@ -0,0 +1,107 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Ladle stories for {@link HireCheckoutModal} — the money-handling modal across
|
|
3
|
+
* idle / pending / success / error states, with + without a referrer
|
|
4
|
+
* disclosure, plus the not-connected gate.
|
|
5
|
+
*
|
|
6
|
+
* Stories render the modal inline (always `open`) so the dialog surface is
|
|
7
|
+
* always visible for the axe a11y check and visual review.
|
|
8
|
+
*/
|
|
9
|
+
import type { Story } from "@ladle/react";
|
|
10
|
+
import { address } from "@solana/kit";
|
|
11
|
+
import { HireCheckoutModal } from "./HireCheckoutModal.js";
|
|
12
|
+
import {
|
|
13
|
+
FIXTURE_REFERRER,
|
|
14
|
+
makeIndexerListing,
|
|
15
|
+
makeListing,
|
|
16
|
+
FIXTURE_LISTING,
|
|
17
|
+
} from "./__fixtures__/index.js";
|
|
18
|
+
import type { ValidatedReferrerConfig } from "../types.js";
|
|
19
|
+
|
|
20
|
+
export default {
|
|
21
|
+
title: "Hire / HireCheckoutModal",
|
|
22
|
+
};
|
|
23
|
+
|
|
24
|
+
const listing = { address: FIXTURE_LISTING, account: makeListing() };
|
|
25
|
+
const referrer: ValidatedReferrerConfig = {
|
|
26
|
+
wallet: address(FIXTURE_REFERRER),
|
|
27
|
+
feeBps: 250,
|
|
28
|
+
};
|
|
29
|
+
|
|
30
|
+
export const Idle: Story = () => (
|
|
31
|
+
<HireCheckoutModal
|
|
32
|
+
open
|
|
33
|
+
onClose={() => {}}
|
|
34
|
+
listing={listing}
|
|
35
|
+
onConfirm={() => {}}
|
|
36
|
+
moderation={makeIndexerListing()}
|
|
37
|
+
/>
|
|
38
|
+
);
|
|
39
|
+
|
|
40
|
+
export const Pending: Story = () => (
|
|
41
|
+
<HireCheckoutModal
|
|
42
|
+
open
|
|
43
|
+
onClose={() => {}}
|
|
44
|
+
listing={listing}
|
|
45
|
+
onConfirm={() => {}}
|
|
46
|
+
status="pending"
|
|
47
|
+
moderation={makeIndexerListing()}
|
|
48
|
+
/>
|
|
49
|
+
);
|
|
50
|
+
|
|
51
|
+
export const Success: Story = () => (
|
|
52
|
+
<HireCheckoutModal
|
|
53
|
+
open
|
|
54
|
+
onClose={() => {}}
|
|
55
|
+
listing={listing}
|
|
56
|
+
onConfirm={() => {}}
|
|
57
|
+
status="success"
|
|
58
|
+
taskPda={FIXTURE_LISTING}
|
|
59
|
+
onViewTask={() => {}}
|
|
60
|
+
moderation={makeIndexerListing()}
|
|
61
|
+
/>
|
|
62
|
+
);
|
|
63
|
+
|
|
64
|
+
export const ErrorState: Story = () => (
|
|
65
|
+
<HireCheckoutModal
|
|
66
|
+
open
|
|
67
|
+
onClose={() => {}}
|
|
68
|
+
listing={listing}
|
|
69
|
+
onConfirm={() => {}}
|
|
70
|
+
status="error"
|
|
71
|
+
error={new Error("0x1771: listing price changed")}
|
|
72
|
+
moderation={makeIndexerListing()}
|
|
73
|
+
/>
|
|
74
|
+
);
|
|
75
|
+
|
|
76
|
+
export const WithReferrerDisclosure: Story = () => (
|
|
77
|
+
<HireCheckoutModal
|
|
78
|
+
open
|
|
79
|
+
onClose={() => {}}
|
|
80
|
+
listing={listing}
|
|
81
|
+
onConfirm={() => {}}
|
|
82
|
+
moderation={makeIndexerListing()}
|
|
83
|
+
referrer={referrer}
|
|
84
|
+
referrerLive={false}
|
|
85
|
+
/>
|
|
86
|
+
);
|
|
87
|
+
|
|
88
|
+
export const NotConnected: Story = () => (
|
|
89
|
+
<HireCheckoutModal
|
|
90
|
+
open
|
|
91
|
+
onClose={() => {}}
|
|
92
|
+
listing={listing}
|
|
93
|
+
onConfirm={() => {}}
|
|
94
|
+
moderation={makeIndexerListing()}
|
|
95
|
+
connected={false}
|
|
96
|
+
/>
|
|
97
|
+
);
|
|
98
|
+
|
|
99
|
+
export const ModerationPending: Story = () => (
|
|
100
|
+
<HireCheckoutModal
|
|
101
|
+
open
|
|
102
|
+
onClose={() => {}}
|
|
103
|
+
listing={listing}
|
|
104
|
+
onConfirm={() => {}}
|
|
105
|
+
moderation={null}
|
|
106
|
+
/>
|
|
107
|
+
);
|