mirror of
https://github.com/caty21/forex-dashboard.git
synced 2026-07-27 20:37:45 +00:00
3a39904ce5
Indicateurs : - JPY CPI : null → IMF/IFS DBnomics MoM% (override 0.1% mai 2026) - AUD CPI : mauvais ID FRED (AUSCPIALLMINMEI→AUSCPIALLQINMEI) + override 1.4% T1 2026 - NZD CPI : mauvais ID FRED (NZLCPIALLMINMEI→NZLCPIALLQINMEI) + override 0.9% T1 2026 - Nouveau data/cpi_overrides.json — surcharge manuelle quand FRED/DBnomics en retard - Override date-comparé : source auto reprend quand elle dépasse l'override Taux directeurs : - GBP : BoE API IUDBEDR primary + IR3TIB01GBM156N fallback FRED (IRSTCB01 inexistant) - USD/EUR/CAD/NZD : sources déduplicées (DFEDTARU, ECBDFR, BoC Valet, IRSTCB01) Zone Euro : - EUR CPI fallback : prc_hicp_mmr (404) → prc_hicp_midx + toIndicatorPct - EUR chômage : geo=EA21 (2026) + fallback EA20 Expectations : - data/rate_expectations.json : données correctes 29/05/2026 (Fed 68bps, ECB 49bps, BoE 53bps, BoJ +32bps, etc.) UI : - Tooltip bps : explication "1 bp = 0,01% de taux" - NarrativeButton : affiche le vrai message d'erreur (était "Erreur Bytez") - Groq API key manquante : message descriptif avec chemin Vercel Types : - IndicatorResult type explicite → corrige erreurs tsc pre-existantes (prev/lastUpdated) - toPmiIndicator retourne IndicatorResult Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
85 lines
2.7 KiB
TypeScript
85 lines
2.7 KiB
TypeScript
"use client";
|
|
|
|
import { useState } from "react";
|
|
import { Sparkles, X } from "lucide-react";
|
|
import type { Currency, CurrencyIndicators } from "@/lib/types";
|
|
|
|
interface Props {
|
|
currency: Currency;
|
|
indicators: CurrencyIndicators;
|
|
macroScore: number;
|
|
}
|
|
|
|
export default function NarrativeButton({ currency, indicators, macroScore }: Props) {
|
|
const [open, setOpen] = useState(false);
|
|
const [analysis, setAnalysis] = useState<string | null>(null);
|
|
const [loading, setLoading] = useState(false);
|
|
const [error, setError] = useState<string | null>(null);
|
|
|
|
const run = async () => {
|
|
setLoading(true);
|
|
setError(null);
|
|
try {
|
|
const res = await fetch("/api/narrative", {
|
|
method: "POST",
|
|
headers: { "Content-Type": "application/json" },
|
|
body: JSON.stringify({
|
|
mode: "summary",
|
|
currency,
|
|
data: { indicators, macroScore },
|
|
}),
|
|
});
|
|
const data = await res.json();
|
|
if (data.error) throw new Error(data.error);
|
|
setAnalysis(data.analysis);
|
|
setOpen(true);
|
|
} catch (err) {
|
|
setError(String(err));
|
|
} finally {
|
|
setLoading(false);
|
|
}
|
|
};
|
|
|
|
return (
|
|
<>
|
|
<button
|
|
onClick={run}
|
|
disabled={loading}
|
|
className="flex items-center gap-1 text-[10px] text-indigo-600 hover:text-indigo-800 disabled:opacity-50"
|
|
>
|
|
<Sparkles size={11} />
|
|
{loading ? "Analyse…" : "Résumé IA"}
|
|
</button>
|
|
|
|
{error && (
|
|
<span className="text-[10px] text-red-500 truncate max-w-[160px]" title={error}>
|
|
⚠ {error.replace(/^Error:\s*/i, "").slice(0, 40)}
|
|
</span>
|
|
)}
|
|
|
|
{open && analysis && (
|
|
<div className="fixed inset-0 z-50 flex items-center justify-center bg-black/30 p-4" onClick={() => setOpen(false)}>
|
|
<div
|
|
className="bg-white rounded-xl shadow-xl max-w-sm w-full p-5"
|
|
onClick={(e) => e.stopPropagation()}
|
|
>
|
|
<div className="flex items-center justify-between mb-3">
|
|
<div className="flex items-center gap-2">
|
|
<Sparkles size={15} className="text-indigo-500" />
|
|
<span className="font-medium text-sm">Analyse {currency} — Groq AI</span>
|
|
</div>
|
|
<button onClick={() => setOpen(false)} className="text-gray-400 hover:text-gray-700">
|
|
<X size={15} />
|
|
</button>
|
|
</div>
|
|
<p className="text-sm text-gray-700 leading-relaxed whitespace-pre-wrap">{analysis}</p>
|
|
<div className="mt-3 text-[10px] text-gray-400 text-right">
|
|
Powered by Groq · Llama 3.1 8B
|
|
</div>
|
|
</div>
|
|
</div>
|
|
)}
|
|
</>
|
|
);
|
|
}
|