import { Loader2, History, ArrowUpRight, ArrowDownLeft, ArrowLeftRight, Zap, Coins, Link } from 'lucide-react'; import type { HistoryEntry } from 'coco-cashu-core'; export interface BitcoinTransaction { id: string; txid: string; type: 'sent' | 'received' | 'consolidate'; amount: number; // in satoshis fee?: number; // in satoshis, only for sent transactions address: string; confirmations: number; blockHeight?: number; timestamp: number; status: 'confirmed' | 'unconfirmed' | 'pending'; } interface TransactionHistoryProps { entries: HistoryEntry[]; isLoading: boolean; // Bitcoin transaction props bitcoinTransactions?: BitcoinTransaction[]; isBitcoinLoading?: boolean; showSats?: boolean; } export function TransactionHistory({ entries, isLoading, bitcoinTransactions = [], isBitcoinLoading = false, showSats = true }: TransactionHistoryProps) { // Icon indicating transaction type (Lightning vs Cashu) const getTransactionTypeIcon = (type: string) => { switch (type) { case 'mint': case 'melt': return ; case 'send': case 'receive': return ; default: return ; } }; // Arrow indicating direction (next to amount) const getDirectionIcon = (type: string) => { switch (type) { case 'mint': case 'receive': return ; case 'melt': case 'send': return ; default: return null; } }; const getHistoryLabel = (type: string) => { switch (type) { case 'mint': case 'receive': return 'Received'; case 'melt': case 'send': return 'Sent'; default: return type; } }; // Bitcoin transaction formatting functions const formatBitcoinAmount = (sats: number): string => { if (showSats) { return `${sats.toLocaleString()} sats`; } else { const btc = sats / 100000000; return `₿${btc.toFixed(8)}`; } }; const formatBitcoinAddress = (address: string): string => { return `${address.slice(0, 8)}...${address.slice(-8)}`; }; const getBitcoinStatusColor = (status: string): string => { switch (status) { case 'confirmed': return 'text-green-500'; case 'unconfirmed': return 'text-yellow-500'; case 'pending': return 'text-blue-500'; default: return 'text-muted-foreground'; } }; return (
{isLoading || isBitcoinLoading ? (
Loading transactions...
) : entries.length === 0 && bitcoinTransactions.length === 0 ? (
No transactions yet
) : ( <> {/* Cashu/Lightning Transactions */} {entries.map((entry) => (
{getTransactionTypeIcon(entry.type)}
{getHistoryLabel(entry.type)}
{new URL(entry.mintUrl).hostname}
{new Date(entry.createdAt).toLocaleString()}
{entry.type === 'send' || entry.type === 'melt' ? '-' : '+'} {entry.amount.toLocaleString()} {entry.unit}
{entry.type === 'melt' && (
+ fees
)}
{getDirectionIcon(entry.type)}
))} {/* Bitcoin Transactions */} {bitcoinTransactions.map((tx) => (
{tx.type === 'received' ? 'Received' : tx.type === 'consolidate' ? 'Consolidate' : 'Sent'} {tx.status}
{formatBitcoinAddress(tx.address)}
{new Date(tx.timestamp).toLocaleString()} {tx.confirmations > 0 && ( • {tx.confirmations} confirmation{tx.confirmations !== 1 ? 's' : ''} )}
{tx.blockHeight && (
Block #{tx.blockHeight}
)}
{tx.type === 'sent' ? '-' : tx.type === 'consolidate' ? '' : '+'} {formatBitcoinAmount(tx.amount)}
{tx.fee !== undefined && tx.fee > 0 && (tx.type === 'sent' || tx.type === 'consolidate') && (
Fee: {formatBitcoinAmount(tx.fee)}
)}
{tx.type === 'received' ? ( ) : tx.type === 'consolidate' ? ( ) : ( )}
))} )}
); }