'use client' import { useState, useEffect } from 'react' import Link from 'next/link' import { usePathname } from 'next/navigation' import { useLocale } from 'next-intl' import { useAccount, useSignMessage } from 'wagmi' import type { BotTrade, TrumpPost } from '@/types' import { getTrades, getPosts } from '@/lib/api' import { useDashboardStore } from '@/store/dashboard' import { getCachedViewEnvelope } from '@/lib/signedRequest' import TradeTable from '@/components/trades/TradeTable' import OpenPositions from '@/components/positions/OpenPositions' import PageHint from '@/components/ui/PageHint' export default function TradesPageClient() { const intlLocale = useLocale() const isZh = false // i18n shelved — Chinese branches kept as dead code for future revival; see messages/zh.json const { address, isConnected } = useAccount() const { isSubscribed, hlApiKeySet } = useDashboardStore() const pathname = usePathname() const locale = pathname.split('/')[1] || 'en' const [mounted, setMounted] = useState(false) const [trades, setTrades] = useState([]) const [posts, setPosts] = useState([]) const [loading, setLoading] = useState(true) const [loadErr, setLoadErr] = useState('') useEffect(() => { setMounted(true) }, []) useEffect(() => { let cancelled = false if (!address || !isConnected) { setTrades([]) setPosts([]) setLoading(false) setLoadErr('') return } setLoading(true) ;(async () => { let failed = false try { const env = getCachedViewEnvelope('view_trades', address) ?? getCachedViewEnvelope('view_user', address) const [t, p] = await Promise.all([ env ? getTrades(address, env, 100, 1).catch(e => { failed = true setLoadErr(e instanceof Error ? e.message : (isZh ? '交易加载失败' : 'Failed to load trades')) return [] as BotTrade[] }) : Promise.resolve([] as BotTrade[]), getPosts(500, 1).catch(() => [] as TrumpPost[]), ]) if (!cancelled) { setTrades(t) setPosts(p) if (!env) { failed = true setLoadErr('Load your settings once on the Settings page to unlock private trade history.') } else if (!failed) { setLoadErr('') } } } finally { if (!cancelled) setLoading(false) } })() return () => { cancelled = true } // isZh intentionally excluded: compile-time constant (always false). // eslint-disable-next-line react-hooks/exhaustive-deps }, [address, isConnected]) const needsSetup = mounted && isConnected && (!isSubscribed || !hlApiKeySet) return (

{isZh ? '交易执行' : 'Trades'}

What the bot actually did with your money — currently-open positions on top, closed-trade history with realized P&L below.
{needsSetup && (
{isZh ? '机器人尚未配置完成' : 'Bot not configured'}
{isZh ? '在机器人开始交易前,请先去设置页订阅并绑定 Hyperliquid API。' : 'Subscribe and link your Hyperliquid API wallet on the Settings page before the bot can trade.'}
{isZh ? '前往设置 →' : 'Go to Settings →'}
)} {!loading && loadErr && (
⚠️ {isZh ? `无法加载交易历史:${loadErr}` : `Couldn’t load trade history — ${loadErr}`}
)}
) }