import React, { useState, useEffect } from 'react'; import { Card, CardContent, CardDescription, CardHeader, CardTitle } from "@/components/ui/card"; import { Badge } from "@/components/ui/badge"; import { Progress } from "@/components/ui/progress"; import { Shield, Link, Activity, FileText } from 'lucide-react'; interface BlockchainMonitorProps { loading: boolean; } const BlockchainMonitor: React.FC = ({ loading }) => { const [transactions, setTransactions] = useState<{ hash: string; type: string; status: string; timestamp: string; gas: number; }[]>([ { hash: '0x7f9e4c8d...', type: 'Machine NFT Minting', status: 'Confirmed', timestamp: '10:30:15', gas: 98500 }, { hash: '0x3e6b9d2f...', type: 'Batch Transfer', status: 'Pending', timestamp: '10:29:42', gas: 124600 }, { hash: '0xc12a45e8...', type: 'Quality Verification', status: 'Confirmed', timestamp: '10:28:07', gas: 75300 }, { hash: '0x9f81d73b...', type: 'Operator Authorization', status: 'Confirmed', timestamp: '10:25:55', gas: 85700 } ]); const [contracts, setContracts] = useState<{ name: string; address: string; type: string; events: number; lastBlock: number; }[]>([ { name: 'MachineIdentity', address: '0x7F9abc...', type: 'ERC-721', events: 346, lastBlock: 18451267 }, { name: 'ProductionBatch', address: '0x3E8def...', type: 'ERC-721', events: 892, lastBlock: 18451265 }, { name: 'OperatorRegistry', address: '0x2C5fgh...', type: 'Custom', events: 127, lastBlock: 18451260 }, { name: 'QualityControl', address: '0xA71ijk...', type: 'Custom', events: 518, lastBlock: 18451254 } ]); // Simulate new transactions coming in useEffect(() => { if (loading) return; const newTxTypes = [ 'Machine NFT Minting', 'Batch Transfer', 'Quality Verification', 'Operator Authorization', 'Maintenance Record', 'Parameter Update' ]; const interval = setInterval(() => { // 30% chance of adding a new transaction if (Math.random() < 0.3) { const randomType = newTxTypes[Math.floor(Math.random() * newTxTypes.length)]; const randomHash = '0x' + Math.random().toString(16).substr(2, 8) + '...'; const isPending = Math.random() < 0.2; setTransactions(prev => [ { hash: randomHash, type: randomType, status: isPending ? 'Pending' : 'Confirmed', timestamp: new Date().toLocaleTimeString([], { hour: '2-digit', minute: '2-digit', second: '2-digit' }), gas: Math.floor(Math.random() * 100000) + 50000 }, ...prev.slice(0, 3) // Keep only the 4 most recent transactions ]); // Update contract event count if (!isPending) { setContracts(prev => prev.map((contract, idx) => { if (idx === Math.floor(Math.random() * contracts.length)) { return { ...contract, events: contract.events + 1, lastBlock: contract.lastBlock + (Math.random() < 0.5 ? 1 : 0) }; } return contract; })); } } }, 3000); return () => clearInterval(interval); }, [loading, contracts]); return (
Smart Contracts Active blockchain contracts for identity & traceability {loading ? (
{Array(4).fill(0).map((_, idx) => (
))}
) : (
{contracts.map((contract) => (
{contract.name}
{contract.type}
Address: {contract.address}
{contract.events} events
Block #{contract.lastBlock}
))}
)}
Blockchain Transactions Recent identity & traceability transactions {loading ? (
{Array(4).fill(0).map((_, idx) => (
))}
) : (
{transactions.map((tx) => (
{tx.type}
{tx.status}
{tx.hash} {tx.timestamp}
Gas used: {tx.gas.toLocaleString()} wei
))}
)}
Blockchain Gateway Services Integration services status and statistics {loading ? (
{Array(3).fill(0).map((_, idx) => (
))}
) : ( <>
Node.js Blockchain Gateway Active
Memory Usage
384 MB / 1024 MB 38%
CPU Usage
2 cores 27%
Event Queue
12 events 6%
HSM Integration
Secure
Private key operations
Solidity Contracts
4 Active
Deployed & verified
Event Handlers
8 Listeners
Processing blockchain events
Smart Rules
12 Active
Quality & maintenance rules
)}
); }; export default BlockchainMonitor;