Some checks failed
Tick / tick (push) Failing after 1s
Cobalt for what is safe (PEA) and for actions, ochre for the AI pot, green and red only for gains and losses. Bricolage Grotesque for amounts and titles, Atkinson Hyperlegible Next for text. Home opens on total wealth with a split bar (safe vs working pot); recipe cards with numbered steps; plain sentences instead of emoji and symbols; back links; AI tab with monthly deposits and reset. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
273 lines
12 KiB
TypeScript
273 lines
12 KiB
TypeScript
import { Suspense } from "react";
|
|
import Link from "next/link";
|
|
import { connection } from "next/server";
|
|
import { ActionCard } from "@/components/action-card";
|
|
import { FindIdeas } from "@/components/find-ideas";
|
|
import { SettingsLink } from "@/components/nav";
|
|
import { Badge, Card, CardSkeleton, Delta, Empty, primaryBtn } from "@/components/ui";
|
|
import { aiEnabled, getAiSpend } from "@/lib/ai";
|
|
import { getLatestRendezvous, getPendingAdhocCards } from "@/lib/cards";
|
|
import { eur, pct, signedEur } from "@/lib/format";
|
|
import { getIdeas } from "@/lib/ideas";
|
|
import { getPortfolioState } from "@/lib/portfolio";
|
|
import { getSettings } from "@/lib/settings";
|
|
import { getGateStatus, getLeaderboard, getPea } from "@/lib/stats";
|
|
import { formatDateFr, parisDate } from "@/lib/time";
|
|
|
|
function hhmm(minutes: number) {
|
|
return `${String(Math.floor(minutes / 60)).padStart(2, "0")}h${String(minutes % 60).padStart(2, "0")}`;
|
|
}
|
|
|
|
/** En-tête : la date du jour, connue sans attendre aucune donnée. */
|
|
async function Today() {
|
|
await connection();
|
|
const d = formatDateFr(parisDate());
|
|
return <p className="text-[15px] font-semibold text-muted">{d.charAt(0).toUpperCase() + d.slice(1)}</p>;
|
|
}
|
|
|
|
/**
|
|
* Le patrimoine et sa répartition : à gauche ce qui est à l'abri (PEA), à droite la cagnotte
|
|
* que l'IA fait travailler (compte-titres). C'est toute l'idée de l'app en une barre.
|
|
*/
|
|
async function Wealth() {
|
|
await connection();
|
|
const settings = await getSettings();
|
|
const [real, pea] = await Promise.all([getPortfolioState("real"), getPea(settings)]);
|
|
const safe = pea?.value ?? 0;
|
|
const pot = real.equity;
|
|
const total = safe + pot;
|
|
const safeShare = total > 0 ? (safe / total) * 100 : 50;
|
|
|
|
return (
|
|
<section aria-label="Mon patrimoine" className="pb-2">
|
|
<p className="text-[15px] text-muted">Mon patrimoine</p>
|
|
<p className="amount mt-1 text-[3.4rem] font-bold">{eur(total)}</p>
|
|
|
|
<div className="mt-5 flex h-3.5 gap-1 overflow-hidden rounded-full" aria-hidden>
|
|
{total > 0 ? (
|
|
<>
|
|
<div className="bar-fill shrink-0 rounded-full bg-accent" style={{ width: `${safeShare}%` }} />
|
|
<div className="bar-fill flex-1 rounded-full bg-pot" style={{ animationDelay: "120ms" }} />
|
|
</>
|
|
) : (
|
|
<div className="flex-1 rounded-full bg-surface-2" />
|
|
)}
|
|
</div>
|
|
|
|
<div className="mt-4 grid grid-cols-2 gap-4">
|
|
<Link href="/reel#pea" className="block">
|
|
<p className="flex items-center gap-2 text-[14px] font-semibold">
|
|
<span className="h-2.5 w-2.5 rounded-full bg-accent" aria-hidden />À l'abri
|
|
</p>
|
|
<p className="amount mt-1.5 text-[1.5rem] font-semibold">{eur(safe, 0)}</p>
|
|
<p className="mt-0.5 text-[13px] text-muted">
|
|
{pea && pea.invested > 0 ? (
|
|
<>
|
|
PEA S&P 500, <Delta value={pea.gain}>{signedEur(pea.gain)}</Delta>
|
|
</>
|
|
) : settings.peaPlan ? (
|
|
"PEA, premier achat à venir"
|
|
) : (
|
|
"PEA à configurer"
|
|
)}
|
|
</p>
|
|
</Link>
|
|
<Link href="/reel" className="block">
|
|
<p className="flex items-center gap-2 text-[14px] font-semibold">
|
|
<span className="h-2.5 w-2.5 rounded-full bg-pot" aria-hidden />
|
|
Cagnotte qui travaille
|
|
</p>
|
|
<p className="amount mt-1.5 text-[1.5rem] font-semibold">{eur(pot, 0)}</p>
|
|
<p className="mt-0.5 text-[13px] text-muted">
|
|
Compte-titres, {real.positions.length ? `${real.positions.length} position${real.positions.length > 1 ? "s" : ""}` : `${eur(real.cash, 0)} en attente`}
|
|
</p>
|
|
</Link>
|
|
</div>
|
|
</section>
|
|
);
|
|
}
|
|
|
|
function WealthSkeleton() {
|
|
return (
|
|
<section aria-busy="true" className="pb-2">
|
|
<p className="text-[15px] text-muted">Mon patrimoine</p>
|
|
<div className="skeleton mt-2 h-12 w-56 rounded-xl" />
|
|
<div className="skeleton mt-5 h-3.5 rounded-full" />
|
|
<div className="mt-4 grid grid-cols-2 gap-4">
|
|
<div className="skeleton h-16 rounded-xl" />
|
|
<div className="skeleton h-16 rounded-xl" />
|
|
</div>
|
|
</section>
|
|
);
|
|
}
|
|
|
|
/** Ce que tu as à faire : seulement la base de données, donc rapide. */
|
|
async function Todo() {
|
|
await connection();
|
|
const [settings, rdv, adhoc, ideas] = await Promise.all([getSettings(), getLatestRendezvous(), getPendingAdhocCards(), getIdeas()]);
|
|
const isToday = rdv?.date === parisDate();
|
|
const cards = [...(rdv?.cards ?? []), ...adhoc.filter((c) => c.rendezvousId !== rdv?.id)];
|
|
const pending = cards.filter((c) => c.status === "pending");
|
|
const shown = isToday ? cards.filter((c) => c.status !== "expired") : pending;
|
|
|
|
return (
|
|
<>
|
|
{!settings.trAccountOpenedAt && (
|
|
<Card tone="pot" title="Dis à l'app où tu en es">
|
|
<p className="text-[15px] leading-relaxed">
|
|
Versements, PEA, actions déjà achetées : une minute suffit, et aucun identifiant Trade Republic n'est demandé.
|
|
</p>
|
|
<Link href="/reel" className={`${primaryBtn} mt-4 w-full`}>
|
|
Configurer mon compte
|
|
</Link>
|
|
</Card>
|
|
)}
|
|
|
|
<Card
|
|
title={rdv && !isToday ? `Rendez-vous du ${formatDateFr(rdv.date)}` : "Ton rendez-vous du soir"}
|
|
tone={pending.length ? "accent" : undefined}
|
|
action={pending.length ? <Badge tone="accent">{pending.length} à traiter</Badge> : undefined}
|
|
>
|
|
{rdv?.summary && isToday && <p className="mb-4 whitespace-pre-line text-[15px] leading-relaxed">{rdv.summary}</p>}
|
|
{!shown.length && (
|
|
<Empty>
|
|
Rien à faire pour l'instant. L'IA prépare ton prochain rendez-vous pour {hhmm(settings.rendezvousMinutes)}, en semaine. Tu peux aussi lancer une recherche maintenant.
|
|
</Empty>
|
|
)}
|
|
<div className="flex flex-col gap-3">
|
|
{shown.map((c) => (
|
|
<ActionCard key={c.id} id={c.id} kind={c.kind} training={c.training} status={c.status} symbol={c.symbol} payload={c.payload} />
|
|
))}
|
|
</div>
|
|
<div className="mt-4">
|
|
<FindIdeas />
|
|
</div>
|
|
</Card>
|
|
|
|
{!pending.length && ideas && ideas.items.length > 0 && (
|
|
<Card
|
|
title="Idées à tester"
|
|
action={
|
|
<Link href="/actions" className="text-[14px] font-semibold text-accent">
|
|
Toutes les actions
|
|
</Link>
|
|
}
|
|
>
|
|
<ul className="-my-1 divide-y divide-line">
|
|
{ideas.items.slice(0, 3).map((i) => (
|
|
<li key={i.symbol}>
|
|
<Link href={`/actions/${encodeURIComponent(i.symbol)}?montant=150&stop=7&objectif=12`} className="flex items-center justify-between gap-3 py-3">
|
|
<span className="font-semibold">{i.name}</span>
|
|
<span className="num shrink-0 text-[14px] text-danger">{pct(i.pullbackPct)} cette semaine</span>
|
|
</Link>
|
|
</li>
|
|
))}
|
|
</ul>
|
|
<p className="mt-3 text-[13px] leading-relaxed text-muted">Des actions en hausse de fond qui viennent de reculer. Repérées par une règle simple, sans IA : essaie-les dans ton bac à sable.</p>
|
|
</Card>
|
|
)}
|
|
</>
|
|
);
|
|
}
|
|
|
|
/** Classement et critères du mode réel : dépendent de l'indice S&P 500. */
|
|
async function Progress() {
|
|
await connection();
|
|
const settings = await getSettings();
|
|
const [ai, sandbox, spend] = await Promise.all([getPortfolioState("ai_sim"), getPortfolioState("sandbox"), getAiSpend()]);
|
|
const [gate, board] = await Promise.all([getGateStatus(settings, ai), getLeaderboard(settings, ai, sandbox)]);
|
|
const met = gate.criteria.filter((c) => c.ok).length;
|
|
|
|
return (
|
|
<>
|
|
<Card
|
|
title="Qui gagne ?"
|
|
action={
|
|
<Link href="/ia" className="text-[14px] font-semibold text-accent">
|
|
Voir l'IA
|
|
</Link>
|
|
}
|
|
>
|
|
<ol className="-my-1 divide-y divide-line">
|
|
{board.map((row, i) => (
|
|
<li key={row.label} className="flex items-center gap-3 py-3">
|
|
<span className={`amount w-6 text-[1.4rem] font-bold ${i === 0 ? "text-accent" : "text-muted"}`}>{i + 1}</span>
|
|
<span className="min-w-0 flex-1">
|
|
<span className="block font-semibold">{row.label}</span>
|
|
<span className="block text-[13px] text-muted">{row.detail}</span>
|
|
</span>
|
|
<Delta value={row.pct}>{pct(row.pct)}</Delta>
|
|
</li>
|
|
))}
|
|
</ol>
|
|
<p className="mt-3 text-[13px] leading-relaxed text-muted">
|
|
L'IA et toi partez de 200 € virtuels. Le S&P 500 montre ce que tu aurais gagné sans rien faire.
|
|
</p>
|
|
</Card>
|
|
|
|
<Card title="Passer à l'argent réel" action={gate.realActive ? <Badge tone="gain">Débloqué</Badge> : <Badge tone="pot">{met} critères sur 5</Badge>}>
|
|
{settings.realLockedReason && <p className="mb-3 text-[15px] text-danger">Coupe-circuit : {settings.realLockedReason}</p>}
|
|
<div className="mb-4 grid grid-cols-5 gap-1.5" aria-hidden>
|
|
{gate.criteria.map((c) => (
|
|
<div key={c.label} className={`h-2 rounded-full ${c.ok ? "bg-gain" : "bg-surface-2"}`} />
|
|
))}
|
|
</div>
|
|
<ul className="-my-1 divide-y divide-line text-[15px]">
|
|
{gate.criteria.map((c) => (
|
|
<li key={c.label} className="flex items-center justify-between gap-3 py-2.5">
|
|
<span className="flex items-center gap-2">
|
|
<span className={`h-2 w-2 shrink-0 rounded-full ${c.ok ? "bg-gain" : "bg-line"}`} aria-hidden />
|
|
{c.label}
|
|
</span>
|
|
<span className="num shrink-0 text-right text-[14px] text-muted">
|
|
<span className="block text-ink">{c.value}</span>
|
|
<span className="block text-[12px]">objectif {c.target}</span>
|
|
</span>
|
|
</li>
|
|
))}
|
|
</ul>
|
|
</Card>
|
|
|
|
<Card title="Budget IA du mois">
|
|
{aiEnabled() ? (
|
|
<>
|
|
<p className="amount text-[1.6rem] font-semibold">
|
|
{spend.monthUsd.toFixed(2)} $ <span className="text-[1rem] font-normal text-muted">sur {settings.aiMonthlyBudgetUsd} $</span>
|
|
</p>
|
|
<div className="mt-3 h-2 overflow-hidden rounded-full bg-surface-2">
|
|
<div className="h-full rounded-full bg-accent" style={{ width: `${Math.min(100, (spend.monthUsd / settings.aiMonthlyBudgetUsd) * 100)}%` }} />
|
|
</div>
|
|
<p className="mt-2 text-[13px] text-muted">Ce coût est déduit des résultats de l'IA avant de la comparer au S&P 500.</p>
|
|
</>
|
|
) : (
|
|
<Empty>
|
|
L'IA n'est pas encore branchée : ajoute ta clé Anthropic (ANTHROPIC_API_KEY, voir le README). En attendant, l'app te propose des idées sans IA.
|
|
</Empty>
|
|
)}
|
|
</Card>
|
|
</>
|
|
);
|
|
}
|
|
|
|
export default function Home() {
|
|
return (
|
|
<main className="mx-auto flex w-full max-w-lg flex-col gap-4 px-4 pb-32 pt-[max(env(safe-area-inset-top),1.5rem)]">
|
|
<header className="flex items-center justify-between gap-3">
|
|
<Suspense fallback={<p className="text-[15px] font-semibold text-muted">Aujourd'hui</p>}>
|
|
<Today />
|
|
</Suspense>
|
|
<SettingsLink />
|
|
</header>
|
|
<Suspense fallback={<WealthSkeleton />}>
|
|
<Wealth />
|
|
</Suspense>
|
|
<Suspense fallback={<CardSkeleton title="Ton rendez-vous du soir" height="h-32" />}>
|
|
<Todo />
|
|
</Suspense>
|
|
<Suspense fallback={<CardSkeleton title="Qui gagne ?" height="h-36" />}>
|
|
<Progress />
|
|
</Suspense>
|
|
</main>
|
|
);
|
|
}
|