apps: - api: Hono REST server, all §26 endpoints, 14 tests - worker: delivery runner + payment-confirm + access-sync + renewal + webhook-retry jobs wired to real package clients - dashboard: Next.js merchant dashboard, full §16/§27 sections + §28 product builder - checkout: Next.js hosted USDC checkout with real delivery materialization - marketplace: Next.js public marketplace + agent metadata.json route - admin: Next.js risk/ops console wired to @settlekit/risk + database - docs: Next.js docs site (9 static routes) - examples: 5 runnable end-to-end examples fix(x402): support pinned config.nonce so a stateless verifier can confirm the challenge nonce round-trips (default stays random; package tests intact). Full workspace: 590 tests passing (122 files), tsc green for all packages + api/worker/examples, all 5 Next apps typecheck clean, docs next build green.
77 lines
2.1 KiB
TypeScript
77 lines
2.1 KiB
TypeScript
"use client";
|
|
|
|
import { useState, useTransition } from "react";
|
|
import { useRouter } from "next/navigation";
|
|
|
|
interface ActionButtonProps {
|
|
/** Endpoint to POST to. */
|
|
readonly endpoint: string;
|
|
/** Optional JSON body. */
|
|
readonly body?: Record<string, unknown>;
|
|
/** Button label. */
|
|
readonly label: string;
|
|
/** Tone class suffix: "ok" | "warn" | "danger". */
|
|
readonly tone?: "ok" | "warn" | "danger";
|
|
/** Message shown on success (otherwise the server message / generic). */
|
|
readonly successText?: string;
|
|
}
|
|
|
|
/**
|
|
* A self-contained action control: POSTs to a route handler, shows an inline
|
|
* result, and refreshes server-component data so tables reflect the mutation.
|
|
*/
|
|
export function ActionButton({
|
|
endpoint,
|
|
body,
|
|
label,
|
|
tone,
|
|
successText,
|
|
}: ActionButtonProps) {
|
|
const router = useRouter();
|
|
const [isPending, startTransition] = useTransition();
|
|
const [result, setResult] = useState<{ ok: boolean; text: string } | null>(
|
|
null,
|
|
);
|
|
|
|
async function run() {
|
|
setResult(null);
|
|
try {
|
|
const res = await fetch(endpoint, {
|
|
method: "POST",
|
|
headers: { "content-type": "application/json" },
|
|
body: body ? JSON.stringify(body) : undefined,
|
|
});
|
|
const json = (await res.json()) as { ok: boolean; error: string | null };
|
|
if (!res.ok || !json.ok) {
|
|
setResult({ ok: false, text: json.error ?? `Failed (${res.status})` });
|
|
return;
|
|
}
|
|
setResult({ ok: true, text: successText ?? "Done" });
|
|
startTransition(() => router.refresh());
|
|
} catch (e) {
|
|
setResult({
|
|
ok: false,
|
|
text: e instanceof Error ? e.message : "Request failed",
|
|
});
|
|
}
|
|
}
|
|
|
|
return (
|
|
<span style={{ display: "inline-flex", alignItems: "center" }}>
|
|
<button
|
|
type="button"
|
|
className={`btn${tone ? ` ${tone}` : ""}`}
|
|
disabled={isPending}
|
|
onClick={run}
|
|
>
|
|
{isPending ? "Working…" : label}
|
|
</button>
|
|
{result && (
|
|
<span className={`toast ${result.ok ? "ok" : "danger"}`}>
|
|
{result.text}
|
|
</span>
|
|
)}
|
|
</span>
|
|
);
|
|
}
|