This commit is contained in:
k
2026-04-21 19:32:53 +08:00
parent 1747fc489f
commit 83e5892ddf
25 changed files with 2582 additions and 916 deletions
+280 -29
View File
@@ -1,64 +1,315 @@
'use client'
import { useState, useEffect } from 'react'
import type { TrumpPost, BotTrade, BotPerformance, Candle } from '@/types'
import { useAccount } from 'wagmi'
import type { TrumpPost, BotPerformance, Candle } from '@/types'
import { useDashboardStore } from '@/store/dashboard'
import { usePriceSocket } from '@/lib/useRealtimeData'
import { getPrices } from '@/lib/api'
import KpiRow from '@/components/dashboard/KpiRow'
import { getPrices, getUserPublic } from '@/lib/api'
import ChartPanel from '@/components/dashboard/ChartPanel'
import BotPanel from '@/components/dashboard/BotPanel'
import TradesTable from '@/components/trades/TradesTable'
import PostRow, { SignalPill, SourceIcon, fmtPct, timeAgo } from '@/components/dashboard/PostCards'
interface Props {
initialPosts: TrumpPost[]
initialPerformance?: BotPerformance
initialTrades: BotTrade[]
}
export default function DashboardClient({ initialPosts, initialPerformance, initialTrades }: Props) {
const { asset, timeframe, setLivePrice } = useDashboardStore()
// ── Inline post detail panel shown in the right rail ──────────────────────────
function PostDetail({ post, onClose }: { post: TrumpPost; onClose: () => void }) {
const impact = post.price_impact
function fmtImpactPct(v: number | null | undefined) {
if (v == null || isNaN(v)) return '—'
const s = Math.abs(v).toFixed(2) + '%'
return v >= 0 ? '+' + s : '-' + s
}
return (
<div className="card" style={{ padding: 20 }}>
{/* header */}
<div className="row between" style={{ marginBottom: 14 }}>
<span className="tiny">Signal detail</span>
<button
className="icon-btn"
onClick={onClose}
style={{ width: 26, height: 26, borderRadius: '50%' }}
title="Close"
>
<svg width="10" height="10" viewBox="0 0 24 24">
<path d="M18 6L6 18M6 6l12 12" stroke="currentColor" strokeWidth="2.5" strokeLinecap="round"/>
</svg>
</button>
</div>
{/* source + time */}
<div className="row gap-s" style={{ marginBottom: 12 }}>
<SourceIcon source={post.source} />
<div>
<div style={{ fontSize: 13, fontWeight: 500, fontFamily: 'var(--mono)' }}>@realDonaldTrump</div>
<div style={{ fontSize: 11, color: 'var(--ink-3)' }}>{timeAgo(post.published_at)} ago · {new Date(post.published_at).toLocaleString()}</div>
</div>
</div>
{/* post text */}
<p style={{ fontSize: 14, lineHeight: 1.55, margin: '0 0 16px', color: 'var(--ink)' }}>{post.text}</p>
{/* signal + sentiment */}
<div className="row gap-s" style={{ marginBottom: 16 }}>
<SignalPill signal={post.signal} />
<span className={`chip ${post.sentiment === 'bullish' ? 'up' : post.sentiment === 'bearish' ? 'down' : 'neutral'}`}>
{post.sentiment}
</span>
</div>
{/* AI confidence */}
<div className="row between" style={{ fontSize: 12, color: 'var(--ink-3)', marginBottom: 6 }}>
<span>AI confidence</span>
<span className="mono" style={{ color: 'var(--ink)', fontWeight: 600 }}>{post.ai_confidence}%</span>
</div>
<div className="confidence-bar" style={{ marginBottom: 16 }}>
<div style={{ width: post.ai_confidence + '%' }} />
</div>
{/* AI reasoning */}
{post.ai_reasoning && (
<>
<div className="tiny" style={{ marginBottom: 8 }}>AI reasoning</div>
<div style={{
padding: 12,
background: 'var(--bg-sunk)',
borderRadius: 'var(--r-sm)',
border: '1px solid var(--line)',
fontSize: 12,
lineHeight: 1.6,
color: 'var(--ink-2)',
marginBottom: 16,
maxHeight: 120,
overflowY: 'auto',
}}>
{post.ai_reasoning}
</div>
</>
)}
{/* Price impact grid */}
{impact && (
<>
<div className="tiny" style={{ marginBottom: 10 }}>Price impact · {impact.asset}</div>
<div style={{ display: 'grid', gridTemplateColumns: '1fr 1fr 1fr', gap: 8 }}>
{([['m5', '5m'], ['m15', '15m'], ['m1h', '1h']] as const).map(([key, label]) => {
const v = impact[key]
const correct = impact[`correct_${key}` as 'correct_m5' | 'correct_m15' | 'correct_m1h']
return (
<div key={key} style={{
padding: 10,
background: 'var(--bg-sunk)',
borderRadius: 'var(--r-sm)',
border: '1px solid var(--line)',
textAlign: 'center',
}}>
<div style={{ fontSize: 10, color: 'var(--ink-3)', marginBottom: 4 }}>{label}</div>
<div className={`delta ${(v ?? 0) >= 0 ? 'up' : 'down'}`} style={{ fontSize: 14, fontWeight: 600 }}>
{fmtImpactPct(v)}
</div>
{correct != null && (
<div style={{ fontSize: 10, marginTop: 4, color: correct ? 'var(--up)' : 'var(--down)' }}>
{correct ? '✓' : '✗'}
</div>
)}
</div>
)
})}
</div>
</>
)}
</div>
)
}
// ── Empty state for when nothing is selected ──────────────────────────────────
function SelectHint() {
return (
<div className="card" style={{ padding: 24, textAlign: 'center', color: 'var(--ink-3)' }}>
<svg width="32" height="32" viewBox="0 0 24 24" fill="none" style={{ margin: '0 auto 12px', display: 'block', opacity: 0.4 }}>
<circle cx="12" cy="12" r="3" stroke="currentColor" strokeWidth="2"/>
<path d="M12 2v3M12 19v3M2 12h3M19 12h3" stroke="currentColor" strokeWidth="2" strokeLinecap="round"/>
</svg>
<p style={{ fontSize: 13, margin: 0, lineHeight: 1.5 }}>
Click any marker on the chart<br/>or a post below to see details
</p>
</div>
)
}
// ── Main dashboard ─────────────────────────────────────────────────────────────
export default function DashboardClient({ initialPosts, initialPerformance }: Props) {
const { asset, setAsset, timeframe, setTimeframe: _setTimeframe, setLivePrice, setSubscribed, setHlApiKeySet, isSubscribed } = useDashboardStore()
function setTimeframe(tf: string) { _setTimeframe(tf as '5m' | '15m' | '1H' | '4H' | '1D' | '1W') }
const { address, isConnected } = useAccount()
const [posts, setPosts] = useState<TrumpPost[]>(initialPosts)
const [candles, setCandles] = useState<Candle[]>([])
const [candlesLoading, setCandlesLoading] = useState(false)
const [selectedPostId, setSelectedPostId] = useState<number | null>(null)
useEffect(() => {
if (!isConnected || !address) {
setSubscribed(false)
setHlApiKeySet(false)
return
}
getUserPublic(address.toLowerCase())
.then((user) => {
setSubscribed(user.active)
setHlApiKeySet(user.hl_api_key_set)
})
.catch(() => {})
}, [address, isConnected, setSubscribed, setHlApiKeySet])
usePriceSocket({
onPrice: (a, price) => setLivePrice(a, price),
onNewPost: (post) => setPosts((prev) => [post as TrumpPost, ...prev].slice(0, 50)),
onNewPost: (post) => setPosts((prev) => [post as TrumpPost, ...prev].slice(0, 500)),
})
useEffect(() => {
setCandles([])
setCandlesLoading(true)
getPrices(asset, timeframe)
.then(setCandles)
.catch(() => {})
.finally(() => setCandlesLoading(false))
}, [asset, timeframe])
return (
<div className="pt-14">
<div className="max-w-[1400px] mx-auto px-6 py-6 flex flex-col gap-4">
{/* KPI 行 */}
<KpiRow performance={initialPerformance} postsCount={posts.length} />
const selectedPost = posts.find(p => p.id === selectedPostId) ?? null
const recentPosts = posts.slice(0, 8)
{/* 主内容区:图表 + Bot 面板 */}
<div className="flex gap-4 items-start w-full">
<div className="flex-1 min-w-0 relative">
<ChartPanel posts={posts} candles={candles} />
{candlesLoading && (
<div className="absolute inset-0 flex items-center justify-center bg-black/40 rounded-[10px] pointer-events-none">
<span className="text-[#555555] text-sm">Loading...</span>
</div>
)}
const lastCandle = candles[candles.length - 1]
const firstCandle = candles[0]
const priceChange = lastCandle && firstCandle
? ((lastCandle.close - firstCandle.open) / firstCandle.open) * 100
: 0
const totalPosts = posts.length
const actionablePosts = posts.filter(p => p.signal === 'buy' || p.signal === 'short').length
const winRate = initialPerformance?.win_rate ?? 0
const netPnl = initialPerformance?.net_pnl_usd ?? 0
return (
<div className="page wide">
<div className="page-head">
<div>
<h1 className="page-title">Signal monitor</h1>
<p className="page-sub">
{actionablePosts} actionable signals · Auto-trader {isSubscribed ? 'running' : 'standby'} · Model v4-selective
</p>
</div>
<div className="row gap-s">
<span className="chip"><span className="live-dot" />Live feed</span>
<span className="chip">{totalPosts} posts tracked</span>
</div>
</div>
{/* KPI Row */}
<div className="kpi-row">
<div className="kpi">
<div className="label"><span className="asset-dot btc" style={{ width: 10, height: 10 }} /> BTC</div>
<div className="value">{lastCandle ? '$' + Math.round(lastCandle.close).toLocaleString() : '—'}</div>
<div className="foot">
<span className={`delta ${priceChange >= 0 ? 'up' : 'down'}`}>{fmtPct(priceChange)}</span>
<span>{timeframe}</span>
</div>
<div className="w-[280px] shrink-0">
<BotPanel performance={initialPerformance} />
</div>
<div className="kpi">
<div className="label">Signals today</div>
<div className="value">{actionablePosts}</div>
<div className="foot"><span>Actionable posts</span></div>
</div>
<div className="kpi accent">
<div className="label">30d Net P&amp;L</div>
<div className="value">{netPnl >= 0 ? '+$' : '-$'}{Math.abs(netPnl).toLocaleString(undefined, { maximumFractionDigits: 0 })}</div>
<div className="foot"><span>Bot performance</span></div>
</div>
<div className="kpi">
<div className="label">Win rate</div>
<div className="value">{initialPerformance ? (winRate * 100).toFixed(1) + '%' : '—'}</div>
<div className="foot"><span>{initialPerformance?.total_trades ?? 0} trades</span></div>
</div>
</div>
<div className="dash-grid">
{/* Left: Chart + signal stream */}
<div className="stack gap-l">
<div className="card" style={{ padding: 24 }}>
<div className="row between" style={{ marginBottom: 18, alignItems: 'flex-start' }}>
<div>
<div className="tiny">Price · {asset}</div>
<div className="row gap-m" style={{ marginTop: 6 }}>
<div className="hero-value mono" style={{ fontSize: 32 }}>
{lastCandle ? '$' + Math.round(lastCandle.close).toLocaleString() : '—'}
</div>
<span className={`chip ${priceChange >= 0 ? 'up' : 'down'}`}>{fmtPct(priceChange)} · {timeframe}</span>
</div>
</div>
<div className="stack gap-s" style={{ alignItems: 'flex-end' }}>
<div className="asset-switch">
<button className={asset === 'BTC' ? 'on' : ''} onClick={() => setAsset('BTC')}>
<span className="asset-dot btc" /> BTC
</button>
<button className={asset === 'ETH' ? 'on' : ''} onClick={() => setAsset('ETH')}>
<span className="asset-dot eth" /> ETH
</button>
</div>
<div className="tf-bar">
{(['5m', '15m', '1H', '4H', '1D'] as const).map(t => (
<button key={t} className={timeframe === t ? 'on' : ''} onClick={() => setTimeframe(t)}>{t}</button>
))}
</div>
</div>
</div>
<div className="chart-wrap">
<ChartPanel
posts={posts}
candles={candles}
externalSelectedId={selectedPostId}
onSelectPost={setSelectedPostId}
/>
</div>
<div className="chart-footnote">
<div className="item"><span className="legend-dot" style={{ background: '#26a69a' }} /> Buy signal</div>
<div className="item"><span className="legend-dot" style={{ background: '#ef5350' }} /> Short signal</div>
<div className="item"><span className="legend-dot" style={{ background: '#aaaaaa' }} /> Hold / filtered</div>
<div style={{ marginLeft: 'auto' }}>Click marker to see details </div>
</div>
</div>
{/* Recent signals list */}
<div>
<div className="section-title">
<h2>Recent signals</h2>
<span className="hint">Showing {recentPosts.length} of {totalPosts}</span>
</div>
<div className="post-stream">
{recentPosts.map(p => (
<PostRow
key={p.id}
post={p}
selected={selectedPostId === p.id}
onClick={() => setSelectedPostId(selectedPostId === p.id ? null : p.id)}
/>
))}
</div>
</div>
</div>
{/* 交易记录 */}
<TradesTable trades={initialTrades} />
{/* Right rail: bot stats + post detail */}
<div className="rail">
<BotPanel performance={initialPerformance} />
{/* Post detail — shown when something is selected, else hint */}
{selectedPost
? <PostDetail post={selectedPost} onClose={() => setSelectedPostId(null)} />
: <SelectHint />
}
</div>
</div>
</div>
)
+94 -7
View File
@@ -1,14 +1,101 @@
import { getTranslations } from 'next-intl/server'
'use client'
export default async function AnalyticsPage() {
const t = await getTranslations('analytics')
import { useState, useEffect } from 'react'
import { getPerformance, getTrades } from '@/lib/api'
import type { BotPerformance, BotTrade } from '@/types'
function fmtMoney(n: number) {
if (n == null || isNaN(n)) return '—'
const abs = Math.abs(n)
const s = abs.toLocaleString('en-US', { maximumFractionDigits: 0 })
if (n < 0) return '-$' + s
if (n > 0) return '+$' + s
return '$' + s
}
function fmtHold(s: number) {
if (s < 60) return s + 's'
const m = Math.floor(s / 60)
if (m < 60) return m + 'm'
return Math.floor(m / 60) + 'h ' + (m % 60) + 'm'
}
export default function AnalyticsPage() {
const [perf, setPerf] = useState<BotPerformance | null>(null)
const [trades, setTrades] = useState<BotTrade[]>([])
const [period, setPeriod] = useState('30d')
useEffect(() => {
Promise.all([
getPerformance().catch(() => null),
getTrades(200, 1).catch(() => []),
]).then(([p, t]) => {
setPerf(p)
setTrades(t)
})
}, [])
const winRate = perf ? perf.win_rate * 100 : 0
const bestTrade = trades.length ? Math.max(...trades.map(t => t.pnl_usd)) : 0
const worstTrade = trades.length ? Math.min(...trades.map(t => t.pnl_usd)) : 0
const avgTrade = trades.length ? trades.reduce((s, t) => s + t.pnl_usd, 0) / trades.length : 0
const metrics = [
{ k: 'Max drawdown', v: perf ? perf.max_drawdown_pct.toFixed(1) + '%' : '—', sub: 'Worst peak-to-trough', down: true },
{ k: 'Total trades', v: String(perf?.total_trades ?? '—'), sub: 'Bot executions' },
{ k: 'Avg hold time', v: perf ? fmtHold(perf.avg_hold_seconds) : '—', sub: 'Per trade' },
{ k: 'Avg trade P&L', v: fmtMoney(avgTrade), sub: 'Mean per trade', up: avgTrade > 0 },
{ k: 'Best trade', v: fmtMoney(bestTrade), sub: 'Largest single win', up: true },
{ k: 'Worst trade', v: fmtMoney(worstTrade), sub: 'Largest single loss', down: true },
]
return (
<div className="max-w-[1400px] mx-auto px-6 py-6">
<div className="bg-[#0a0a0a] border border-[#141414] rounded-[10px] p-10 text-center">
<h1 className="text-[22px] font-medium text-white mb-3">{t('title')}</h1>
<p className="text-[14px] text-[#555555]">{t('comingSoon')}</p>
<div className="page">
<div className="page-head">
<div>
<h1 className="page-title">Analytics</h1>
<p className="page-sub">Deep dive into {period} of signals and trades.</p>
</div>
<div className="nav-tabs">
{['7d', '30d', '90d', 'All'].map(p => (
<button key={p} className={`nav-tab ${period === p ? 'active' : ''}`} onClick={() => setPeriod(p)}>{p}</button>
))}
</div>
</div>
{/* Summary card */}
<div className="card" style={{ padding: 28, marginBottom: 20 }}>
<div className="row between" style={{ alignItems: 'flex-start', marginBottom: 20 }}>
<div>
<div className="tiny">Performance · {period}</div>
<div className="hero-value mono" style={{ marginTop: 6, fontSize: 40 }}>
{perf ? fmtMoney(perf.net_pnl_usd) : '—'}
</div>
<div className="row gap-s" style={{ marginTop: 8 }}>
<span className={`chip ${(perf?.win_rate ?? 0) >= 0.5 ? 'up' : 'down'}`}>{winRate.toFixed(1)}% win rate</span>
<span className="chip">{perf?.total_trades ?? 0} trades</span>
</div>
</div>
</div>
</div>
{/* Metric grid */}
<div className="metric-grid" style={{ marginBottom: 20 }}>
{metrics.map(m => (
<div key={m.k} className="card" style={{ padding: 20 }}>
<div className="tiny" style={{ marginBottom: 8 }}>{m.k}</div>
<div className={`mono ${m.up ? 'delta up' : m.down ? 'delta down' : ''}`} style={{ fontSize: 24, fontWeight: 500, letterSpacing: '-0.01em' }}>{m.v}</div>
<div style={{ fontSize: 12, color: 'var(--ink-3)', marginTop: 4 }}>{m.sub}</div>
</div>
))}
</div>
{/* No data message */}
{!perf && !trades.length && (
<div className="card" style={{ padding: 60, textAlign: 'center', color: 'var(--ink-3)' }}>
<p style={{ fontSize: 14 }}>No trade data yet. The bot will populate analytics once it starts executing.</p>
</div>
)}
</div>
)
}
+895 -14
View File
@@ -1,22 +1,903 @@
@tailwind base;
@tailwind components;
@tailwind utilities;
/* ============================================================
Trump Alpha — Design System
============================================================ */
* {
box-sizing: border-box;
:root {
/* Surfaces — warm off-whites */
--bg: oklch(99% 0.004 85);
--bg-sunk: oklch(97.8% 0.006 85);
--surface: #ffffff;
--surface-2: oklch(97.2% 0.006 85);
--surface-3: oklch(94% 0.008 85);
/* Text */
--ink: oklch(18% 0.008 85);
--ink-2: oklch(38% 0.008 85);
--ink-3: oklch(55% 0.008 85);
--ink-4: oklch(70% 0.006 85);
/* Borders */
--line: oklch(93% 0.008 85);
--line-2: oklch(88% 0.01 85);
/* Amber accent */
--amber: oklch(78% 0.17 75);
--amber-ink: oklch(45% 0.16 70);
--amber-soft: oklch(96% 0.05 85);
--amber-ring: oklch(88% 0.12 80);
/* Signal colors */
--up: oklch(62% 0.17 148);
--up-soft: oklch(95% 0.05 148);
--down: oklch(58% 0.22 25);
--down-soft: oklch(95% 0.05 25);
--violet: oklch(55% 0.17 280);
--violet-soft: oklch(96% 0.04 280);
/* Radii */
--r-xs: 8px;
--r-sm: 10px;
--r-md: 14px;
--r-lg: 20px;
--r-xl: 28px;
--r-pill: 999px;
/* Shadow */
--shadow-1: 0 1px 2px rgba(20, 18, 14, 0.04), 0 1px 1px rgba(20, 18, 14, 0.02);
--shadow-2: 0 4px 16px rgba(20, 18, 14, 0.06), 0 1px 2px rgba(20, 18, 14, 0.03);
--shadow-3: 0 12px 40px rgba(20, 18, 14, 0.08), 0 2px 4px rgba(20, 18, 14, 0.04);
--sans: 'Geist', ui-sans-serif, system-ui, -apple-system, 'Helvetica Neue', sans-serif;
--mono: 'Geist Mono', ui-monospace, 'SF Mono', Menlo, monospace;
}
body {
background-color: #000000;
html[data-theme="dark"] {
--bg: oklch(15% 0.008 85);
--bg-sunk: oklch(12% 0.008 85);
--surface: oklch(18% 0.008 85);
--surface-2: oklch(21% 0.008 85);
--surface-3: oklch(25% 0.01 85);
--ink: oklch(97% 0.005 85);
--ink-2: oklch(82% 0.006 85);
--ink-3: oklch(62% 0.006 85);
--ink-4: oklch(45% 0.006 85);
--line: oklch(24% 0.008 85);
--line-2: oklch(30% 0.01 85);
--amber: oklch(78% 0.17 75);
--amber-ink: oklch(82% 0.16 75);
--amber-soft: oklch(25% 0.05 75);
--amber-ring: oklch(38% 0.12 75);
--up: oklch(70% 0.18 148);
--up-soft: oklch(24% 0.06 148);
--down: oklch(68% 0.22 25);
--down-soft: oklch(24% 0.08 25);
--violet: oklch(70% 0.17 280);
--violet-soft: oklch(24% 0.06 280);
--shadow-1: 0 1px 2px rgba(0, 0, 0, 0.3);
--shadow-2: 0 4px 16px rgba(0, 0, 0, 0.35);
--shadow-3: 0 12px 40px rgba(0, 0, 0, 0.5);
color-scheme: dark;
}
/* Remove default focus ring and apply custom */
button:focus-visible {
outline: 1px solid #f97316;
outline-offset: 2px;
html[data-theme="dark"] .src-ico.x { background: oklch(92% 0.005 85); color: oklch(15% 0.008 85); }
html[data-theme="dark"] .bot-status {
background: linear-gradient(160deg, oklch(28% 0.015 85) 0%, oklch(20% 0.01 85) 100%);
border: 1px solid oklch(30% 0.01 85);
}
input:focus-visible {
outline: 1px solid #222222;
outline-offset: 0;
html[data-theme="dark"] .kpi.accent {
background: linear-gradient(135deg, oklch(28% 0.05 75), oklch(24% 0.07 70));
}
html[data-theme="dark"] .landing-nav {
background: oklch(15% 0.008 85 / 0.8);
}
html[data-theme="dark"] .src-ico.truth {
background: oklch(30% 0.08 25); color: oklch(80% 0.15 25);
}
html[data-theme="dark"] .post-row.selected {
background: oklch(22% 0.03 75);
}
html, body {
margin: 0;
padding: 0;
background: var(--bg);
color: var(--ink);
font-family: var(--sans);
-webkit-font-smoothing: antialiased;
-moz-osx-font-smoothing: grayscale;
font-feature-settings: 'ss01', 'cv11';
transition: background 200ms, color 200ms;
}
* { box-sizing: border-box; }
button { font-family: inherit; cursor: pointer; border: 0; background: transparent; color: inherit; }
input, textarea { font-family: inherit; }
a { color: inherit; text-decoration: none; }
.mono { font-family: var(--mono); font-feature-settings: 'tnum', 'zero'; }
.tnum { font-variant-numeric: tabular-nums; }
/* ============================================================
App scaffold
============================================================ */
.app {
min-height: 100vh;
display: flex;
flex-direction: column;
}
/* ---------- Top navbar ---------- */
.nav {
height: 64px;
padding: 0 28px;
display: flex;
align-items: center;
gap: 32px;
background: var(--bg);
border-bottom: 1px solid var(--line);
position: sticky;
top: 0;
z-index: 40;
}
.brand {
display: flex;
align-items: center;
gap: 10px;
font-weight: 600;
font-size: 15px;
letter-spacing: -0.01em;
}
.brand-mark {
width: 28px;
height: 28px;
border-radius: 8px;
background: var(--ink);
color: var(--bg);
display: grid;
place-items: center;
font-family: var(--mono);
font-size: 15px;
font-weight: 500;
position: relative;
}
.brand-mark::after {
content: '';
position: absolute;
right: -3px;
bottom: -3px;
width: 10px;
height: 10px;
border-radius: 999px;
background: var(--amber);
border: 2px solid var(--bg);
}
.nav-tabs {
display: flex;
align-items: center;
gap: 4px;
padding: 4px;
background: var(--bg-sunk);
border: 1px solid var(--line);
border-radius: var(--r-pill);
}
.nav-tab {
padding: 7px 14px;
border-radius: var(--r-pill);
font-size: 13px;
font-weight: 500;
color: var(--ink-3);
transition: color 120ms, background 120ms;
}
.nav-tab:hover { color: var(--ink); }
.nav-tab.active {
background: var(--surface);
color: var(--ink);
box-shadow: var(--shadow-1);
}
.nav-spacer { flex: 1; }
.nav-right {
display: flex;
align-items: center;
gap: 10px;
}
.icon-btn {
width: 36px;
height: 36px;
border-radius: var(--r-pill);
background: var(--bg-sunk);
border: 1px solid var(--line);
display: grid;
place-items: center;
color: var(--ink-2);
transition: background 120ms, color 120ms;
}
.icon-btn:hover { background: var(--surface-3); color: var(--ink); }
.connect-btn {
padding: 12px 22px;
border-radius: var(--r-pill);
background: var(--ink);
color: var(--bg);
font-size: 14px;
font-weight: 600;
letter-spacing: -0.005em;
transition: background 120ms, transform 120ms, box-shadow 120ms;
box-shadow: var(--shadow-1);
}
.connect-btn:hover { background: oklch(30% 0.01 85); box-shadow: var(--shadow-2); }
.connect-btn:active { transform: scale(0.98); }
.connect-btn.lg { padding: 13px 26px; font-size: 14px; }
html[data-theme="dark"] .connect-btn { background: var(--amber); color: oklch(20% 0.04 75); }
html[data-theme="dark"] .connect-btn:hover { background: oklch(82% 0.17 75); }
.theme-toggle { width: 40px; height: 40px; }
html[data-theme="dark"] .icon-btn { background: var(--surface-2); border-color: var(--line); }
html[data-theme="dark"] .icon-btn:hover { background: var(--surface-3); }
html[data-theme="dark"] .nav-tab.active { background: var(--surface-2); }
html[data-theme="dark"] .asset-switch button.on { background: var(--surface-2); }
.wallet-chip {
display: flex;
align-items: center;
gap: 8px;
padding: 6px 12px 6px 6px;
border-radius: var(--r-pill);
background: var(--bg-sunk);
border: 1px solid var(--line);
font-size: 13px;
}
.wallet-chip .ava {
width: 24px;
height: 24px;
border-radius: 999px;
background: linear-gradient(135deg, var(--amber), oklch(65% 0.2 35));
}
/* ============================================================
Page shell
============================================================ */
.page {
max-width: 1360px;
margin: 0 auto;
padding: 32px 28px 80px;
width: 100%;
}
.page.wide { max-width: 1600px; }
.page-head {
display: flex;
align-items: flex-end;
justify-content: space-between;
margin-bottom: 28px;
gap: 24px;
}
.page-title {
font-size: 34px;
letter-spacing: -0.02em;
font-weight: 600;
line-height: 1.05;
margin: 0;
}
.page-sub {
color: var(--ink-3);
font-size: 14px;
margin-top: 6px;
margin-bottom: 0;
}
/* ============================================================
Cards + primitives
============================================================ */
.card {
background: var(--surface);
border: 1px solid var(--line);
border-radius: var(--r-md);
padding: 20px;
}
.card.flush { padding: 0; }
.card.soft { background: var(--bg-sunk); }
.card.raise { box-shadow: var(--shadow-1); }
.section-title {
display: flex;
align-items: center;
justify-content: space-between;
margin-bottom: 14px;
}
.section-title h2 {
margin: 0;
font-size: 16px;
font-weight: 600;
letter-spacing: -0.01em;
}
.section-title .hint {
font-size: 12px;
color: var(--ink-3);
}
.chip {
display: inline-flex;
align-items: center;
gap: 6px;
padding: 4px 10px;
border-radius: var(--r-pill);
background: var(--bg-sunk);
border: 1px solid var(--line);
font-size: 12px;
color: var(--ink-2);
font-weight: 500;
}
.chip .dot { width: 6px; height: 6px; border-radius: 999px; background: currentColor; }
.chip.up { color: oklch(40% 0.16 148); background: var(--up-soft); border-color: oklch(85% 0.08 148); }
.chip.down { color: oklch(44% 0.2 25); background: var(--down-soft); border-color: oklch(87% 0.08 25); }
.chip.amber { color: var(--amber-ink); background: var(--amber-soft); border-color: var(--amber-ring); }
.chip.violet { color: oklch(38% 0.15 280); background: var(--violet-soft); border-color: oklch(86% 0.08 280); }
.chip.neutral { color: var(--ink-2); }
.live-dot {
width: 6px;
height: 6px;
border-radius: 999px;
background: var(--up);
position: relative;
display: inline-block;
}
.live-dot::after {
content: '';
position: absolute;
inset: -4px;
border-radius: 999px;
background: var(--up);
opacity: 0.3;
animation: pulse 1.6s ease-out infinite;
}
@keyframes pulse {
0% { transform: scale(0.6); opacity: 0.5; }
100% { transform: scale(2.2); opacity: 0; }
}
.btn {
display: inline-flex;
align-items: center;
justify-content: center;
gap: 8px;
padding: 10px 16px;
border-radius: var(--r-pill);
font-size: 13px;
font-weight: 500;
transition: background 120ms, transform 120ms;
border: 1px solid transparent;
}
.btn.primary { background: var(--ink); color: var(--bg); }
.btn.primary:hover { background: oklch(30% 0.01 85); }
.btn.amber {
background: var(--amber);
color: oklch(22% 0.04 75);
font-weight: 600;
}
.btn.amber:hover { background: oklch(82% 0.17 75); }
.btn.ghost { background: var(--bg-sunk); color: var(--ink); border-color: var(--line); }
.btn.ghost:hover { background: var(--surface-3); }
.btn.lg { padding: 14px 22px; font-size: 15px; }
.btn:active { transform: scale(0.98); }
.delta { font-family: var(--mono); font-weight: 500; }
.delta.up { color: oklch(42% 0.16 148); }
.delta.down { color: oklch(46% 0.2 25); }
/* ============================================================
Dashboard specific
============================================================ */
.dash-grid {
display: grid;
grid-template-columns: minmax(0, 1fr) 360px;
gap: 20px;
align-items: start;
}
.hero-value {
font-size: 44px;
font-weight: 500;
letter-spacing: -0.025em;
line-height: 1;
font-family: var(--mono);
font-feature-settings: 'tnum';
}
.hero-value .cents { color: var(--ink-3); font-size: 0.6em; }
.asset-switch {
display: inline-flex;
padding: 4px;
background: var(--bg-sunk);
border: 1px solid var(--line);
border-radius: var(--r-pill);
gap: 2px;
}
.asset-switch button {
padding: 7px 14px;
border-radius: var(--r-pill);
font-size: 13px;
font-weight: 500;
color: var(--ink-3);
display: flex;
align-items: center;
gap: 6px;
}
.asset-switch button.on {
background: var(--surface);
color: var(--ink);
box-shadow: var(--shadow-1);
}
.asset-dot {
width: 14px;
height: 14px;
border-radius: 999px;
}
.asset-dot.btc { background: linear-gradient(135deg, #f7931a, #f2a93b); }
.asset-dot.eth { background: linear-gradient(135deg, #627eea, #8fa2ff); }
.tf-bar {
display: inline-flex;
gap: 2px;
padding: 3px;
background: var(--bg-sunk);
border: 1px solid var(--line);
border-radius: var(--r-pill);
}
.tf-bar button {
padding: 5px 10px;
border-radius: var(--r-pill);
font-size: 12px;
font-weight: 500;
color: var(--ink-3);
font-family: var(--mono);
}
.tf-bar button.on { background: var(--ink); color: var(--bg); }
.chart-wrap {
margin-top: 8px;
position: relative;
height: 360px;
}
.chart-footnote {
display: flex;
gap: 18px;
font-size: 12px;
color: var(--ink-3);
border-top: 1px dashed var(--line);
padding-top: 14px;
margin-top: 4px;
}
.chart-footnote .item { display: flex; align-items: center; gap: 6px; }
.legend-dot { width: 8px; height: 8px; border-radius: 2px; }
/* KPI tiles */
.kpi-row {
display: grid;
grid-template-columns: repeat(4, 1fr);
gap: 12px;
margin-bottom: 20px;
}
.kpi {
background: var(--surface);
border: 1px solid var(--line);
border-radius: var(--r-md);
padding: 16px 18px;
display: flex;
flex-direction: column;
gap: 6px;
position: relative;
overflow: hidden;
}
.kpi .label {
font-size: 12px;
color: var(--ink-3);
display: flex;
align-items: center;
gap: 6px;
}
.kpi .value {
font-size: 22px;
font-weight: 500;
letter-spacing: -0.01em;
font-family: var(--mono);
}
.kpi .foot {
font-size: 12px;
color: var(--ink-3);
display: flex;
align-items: center;
gap: 6px;
}
.kpi.accent {
background: linear-gradient(135deg, oklch(97% 0.04 85), oklch(95% 0.07 80));
border-color: var(--amber-ring);
}
.kpi.accent .label { color: var(--amber-ink); }
/* Right rail */
.rail { display: flex; flex-direction: column; gap: 20px; }
.signal-card {
background: var(--surface);
border: 1px solid var(--line);
border-radius: var(--r-md);
padding: 18px;
}
.signal-head {
display: flex;
align-items: center;
justify-content: space-between;
margin-bottom: 14px;
}
.signal-head h3 {
margin: 0;
font-size: 14px;
font-weight: 600;
}
.latest-post {
border: 1px solid var(--line);
border-radius: var(--r-sm);
padding: 14px;
background: var(--bg-sunk);
}
.latest-post .meta {
display: flex;
align-items: center;
gap: 8px;
font-size: 12px;
color: var(--ink-3);
margin-bottom: 10px;
}
.latest-post .text {
font-size: 13px;
line-height: 1.55;
color: var(--ink);
margin: 0 0 12px;
}
.latest-post .divider {
height: 1px;
background: var(--line);
margin: 12px 0;
}
.latest-post .lp-row {
display: flex;
justify-content: space-between;
align-items: center;
font-size: 12px;
}
.latest-post .lp-row + .lp-row { margin-top: 6px; }
.latest-post .lp-row .k { color: var(--ink-3); }
.confidence-bar {
height: 6px;
background: var(--surface-3);
border-radius: 999px;
overflow: hidden;
position: relative;
margin-top: 6px;
}
.confidence-bar > div {
height: 100%;
background: linear-gradient(90deg, var(--amber) 0%, oklch(68% 0.2 45) 100%);
border-radius: 999px;
transition: width 600ms ease-out;
}
/* Bot status */
.bot-status {
background: linear-gradient(160deg, oklch(22% 0.01 85) 0%, oklch(14% 0.01 85) 100%);
color: oklch(96% 0.005 85);
border-radius: var(--r-lg);
padding: 22px;
position: relative;
overflow: hidden;
}
.bot-status::after {
content: '';
position: absolute;
right: -40px;
top: -40px;
width: 180px;
height: 180px;
background: radial-gradient(circle, oklch(75% 0.17 75 / 0.4) 0%, transparent 70%);
pointer-events: none;
}
.bot-head {
display: flex;
justify-content: space-between;
align-items: center;
margin-bottom: 18px;
}
.bot-head h3 { margin: 0; font-size: 15px; font-weight: 600; display: flex; align-items: center; gap: 8px; }
.bot-stats {
display: grid;
grid-template-columns: 1fr 1fr;
gap: 14px 20px;
position: relative;
z-index: 1;
}
.bot-stat .k {
font-size: 11px;
color: oklch(70% 0.01 85);
text-transform: uppercase;
letter-spacing: 0.08em;
margin-bottom: 4px;
}
.bot-stat .v {
font-size: 20px;
font-family: var(--mono);
font-weight: 500;
letter-spacing: -0.01em;
}
.bot-stat .v.up { color: oklch(75% 0.17 148); }
.bot-stat .v.amber { color: var(--amber); }
.bot-cta {
margin-top: 18px;
display: flex;
gap: 8px;
position: relative;
z-index: 1;
}
.bot-cta .btn { flex: 1; }
/* Post list (stream) */
.post-stream {
display: flex;
flex-direction: column;
gap: 10px;
}
.post-row {
display: grid;
grid-template-columns: 36px 1fr auto;
gap: 14px;
padding: 14px 16px;
background: var(--surface);
border: 1px solid var(--line);
border-radius: var(--r-md);
align-items: flex-start;
transition: border-color 120ms, background 120ms;
cursor: pointer;
}
.post-row:hover { border-color: var(--line-2); }
.post-row.selected { border-color: var(--amber-ring); background: oklch(99% 0.02 85); }
.src-ico {
width: 36px;
height: 36px;
border-radius: 10px;
display: grid;
place-items: center;
font-family: var(--mono);
font-weight: 600;
font-size: 15px;
flex-shrink: 0;
}
.src-ico.x { background: #111; color: #fff; }
.src-ico.truth { background: oklch(94% 0.05 25); color: oklch(45% 0.2 25); }
.post-body .meta {
display: flex;
align-items: center;
gap: 8px;
margin-bottom: 6px;
font-size: 12px;
color: var(--ink-3);
}
.post-body .text {
font-size: 14px;
line-height: 1.5;
color: var(--ink);
margin: 0 0 10px;
}
.post-aside {
display: flex;
flex-direction: column;
gap: 8px;
align-items: flex-end;
min-width: 120px;
}
/* Signal pill */
.sig {
display: inline-flex;
align-items: center;
gap: 6px;
padding: 5px 10px;
border-radius: var(--r-pill);
font-size: 12px;
font-weight: 600;
letter-spacing: 0.02em;
}
.sig.buy { background: var(--up-soft); color: oklch(38% 0.16 148); }
.sig.sell, .sig.short { background: var(--down-soft); color: oklch(42% 0.2 25); }
.sig.hold { background: var(--bg-sunk); color: var(--ink-2); }
.impact-mini {
display: flex;
gap: 8px;
align-items: center;
font-family: var(--mono);
font-size: 12px;
}
.impact-mini .tf { color: var(--ink-4); font-size: 11px; }
/* Trades table */
.table {
width: 100%;
border-collapse: separate;
border-spacing: 0;
font-size: 13px;
}
.table th {
text-align: left;
font-weight: 500;
color: var(--ink-3);
padding: 14px 18px;
border-bottom: 1px solid var(--line);
font-size: 12px;
background: var(--bg-sunk);
}
.table th:first-child { border-top-left-radius: var(--r-md); }
.table th:last-child { border-top-right-radius: var(--r-md); text-align: right; }
.table td {
padding: 14px 18px;
border-bottom: 1px solid var(--line);
}
.table td:last-child { text-align: right; }
.table tr:last-child td { border-bottom: 0; }
.table tr:hover td { background: var(--bg-sunk); }
.side-pill {
display: inline-flex;
align-items: center;
gap: 6px;
padding: 3px 9px;
border-radius: var(--r-pill);
font-size: 12px;
font-weight: 600;
}
.side-pill.long { background: var(--up-soft); color: oklch(38% 0.16 148); }
.side-pill.short { background: var(--down-soft); color: oklch(42% 0.2 25); }
/* Settings */
.settings-grid {
display: grid;
grid-template-columns: 260px 1fr;
gap: 32px;
align-items: start;
}
.settings-side {
position: sticky;
top: 84px;
display: flex;
flex-direction: column;
gap: 2px;
}
.settings-side button {
text-align: left;
padding: 10px 14px;
border-radius: var(--r-sm);
font-size: 13px;
color: var(--ink-2);
font-weight: 500;
}
.settings-side button.on { background: var(--bg-sunk); color: var(--ink); }
.settings-side button:hover { background: var(--bg-sunk); color: var(--ink); }
.field {
display: flex;
flex-direction: column;
gap: 6px;
margin-bottom: 20px;
}
.field label {
font-size: 13px;
font-weight: 500;
}
.field .hint {
font-size: 12px;
color: var(--ink-3);
}
.field input, .field select, .field textarea {
border: 1px solid var(--line);
background: var(--surface);
border-radius: var(--r-sm);
padding: 11px 14px;
font-size: 14px;
outline: none;
transition: border-color 120ms, box-shadow 120ms;
color: var(--ink);
}
.field input:focus, .field textarea:focus {
border-color: var(--amber-ring);
box-shadow: 0 0 0 3px oklch(88% 0.12 80 / 0.4);
}
.switch {
--w: 40px;
width: var(--w);
height: 24px;
border-radius: 999px;
background: var(--surface-3);
position: relative;
cursor: pointer;
transition: background 150ms;
border: 1px solid var(--line);
flex-shrink: 0;
}
.switch::after {
content: '';
position: absolute;
top: 2px;
left: 2px;
width: 18px;
height: 18px;
border-radius: 999px;
background: var(--surface);
box-shadow: var(--shadow-1);
transition: transform 180ms;
}
.switch.on {
background: var(--ink);
border-color: var(--ink);
}
.switch.on::after { transform: translateX(16px); }
.setting-row {
display: flex;
align-items: flex-start;
justify-content: space-between;
gap: 24px;
padding: 16px 0;
border-bottom: 1px solid var(--line);
}
.setting-row:last-child { border-bottom: 0; }
.setting-row .desc { font-size: 12px; color: var(--ink-3); margin-top: 4px; max-width: 440px; line-height: 1.5; }
/* Analytics */
.metric-grid {
display: grid;
grid-template-columns: repeat(3, 1fr);
gap: 16px;
}
/* Misc utilities */
.stack { display: flex; flex-direction: column; }
.row { display: flex; align-items: center; }
.between { justify-content: space-between; }
.gap-s { gap: 8px; }
.gap-m { gap: 14px; }
.gap-l { gap: 20px; }
.grow { flex: 1; }
.mono-num { font-family: var(--mono); font-variant-numeric: tabular-nums; }
.muted { color: var(--ink-3); }
.tiny { font-size: 11px; text-transform: uppercase; letter-spacing: 0.08em; color: var(--ink-3); font-weight: 500; }
/* Scrollbar */
::-webkit-scrollbar { width: 10px; height: 10px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--line-2); border-radius: 999px; border: 2px solid var(--bg); }
::-webkit-scrollbar-thumb:hover { background: oklch(80% 0.01 85); }
+13 -8
View File
@@ -1,17 +1,14 @@
import type { Metadata } from 'next'
import { Inter } from 'next/font/google'
import { NextIntlClientProvider } from 'next-intl'
import { getMessages } from 'next-intl/server'
import { notFound } from 'next/navigation'
import { locales } from '@/i18n'
import Navbar from '@/components/nav/Navbar'
import Providers from './Providers'
import Navbar from '@/components/nav/Navbar'
import './globals.css'
const inter = Inter({ subsets: ['latin'] })
export const metadata: Metadata = {
title: 'TrumpSignal — AI-powered crypto trading signals',
title: 'Trump Alpha — AI signal trading',
description: 'Trade crypto based on Trump social media signals with AI confidence scoring.',
}
@@ -29,11 +26,19 @@ export default async function LocaleLayout({ children, params: { locale } }: Lay
return (
<html lang={locale}>
<body className={`${inter.className} bg-[#000000] min-h-screen text-white`}>
<head>
<link rel="preconnect" href="https://fonts.googleapis.com" />
<link rel="preconnect" href="https://fonts.gstatic.com" crossOrigin="anonymous" />
<link
href="https://fonts.googleapis.com/css2?family=Geist:wght@400;500;600;700&family=Geist+Mono:wght@400;500;600&display=swap"
rel="stylesheet"
/>
</head>
<body>
<NextIntlClientProvider messages={messages}>
<Providers>
<Navbar locale={locale} />
<main className="pt-14">{children}</main>
<Navbar />
<main>{children}</main>
</Providers>
</NextIntlClientProvider>
</body>
+2 -4
View File
@@ -1,20 +1,18 @@
import { getPosts, getPerformance, getTrades } from '@/lib/api'
import { getPosts, getPerformance } from '@/lib/api'
import DashboardClient from './DashboardClient'
export const revalidate = 30
export default async function OverviewPage() {
const [posts, performance, trades] = await Promise.allSettled([
const [posts, performance] = await Promise.allSettled([
getPosts(500, 1),
getPerformance(),
getTrades(20, 1),
])
return (
<DashboardClient
initialPosts={posts.status === 'fulfilled' ? posts.value : []}
initialPerformance={performance.status === 'fulfilled' ? performance.value : undefined}
initialTrades={trades.status === 'fulfilled' ? trades.value : []}
/>
)
}
+118 -8
View File
@@ -1,14 +1,124 @@
import { useTranslations } from 'next-intl'
import { getTranslations } from 'next-intl/server'
'use client'
export default async function PostsPage() {
const t = await getTranslations('posts')
import { useState, useEffect } from 'react'
import type { TrumpPost } from '@/types'
import { getPosts } from '@/lib/api'
import PostRow, { SignalPill, SourceIcon, fmtPct, timeAgo } from '@/components/dashboard/PostCards'
function PostDetail({ post, onClose }: { post: TrumpPost; onClose: () => void }) {
return (
<div className="card" style={{ padding: 24, position: 'sticky', top: 84 }}>
<div className="row between" style={{ marginBottom: 16 }}>
<span className="tiny">Signal detail</span>
<button className="icon-btn" onClick={onClose} style={{ width: 28, height: 28 }}>
<svg width="12" height="12" viewBox="0 0 24 24"><path d="M18 6L6 18M6 6l12 12" stroke="currentColor" strokeWidth="2" strokeLinecap="round"/></svg>
</button>
</div>
<div className="row gap-s" style={{ marginBottom: 14 }}>
<SourceIcon source={post.source} />
<div>
<div style={{ fontSize: 13, fontWeight: 500 }} className="mono">@realDonaldTrump</div>
<div style={{ fontSize: 12, color: 'var(--ink-3)' }}>{new Date(post.published_at).toLocaleString()}</div>
</div>
</div>
<p style={{ fontSize: 15, lineHeight: 1.55, margin: '0 0 20px' }}>{post.text}</p>
<div className="row gap-s" style={{ marginBottom: 20 }}>
<SignalPill signal={post.signal} />
<span className={`chip ${post.sentiment === 'bullish' ? 'up' : post.sentiment === 'bearish' ? 'down' : 'neutral'}`}>{post.sentiment}</span>
</div>
<div className="tiny" style={{ marginBottom: 8 }}>AI reasoning</div>
<div style={{ padding: 14, background: 'var(--bg-sunk)', borderRadius: 10, border: '1px solid var(--line)', fontSize: 13, lineHeight: 1.55, color: 'var(--ink-2)', marginBottom: 20 }}>
{post.ai_reasoning || 'No reasoning available.'}
</div>
<div className="row between" style={{ fontSize: 12, color: 'var(--ink-3)', marginBottom: 6 }}>
<span>AI confidence</span>
<span className="mono" style={{ color: 'var(--ink)', fontWeight: 500 }}>{post.ai_confidence}%</span>
</div>
<div className="confidence-bar"><div style={{ width: post.ai_confidence + '%' }} /></div>
{post.price_impact && (
<div style={{ marginTop: 24 }}>
<div className="tiny" style={{ marginBottom: 10 }}>Actual price impact · {post.price_impact.asset}</div>
<div style={{ display: 'grid', gridTemplateColumns: '1fr 1fr 1fr', gap: 10 }}>
{(['m5', 'm15', 'm1h'] as const).map(k => {
const v = post.price_impact![k]
const correct = post.price_impact!['correct_' + k as 'correct_m5' | 'correct_m15' | 'correct_m1h']
const label = k === 'm5' ? '5m' : k === 'm15' ? '15m' : '1h'
return (
<div key={k} style={{ padding: 12, background: 'var(--bg-sunk)', borderRadius: 10, border: '1px solid var(--line)' }}>
<div style={{ fontSize: 11, color: 'var(--ink-3)', marginBottom: 4 }}>{label}</div>
<div className={`delta ${(v ?? 0) >= 0 ? 'up' : 'down'}`} style={{ fontSize: 15 }}>{fmtPct(v)}</div>
{correct != null && (
<div style={{ fontSize: 11, color: correct ? 'var(--up)' : 'var(--down)', marginTop: 4 }}>
{correct ? '✓ correct' : '✗ missed'}
</div>
)}
</div>
)
})}
</div>
</div>
)}
</div>
)
}
export default function PostsPage() {
const [posts, setPosts] = useState<TrumpPost[]>([])
const [loading, setLoading] = useState(true)
const [filter, setFilter] = useState('all')
const [selected, setSelected] = useState<number | null>(null)
useEffect(() => {
getPosts(200, 1).then(setPosts).catch(() => {}).finally(() => setLoading(false))
}, [])
const filtered = posts.filter(p => {
if (filter !== 'all' && p.sentiment !== filter) return false
return true
})
const counts = {
all: posts.length,
bullish: posts.filter(p => p.sentiment === 'bullish').length,
bearish: posts.filter(p => p.sentiment === 'bearish').length,
neutral: posts.filter(p => p.sentiment === 'neutral').length,
}
const selectedPost = posts.find(p => p.id === selected)
return (
<div className="max-w-[1400px] mx-auto px-6 py-6">
<div className="bg-[#0a0a0a] border border-[#141414] rounded-[10px] p-10 text-center">
<h1 className="text-[22px] font-medium text-white mb-3">{t('title')}</h1>
<p className="text-[14px] text-[#555555]">{t('comingSoon')}</p>
<div className="page">
<div className="page-head">
<div>
<h1 className="page-title">Signals feed</h1>
<p className="page-sub">Every post we tracked, every prediction we made. {posts.length} posts in the last 30 days.</p>
</div>
<span className="chip"><span className="live-dot" />Streaming</span>
</div>
<div className="row between" style={{ marginBottom: 18 }}>
<div className="nav-tabs" style={{ background: 'var(--bg-sunk)' }}>
{(['all', 'bullish', 'bearish', 'neutral'] as const).map(f => (
<button key={f} className={`nav-tab ${filter === f ? 'active' : ''}`} onClick={() => setFilter(f)}>
{f.charAt(0).toUpperCase() + f.slice(1)} <span style={{ color: 'var(--ink-4)', marginLeft: 4 }}>{counts[f]}</span>
</button>
))}
</div>
</div>
{loading && <div style={{ textAlign: 'center', padding: 60, color: 'var(--ink-3)' }}>Loading</div>}
<div style={{ display: 'grid', gridTemplateColumns: selected ? '1fr 420px' : '1fr', gap: 24, alignItems: 'start' }}>
<div className="post-stream">
{filtered.map(p => (
<PostRow key={p.id} post={p} selected={selected === p.id} onClick={() => setSelected(selected === p.id ? null : p.id)} />
))}
</div>
{selected && selectedPost && <PostDetail post={selectedPost} onClose={() => setSelected(null)} />}
</div>
</div>
)
+311 -17
View File
@@ -1,31 +1,325 @@
'use client'
import { useTranslations } from 'next-intl'
import { useAccount } from 'wagmi'
import { useConnectModal } from '@rainbow-me/rainbowkit'
import { useEffect, useState } from 'react'
import Link from 'next/link'
import { useAccount, useSignMessage } from 'wagmi'
import { useDashboardStore } from '@/store/dashboard'
import { getUser, getUserPublic, setUserSettings, type UserSettings } from '@/lib/api'
import { getOrCreateViewEnvelope, signRequest } from '@/lib/signedRequest'
import BotPanel from '@/components/dashboard/BotPanel'
export default function SettingsClient() {
const t = useTranslations('settings')
const { isConnected } = useAccount()
const { openConnectModal } = useConnectModal()
const ACTION_SET_SETTINGS = 'set_settings'
const ACTION_VIEW_USER = 'view_user'
const DEFAULT_SETTINGS: UserSettings = {
leverage: 3,
position_size_usd: 20,
take_profit_pct: null,
stop_loss_pct: null,
min_confidence: 80,
}
if (!isConnected) {
function LockedCard({ label }: { label: string }) {
return (
<div className="card" style={{ padding: 40, textAlign: 'center', color: 'var(--ink-3)' }}>
<div style={{ width: 44, height: 44, borderRadius: 12, background: 'var(--bg-sunk)', margin: '0 auto 12px', display: 'grid', placeItems: 'center' }}>
<svg width="20" height="20" viewBox="0 0 24 24" fill="none"><rect x="5" y="11" width="14" height="10" rx="2" stroke="currentColor" strokeWidth="2"/><path d="M8 11V8a4 4 0 118 0v3" stroke="currentColor" strokeWidth="2"/></svg>
</div>
{label}
</div>
)
}
function BotSettings({
connected, subscribed, wallet, initial,
}: {
connected: boolean
subscribed: boolean
wallet?: string
initial: UserSettings
}) {
if (!connected) {
return (
<div className="bg-[#0a0a0a] border border-[#141414] rounded-[10px] p-10 text-center">
<p className="text-[14px] text-[#555555] mb-4">{t('connectRequired')}</p>
<button
onClick={openConnectModal}
className="bg-[#f97316] text-black font-medium text-[13px] rounded-lg px-6 py-2.5 hover:bg-[#fb923c] transition-colors"
>
Connect wallet
<div className="card" style={{ padding: 40, textAlign: 'center' }}>
<div style={{ width: 56, height: 56, borderRadius: 16, background: 'var(--bg-sunk)', margin: '0 auto 16px', display: 'grid', placeItems: 'center' }}>
<svg width="24" height="24" viewBox="0 0 24 24" fill="none"><rect x="3" y="5" width="18" height="14" rx="3" stroke="currentColor" strokeWidth="2"/><path d="M3 10h18" stroke="currentColor" strokeWidth="2"/></svg>
</div>
<h3 style={{ margin: '0 0 8px', fontSize: 18 }}>Connect wallet to configure</h3>
<p style={{ color: 'var(--ink-3)', fontSize: 14, maxWidth: 380, margin: '0 auto 20px', lineHeight: 1.5 }}>
Your wallet is used to verify access and sign bot commands. We never custody your funds.
</p>
<button className="btn amber lg" onClick={() => document.querySelector<HTMLButtonElement>('.connect-btn')?.click()}>
Connect wallet · free
</button>
</div>
)
}
if (!subscribed) {
return (
<div className="card" style={{ padding: 32 }}>
<div className="row between" style={{ marginBottom: 20 }}>
<div>
<h3 style={{ margin: '0 0 4px', fontSize: 18 }}>Subscribe to unlock the bot</h3>
<p style={{ color: 'var(--ink-3)', fontSize: 13, margin: 0 }}>Get automated execution, real-time alerts, and advanced configuration.</p>
</div>
<span className="chip amber">14-day free trial</span>
</div>
<div style={{ display: 'grid', gridTemplateColumns: '1fr 1fr', gap: 12, marginBottom: 20 }}>
{['Auto-execute trades on your exchange', 'SMS + Telegram alerts within 2s', 'Custom confidence + position-size rules', 'Backtest any strategy on 2y of data'].map(f => (
<div key={f} className="row gap-s" style={{ padding: 12, background: 'var(--bg-sunk)', borderRadius: 10, fontSize: 13 }}>
<span style={{ color: 'var(--up)' }}></span>{f}
</div>
))}
</div>
<Link href="/" className="btn amber lg" style={{ textAlign: 'center' }}>
Activate on dashboard
</Link>
</div>
)
}
return <BotSettingsForm wallet={wallet!} initial={initial} />
}
function BotSettingsForm({ wallet, initial }: { wallet: string; initial: UserSettings }) {
const { signMessageAsync } = useSignMessage()
const [s, setS] = useState<UserSettings>(initial)
const [useTp, setUseTp] = useState<boolean>(initial.take_profit_pct != null)
const [useSl, setUseSl] = useState<boolean>(initial.stop_loss_pct != null)
const [state, setState] = useState<'idle' | 'signing' | 'saving' | 'ok' | 'err'>('idle')
const [err, setErr] = useState('')
// Re-sync when initial changes (after /user fetch resolves)
useEffect(() => {
setS(initial)
setUseTp(initial.take_profit_pct != null)
setUseSl(initial.stop_loss_pct != null)
}, [initial])
const dirty = JSON.stringify(s) !== JSON.stringify(initial) ||
useTp !== (initial.take_profit_pct != null) ||
useSl !== (initial.stop_loss_pct != null)
async function save() {
setErr('')
try {
const payload: UserSettings = {
...s,
take_profit_pct: useTp ? s.take_profit_pct ?? 2 : null,
stop_loss_pct: useSl ? s.stop_loss_pct ?? 1.5 : null,
}
setState('signing')
const env = await signRequest({
action: ACTION_SET_SETTINGS,
wallet,
body: payload,
signMessageAsync,
})
setState('saving')
await setUserSettings(env, payload)
setS(payload)
setState('ok')
setTimeout(() => setState('idle'), 2000)
} catch (e: unknown) {
const m = e instanceof Error ? e.message : 'Save failed'
setErr(m.includes('User rejected') || m.includes('denied') ? 'Signature cancelled' : m.slice(0, 140))
setState('err')
}
}
const label = state === 'signing' ? 'Waiting for signature…' : state === 'saving' ? 'Saving…' : state === 'ok' ? '✓ Saved' : 'Save changes'
return (
<div className="bg-[#0a0a0a] border border-[#141414] rounded-[10px] p-10 text-center">
<p className="text-[14px] text-[#555555]">{t('comingSoon')}</p>
<div>
<div className="card" style={{ padding: 24, marginBottom: 16 }}>
<div className="section-title"><h2>Execution</h2></div>
<div className="setting-row" style={{ padding: '14px 0', borderTop: '1px solid var(--line)' }}>
<div style={{ flex: 1 }}>
<div style={{ fontSize: 14, fontWeight: 500, marginBottom: 4 }}>Position size (USD)</div>
<div className="desc" style={{ marginBottom: 8 }}>Fixed notional per trade. Margin = size / leverage.</div>
<input
type="number" min={5} max={10000} step={5}
value={s.position_size_usd}
onChange={e => setS({ ...s, position_size_usd: Math.max(5, +e.target.value || 0) })}
style={{ width: 140 }}
/>
</div>
<div className="tiny mono" style={{ color: 'var(--ink-3)' }}>margin ${(s.position_size_usd / s.leverage).toFixed(2)}</div>
</div>
<div className="setting-row" style={{ padding: '14px 0', borderTop: '1px solid var(--line)' }}>
<div style={{ flex: 1 }}>
<div style={{ fontSize: 14, fontWeight: 500, marginBottom: 4 }}>Leverage</div>
<div className="desc" style={{ marginBottom: 8 }}>Isolated margin, 150×. Higher = bigger PnL swings.</div>
<div className="row gap-m">
<input type="range" min={1} max={50} value={s.leverage}
onChange={e => setS({ ...s, leverage: +e.target.value })}
style={{ flex: 1, accentColor: 'var(--amber)' }} />
<div className="mono" style={{ minWidth: 60, fontSize: 16, fontWeight: 500 }}>{s.leverage}×</div>
</div>
</div>
</div>
<div className="setting-row" style={{ padding: '14px 0', borderTop: '1px solid var(--line)' }}>
<div style={{ flex: 1 }}>
<div style={{ fontSize: 14, fontWeight: 500, marginBottom: 4 }}>Minimum AI confidence</div>
<div className="desc" style={{ marginBottom: 8 }}>Platform floor is 80%. Raise to be pickier; can&apos;t lower.</div>
<div className="row gap-m">
<input type="range" min={80} max={100} value={s.min_confidence}
onChange={e => setS({ ...s, min_confidence: +e.target.value })}
style={{ flex: 1, accentColor: 'var(--amber)' }} />
<div className="mono" style={{ minWidth: 60, fontSize: 16, fontWeight: 500 }}>{s.min_confidence}%</div>
</div>
</div>
</div>
</div>
<div className="card" style={{ padding: 24, marginBottom: 16 }}>
<div className="section-title"><h2>Risk management</h2></div>
<div className="setting-row" style={{ padding: '14px 0', borderTop: '1px solid var(--line)' }}>
<div style={{ flex: 1 }}>
<div className="row gap-s" style={{ marginBottom: 4 }}>
<div style={{ fontSize: 14, fontWeight: 500 }}>Take profit</div>
<label style={{ fontSize: 12, color: 'var(--ink-3)', cursor: 'pointer' }}>
<input type="checkbox" checked={useTp} onChange={e => setUseTp(e.target.checked)} style={{ marginRight: 6 }} />
enable
</label>
</div>
<div className="desc" style={{ marginBottom: 8 }}>Auto-close when price moves your way by this %.</div>
<div className="row gap-s" style={{ opacity: useTp ? 1 : 0.45 }}>
<input type="number" min={0.1} max={50} step={0.1}
value={s.take_profit_pct ?? 2}
disabled={!useTp}
onChange={e => setS({ ...s, take_profit_pct: +e.target.value })}
style={{ width: 100 }} />
<span className="muted">% gain</span>
</div>
</div>
</div>
<div className="setting-row" style={{ padding: '14px 0', borderTop: '1px solid var(--line)' }}>
<div style={{ flex: 1 }}>
<div className="row gap-s" style={{ marginBottom: 4 }}>
<div style={{ fontSize: 14, fontWeight: 500 }}>Stop loss</div>
<label style={{ fontSize: 12, color: 'var(--ink-3)', cursor: 'pointer' }}>
<input type="checkbox" checked={useSl} onChange={e => setUseSl(e.target.checked)} style={{ marginRight: 6 }} />
enable
</label>
</div>
<div className="desc" style={{ marginBottom: 8 }}>Auto-close when price moves against you by this %.</div>
<div className="row gap-s" style={{ opacity: useSl ? 1 : 0.45 }}>
<input type="number" min={0.1} max={50} step={0.1}
value={s.stop_loss_pct ?? 1.5}
disabled={!useSl}
onChange={e => setS({ ...s, stop_loss_pct: +e.target.value })}
style={{ width: 100 }} />
<span className="muted">% loss</span>
</div>
</div>
</div>
</div>
<div className="row gap-s" style={{ alignItems: 'center' }}>
<button
className={`btn ${state === 'ok' ? 'ghost' : 'amber'} lg`}
onClick={save}
disabled={!dirty || state === 'signing' || state === 'saving'}
>
{label}
</button>
{!dirty && state === 'idle' && <span className="tiny" style={{ color: 'var(--ink-3)' }}>No changes to save</span>}
{state === 'err' && <span className="tiny" style={{ color: 'var(--down)' }}>{err}</span>}
</div>
</div>
)
}
function ExchangeSettings({ subscribed }: { subscribed: boolean }) {
if (!subscribed) return <LockedCard label="Subscribe to add Hyperliquid API key" />
return <BotPanel />
}
function AccountSettings({ address }: { address?: string }) {
return (
<div className="card" style={{ padding: 24 }}>
<div className="section-title"><h2>Account</h2></div>
<div className="field">
<label>Wallet</label>
<input disabled value={address ? `${address.slice(0, 8)}${address.slice(-6)}` : 'Not connected'} />
</div>
</div>
)
}
export default function SettingsClient() {
const [section, setSection] = useState('bot')
const { address, isConnected } = useAccount()
const { signMessageAsync } = useSignMessage()
const { isSubscribed, setSubscribed, setHlApiKeySet } = useDashboardStore()
const [settings, setSettings] = useState<UserSettings>(DEFAULT_SETTINGS)
const [loadErr, setLoadErr] = useState<string>('')
useEffect(() => {
if (!isConnected || !address) return
let cancelled = false
// First fetch public state (no sig). Only request a view signature if user
// is actually subscribed — otherwise there's nothing private to fetch.
;(async () => {
try {
const pub = await getUserPublic(address.toLowerCase())
if (cancelled) return
setSubscribed(pub.active)
setHlApiKeySet(pub.hl_api_key_set)
if (!pub.active) return
const env = await getOrCreateViewEnvelope({
action: ACTION_VIEW_USER,
wallet: address,
signMessageAsync,
})
if (cancelled) return
const u = await getUser(address, env)
if (cancelled) return
setSubscribed(u.active)
setHlApiKeySet(u.hl_api_key_set, u.hl_api_key_masked ?? undefined)
if (u.settings) setSettings(u.settings)
} catch (e: unknown) {
const m = e instanceof Error ? e.message : 'Failed to load settings'
// Swallow cancelled signatures; surface real failures
if (!m.includes('User rejected') && !m.includes('denied')) {
setLoadErr(m.slice(0, 140))
}
}
})()
return () => { cancelled = true }
}, [address, isConnected, setSubscribed, setHlApiKeySet, signMessageAsync])
const sections = [
{ key: 'bot', label: 'Trading bot' },
{ key: 'exchange', label: 'Exchange keys' },
{ key: 'account', label: 'Account' },
]
return (
<div className="settings-grid">
<div className="settings-side">
{sections.map(s => (
<button key={s.key} className={section === s.key ? 'on' : ''} onClick={() => setSection(s.key)}>
{s.label}
</button>
))}
</div>
<div>
{loadErr && (
<div className="card" style={{ padding: 12, marginBottom: 12, border: '1px solid var(--down)', color: 'var(--down)', fontSize: 13 }}>
{loadErr}
</div>
)}
{section === 'bot' && <BotSettings connected={isConnected} subscribed={isSubscribed} wallet={address} initial={settings} />}
{section === 'exchange' && <ExchangeSettings subscribed={isSubscribed} />}
{section === 'account' && <AccountSettings address={address} />}
</div>
</div>
)
}
+8 -6
View File
@@ -1,12 +1,14 @@
import { getTranslations } from 'next-intl/server'
import SettingsClient from './SettingsClient'
export default async function SettingsPage() {
const t = await getTranslations('settings')
export default function SettingsPage() {
return (
<div className="max-w-[1400px] mx-auto px-6 py-6">
<h1 className="text-[22px] font-medium text-white mb-5">{t('title')}</h1>
<div className="page">
<div className="page-head">
<div>
<h1 className="page-title">Settings</h1>
<p className="page-sub">Configure your bot, alerts, and account.</p>
</div>
</div>
<SettingsClient />
</div>
)
+172 -10
View File
@@ -1,17 +1,179 @@
import { getTranslations } from 'next-intl/server'
import TradesTable from '@/components/trades/TradesTable'
import { getTrades } from '@/lib/api'
'use client'
export const revalidate = 10
import { useState, useEffect } from 'react'
import type { BotTrade, TrumpPost } from '@/types'
import { getTrades, getPosts } from '@/lib/api'
export default async function TradesPage() {
const t = await getTranslations('trades')
const trades = await getTrades(100, 1).catch(() => [])
function fmtMoney(n: number, opts: { sign?: boolean; decimals?: number } = {}) {
const { decimals = 2, sign = false } = opts
if (n == null || isNaN(n)) return '—'
const abs = Math.abs(n)
const s = abs.toLocaleString('en-US', { minimumFractionDigits: decimals, maximumFractionDigits: decimals })
if (n < 0) return '-$' + s
if (sign && n > 0) return '+$' + s
return '$' + s
}
function fmtPct(n: number) {
const s = n.toFixed(2) + '%'
return n >= 0 ? '+' + s : s
}
function fmtHold(s: number) {
if (s < 60) return s + 's'
const m = Math.floor(s / 60)
if (m < 60) return m + 'm'
return Math.floor(m / 60) + 'h ' + (m % 60) + 'm'
}
function SourceIcon({ source }: { source: string }) {
if (source === 'x') return <div className="src-ico x" style={{ width: 28, height: 28, fontSize: 12 }}>𝕏</div>
return <div className="src-ico truth" style={{ width: 28, height: 28, fontSize: 12 }}>T</div>
}
export default function TradesPage() {
const [trades, setTrades] = useState<BotTrade[]>([])
const [posts, setPosts] = useState<TrumpPost[]>([])
const [loading, setLoading] = useState(true)
const [assetFilter, setAssetFilter] = useState('all')
const [sideFilter, setSideFilter] = useState('all')
useEffect(() => {
Promise.all([
getTrades(200, 1).catch(() => []),
getPosts(500, 1).catch(() => []),
]).then(([t, p]) => {
setTrades(t)
setPosts(p)
}).finally(() => setLoading(false))
}, [])
const filtered = trades.filter(t => {
if (assetFilter !== 'all' && t.asset !== assetFilter) return false
if (sideFilter !== 'all' && t.side !== sideFilter) return false
return true
})
const totalPnl = filtered.reduce((s, t) => s + t.pnl_usd, 0)
const wins = filtered.filter(t => t.pnl_usd > 0).length
const avgHold = filtered.length > 0 ? Math.round(filtered.reduce((s, t) => s + t.hold_seconds, 0) / filtered.length) : 0
return (
<div className="max-w-[1400px] mx-auto px-6 py-6 pt-20">
<h1 className="text-[22px] font-medium text-white mb-5">{t('title')}</h1>
<TradesTable trades={trades} />
<div className="page">
<div className="page-head">
<div>
<h1 className="page-title">Trades</h1>
<p className="page-sub">Every trade your bot executed. Transparent and auditable.</p>
</div>
<div className="row gap-s">
<span className="chip">30 days</span>
</div>
</div>
<div className="kpi-row" style={{ gridTemplateColumns: 'repeat(4, 1fr)' }}>
<div className="kpi">
<div className="label">Total trades</div>
<div className="value">{filtered.length}</div>
<div className="foot"><span>Filtered</span></div>
</div>
<div className="kpi">
<div className="label">Win rate</div>
<div className="value">{filtered.length ? ((wins / filtered.length) * 100).toFixed(1) + '%' : '—'}</div>
<div className="foot"><span>{wins}W · {filtered.length - wins}L</span></div>
</div>
<div className="kpi accent">
<div className="label">Net P&amp;L</div>
<div className="value">{fmtMoney(totalPnl, { sign: true, decimals: 0 })}</div>
<div className="foot"><span>All assets</span></div>
</div>
<div className="kpi">
<div className="label">Avg hold</div>
<div className="value">{avgHold ? fmtHold(avgHold) : '—'}</div>
<div className="foot"><span>Per trade</span></div>
</div>
</div>
<div className="row between" style={{ margin: '20px 0 14px' }}>
<div className="row gap-s">
<div className="nav-tabs">
{(['all', 'BTC', 'ETH'] as const).map(a => (
<button key={a} className={`nav-tab ${assetFilter === a ? 'active' : ''}`} onClick={() => setAssetFilter(a)}>
{a === 'all' ? 'All assets' : a}
</button>
))}
</div>
<div className="nav-tabs">
{(['all', 'long', 'short'] as const).map(s => (
<button key={s} className={`nav-tab ${sideFilter === s ? 'active' : ''}`} onClick={() => setSideFilter(s)}>
{s.charAt(0).toUpperCase() + s.slice(1)}
</button>
))}
</div>
</div>
</div>
{loading && <div style={{ textAlign: 'center', padding: 60, color: 'var(--ink-3)' }}>Loading</div>}
{!loading && (
<div className="card flush" style={{ overflow: 'hidden' }}>
<table className="table">
<thead>
<tr>
<th>Asset</th>
<th>Side</th>
<th>Entry</th>
<th>Exit</th>
<th>Hold</th>
<th>Trigger</th>
<th>P&amp;L</th>
</tr>
</thead>
<tbody>
{filtered.length === 0 && (
<tr><td colSpan={7} style={{ textAlign: 'center', padding: 40, color: 'var(--ink-3)' }}>No trades found</td></tr>
)}
{filtered.map(t => {
const triggerPost = posts.find(p => p.id === t.trigger_post_id)
const roiPct = ((t.exit_price - t.entry_price) / t.entry_price) * 100 * (t.side === 'long' ? 1 : -1)
return (
<tr key={t.id}>
<td>
<div className="row gap-s">
<span className={`asset-dot ${t.asset.toLowerCase()}`} />
<span style={{ fontWeight: 500 }}>{t.asset}</span>
</div>
</td>
<td><span className={`side-pill ${t.side}`}>{t.side === 'long' ? '↗ LONG' : '↘ SHORT'}</span></td>
<td className="mono">${t.entry_price.toLocaleString()}</td>
<td className="mono">${t.exit_price.toLocaleString()}</td>
<td className="mono" style={{ color: 'var(--ink-2)' }}>{fmtHold(t.hold_seconds)}</td>
<td style={{ maxWidth: 280 }}>
{triggerPost ? (
<div className="row gap-s" style={{ alignItems: 'center' }}>
<SourceIcon source={triggerPost.source} />
<span style={{ fontSize: 12, color: 'var(--ink-2)', overflow: 'hidden', textOverflow: 'ellipsis', whiteSpace: 'nowrap' }}>
{triggerPost.text.slice(0, 50)}
</span>
</div>
) : (
<span style={{ fontSize: 12, color: 'var(--ink-4)' }}></span>
)}
</td>
<td>
<div className="stack" style={{ alignItems: 'flex-end' }}>
<span className={`delta ${t.pnl_usd >= 0 ? 'up' : 'down'}`} style={{ fontWeight: 600, fontSize: 14 }}>
{fmtMoney(t.pnl_usd, { sign: true })}
</span>
<span className={`delta ${roiPct >= 0 ? 'up' : 'down'}`} style={{ fontSize: 11, opacity: 0.7 }}>{fmtPct(roiPct)}</span>
</div>
</td>
</tr>
)
})}
</tbody>
</table>
</div>
)}
</div>
)
}