/* global React, Icon, EquityChart */ const { useState, useEffect, useMemo, useCallback } = React; const DA = window.AURA_DATA; const STATUS_OPTIONS = [ { value: "", label: "All statuses" }, { value: "connected", label: "Connected" }, { value: "disconnected", label: "Disconnected" }, { value: "error", label: "Error" }, ]; const BOT_OPTIONS = [ { value: "", label: "All bots" }, { value: "true", label: "Bot active" }, { value: "false", label: "Bot inactive" }, ]; const selectStyle = { background: "var(--bg-2)", color: "var(--text-1)", border: "1px solid var(--line)", borderRadius: 4, fontSize: 12, padding: "6px 8px", cursor: "pointer", }; const inputStyle = { ...selectStyle, cursor: "text" }; function stateColor(s) { return s === "active" ? "var(--green)" : s === "stale" ? "var(--amber)" : "var(--text-2)"; } function AdminDashboard() { const [users, setUsers] = useState([]); const [stats, setStats] = useState(null); const [filters, setFilters] = useState({ user_id: "", status: "", bot_active: "", start: "", end: "" }); const [loading, setLoading] = useState(true); const [error, setError] = useState(null); useEffect(() => { window.api.adminUsers().then((u) => { if (u) setUsers(u); }).catch(() => {}); }, []); const load = useCallback(() => { setLoading(true); setError(null); const payload = { user_id: filters.user_id || undefined, status: filters.status || undefined, bot_active: filters.bot_active === "" ? undefined : filters.bot_active, start: filters.start || undefined, // make `end` inclusive of the whole selected day end: filters.end ? `${filters.end}T23:59:59` : undefined, }; window.api.adminStats(payload) .then((s) => { setStats(s); setLoading(false); }) .catch((e) => { setError(e.message || "Failed to load admin stats"); setLoading(false); }); }, [filters]); useEffect(() => { load(); }, [load]); const setFilter = (k, v) => setFilters((f) => ({ ...f, [k]: v })); const clearFilters = () => setFilters({ user_id: "", status: "", bot_active: "", start: "", end: "" }); const totals = stats ? stats.totals : null; const accounts = stats ? stats.accounts : []; const equityCurve = useMemo( () => (stats && stats.platform_daily_pnl && stats.platform_daily_pnl.length ? stats.platform_daily_pnl : []), [stats] ); return ( <>

Admin · Platform Overview

All users, accounts and bot KPIs · realized PnL from recorded trades
{/* Filters */}
setFilter("start", e.target.value)} /> setFilter("end", e.target.value)} />
{error && (
{Icon.alert} {error}
)} {/* KPI summary */} {totals && (
Total Balance {Icon.dollar}
${totals.total_balance.toLocaleString("en-US", { minimumFractionDigits: 2, maximumFractionDigits: 2 })}
Equity {DA.fmtUSD(totals.total_equity)}
= 0 ? "pos" : "neg"}`}>
Net P&L (period) {Icon.activity}
= 0 ? "pos" : "neg"}`}>{DA.fmtSigned(totals.net_pnl)}
Today {DA.fmtSigned(totals.today_pnl)}
Win Rate {Icon.target}
{totals.win_rate.toFixed(1)}%
{totals.total_trades} trades
Total Lots {Icon.zap}
{totals.total_lots.toLocaleString("en-US", { minimumFractionDigits: 2, maximumFractionDigits: 2 })}
{totals.total_accounts} accounts · {totals.total_trades} trades
Fleet {Icon.bot}
{totals.active_bots}/ {totals.total_accounts} active
{totals.total_users} users {totals.stale_bots > 0 && {totals.stale_bots} stale} {totals.circuit_broken > 0 && {totals.circuit_broken} CB tripped}
)} {/* Platform equity curve */}
Platform Realized P&L · Cumulative
{equityCurve.length} days
{equityCurve.length > 0 ? ( ) : (
No closed trades in range
)}
{/* Per-account table */}
Accounts · {accounts.length}
{accounts.length === 0 && ( )} {accounts.map((a) => ( ))}
Account Owner Bot Balance Equity Trades Win % PF Streak Net P&L Today Net % Max DD Risk Lots Avg Lot Sessions
{loading ? "Loading…" : "No accounts match these filters"}
{a.nickname || a.login}
#{a.login} · {a.server}
{a.owner_name}
{a.owner_email}
● {a.bot_state}
{a.connection_status} · {a.strategy}
{DA.fmtUSD(a.balance)} {DA.fmtUSD(a.equity)} {a.total_trades}{a.open_positions > 0 && +{a.open_positions}} = 50 ? "pos" : "neg"}`}>{a.win_rate.toFixed(1)}% = 1 ? "pos" : "neg"}`}>{a.profit_factor.toFixed(2)} = 0 ? "pos" : "neg"}`}>{a.streak > 0 ? `+${a.streak}W` : a.streak < 0 ? `${-a.streak}L` : "—"} = 0 ? "pos" : "neg"}`} style={{ fontWeight: 600 }}>{DA.fmtSigned(a.net_pnl)} = 0 ? "pos" : "neg"}`}>{DA.fmtSigned(a.today_pnl)} = 0 ? "pos" : "neg"}`}>{DA.fmtPct(a.net_pnl_pct)} -{a.max_drawdown_pct.toFixed(2)}% {a.circuit_broken ? "● CB tripped" : "● OK"}
streak {a.loss_streak}{a.max_loss_streak != null ? `/${a.max_loss_streak}` : ""}
{a.total_lots.toFixed(2)} {a.avg_lot.toFixed(3)} {a.sessions.length === 0 ? : a.sessions.map((s) => {s})}
); } function FilterField({ label, children }) { return (
{label} {children}
); } window.AdminDashboard = AdminDashboard;