import { useState } from "react"; import { Plus, RefreshCw } from "lucide-react"; import { Button } from "@/components/ui/Button"; import { Card, CardContent, CardHeader, CardTitle } from "@/components/ui/Card"; import { CryptoAddModal } from "@/components/crypto/CryptoAddModal"; import { CryptoEditModal } from "@/components/crypto/CryptoEditModal"; import { CryptoHoldingsList } from "@/components/crypto/CryptoHoldingsList"; import { useCryptoHoldings, useDeleteCryptoHolding, useRefreshCryptoPrices } from "@/hooks/useCrypto"; import { formatCurrency, getIntlLocale } from "@/lib/format"; import { useTranslation } from "@/lib/i18n"; import type { CryptoHolding } from "@/types"; function formatSyncedAt(iso: string): string { return new Intl.DateTimeFormat(getIntlLocale(), { dateStyle: "medium", timeStyle: "short" }).format(new Date(iso)); } export function CryptoPage() { const { t } = useTranslation(); const { data, isLoading } = useCryptoHoldings(); const refresh = useRefreshCryptoPrices(); const deleteHolding = useDeleteCryptoHolding(); const [addOpen, setAddOpen] = useState(false); const [editingHolding, setEditingHolding] = useState(null); const holdings = data?.holdings ?? []; const totalValue = holdings.reduce((sum, holding) => sum + (holding.value !== null ? Number(holding.value) : 0), 0); function handleDelete(holding: CryptoHolding) { if (window.confirm(t("crypto.confirmDelete", { name: holding.name }))) { deleteHolding.mutate(holding.asset_id); } } return (
{t("nav.crypto")}
{isLoading ? (

{t("common.loading")}

) : ( <>

{t("crypto.totalValueLabel")}

{formatCurrency(totalValue)}

{data?.last_synced_at ? t("crypto.lastSynced", { time: formatSyncedAt(data.last_synced_at) }) : t("crypto.neverSynced")}

{data?.error_key &&

{t(`crypto.syncError.${data.error_key}`)}

} )}
setAddOpen(false)} /> setEditingHolding(null)} holding={editingHolding} />
); }