- Buy by EUR amount (fractional shares, like Trade Republic): 200 EUR can now reach every large cap; risk engine sizes in whole euros - No-AI screener (pullback in uptrend) feeds training cards and AI candidates - Auto-update on app open via after(); "find ideas now" button (3/day) - New Actions tab: stock list, stock page with chart, news, AI opinion, sandbox buy by amount or shares - "Mon compte" tab: declare deposits, cash, holdings and PEA plan (no broker credentials, no PEA invented by default) - Yahoo data cached and deduplicated, pages stream per section - Tests: fractional sizing, screener, no-AI idea flow Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
102 lines
4.1 KiB
TypeScript
102 lines
4.1 KiB
TypeScript
"use client";
|
|
|
|
import Link from "next/link";
|
|
import { useState, useTransition } from "react";
|
|
import { respondCard } from "@/app/actions";
|
|
import type { ActionPayload } from "@/lib/db/schema";
|
|
import { Badge, inputCls, primaryBtn, secondaryBtn } from "./ui";
|
|
|
|
type Props = {
|
|
id: number;
|
|
kind: string;
|
|
training: boolean;
|
|
status: string;
|
|
symbol?: string | null;
|
|
payload: ActionPayload;
|
|
};
|
|
|
|
/** Lien vers la fiche de l'action, formulaire d'achat pré-rempli avec la recette. */
|
|
function sandboxHref(symbol: string, p: ActionPayload) {
|
|
const q = new URLSearchParams();
|
|
if (p.amountEur) q.set("montant", String(Math.min(p.amountEur, 198)));
|
|
if (p.stopPct) q.set("stop", String(p.stopPct));
|
|
if (p.targetPct) q.set("objectif", String(p.targetPct));
|
|
return `/actions/${encodeURIComponent(symbol)}?${q}`;
|
|
}
|
|
|
|
export function ActionCard({ id, kind, training, status, symbol, payload }: Props) {
|
|
const [pending, start] = useTransition();
|
|
const [open, setOpen] = useState(false);
|
|
const [priceVal, setPrice] = useState(payload.limitPrice?.toString() ?? "");
|
|
const [sharesVal, setShares] = useState(payload.shares?.toString() ?? "");
|
|
const [error, setError] = useState<string | null>(null);
|
|
const needsFill = !training && (kind === "buy" || kind === "sell");
|
|
|
|
const answer = (a: "done" | "skipped") =>
|
|
start(async () => {
|
|
setError(null);
|
|
try {
|
|
await respondCard(id, a, needsFill ? Number(priceVal.replace(",", ".")) : undefined, needsFill ? Number(sharesVal.replace(",", ".")) : undefined);
|
|
} catch (e) {
|
|
setError(e instanceof Error ? e.message : "Erreur");
|
|
}
|
|
});
|
|
|
|
const icon = { buy: "🟢", sell: "🔴", move_stop: "🛡️", to_pea: "🏦" }[kind] ?? "•";
|
|
|
|
return (
|
|
<article className="rounded-2xl border border-line bg-surface-2 p-4">
|
|
<div className="mb-2 flex flex-wrap items-center gap-2">
|
|
{training ? <Badge tone="warn">Entraînement</Badge> : <Badge tone="accent">Argent réel</Badge>}
|
|
{status !== "pending" && <Badge>{status === "done" ? (training ? "Tu l'aurais pris" : "Fait") : "Passé"}</Badge>}
|
|
</div>
|
|
<h3 className="text-base font-semibold leading-snug">
|
|
{icon} {payload.title}
|
|
</h3>
|
|
|
|
<button type="button" onClick={() => setOpen(!open)} className="mt-2 text-sm font-medium text-accent">
|
|
{open ? "Masquer le pourquoi" : "Pourquoi ?"}
|
|
</button>
|
|
{open && <p className="mt-2 whitespace-pre-line text-sm leading-relaxed text-muted">{payload.why}</p>}
|
|
|
|
<ol className="mt-3 flex list-decimal flex-col gap-1.5 pl-5 text-sm leading-relaxed">
|
|
{payload.steps.map((s) => (
|
|
<li key={s}>{s}</li>
|
|
))}
|
|
</ol>
|
|
|
|
{kind === "buy" && symbol && (
|
|
<Link href={sandboxHref(symbol, payload)} className={`${training ? primaryBtn : secondaryBtn} mt-4 w-full`}>
|
|
🧪 Essayer dans mon bac à sable
|
|
</Link>
|
|
)}
|
|
|
|
{status === "pending" && (
|
|
<div className="mt-3 flex flex-col gap-3">
|
|
{needsFill && (
|
|
<div className="grid grid-cols-2 gap-2">
|
|
<label className="text-xs text-muted">
|
|
Prix exécuté ({payload.currency === "USD" ? "$" : "€"})
|
|
<input className={`${inputCls} mt-1`} inputMode="decimal" value={priceVal} onChange={(e) => setPrice(e.target.value)} placeholder="prix réel" />
|
|
</label>
|
|
<label className="text-xs text-muted">
|
|
Nombre d'actions
|
|
<input className={`${inputCls} mt-1`} inputMode="decimal" value={sharesVal} onChange={(e) => setShares(e.target.value)} />
|
|
</label>
|
|
</div>
|
|
)}
|
|
<div className="grid grid-cols-2 gap-2">
|
|
<button className={training ? secondaryBtn : primaryBtn} disabled={pending} onClick={() => answer("done")}>
|
|
{training ? "✅ Je l'aurais pris" : "✅ C'est fait"}
|
|
</button>
|
|
<button className={secondaryBtn} disabled={pending} onClick={() => answer("skipped")}>
|
|
❌ Je passe
|
|
</button>
|
|
</div>
|
|
{error && <p className="text-sm text-danger">{error}</p>}
|
|
</div>
|
|
)}
|
|
</article>
|
|
);
|
|
}
|