mirror of
https://github.com/NoFxAiOS/nofx.git
synced 2026-07-11 23:07:01 +08:00
fix: dashboard metrics — real drawdown baseline, realized/unrealized split, risk radar fields
- Max drawdown was double-broken: the backend built the equity curve on a hardcoded $10k baseline (understating a small account's drawdown ~20x) and the frontend multiplied the already-percent value by 100 again (0.87% shown as -86.9%). The curve now starts from the trader's real initial balance (10k fallback when unknown) and the UI renders the percent once; the demo engine and type docs are aligned to percent semantics. - Header now separates equity-based 'Total P/L (incl. unrealized)' from 'Realized P/L (closed trades)' so it no longer contradicts profit factor / win rate, and the stats strip shows the fee-drag chain (gross - fees = net) plus a per-trade-labelled sharpe. - Risk radar read a non-existent account field (total_unrealized_profit) so unrealized PnL always showed $0; small PnLs also render with cents now. - Nav 'Connect Hyperliquid' turns into a green connected chip when the server already holds a fully-authorized exchange, instead of nagging forever from a browser without the localStorage flow state.
This commit is contained in:
@@ -239,6 +239,11 @@ export function HyperliquidWalletConnect({
|
||||
const [agentInfo, setAgentInfo] = useState<HyperliquidAgentInfo | null>(null)
|
||||
const [agentInfoLoading, setAgentInfoLoading] = useState(false)
|
||||
const [hasWalletProvider, setHasWalletProvider] = useState(false)
|
||||
// Address of a fully-authorized hyperliquid exchange saved on the SERVER.
|
||||
// The local FlowState lives in this browser's localStorage, so a fresh
|
||||
// browser would otherwise show the red "Connect" CTA even though trading
|
||||
// authorization is complete and the bot is running.
|
||||
const [serverExchangeAddr, setServerExchangeAddr] = useState('')
|
||||
const text = useMemo(
|
||||
() => ({
|
||||
title: language === 'zh' ? 'Hyperliquid Wallet' : 'Hyperliquid Wallet',
|
||||
@@ -300,6 +305,31 @@ export function HyperliquidWalletConnect({
|
||||
saveState(state)
|
||||
}, [state])
|
||||
|
||||
useEffect(() => {
|
||||
if (!isLoggedIn) {
|
||||
setServerExchangeAddr('')
|
||||
return
|
||||
}
|
||||
let cancelled = false
|
||||
api
|
||||
.getExchangeConfigs()
|
||||
.then((configs) => {
|
||||
if (cancelled) return
|
||||
const ready = configs.find(
|
||||
(exchange) =>
|
||||
exchange.exchange_type === 'hyperliquid' &&
|
||||
exchange.enabled &&
|
||||
Boolean(exchange.hyperliquidBuilderApproved) &&
|
||||
(exchange.hyperliquidWalletAddr || '').trim() !== ''
|
||||
)
|
||||
setServerExchangeAddr(ready?.hyperliquidWalletAddr || '')
|
||||
})
|
||||
.catch(() => undefined)
|
||||
return () => {
|
||||
cancelled = true
|
||||
}
|
||||
}, [isLoggedIn])
|
||||
|
||||
useEffect(() => {
|
||||
if (!isLoggedIn || !state.mainWallet) return
|
||||
let cancelled = false
|
||||
@@ -493,6 +523,11 @@ export function HyperliquidWalletConnect({
|
||||
const complete = Boolean(
|
||||
state.mainWallet && state.savedExchangeId && state.builderApproved
|
||||
)
|
||||
// Trigger shows "connected" when either this browser finished the flow or
|
||||
// the server already holds a fully-authorized exchange.
|
||||
const connectedAddr = complete
|
||||
? state.mainWallet
|
||||
: serverExchangeAddr || undefined
|
||||
|
||||
async function connectWallet() {
|
||||
setError('')
|
||||
@@ -898,14 +933,14 @@ export function HyperliquidWalletConnect({
|
||||
type="button"
|
||||
onClick={() => setOpen((value) => !value)}
|
||||
className={`flex items-center gap-2 px-3 py-2 rounded-lg text-sm font-bold transition-all border ${
|
||||
complete
|
||||
connectedAddr
|
||||
? 'bg-nofx-success/10 border-nofx-success/30 text-nofx-success'
|
||||
: 'bg-nofx-gold/10 border-nofx-gold/30 text-nofx-gold hover:bg-nofx-gold/20'
|
||||
}`}
|
||||
>
|
||||
<Wallet className="w-4 h-4" />
|
||||
<span>
|
||||
{complete ? shortAddress(state.mainWallet) : text.connect}
|
||||
{connectedAddr ? shortAddress(connectedAddr) : text.connect}
|
||||
</span>
|
||||
<ChevronDown className="w-4 h-4" />
|
||||
</button>
|
||||
|
||||
Reference in New Issue
Block a user