From 2220e260e5a0fba5f9b2f7129dedba7d03913c2e Mon Sep 17 00:00:00 2001 From: Thibaud Moustier Date: Sat, 28 Feb 2026 21:25:54 +0100 Subject: [PATCH] =?utf8?q?Module=20:=20Refractor=20dashboardScreen=20(r?= =?utf8?q?=C3=A9ajout=20box=20alert)?= MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit --- .../mobile/src/screens/DashboardScreen.tsx | 107 ++++++++++++++---- 1 file changed, 82 insertions(+), 25 deletions(-) diff --git a/Wallette/mobile/src/screens/DashboardScreen.tsx b/Wallette/mobile/src/screens/DashboardScreen.tsx index b0aab8d..8834cfd 100644 --- a/Wallette/mobile/src/screens/DashboardScreen.tsx +++ b/Wallette/mobile/src/screens/DashboardScreen.tsx @@ -43,9 +43,11 @@ const CRYPTOS: CryptoSymbol[] = ["BTC", "ETH", "LTC"]; function walletAddressKey(userId: string) { return `walletAddress:${userId}`; } + function normalizeSymbol(s: string) { return s.trim().toUpperCase(); } + function mergePortfolios(base: PortfolioState, patch: PortfolioState): PortfolioState { const map = new Map(); for (const a of base.assets) map.set(normalizeSymbol(a.symbol), a.quantity); @@ -67,7 +69,10 @@ export default function DashboardScreen() { const [userId, setUserId] = useState(null); const [settings, setSettings] = useState(null); - const [portfolio, setPortfolio] = useState({ assets: [], updatedAtMs: Date.now() }); + const [portfolio, setPortfolio] = useState({ + assets: [], + updatedAtMs: Date.now(), + }); const [selectedCrypto, setSelectedCrypto] = useState("BTC"); @@ -95,10 +100,13 @@ export default function DashboardScreen() { const urgentAlert = useMemo(() => { if (liveAlerts.length === 0) return null; + const critical = liveAlerts.find((a) => String(a.alertLevel).toUpperCase() === "CRITICAL"); if (critical) return critical; + const warning = liveAlerts.find((a) => String(a.alertLevel).toUpperCase() === "WARNING"); if (warning) return warning; + return liveAlerts[0]; }, [liveAlerts]); @@ -122,6 +130,7 @@ export default function DashboardScreen() { setWalletAddress(""); } + // Dashboard summary (prix+signal) try { const dash = await getDashboardSummary(); setSummary(dash); @@ -130,6 +139,7 @@ export default function DashboardScreen() { setSoftError(`Signal/Prix indisponibles (API). DEV=${ENV_MODE}. Base REST: ${API_BASE_URL}`); } + // Wallet API (si dispo) -> fusion if (uid) { try { const apiPortfolio = await getPortfolioFromApi(); @@ -141,6 +151,7 @@ export default function DashboardScreen() { } } + // Alertes REST (liste) if (uid) { try { const history = await getAlertHistory(10); @@ -163,13 +174,14 @@ export default function DashboardScreen() { if (alive) setLoading(false); } })(); + return () => { alive = false; }; }, [refreshAll]) ); - // ✅ FIX string|null : on connecte socket seulement si uid existe + // Socket live (✅ connect seulement si userId existe) useEffect(() => { let unsub: null | (() => void) = null; let alive = true; @@ -303,15 +315,19 @@ export default function DashboardScreen() { )} + {/* Compte */} Compte utilisateur - UserId : {userId ?? "—"} + + UserId : {userId ?? "—"} + Socket : {socketConnected ? "ON ✅" : "OFF ⚠️"} {!!socketInfo && {socketInfo}} + {/* Crypto + adresse */} Choisir une cryptomonnaie @@ -350,39 +366,78 @@ export default function DashboardScreen() { {!!walletAddressInfo && {walletAddressInfo}} + {/* Solde */} + + Solde + + {selectedQty.toFixed(6)} {selectedCrypto} + + Portefeuille local (+ sync serveur si dispo) + + + {/* Prix */} Prix {pair} - {(summary?.price ?? 0).toFixed(2)} {currency} + + {(summary?.price ?? 0).toFixed(2)} {currency} + + void refreshAll()}> Actualiser + {/* Signal */} Signal du marché {summary ? ( <> {summary.decision} - {summary.alertLevel} — Confiance {Math.round(summary.confidence * 100)}% - {summary.reason} + + {summary.alertLevel} — Confiance {Math.round(summary.confidence * 100)}% + + + {summary.reason} + ) : ( Aucune donnée pour le moment. )} + - {urgentAlert && ( - - - {String(urgentAlert.alertLevel ?? "INFO")} — {String(urgentAlert.action ?? "HOLD")} - - - {urgentAlert.reason ?? urgentAlert.message ?? "—"} - + {/* Alertes (bloc dédié) */} + navigation.navigate("Alerts" as never)}> + + + Alertes + Ouvrir - )} - + {urgentAlert ? ( + <> + + {String(urgentAlert.alertLevel ?? "INFO")} — {String(urgentAlert.action ?? "HOLD")} + + + + {urgentAlert.reason ?? urgentAlert.message ?? "—"} + + + + {urgentAlert.pair ?? ""}{" "} + {typeof urgentAlert.confidence === "number" + ? `— ${Math.round(urgentAlert.confidence * 100)}%` + : ""} + + + ) : ( + Aucune alerte pour le moment. + )} + + + + {/* Stratégie */} navigation.navigate("Strategy" as never)}> @@ -395,6 +450,7 @@ export default function DashboardScreen() { + {/* Actions */} Actions @@ -405,8 +461,12 @@ export default function DashboardScreen() { Vendre + + Note : Acheter/Vendre = simulation (registre local). Pas de trading réel. + + {/* Modal BUY/SELL */} setTradeOpen(false)}> @@ -415,7 +475,9 @@ export default function DashboardScreen() { {tradeSide === "BUY" ? "Acheter" : "Vendre"} {selectedCrypto} - Prix : {(summary?.price ?? 0).toFixed(2)} {currency} + + Prix : {(summary?.price ?? 0).toFixed(2)} {currency} + Quantité