import { Suspense } from "react"; import { connection } from "next/server"; import { eq } from "drizzle-orm"; import { AccountForm, AddHolding, CashForms, PeaForm, RealPositions } from "@/components/account-forms"; import { SettingsLink } from "@/components/nav"; import { ClosedList } from "@/components/positions"; import { Badge, Card, CardSkeleton, Delta, Page, Stat } from "@/components/ui"; import { getDb, schema } from "@/lib/db"; import { eur, signedEur } from "@/lib/format"; import { getClosedPositions, getPortfolioState } from "@/lib/portfolio"; import { defaultPeaPlan, getSettings } from "@/lib/settings"; import { getPea } from "@/lib/stats"; import { formatDateFr, parisDate } from "@/lib/time"; async function AccountContent() { await connection(); const db = await getDb(); const settings = await getSettings(); const [state, closed, flows] = await Promise.all([ getPortfolioState("real"), getClosedPositions("real"), db.select().from(schema.cashFlows).where(eq(schema.cashFlows.portfolioId, "real")), ]); const deposited = flows.filter((f) => f.kind === "deposit" || f.kind === "withdrawal").reduce((s, f) => s + f.amount, 0); const toPea = Math.max(0, -flows.filter((f) => f.kind === "to_pea").reduce((s, f) => s + f.amount, 0)); const realActive = Boolean(settings.realUnlockedAt) && !settings.realLockedReason; const configured = Boolean(settings.trAccountOpenedAt); const gain = state.equity + toPea - deposited; return ( <>

đź”’ Trade Republic n'offre pas de connexion pour les applications : l'app ne se branche jamais Ă  ton compte et ne te demandera jamais tes identifiants. Tu lui indiques ce que tu as, elle fait les calculs et te dit quoi faire.

configuré : à faire}> {configured &&

Ouvert le {formatDateFr(settings.trAccountOpenedAt!)}.

}
Mode réel actif : Simulation d'abord}>

{eur(state.equity)}

{deposited > 0 && {signedEur(gain)}}
{eur(state.cash, 0)} {eur(deposited, 0)} {eur(toPea, 0)}
{!realActive && (

Tant que l'IA n'a pas prouvé en simulation qu'elle bat le S&P 500, elle ne te propose pas de trade réel : ton argent attend sur le compte. Tu peux quand même enregistrer ici ce que tu fais de ton côté.

)}
}> {closed.length > 0 && ( )} ); } async function PeaSection() { await connection(); const settings = await getSettings(); const plan = settings.peaPlan ?? defaultPeaPlan(parisDate()); const pea = await getPea(settings); return (
{pea && (
{eur(pea.value, 0)} {eur(pea.invested, 0)} {pea.shares.toLocaleString("fr-FR", { maximumFractionDigits: 3 })}
)}
); } export default function AccountPage() { return ( }> }> ); }