import { useEffect, useState } from 'react'; import { invoke } from '@tauri-apps/api/core'; import { ArrowUpRight, ArrowDownLeft, ExternalLink, RefreshCw, } from 'lucide-react'; interface Transaction { txid: string; direction: 'sent' | 'received'; amount: number; fee?: number; timestamp: number; confirmations: number; counterparty?: string; } export default function History() { const [transactions, setTransactions] = useState([]); const [loading, setLoading] = useState(true); const fetchHistory = async () => { setLoading(true); try { const history = await invoke('get_transaction_history', { limit: 50, }); setTransactions(history); } catch (error) { console.error('Failed to fetch history:', error); } finally { setLoading(false); } }; useEffect(() => { fetchHistory(); }, []); const formatDate = (timestamp: number) => { return new Date(timestamp * 1000).toLocaleDateString('en-US', { month: 'short', day: 'numeric', year: 'numeric', hour: '2-digit', minute: '2-digit', }); }; const formatAmount = (amount: number, direction: string) => { const syn = amount / 100_000_000; const sign = direction === 'received' ? '+' : '-'; return `${sign}${syn.toFixed(8)} SYN`; }; return (

Transaction History

{loading && transactions.length === 0 ? (

Loading transactions...

) : transactions.length === 0 ? (

No transactions yet.

Transactions will appear here once you send or receive SYN.

) : (
{transactions.map((tx) => (
{/* Icon */}
{tx.direction === 'received' ? ( ) : ( )}
{/* Details */}
{tx.direction} {tx.confirmations < 10 && ( {tx.confirmations} conf )}

{formatDate(tx.timestamp)}

{/* Amount */}

{formatAmount(tx.amount, tx.direction)}

{tx.fee && (

Fee: {(tx.fee / 100_000_000).toFixed(8)} SYN

)}
{/* External link */}
{/* TXID */}

{tx.txid}

))}
)}
); }