"use client" import { useState } from "react" import { Card, CardContent, CardHeader, CardTitle } from "@/components/ui/card" import { Button } from "@/components/ui/button" import { ChevronDown, ChevronUp, CheckCircle, AlertCircle, Lock, Zap } from "lucide-react" export interface Block { index: number prev_hash: string timestamp: number encrypted_vote: string transaction_id: string block_hash: string signature: string } export interface BlockchainData { blocks: Block[] verification: { chain_valid: boolean total_blocks: number total_votes: number } } interface BlockchainViewerProps { data: BlockchainData isLoading?: boolean isVerifying?: boolean onVerify?: () => void } export function BlockchainViewer({ data, isLoading = false, isVerifying = false, onVerify, }: BlockchainViewerProps) { const [expandedBlocks, setExpandedBlocks] = useState([]) const toggleBlockExpand = (index: number) => { setExpandedBlocks((prev) => prev.includes(index) ? prev.filter((i) => i !== index) : [...prev, index] ) } const truncateHash = (hash: string, length: number = 16) => { return hash.length > length ? `${hash.slice(0, length)}...` : hash } const formatTimestamp = (timestamp: number) => { return new Date(timestamp * 1000).toLocaleString("fr-FR") } if (isLoading) { return (

Chargement de la blockchain...

) } return (
{/* Verification Summary */} État de la Blockchain
{data.verification.chain_valid ? (
Valide
) : (
Invalide
)}
{/* Total Blocks */}
Nombre de Blocs
{data.verification.total_blocks}
Dont 1 bloc de genèse
{/* Total Votes */}
Votes Enregistrés
{data.verification.total_votes}
Votes chiffrés
{/* Integrity Check */}
Intégrité
{data.verification.chain_valid ? "✓" : "✗"}
Chaîne de hachage valide
{/* Verify Button */} {onVerify && ( )}
{/* Chain Visualization */} Chaîne de Blocs
{data.blocks.map((block, index) => (
{/* Block Header */} {/* Block Details */} {expandedBlocks.includes(index) && (
{/* Index */}
Index
{block.index}
{/* Timestamp */}
Timestamp
{formatTimestamp(block.timestamp)}
{/* Previous Hash */}
Hash Précédent
{block.prev_hash}
{/* Block Hash */}
Hash du Bloc
{block.block_hash}
{/* Encrypted Vote */} {block.encrypted_vote && (
Vote Chiffré
{truncateHash(block.encrypted_vote, 64)}
)} {/* Transaction ID */}
Identifiant de Transaction
{block.transaction_id}
{/* Signature */} {block.signature && (
Signature
{truncateHash(block.signature, 64)}
)} {/* Chain Verification Status */}
Vérification
✓ Hash valide
{block.index > 0 && (
✓ Chaîne liée
)}
)} {/* Chain Link Indicator */} {index < data.blocks.length - 1 && (
)}
))}
{/* Security Info */} Information de Sécurité

Immuabilité: Chaque bloc contient le hash du bloc précédent. Toute modification invalide toute la chaîne.

Transparence: Tous les votes sont enregistrés et vérifiables sans révéler le contenu du vote.

Chiffrement: Les votes sont chiffrés avec ElGamal. Seul le dépouillement utilise les clés privées.

) }