'use client'
import useSWR from 'swr'
import { Card, CardContent } from '@/components/ui/card'
import { Badge } from '@/components/ui/badge'
import { Table, TableBody, TableCell, TableHead, TableHeader, TableRow } from '@/components/ui/table'
const fetcher = (url: string) => fetch(url).then((r) => r.json())
export default function HistoryPage() {
const { data } = useSWR('/api/history?limit=100', fetcher, { refreshInterval: 5000 })
const rows = data || []
const statusBadge = (status: string) => {
switch (status) {
case 'success':
return {status}
case 'failed':
return {status}
case 'executing':
return {status}
case 'skipped':
default:
return {status}
}
}
return (
Copy Trade History
{rows.length === 0 ? (
No history yet
) : (
Time
Operation
Target
Target TX
Our TX
Amount A
Amount B
Status
Error
{rows.map(
(row: {
id: number
created_at: string
operation: string
target_address: string
target_tx_sig: string
our_tx_sig: string | null
our_amount_a: string | null
our_amount_b: string | null
status: string
error_message: string | null
}) => (
{new Date(row.created_at + 'Z').toLocaleString()}
{row.operation}
{row.target_address.slice(0, 4)}...{row.target_address.slice(-4)}
{row.target_tx_sig.slice(0, 8)}...
{row.our_tx_sig ? (
{row.our_tx_sig.slice(0, 8)}...
) : (
-
)}
{row.our_amount_a || '-'}
{row.our_amount_b || '-'}
{statusBadge(row.status)}
{row.error_message || ''}
),
)}
)}
)
}