// NetWorthTile — Dashboard KPI-row tile showing the Bilan's latest net worth. // // Issue #279. Deliberately NOT `HubNetBalanceTile` (that one is the reports // hub's transaction-P&L net balance — a different metric). This tile mirrors // `BalanceOverviewCard`'s "latest total" figure and reuses its exact i18n // copy (`balance.overview.latestTotal` / `asOf`) so the label is unambiguous // next to the transactional KPI cards and the "import sources" account // filter — same words as the Bilan page itself, never "balance"/"solde". // // Renders nothing when `data.visible` is false (no balance account yet, or // accounts but no snapshot yet) — never a misleading "$0" tile. import { Link } from "react-router-dom"; import { useTranslation } from "react-i18next"; import { Wallet } from "lucide-react"; import type { NetWorthTileData } from "../../services/dashboardService"; export interface NetWorthTileProps { data: NetWorthTileData; } function formatCurrency(amount: number, language: string): string { return new Intl.NumberFormat(language === "fr" ? "fr-CA" : "en-CA", { style: "currency", currency: "CAD", maximumFractionDigits: 0, }).format(amount); } export default function NetWorthTile({ data }: NetWorthTileProps) { const { t, i18n } = useTranslation(); if (!data.visible || data.total === null || data.asOfDate === null) { return null; } const dateLocale = i18n.language === "fr" ? "fr-CA" : "en-CA"; const formattedDate = new Date(data.asOfDate).toLocaleDateString(dateLocale, { year: "numeric", month: "long", day: "numeric", }); return (
{formatCurrency(data.total, i18n.language)}
{t("balance.overview.asOf", { date: formattedDate })}
); }