import React from 'react'; const API = process.env.REACT_APP_API_URL || 'http://localhost:8000'; const styles = { card: { background: '#1a1a1a', padding: '1.5rem', borderRadius: '12px', border: '1px solid #333', marginBottom: '1.5rem' }, title: { fontSize: '1.1rem', fontWeight: 700, marginBottom: '1rem', color: '#f7931a' }, table: { width: '100%', borderCollapse: 'collapse' }, th: { textAlign: 'left', padding: '0.5rem 0.75rem', borderBottom: '1px solid #333', color: '#888', fontSize: '0.85rem' }, td: { padding: '0.6rem 0.75rem', borderBottom: '1px solid #222', fontSize: '0.95rem' }, deleteBtn: { background: 'none', border: '1px solid #555', color: '#ff6b6b', borderRadius: '6px', padding: '0.25rem 0.6rem', cursor: 'pointer', fontSize: '0.85rem' }, empty: { color: '#555', textAlign: 'center', padding: '1rem' }, }; export default function PurchaseList({ purchases, onDeleted }) { const handleDelete = async (id) => { const token = localStorage.getItem('token'); await fetch(`${API}/purchases/${id}`, { method: 'DELETE', headers: { Authorization: `Bearer ${token}` }, }); onDeleted(); }; return (
Purchases
{purchases.length === 0 ? (
No purchases yet.
) : ( {purchases.map(p => ( ))}
Date Amount (€) Price (€/BTC) BTC
{new Date(p.created_at).toLocaleDateString()} €{p.amount_eur.toLocaleString()} €{p.price_eur.toLocaleString()} {(p.amount_eur / p.price_eur).toFixed(6)}
)}
); }