import { useEffect, useRef, useState } from "react"; import { X, CheckCircle, XCircle, ChevronDown, Copy, Check, ExternalLink, } from "lucide-react"; import type { ActionReceipt } from "../types"; import { cn, formatRelativeTime, formatDuration } from "../utils"; interface Props { receipt: ActionReceipt | null; onClose: () => void; } const tierBadge: Record = { low: "bg-emerald-500/10 text-emerald-400", medium: "bg-yellow-500/10 text-yellow-400", high: "bg-red-500/10 text-red-400", }; function CopyableHash({ label, hash }: { label: string; hash: string }) { const [copied, setCopied] = useState(false); const ariaLabel = `Copy ${label.toLowerCase().includes("arguments") ? "arguments" : "result"} hash`; function handleCopy() { navigator.clipboard.writeText(hash).then(() => { setCopied(true); setTimeout(() => setCopied(false), 2000); }); } return (
{label}
{hash}
); } function Accordion({ title, children, }: { title: string; children: React.ReactNode; }) { const [open, setOpen] = useState(false); const sanitizedLabel = title.toLowerCase().replace(/\s+/g, "-"); return (
{open &&
{children}
}
); } export default function ReceiptDetail({ receipt, onClose }: Props) { const closeButtonRef = useRef(null); useEffect(() => { function handleKey(e: KeyboardEvent) { if (e.key === "Escape") onClose(); } if (receipt) { document.addEventListener("keydown", handleKey); return () => document.removeEventListener("keydown", handleKey); } }, [receipt, onClose]); useEffect(() => { if (receipt) { closeButtonRef.current?.focus(); } }, [receipt]); if (!receipt) return null; return ( <>

{receipt.toolName}

{receipt.tier} {receipt.success ? ( ) : ( )}
Time
{formatRelativeTime(receipt.timestamp)}
{receipt.timestamp}
Duration
{formatDuration(receipt.durationMs)}
Session
{receipt.sessionKey}
Anomalies
{receipt.anomalies.length > 0 ? (
{receipt.anomalies.map((a, i) => ( {a} ))}
) : (
Clean
)}
{receipt.daCommitment ? (
{receipt.daCommitment}
) : (
Unverified — no DA commitment
)}
TEE attestation verification coming soon
closeButtonRef.current?.focus()} aria-hidden="true" />
); }