| // src/components/provenance/VerifyChainButton.tsx | |
| import { useState } from "react"; | |
| import { useProvenance } from "@/hooks/useProvenance"; | |
| import { ShieldCheck, ShieldAlert, Loader2 } from "lucide-react"; | |
| import { toast } from "react-toastify"; | |
| interface VerifyChainButtonProps { | |
| entityId: string; | |
| entityType: "article" | "user" | "chemical" | "project"; | |
| onVerified?: (isValid: boolean) => void; | |
| className?: string; | |
| } | |
| export function VerifyChainButton({ | |
| entityId, | |
| entityType, | |
| onVerified, | |
| className = "", | |
| }: VerifyChainButtonProps) { | |
| const { verifyChain, verifying, chainValid } = useProvenance(entityId, entityType); | |
| const [checked, setChecked] = useState(false); | |
| const handleVerify = async () => { | |
| await verifyChain(); | |
| setChecked(true); | |
| if (chainValid) { | |
| toast.success("✅ Provenance chain is valid – no tampering detected."); | |
| } else { | |
| toast.error("❌ Provenance chain verification failed! Data may have been altered."); | |
| } | |
| onVerified?.(chainValid ?? false); | |
| }; | |
| // Determine button style based on state | |
| let buttonStyle = "bg-gray-100 text-gray-700 hover:bg-gray-200 dark:bg-gray-800 dark:text-gray-300 dark:hover:bg-gray-700"; | |
| if (checked) { | |
| buttonStyle = chainValid | |
| ? "bg-green-100 text-green-700 dark:bg-green-900/30 dark:text-green-400" | |
| : "bg-red-100 text-red-700 dark:bg-red-900/30 dark:text-red-400"; | |
| } | |
| return ( | |
| <button | |
| onClick={handleVerify} | |
| disabled={verifying} | |
| className={`flex items-center gap-2 rounded-lg px-3 py-1.5 text-sm font-medium transition ${buttonStyle} ${className}`} | |
| > | |
| {verifying ? ( | |
| <Loader2 className="h-4 w-4 animate-spin" /> | |
| ) : checked ? ( | |
| chainValid ? <ShieldCheck className="h-4 w-4" /> : <ShieldAlert className="h-4 w-4" /> | |
| ) : ( | |
| <ShieldCheck className="h-4 w-4" /> | |
| )} | |
| {verifying | |
| ? "Verifying..." | |
| : checked | |
| ? chainValid | |
| ? "Chain Valid" | |
| : "Invalid" | |
| : "Verify Chain"} | |
| </button> | |
| ); | |
| } |
Xet Storage Details
- Size:
- 2.04 kB
- Xet hash:
- 98e99ca5ee37fe1109fe07d4e47a92391676e9cd5bc155f3555cb6eb19f1cbd7
·
Xet efficiently stores files, intelligently splitting them into unique chunks and accelerating uploads and downloads. More info.