KOL count: 29 → 25 across marketing/SEO copy

Backend KOL_FEEDS trimmed from 29 to 25 (dead feeds removed).
Sync all hardcoded count mentions:
- layout.tsx JSON-LD, page.tsx (metric + comparison + copy)
- kol/page.tsx, KolPageClient.tsx ("and 26 more" → "and 22 more")
- glossary/page.tsx, opengraph-image.tsx
- public/llms.txt, llms-full.txt
- drop removed KOLs (Dragonfly Capital, Nic Carter) from named lists

Bundles other in-flight frontend work already in the working tree.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
This commit is contained in:
k
2026-06-09 22:55:27 +08:00
parent 9e0f6554cb
commit 4c3c8c6f87
57 changed files with 3464 additions and 1855 deletions
+2 -2
View File
@@ -2,10 +2,10 @@
"version": "0.0.1",
"configurations": [
{
"name": "trumpsignal",
"name": "frontend",
"runtimeExecutable": "npm",
"runtimeArgs": ["run", "dev"],
"cwd": "/Users/k/Public/Claude/trumpsignal",
"cwd": "/Users/k/Public/trumpsignal/frontend",
"port": 3001
}
]
+6
View File
@@ -14,3 +14,9 @@ NEXT_PUBLIC_WS_URL=wss://api.yourdomain.com
# Dev: http://localhost:3001
# Production: https://yourdomain.com
NEXT_PUBLIC_SITE_URL=https://yourdomain.com
# WalletConnect v2 project ID — enables QR-code pairing (desktop → mobile wallet)
# and all WalletConnect-compatible mobile wallets (Trust, Rainbow, etc.)
# Get a FREE project ID at https://cloud.walletconnect.com (takes ~2 min)
# Leave empty: injected-only mode (browser extension wallets on desktop only)
NEXT_PUBLIC_WALLETCONNECT_PROJECT_ID=
+45 -18
View File
@@ -15,8 +15,8 @@ This is the AI-readable entry doc. Read this first on entering the repo.
client components, deployed to Vercel.
- **Talks to a Python backend** at `https://api.trumpsignal.com` (or
`localhost:8000` in dev). All trading state, signals, AI scoring,
Hyperliquid integration lives in the sibling **`/Users/k/Public/Claude/
backend`** repo. See its CLAUDE.md.
Hyperliquid integration lives in the sibling **`../backend`**
repo. See its CLAUDE.md.
- **No server-side trading logic** lives here. Frontend is a thin layer
over the API + WebSocket — even "open a position" routes to a backend
endpoint that does the signed-request verification + HL call.
@@ -51,7 +51,7 @@ This is the AI-readable entry doc. Read this first on entering the repo.
```
app/
├── layout.tsx Root layout: JSON-LD schema.org, fonts, meta
├── page.tsx / (root) → redirects to /en
├── page.tsx / (root) → marketing / landing page
├── icon.tsx Dynamic favicon (α on dark bg, edge runtime)
├── apple-icon.tsx PWA install icon
├── opengraph-image.tsx OG card generator (1200x630)
@@ -89,30 +89,33 @@ app/[locale]/
components/
├── nav/Navbar.tsx Top nav + tabs (Trump | Macro Vibes | KOL ...)
├── signals/
│ ├── SignalMonitor.tsx Live signal stream (WS-driven)
│ ├── SourceChips.tsx Filter chips per source
── SystemControl.tsx Sys1/sys2 toggle widgets, Auto-Trade switch
│ └── ConfirmCloseTrade.tsx Modal for manual close
── SystemControl.tsx Sys1/sys2 toggle widgets, Auto-Trade switch
├── dashboard/
│ ├── PostCards.tsx Trump post cards
│ ├── SignalMonitor.tsx (older — being consolidated)
│ └── BtcReversalAlert.tsx Pinned alert when sys2 fires
│ ├── SignalMonitor.tsx Live signal stream (WS-driven)
│ └── ChartPanel.tsx Price chart panel
├── btc/MacroPanel.tsx ★ 8-indicator Macro Vibes layout (4 sections,
│ composite needle, threshold chips, peak-trail viz)
├── positions/
── OpenPositions.tsx Polls /positions/open + /positions/today every 15s
└── TradeCard.tsx Single trade row w/ grow toggle + close button
├── kol/KolDigest.tsx Daily KOL summary widget
── OpenPositions.tsx Polls /positions/open + /positions/today every 15s
Includes grow toggle + manual close button
├── trades/
│ ├── TradeTable.tsx Closed trade history table (dynamic asset filter)
│ └── BotConfigPanel.tsx Bot configuration (SL, TP, leverage, paper mode).
│ Includes 3-step onboarding stepper + inline Auto-Trade toggle.
├── telegram/
── TelegramCard.tsx Settings — connect via 6-char code
── TelegramCard.tsx Settings — connect via 6-char code
├── wallet/
│ └── SignConfirmSheet.tsx EIP-191 signed request preview
├── nav/WalletConnect.tsx Wagmi-style wallet connect (MetaMask etc.)
├── seo/Breadcrumbs.tsx Structured breadcrumb nav for SEO
├── ui/
│ ├── InfoTip.tsx CSS-only tooltip with `?` icon
│ ├── PageHint.tsx Strong page subtitle (replaces page-sub)
│ ├── Toast.tsx
│ └── Modal.tsx
└── ws/WsProvider.tsx WebSocket singleton context provider
│ ├── PageHint.tsx Strong page subtitle
│ ├── Pagination.tsx Reusable pagination control
│ └── TradeAlertBanner.tsx Fixed-position WS alert banner (trade_alert events).
│ Auto-dismisses after 10s. Filtered by wallet address.
└── lib/wsContext.tsx WebSocket singleton context (replaces WsProvider)
```
---
@@ -240,6 +243,30 @@ Tokens in `app/[locale]/globals.css`:
`growErr` state with a 4-second auto-clear, instead of squatting in the
panel-header `err` banner shared with the 15-s poll error.
- ~~**H2 Chart data race** (FIXED 2026-06-01):~~ `cancelled` flag added to the
candles `useEffect` — stale BTC response can no longer overwrite ETH candles
when asset is switched mid-fetch.
- ~~**M8 Duplicate React keys** (FIXED 2026-06-01):~~ `onNewPost` now deduplicates
by `post.id` before prepending to the posts list.
- ~~**L2 fittedRef not reset on asset change** (FIXED 2026-06-01):~~ Chart view
is re-fitted when `asset` changes, not only on `timeframe` change.
- ~~**L4 invalid ARIA role** (FIXED 2026-06-01):~~ `Ticker.tsx` `role="marquee"`
replaced with `role="region"`.
- ~~**L5 ws:// mixed-content block** (FIXED 2026-06-01):~~ `wsContext.tsx` now
auto-upgrades to `wss://` when served over HTTPS, instead of hard-coding `ws://`.
**Open / deferred (need interface change or DB migration):**
- **C3** Signed READ endpoints (`allow_replay=True`) put `ts`/`sig` in URL → access logs. Fix requires changing read endpoints to POST body (interface change + frontend update).
- **H4** KEK derived with single SHA-256, no salt/KDF. Fix requires re-encrypting all HL API keys (DB migration).
- **M1** Adopted (sys2) positions incorrectly counted against sys1 daily budget.
- **M5** `GET /telegram/{wallet}/status` is unauthenticated — exposes `chat_id`/`tg_username`.
- **M7** Rate limit bypassable via spoofed XFF — infrastructure-level fix (nginx/Cloudflare).
- **M9** SWR cache only notifies the first caller on background refresh — others get stale data.
## How to verify changes locally
```bash
@@ -303,6 +330,6 @@ in Vercel dashboard:
## Sibling repo
- **`/Users/k/Public/Claude/backend`** — Python/FastAPI backend, includes
- **`/Users/k/Public/trumpsignal/backend`** — Python/FastAPI backend, includes
Hyperliquid integration, Telegram bot, AI scoring (DeepSeek), all
signal scanners, the adoption/release flow. See its CLAUDE.md.
+227 -74
View File
@@ -9,12 +9,14 @@ import { useAccount } from 'wagmi'
import type { TrumpPost, BotPerformance, Candle } from '@/types'
import { useDashboardStore } from '@/store/dashboard'
import { usePriceSocket } from '@/lib/useRealtimeData'
import { getMacroSnapshot, getPerformance, getPrices, getUserPublic, type MacroSnapshot } from '@/lib/api'
import { getMacroSnapshot, getPerformance, getPrices, getUserPublic, getKolDivergence, getKolDigest, type MacroSnapshot } from '@/lib/api'
import type { KolDivergence, KolDigest } from '@/types'
import { getCachedViewEnvelope } from '@/lib/signedRequest'
import { swrFetch } from '@/lib/cache'
import PostRow, { SignalPill, SourceIcon, fmtPct, TimeAgo, LocalDateTime } from '@/components/dashboard/PostCards'
import { swrFetch, invalidate as invalidateCache } from '@/lib/cache'
import PostRow, { SignalPill, SourceIcon, SOURCE_DISPLAY, fmtPct, TimeAgo, LocalDateTime } from '@/components/dashboard/PostCards'
import OpenPositions from '@/components/positions/OpenPositions'
import PageHint from '@/components/ui/PageHint'
import AnimatedNumber from '@/components/ui/AnimatedNumber'
// Heavy components — lazy-loaded so they don't bloat the initial JS bundle.
// ChartPanel pulls in lightweight-charts (~200KB gz); split it out.
@@ -58,7 +60,9 @@ function PostDetail({ post, onClose }: { post: TrumpPost; onClose: () => void })
<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: 13, fontWeight: 500, fontFamily: 'var(--mono)' }}>
{SOURCE_DISPLAY[post.source?.toLowerCase?.()]?.label ?? post.source ?? 'Signal'}
</div>
<div style={{ fontSize: 11, color: 'var(--ink-3)' }}><TimeAgo iso={post.published_at} suffix=" ago" /> · <LocalDateTime iso={post.published_at} /></div>
</div>
</div>
@@ -86,7 +90,9 @@ function PostDetail({ post, onClose }: { post: TrumpPost; onClose: () => void })
{/* AI reasoning */}
{post.ai_reasoning && (
<>
<div className="ai-reasoning-label">AI reasoning</div>
<div className="ai-reasoning-label">
{post.signal === 'buy' || post.signal === 'short' ? 'Why this signal fired' : 'Why this was filtered out'}
</div>
<div className="ai-reasoning-card scroll" style={{ marginBottom: 16 }}>
{post.ai_reasoning}
</div>
@@ -147,7 +153,7 @@ function SelectHint() {
export default function DashboardClient({ initialPosts }: Props) {
const intlLocale = useLocale()
const isZh = false // i18n shelved — Chinese branches kept as dead code for future revival; see messages/zh.json
const { asset, setAsset, timeframe, setTimeframe: _setTimeframe, setLivePrice, setSubscribed, setBotReadiness, setHlApiKeySet, isSubscribed, hlApiKeySet, botReadiness, livePrices } = useDashboardStore()
const { asset, setAsset, timeframe, setTimeframe: _setTimeframe, setLivePrice, setSubscribed, setBotReadiness, setHlApiKeySet, setPaperMode, isSubscribed, hlApiKeySet, botReadiness, livePrices } = useDashboardStore()
function setTimeframe(tf: string) { _setTimeframe(tf as '5m' | '15m' | '1H' | '4H' | '1D' | '1W') }
const { address, isConnected } = useAccount()
const params = useParams()
@@ -159,29 +165,40 @@ export default function DashboardClient({ initialPosts }: Props) {
const [chartReload, setChartReload] = useState(0)
const [selectedPostId, setSelectedPostId] = useState<number | null>(null)
const [macro, setMacro] = useState<MacroSnapshot | null>(null)
const [kolDivergences, setKolDivergences] = useState<KolDivergence[]>([])
const [kolDigest, setKolDigest] = useState<KolDigest | null>(null)
// For 1D: show all posts from selected day
const [selectedDayPosts, setSelectedDayPosts] = useState<TrumpPost[] | null>(null)
useEffect(() => {
// B42: cancel the in-flight getUserPublic if the wallet switches again
// before it resolves — prevents old wallet's data polluting new wallet's state.
let cancelled = false
if (!isConnected || !address) {
setSubscribed(false)
setHlApiKeySet(false)
setBotReadiness('unknown')
setPerformance(undefined)
return
return () => { cancelled = true }
}
// Clear account-scoped bot state immediately when the connected wallet
// changes so a previous wallet's status never leaks into the next one.
// Clear account-scoped bot state immediately (setWallet already resets these
// via store, but DashboardClient may be rendered without a wallet switch —
// keep explicit resets here for clarity and safety).
setSubscribed(false)
setHlApiKeySet(false)
setBotReadiness('unknown')
// `snapAddr !== address` would be a stale-closure trap: both are the same
// closed-over value. Use `cancelled` (set by effect cleanup) as the sole guard.
getUserPublic(address.toLowerCase())
.then((user) => {
if (cancelled) return // effect cleaned up = wallet changed or unmounted
setSubscribed(user.active)
setHlApiKeySet(user.hl_api_key_set)
setBotReadiness(user.hl_api_key_set ? 'saved' : 'unknown')
setPaperMode(!!user.paper_mode)
})
.catch(() => {})
return () => { cancelled = true }
}, [address, isConnected, setSubscribed, setHlApiKeySet, setBotReadiness])
useEffect(() => {
@@ -207,19 +224,37 @@ export default function DashboardClient({ initialPosts }: Props) {
return () => { cancelled = true }
}, [address, isConnected])
const [freshPostId, setFreshPostId] = useState<number | null>(null)
usePriceSocket({
onPrice: (a, price) => setLivePrice(a, price),
onNewPost: (post) => setPosts((prev) => [post as TrumpPost, ...prev].slice(0, 500)),
onNewPost: (post) => {
const p = post as TrumpPost
// Dedup: WS may resend a post already in initialPosts or a prior push.
setPosts((prev) => prev.some(x => x.id === p.id) ? prev : [p, ...prev].slice(0, 500))
setFreshPostId(p.id)
// Keep a ref to the timer so we can cancel it if the component unmounts
// before it fires (avoids setState-after-unmount warning).
const timer = setTimeout(() => setFreshPostId((id) => (id === p.id ? null : id)), 1400)
return () => clearTimeout(timer) // returned but not used by usePriceSocket — see L1 note
},
})
useEffect(() => {
let cancelled = false
setCandles([])
setChartErr('')
getPrices(asset, timeframe)
.then(c => { setCandles(c); setChartErr('') })
.catch(e => setChartErr(e instanceof Error ? e.message : (isZh ? '价格数据加载失败' : 'Failed to load price data')))
// isZh intentionally excluded: it is a compile-time constant (always false)
// and including it would restart the chart fetch on every render.
const priceKey = `prices-${asset}-${timeframe}`
if (chartReload > 0) invalidateCache(priceKey)
swrFetch(
priceKey,
90_000,
() => getPrices(asset, timeframe),
fresh => { if (!cancelled) { setCandles(fresh); setChartErr('') } },
)
.then(c => { if (!cancelled) { setCandles(c); setChartErr('') } })
.catch(e => { if (!cancelled) setChartErr(e instanceof Error ? e.message : 'Failed to load price data') })
return () => { cancelled = true }
// eslint-disable-next-line react-hooks/exhaustive-deps
}, [asset, timeframe, chartReload])
@@ -240,6 +275,21 @@ export default function DashboardClient({ initialPosts }: Props) {
return () => { alive = false; clearInterval(id) }
}, [])
// KOL divergence + digest — loaded once, 30 min cache (changes daily)
useEffect(() => {
let alive = true
// KOL ingestion is daily and sparse — a 7d window is frequently empty
// (e.g. 7d=0 while 30d=196), which hid the whole sidebar card. Use a 30d
// window so the Overview reflects the data that actually exists.
swrFetch('kol-divergence-30d', 30 * 60_000, () => getKolDivergence({ days: 30 }), f => { if (alive) setKolDivergences(f.items ?? []) })
.then(r => { if (alive) setKolDivergences(r.items ?? []) })
.catch(() => {})
swrFetch('kol-digest-30d', 30 * 60_000, () => getKolDigest(30), f => { if (alive) setKolDigest(f) })
.then(r => { if (alive) setKolDigest(r) })
.catch(() => {})
return () => { alive = false }
}, [])
const selectedPost = posts.find(p => p.id === selectedPostId) ?? null
// Show actionable signals first (buy/short), then most recent hold/neutral.
@@ -278,7 +328,9 @@ export default function DashboardClient({ initialPosts }: Props) {
const actionablePosts = posts.filter(p => p.signal === 'buy' || p.signal === 'short').length
const trumpActionable = posts.filter(p => (p.source || '') === 'truth' && (p.signal === 'buy' || p.signal === 'short')).length
const macroActionable = posts.filter(p => ((p.source || '') === 'btc_bottom_reversal' || (p.source || '') === 'funding_reversal') && (p.signal === 'buy' || p.signal === 'short')).length
const kolMentions = posts.filter(p => (p.source || '') === 'kol').length
// Use actual KOL divergence count (divergence-flagged items from the API),
// not a source==='kol' post count (which never matches — source is 'substack'/'blog'/etc.).
const kolMentions = kolDivergences.filter(d => d.signal_type === 'divergence').length
const winRate = performance?.win_rate ?? 0
const netPnl = performance?.net_pnl_usd ?? 0
const hasPriceData = candles.length > 0
@@ -286,37 +338,38 @@ export default function DashboardClient({ initialPosts }: Props) {
const macroScore = macro?.composite_score ?? null
const macroRegime = macro?.regime_label ?? null
const macroPct = macroScore == null ? 50 : Math.max(0, Math.min(100, (macroScore + 100) / 2))
// Derive tone from the backend's regime_label, NOT a re-thresholded score.
// The backend uses ±20 for BULLISH/BEARISH; re-deriving with ±15 here made
// a score of e.g. 15.2 read "Supportive" in the card while the same card's
// regime label said NEUTRAL. Trusting regime_label keeps them consistent.
const macroTone =
macroScore == null ? 'neutral'
: macroScore > 15 ? 'bull'
: macroScore < -15 ? 'bear'
macroRegime == null ? (macroScore == null ? 'neutral' : 'neutral')
: macroRegime === 'BULL' || macroRegime === 'BULLISH' ? 'bull'
: macroRegime === 'BEAR' || macroRegime === 'BEARISH' ? 'bear'
: 'neutral'
const macroSummary =
macroScore == null ? 'Daily macro composite not loaded yet.'
: macroTone === 'bull' ? 'Risk backdrop is supportive. Trend-following setups get more room.'
: macroTone === 'bear' ? 'Backdrop is defensive. Preserve size and expect cleaner downside moves.'
: 'Backdrop is mixed. Useful for context, not a blind directional trigger.'
: macroTone === 'bull' ? 'Supportive backdrop — trend setups have room.'
: macroTone === 'bear' ? 'Defensive backdrop — preserve size, downside moves are cleaner.'
: 'Mixed backdrop context only, not a directional trigger.'
return (
<div className="page wide">
<div className="page-head">
<div>
<h1 className="page-title">{isZh ? '信号总览' : 'Signal monitor'}</h1>
<PageHint count={`${actionablePosts} actionable · ${totalPosts} tracked`}>
Four signals that move crypto before the crowd sees them Trump
posts, BTC macro bottoms, funding extremes, and what KOLs do vs
say. Tracked live, in public, every call timestamped.
<PageHint count={actionablePosts > 0 ? `${actionablePosts} actionable · ${totalPosts} tracked` : undefined}>
Trump · Macro · KOL divergence live.
</PageHint>
</div>
<div className="row gap-s">
<span className="chip"><span className="live-dot" />Live feed</span>
</div>
<span className="chip"><span className="live-dot" />Live</span>
</div>
{/* Open positions — what's on the book right now. Renders only when
a subscribed wallet is connected, so guests see the normal feed. */}
<OpenPositions />
<div className="overview-shell">
<div className="overview-main">
<section className="overview-market-card">
@@ -324,12 +377,15 @@ export default function DashboardClient({ initialPosts }: Props) {
<div>
<div className="overview-kicker">Market and macro</div>
<div className="overview-headline-row">
<div className="hero-value mono" style={{ fontSize: 40 }}>
{displayPrice != null ? '$' + Math.round(displayPrice).toLocaleString() : '—'}
</div>
<AnimatedNumber
className="hero-value mono"
style={{ fontSize: 40 }}
value={displayPrice}
display={displayPrice != null ? '$' + Math.round(displayPrice).toLocaleString() : '—'}
/>
<span className={`chip ${priceChange >= 0 ? 'up' : 'down'}`}>{hasPriceData ? fmtPct(priceChange) : 'Feed pending'} · 24h</span>
</div>
<div className="overview-market-subtitle">BTC spot with live signal context</div>
<div className="overview-market-subtitle">{asset} · live signal context</div>
</div>
<div className="overview-controls">
<div className="asset-switch">
@@ -374,62 +430,134 @@ export default function DashboardClient({ initialPosts }: Props) {
</div>
</div>
<div className="overview-system-strip">
<Link href={`/${locale}/trump`} className="overview-system-chip">
<span className="overview-system-chip-name">Trump</span>
<strong>{trumpActionable}</strong>
</Link>
<Link href={`/${locale}/macro`} className="overview-system-chip">
<span className="overview-system-chip-name">Macro</span>
<strong>{macroActionable}</strong>
</Link>
<Link href={`/${locale}/kol`} className="overview-system-chip">
<span className="overview-system-chip-name">KOL</span>
<strong>{kolMentions}</strong>
</Link>
<div className="overview-system-chip passive">
<span className="overview-system-chip-name">Signals today</span>
<strong>{signalsToday}</strong>
</div>
</div>
</section>
<div className="overview-secondary-grid">
<section className="overview-stat-card">
<div className="overview-kicker">Execution</div>
<div className="overview-stat-value">{actionablePosts}</div>
<div className="overview-stat-label">actionable signals tracked in feed</div>
</section>
<section className="overview-stat-card accent">
<div className="overview-kicker">Performance</div>
<div className="overview-stat-value">{hasPerformanceData ? `${netPnl >= 0 ? '+$' : '-$'}${Math.abs(netPnl).toLocaleString('en-US', { maximumFractionDigits: 0 })}` : '—'}</div>
<div className="overview-stat-label">{hasPerformanceData ? '30d live net P&L (real trades only)' : 'Load settings once to unlock private performance'}</div>
</section>
{/* ── Unified stats row ─────────────────────────────────────────── */}
<div className="overview-stats-bar">
{([
{ label: 'Trump signals', value: trumpActionable, href: `/${locale}/trump` },
{ label: 'Macro signals', value: macroActionable, href: `/${locale}/macro` },
{ label: 'KOL divergence', value: kolMentions, href: `/${locale}/kol` },
] as const).map(({ label, value, href }) => {
const empty = value === 0
const inner = (
<>
<span className="stats-bar-label">{label}</span>
<span className="stats-bar-value" style={{ color: empty ? 'var(--ink-4)' : 'var(--ink)' }}>
{empty ? '—' : value}
</span>
</>
)
return <Link key={label} href={href} className="stats-bar-item">{inner}</Link>
})}
<div className="stats-bar-item passive" style={{ borderRight: 'none' }}>
<span className="stats-bar-label">My P&amp;L · 30d</span>
<span className="stats-bar-value" style={{
color: hasPerformanceData ? (netPnl >= 0 ? 'var(--up)' : 'var(--down)') : 'var(--ink-4)',
}}>
{hasPerformanceData
? `${netPnl >= 0 ? '+' : ''}$${Math.abs(netPnl).toLocaleString('en-US', { maximumFractionDigits: 0 })}`
: '—'}
</span>
</div>
</div>
</div>
<aside className="overview-side">
{isConnected ? (
<section className="overview-side-card">
<div className="overview-kicker">Account</div>
<div className="overview-account-list">
<div className="overview-account-item">
<span>Wallet</span>
<strong>{isConnected && address ? `${address.slice(0, 6)}${address.slice(-4)}` : 'Not connected'}</strong>
<strong className="mono">{address ? `${address.slice(0, 6)}${address.slice(-4)}` : ''}</strong>
</div>
<div className="overview-account-item">
<span>Private data</span>
<strong>{hasPerformanceData ? 'Unlocked' : 'Locked until Settings load'}</strong>
<span>Settings</span>
<strong>{hasPerformanceData ? 'Loaded' : 'Not loaded'}</strong>
</div>
{hasPerformanceData && (
<div className="overview-account-item">
<span>Win rate</span>
<strong>{hasPerformanceData ? `${(winRate * 100).toFixed(1)}%` : '—'}</strong>
<strong>{`${(winRate * 100).toFixed(1)}%`}</strong>
</div>
)}
</div>
</section>
<section className="overview-side-card compact">
<div className="overview-kicker">Chart focus</div>
<div className="overview-side-copy">Live chart with signal markers and drill-down on click.</div>
) : (
<section className="overview-side-card" style={{ padding: '14px 16px' }}>
<div className="overview-kicker" style={{ marginBottom: 12 }}>Get started</div>
{([
{ icon: '📡', head: 'Free signals', sub: 'Trump · Macro · KOL — no account needed' },
{ icon: '🔔', head: 'Telegram alerts', sub: 'Signal fires → your phone in seconds' },
{ icon: '⚡', head: 'Auto-trade', sub: 'Trade-only key · no withdrawal access' },
] as const).map(({ icon, head, sub }) => (
<div key={head} style={{ display: 'flex', gap: 10, alignItems: 'flex-start', marginBottom: 12 }}>
<span style={{ fontSize: 16, flexShrink: 0, marginTop: 1 }}>{icon}</span>
<div>
<div style={{ fontSize: 12, fontWeight: 700, lineHeight: 1.3 }}>{head}</div>
<div style={{ fontSize: 11, color: 'var(--ink-4)', lineHeight: 1.4, marginTop: 1 }}>{sub}</div>
</div>
</div>
))}
</section>
)}
{/* KOL divergence hook — highest-conviction signal type */}
{(kolDivergences.length > 0 || (kolDigest && kolDigest.tickers.length > 0)) && (
<section className="overview-side-card" style={{ padding: '14px 16px' }}>
<div style={{ display: 'flex', justifyContent: 'space-between', alignItems: 'center', marginBottom: 10 }}>
<div className="overview-kicker">KOL intel · 30d</div>
<a href={`/${locale}/kol`} style={{ fontSize: 10, color: 'var(--amber-ink)', textDecoration: 'none', fontWeight: 700 }}>
Full feed
</a>
</div>
{/* Latest divergence — the money signal */}
{kolDivergences.filter(d => d.signal_type === 'divergence').slice(0, 1).map(d => (
<div key={d.id} style={{
padding: '9px 11px', borderRadius: 7, marginBottom: 8,
background: 'rgba(245,158,11,0.08)', border: '1px solid rgba(245,158,11,0.25)',
}}>
<div style={{ display: 'flex', alignItems: 'center', gap: 6, marginBottom: 4 }}>
<span style={{ fontSize: 10, fontWeight: 800, color: '#f59e0b', letterSpacing: '0.05em' }}> DIVERGENCE</span>
<span style={{ fontSize: 10, color: 'var(--ink-4)' }}>
{/* post_at = when the KOL actually published. created_at
is the DB write time, which a backfill/late scan can
set to "now", making an old event look fresh. */}
{Math.round((Date.now() - new Date(d.post_at).getTime()) / 864e5)}d ago
</span>
</div>
<div style={{ fontSize: 12, fontWeight: 600 }}>
@{d.handle} said <span style={{ color: d.post_action === 'bullish' || d.post_action === 'buy' ? 'var(--up)' : 'var(--down)' }}>{d.post_action}</span>
{' '}on <strong>{d.ticker}</strong>
</div>
<div style={{ fontSize: 11, color: 'var(--ink-3)', marginTop: 2 }}>
Then {d.onchain_action.replace('_', ' ')}{d.usd_after != null ? `$${(d.usd_after / 1000).toFixed(0)}k on-chain` : ''}
</div>
</div>
))}
{/* Top digest tickers */}
{kolDigest && kolDigest.tickers.slice(0, 2).map(t => (
<div key={t.ticker} style={{
display: 'flex', alignItems: 'center', justifyContent: 'space-between',
padding: '6px 0', borderBottom: '1px solid var(--line)',
}}>
<div>
<span style={{ fontSize: 12, fontWeight: 700 }}>{t.ticker}</span>
<span style={{ fontSize: 10, color: 'var(--ink-4)', marginLeft: 6 }}>{t.kol_count} KOLs</span>
</div>
<span style={{
fontSize: 10, fontWeight: 700, padding: '2px 7px', borderRadius: 4,
background: t.side === 'long' ? 'var(--up-soft)' : t.side === 'short' ? 'rgba(220,38,38,.12)' : 'var(--bg-sunk)',
color: t.side === 'long' ? 'var(--up)' : t.side === 'short' ? 'var(--down)' : 'var(--ink-3)',
}}>
{t.dominant_action.toUpperCase()}
</span>
</div>
))}
</section>
)}
</aside>
</div>
@@ -441,9 +569,12 @@ export default function DashboardClient({ initialPosts }: Props) {
<div>
<div className="tiny">Price · {asset}</div>
<div className="row gap-m" style={{ marginTop: 6 }}>
<div className="hero-value mono" style={{ fontSize: 32 }}>
{displayPrice != null ? '$' + Math.round(displayPrice).toLocaleString() : '—'}
</div>
<AnimatedNumber
className="hero-value mono"
style={{ fontSize: 32 }}
value={displayPrice}
display={displayPrice != null ? '$' + Math.round(displayPrice).toLocaleString() : '—'}
/>
<span className={`chip ${priceChange >= 0 ? 'up' : 'down'}`}>{hasPriceData ? fmtPct(priceChange) : 'Feed pending'} · 24h</span>
</div>
</div>
@@ -459,7 +590,20 @@ export default function DashboardClient({ initialPosts }: Props) {
onClick={() => setChartReload(n => n + 1)}>Retry</button>
</div>
)}
<div className="chart-wrap">
<div className="chart-wrap" style={{ position: 'relative' }}>
{/* Loading overlay — shown while candles are fetching (candles=[] and no error).
Prevents the user from seeing a blank lightweight-charts canvas. */}
{!hasPriceData && !chartErr && (
<div style={{
position: 'absolute', inset: 0, zIndex: 4,
background: 'var(--bg-sunk)', borderRadius: 'var(--r-sm)',
display: 'flex', alignItems: 'center', justifyContent: 'center',
gap: 10, color: 'var(--ink-3)', fontSize: 13,
}}>
<span className="live-dot" style={{ background: 'var(--amber)' }} />
Loading chart
</div>
)}
<ChartPanel
posts={posts}
candles={candles}
@@ -495,7 +639,16 @@ export default function DashboardClient({ initialPosts }: Props) {
</div>
<div className="post-stream">
{recentPosts.map(p => (
<PostRow key={p.id} post={p} />
<div key={p.id} className={p.id === freshPostId ? 'signal-enter' : undefined}>
<PostRow post={p} selected={selectedPostId === p.id} onClick={() => {
// Clear the day-list view first: the right panel renders
// selectedDayPosts with higher priority than selectedPost,
// so without this the detail never appears while a candle's
// multi-post list is open.
setSelectedDayPosts(null)
setSelectedPostId(selectedPostId === p.id ? null : p.id)
}} />
</div>
))}
</div>
</div>
+91 -64
View File
@@ -7,6 +7,7 @@ import { getTrades, getSignalAccuracy } from '@/lib/api'
import type { BotTrade } from '@/types'
import type { SignalAccuracy } from '@/lib/api'
import { getCachedViewEnvelope, getOrCreateViewEnvelope, type SignedEnvelope } from '@/lib/signedRequest'
import { swrFetch } from '@/lib/cache'
import PageHint from '@/components/ui/PageHint'
import InfoTip from '@/components/ui/InfoTip'
@@ -32,7 +33,8 @@ function fmtAccuracyPct(pct: number | null | undefined) {
return pct == null || Number.isNaN(pct) ? '—' : `${pct.toFixed(0)}%`
}
function inPeriod(iso: string, period: Period) {
function inPeriod(iso: string | null, period: Period) {
if (!iso) return false // trades without closed_at are excluded from all windows
if (period === 'All') return true
const days = Number.parseInt(period, 10)
if (Number.isNaN(days)) return true
@@ -42,8 +44,8 @@ function inPeriod(iso: string, period: Period) {
function calcDrawdownPct(trades: BotTrade[]) {
const ordered = [...trades]
.filter((t) => t.pnl_usd !== null && t.pnl_usd !== undefined)
.sort((a, b) => new Date(a.closed_at).getTime() - new Date(b.closed_at).getTime())
.filter((t) => t.pnl_usd !== null && t.pnl_usd !== undefined && t.closed_at !== null)
.sort((a, b) => new Date(a.closed_at!).getTime() - new Date(b.closed_at!).getTime())
let equity = 0
let peak = 0
let maxDrawdownPct = 0
@@ -78,6 +80,14 @@ export default function AnalyticsPageClient() {
return () => { aliveRef.current = false }
}, [])
// genRef guards loadAll against stale-closure wallet-switch races.
// snapAddr === address inside an async function is a stale-closure trap:
// both refer to the same closed-over value at render time, so the check
// is always true even when the wallet has changed. genRef is a mutable
// ref that any closure can read to detect it has been superseded.
const genRef = useRef(0)
useEffect(() => { genRef.current++ }, [address])
// `forcedEnv` (a freshly-minted view_user) lets the in-page Unlock button
// load private data without a detour through the Settings page. Public
// signal-accuracy always loads regardless.
@@ -89,25 +99,37 @@ export default function AnalyticsPageClient() {
// disagreed with the closed_at-based metric grid on the same screen. Limit
// raised to 500 so the local computation covers ample history.
async function loadAll(forcedEnv?: SignedEnvelope) {
const accuracyPromise = swrFetch('signal-accuracy', 10 * 60_000, () => getSignalAccuracy()).catch(() => null)
if (!address || !isConnected) {
setTrades([]); setAccuracy(null); setPrivateLocked(false)
setTrades([]); setPrivateLocked(false)
const a = await accuracyPromise
if (aliveRef.current) setAccuracy(a)
return
}
const tradesEnv = getCachedViewEnvelope('view_trades', address)
?? (forcedEnv ?? getCachedViewEnvelope('view_user', address))
const snapAddr = address
const gen = genRef.current
const tradesEnv = getCachedViewEnvelope('view_trades', snapAddr)
?? (forcedEnv ?? getCachedViewEnvelope('view_user', snapAddr))
if (aliveRef.current) setPrivateLocked(!tradesEnv)
try {
const [t, a] = await Promise.all([
tradesEnv ? getTrades(address, tradesEnv, 500, 1).catch(() => []) : Promise.resolve([]),
getSignalAccuracy().catch(() => null),
tradesEnv ? getTrades(snapAddr, tradesEnv, 500, 1).catch(() => []) : Promise.resolve([]),
accuracyPromise,
])
if (aliveRef.current) { setTrades(t); setAccuracy(a) }
// Discard if unmounted or if a newer loadAll call has started (wallet/tab change).
if (aliveRef.current && gen === genRef.current) { setTrades(t); setAccuracy(a) }
} catch {
if (aliveRef.current) setTrades([])
if (aliveRef.current && gen === genRef.current) setTrades([])
}
}
useEffect(() => {
// B28/B36: clear stale previous-wallet data immediately before the async
// fetch so the UI never shows another wallet's private P&L.
setTrades([])
setPrivateLocked(false)
// Navigation only uses a cached envelope — never auto-popup the wallet.
void loadAll()
// eslint-disable-next-line react-hooks/exhaustive-deps
@@ -157,7 +179,8 @@ export default function AnalyticsPageClient() {
const bestTrade = pnls.length ? Math.max(...pnls) : 0
const worstTrade = pnls.length ? Math.min(...pnls) : 0
const avgTrade = pnls.length ? totalPnl / pnls.length : 0
const avgHold = filteredTrades.length ? filteredTrades.reduce((sum, trade) => sum + trade.hold_seconds, 0) / filteredTrades.length : 0
const heldTrades = filteredTrades.filter(t => t.hold_seconds !== null)
const avgHold = heldTrades.length ? heldTrades.reduce((sum, trade) => sum + (trade.hold_seconds ?? 0), 0) / heldTrades.length : 0
// One basis for every window: derive from the closed_at-filtered trades.
const maxDrawdown = calcDrawdownPct(filteredTrades)
const summaryPnl = totalPnl
@@ -169,11 +192,11 @@ export default function AnalyticsPageClient() {
tip: 'How many closed positions in this window. Open trades not counted.' },
{ k: isZh ? '平均持仓时间' : 'Avg hold time', v: filteredTrades.length ? fmtHold(Math.round(avgHold)) : '—', sub: isZh ? '按单笔计算' : 'Per trade',
tip: 'Entry → exit duration averaged across every closed trade.' },
{ k: isZh ? '平均单笔盈亏' : 'Avg trade P&L', v: fmtMoney(avgTrade), sub: isZh ? '每笔交易均值' : 'Mean per trade', up: avgTrade > 0,
{ k: isZh ? '平均单笔盈亏' : 'Avg trade P&L', v: pnls.length ? fmtMoney(avgTrade) : '—', sub: isZh ? '每笔交易均值' : 'Mean per trade', up: avgTrade > 0,
tip: 'Total P&L ÷ number of trades. Positive = the strategy has edge per trade.' },
{ k: isZh ? '最佳单笔' : 'Best trade', v: fmtMoney(bestTrade), sub: isZh ? '单笔最大盈利' : 'Largest single win', up: true,
{ k: isZh ? '最佳单笔' : 'Best trade', v: pnls.length ? fmtMoney(bestTrade) : '—', sub: isZh ? '单笔最大盈利' : 'Largest single win', up: true,
tip: 'Biggest realized gain on one trade in this window.' },
{ k: isZh ? '最差单笔' : 'Worst trade', v: fmtMoney(worstTrade), sub: isZh ? '单笔最大亏损' : 'Largest single loss', down: true,
{ k: isZh ? '最差单笔' : 'Worst trade', v: pnls.length ? fmtMoney(worstTrade) : '—', sub: isZh ? '单笔最大亏损' : 'Largest single loss', down: true,
tip: 'Biggest realized loss on one trade. Should be bounded by your stop-loss setting.' },
]
@@ -183,8 +206,7 @@ export default function AnalyticsPageClient() {
<div>
<h1 className="page-title">{isZh ? '分析面板' : 'Analytics'}</h1>
<PageHint>
Did the bot actually make money? Win rate, drawdown, average trade,
and AI signal accuracy across the time window you pick on the right.
P&amp;L · win rate · drawdown · signal accuracy pick a time window on the right.
</PageHint>
</div>
<div style={{ display: 'flex', flexDirection: 'column', gap: 8, alignItems: 'flex-end' }}>
@@ -207,6 +229,55 @@ export default function AnalyticsPageClient() {
</div>
</div>
{/* Signal accuracy — always public, shown first so non-connected visitors
can immediately see proof of signal quality without needing to log in. */}
{accuracy && (
<div className="card" style={{ padding: 20, marginBottom: 20 }}>
<div style={{ display: 'flex', alignItems: 'baseline', gap: 12, marginBottom: 14, flexWrap: 'wrap' }}>
<div className="tiny">AI Signal Accuracy</div>
<span style={{ fontSize: 12, color: 'var(--ink-4)' }}>{accuracy.total_directional_signals} directional signals measured</span>
<span style={{ fontSize: 11, color: 'var(--up)', fontWeight: 600, marginLeft: 'auto' }}>Public · no login needed</span>
</div>
<div style={{ display: 'grid', gridTemplateColumns: 'repeat(auto-fill, minmax(140px, 1fr))', gap: 8 }}>
{/* Overall */}
<div style={{ background: 'var(--surface-2)', borderRadius: 10, padding: '12px 14px' }}>
<div style={{ fontSize: 11, fontWeight: 600, color: 'var(--ink-3)', marginBottom: 8, textTransform: 'uppercase', letterSpacing: '0.06em' }}>Overall</div>
{(['m5','m15','m1h'] as const).map(w => {
const d = accuracy.overall[w]
const pct = d.accuracy_pct
const color = pct >= 55 ? 'var(--up)' : pct >= 45 ? 'var(--ink-2)' : 'var(--down)'
return (
<div key={w} className="row between" style={{ marginBottom: 3 }}>
<span style={{ fontSize: 11, color: 'var(--ink-3)' }}>{w.replace('m1','1').replace('m','')}</span>
<span style={{ fontSize: 13, fontWeight: 700, color, fontVariantNumeric: 'tabular-nums' }}>{pct != null ? `${pct.toFixed(0)}%` : '—'}</span>
</div>
)
})}
</div>
{Object.entries(accuracy.by_signal).map(([sig, data]) => {
const label = sig === 'buy' ? '🟢 Buy' : sig === 'short' ? '🔴 Short' : '🟡 Sell'
return (
<div key={sig} style={{ background: 'var(--surface-2)', borderRadius: 10, padding: '12px 14px' }}>
<div style={{ fontSize: 11, fontWeight: 600, color: 'var(--ink-3)', marginBottom: 8, textTransform: 'uppercase', letterSpacing: '0.06em' }}>{label} <span style={{ fontWeight: 400 }}>({data.count})</span></div>
{(['m5','m15','m1h'] as const).map(w => {
const d = data[w]
if (d.checked < 2) return <div key={w} className="row between" style={{ marginBottom: 3 }}><span style={{ fontSize: 11, color: 'var(--ink-3)' }}>{w.replace('m1','1').replace('m','')}</span><span style={{ fontSize: 12, color: 'var(--ink-3)' }}></span></div>
const pct = d.accuracy_pct
const color = pct >= 55 ? 'var(--up)' : pct >= 45 ? 'var(--ink-2)' : 'var(--down)'
return (
<div key={w} className="row between" style={{ marginBottom: 3 }}>
<span style={{ fontSize: 11, color: 'var(--ink-3)' }}>{w.replace('m1','1').replace('m','')}</span>
<span style={{ fontSize: 13, fontWeight: 700, color, fontVariantNumeric: 'tabular-nums' }}>{pct.toFixed(0)}%</span>
</div>
)
})}
</div>
)
})}
</div>
</div>
)}
{isPaperView && filteredTrades.length > 0 && (
<div className="card" style={{
padding: '10px 16px', marginBottom: 16, fontSize: 12, fontWeight: 600,
@@ -265,60 +336,16 @@ export default function AnalyticsPageClient() {
))}
</div>
{accuracy && (
<div className="card" style={{ padding: 24, marginBottom: 20 }}>
<div className="tiny" style={{ marginBottom: 16 }}>{isZh ? `AI 信号准确率 · ${accuracy.total_directional_signals} 条方向性信号` : `AI Signal Accuracy · ${accuracy.total_directional_signals} directional signals`}</div>
<div style={{ display: 'grid', gridTemplateColumns: 'repeat(auto-fill, minmax(200px, 1fr))', gap: 12 }}>
<div style={{ background: 'var(--surface-2)', borderRadius: 10, padding: '14px 16px' }}>
<div style={{ fontSize: 11, fontWeight: 600, color: 'var(--ink-3)', marginBottom: 8, textTransform: 'uppercase', letterSpacing: '0.06em' }}>{isZh ? '整体' : 'Overall'}</div>
{(['m5','m15','m1h'] as const).map(w => {
const d = accuracy.overall[w]
const pct = d.accuracy_pct
const color = pct >= 55 ? 'var(--up)' : pct >= 45 ? 'var(--ink-2)' : 'var(--down)'
return (
<div key={w} className="row between" style={{ marginBottom: 4 }}>
<span style={{ fontSize: 12, color: 'var(--ink-3)' }}>{w.replace('m','').replace('1h','1h')}</span>
<span style={{ fontSize: 13, fontWeight: 600, color, fontVariantNumeric: 'tabular-nums' }}>{fmtAccuracyPct(pct)}</span>
</div>
)
})}
<div style={{ fontSize: 11, color: 'var(--ink-3)', marginTop: 6 }}>{isZh ? `${accuracy.overall.m5.checked} 条已测` : `${accuracy.overall.m5.checked} measured`}</div>
</div>
{Object.entries(accuracy.by_signal).map(([sig, data]) => {
const label = sig === 'buy' ? (isZh ? '🟢 做多' : '🟢 Buy') : sig === 'short' ? (isZh ? '🔴 做空' : '🔴 Short') : (isZh ? '🟡 卖出' : '🟡 Sell')
return (
<div key={sig} style={{ background: 'var(--surface-2)', borderRadius: 10, padding: '14px 16px' }}>
<div style={{ fontSize: 11, fontWeight: 600, color: 'var(--ink-3)', marginBottom: 8, textTransform: 'uppercase', letterSpacing: '0.06em' }}>{label} <span style={{ fontWeight: 400 }}>({data.count})</span></div>
{(['m5','m15','m1h'] as const).map(w => {
const d = data[w]
if (d.checked < 2) return (
<div key={w} className="row between" style={{ marginBottom: 4 }}>
<span style={{ fontSize: 12, color: 'var(--ink-3)' }}>{w}</span>
<span style={{ fontSize: 12, color: 'var(--ink-3)' }}></span>
</div>
)
const pct = d.accuracy_pct
const color = pct >= 55 ? 'var(--up)' : pct >= 45 ? 'var(--ink-2)' : 'var(--down)'
return (
<div key={w} className="row between" style={{ marginBottom: 4 }}>
<span style={{ fontSize: 12, color: 'var(--ink-3)' }}>{w}</span>
<span style={{ fontSize: 13, fontWeight: 600, color, fontVariantNumeric: 'tabular-nums' }}>{fmtAccuracyPct(pct)}</span>
</div>
)
})}
<div style={{ fontSize: 11, color: 'var(--ink-3)', marginTop: 6 }}>{isZh ? `${data.m5.checked} 条已测` : `${data.m5.checked} measured`}</div>
</div>
)
})}
</div>
</div>
)}
{/* Signal accuracy is now shown at the top of the page (public, no login needed).
Removed duplicate block here to avoid showing the same data twice. */}
{!filteredTrades.length && (
<div className="card" style={{ padding: 60, textAlign: 'center', color: 'var(--ink-3)' }}>
<p style={{ fontSize: 14 }}>
{!isConnected || !address
? (isZh ? '连接钱包以加载你的分析数据。' : 'Connect your wallet to load your analytics.')
: privateLocked
? (isZh ? '签名解锁后可查看你的真实业绩和交易历史。' : 'Sign once above to unlock your personal P&L and trade history.')
: trades.length
? (isZh ? `${period} 时间窗内还没有已平仓交易。` : `No trades closed in the ${period} window yet.`)
: (isZh ? '还没有交易数据。机器人开始执行后,这里会自动出现统计。' : 'No trade data yet. The bot will populate analytics once it starts executing.')}
+28
View File
@@ -0,0 +1,28 @@
/** Instant skeleton while AnalyticsPage loads. */
export default function AnalyticsLoading() {
return (
<div className="page">
<div className="page-head" style={{ marginBottom: 24 }}>
<div className="skeleton sk-title" style={{ width: 160, marginBottom: 8 }} />
</div>
<div style={{ display: 'grid', gridTemplateColumns: 'repeat(auto-fit, minmax(140px, 1fr))', gap: 12, marginBottom: 20 }}>
{Array.from({ length: 3 }).map((_, i) => (
<div key={i} className="skeleton-card" style={{ padding: 20 }}>
<div className="skeleton sk-line sk-w-half" style={{ marginBottom: 12 }} />
<div className="skeleton" style={{ height: 40, width: 100 }} />
</div>
))}
</div>
<div className="skeleton-card" style={{ padding: 24 }}>
<div className="skeleton sk-line" style={{ width: 140, marginBottom: 16 }} />
{Array.from({ length: 5 }).map((_, i) => (
<div key={i} style={{ display: 'flex', gap: 12, marginBottom: 10 }}>
<div className="skeleton sk-line" style={{ width: 80 }} />
<div className="skeleton sk-line" style={{ width: 60 }} />
<div className="skeleton sk-line sk-w-3q" />
</div>
))}
</div>
</div>
)
}
+79 -49
View File
@@ -1,68 +1,98 @@
'use client'
import { useState, useEffect, useMemo } from 'react'
import { useLocale } from 'next-intl'
import { useState, useEffect } from 'react'
import type { TrumpPost } from '@/types'
import { getPosts } from '@/lib/api'
import { getPosts, getPostsPage, type PostListResponse } from '@/lib/api'
import { hasCached, swrFetch } from '@/lib/cache'
import PostRow from '@/components/dashboard/PostCards'
import PageHint from '@/components/ui/PageHint'
import Pagination from '@/components/ui/Pagination'
import { buildArchiveFallbackResponse } from '@/lib/postPage'
const ARCHIVE_PAGE_SIZE = 30
const LIVE_SOURCES = new Set([
'truth',
'btc_bottom_reversal',
'funding_reversal',
'kol_divergence',
])
interface ArchivePageClientProps {
initialData?: PostListResponse | null
}
/**
* Archive — legacy / test signals (rsi_reversal, sma_reclaim, breakout,
* test, phase1…). NOT a live system. Kept only so old data is inspectable.
*/
export default function ArchivePageClient() {
const locale = useLocale()
const isZh = false // i18n shelved — Chinese branches kept as dead code for future revival; see messages/zh.json
const [posts, setPosts] = useState<TrumpPost[]>([])
const [loading, setLoading] = useState(true)
export default function ArchivePageClient({ initialData = null }: ArchivePageClientProps) {
const [posts, setPosts] = useState<TrumpPost[]>(initialData?.items ?? [])
const [totalPosts, setTotalPosts] = useState(initialData?.total ?? 0)
const [sourceCounts, setSourceCounts] = useState(initialData?.source_counts ?? [])
const [loading, setLoading] = useState(initialData === null)
const [loadErr, setLoadErr] = useState('')
const [src, setSrc] = useState<string>('all')
const [archivePage, setArchivePage] = useState(1)
useEffect(() => {
getPosts(500, 1)
.then(p => { setPosts(p); setLoadErr('') })
.catch(e => setLoadErr(e instanceof Error ? e.message : (isZh ? '历史归档加载失败' : 'Failed to load archive')))
.finally(() => setLoading(false))
}, [isZh])
const key = `archive-page-${archivePage}-src-${src}`
setLoadErr('')
setLoading(posts.length === 0 && !hasCached(key))
// Archive = legacy / test data only. Exclude every live signal source so
// active modules don't leak in here as users explore old experiments. Keep
// this set in sync with sources emitted by app/services/scanners/*.
const archivePosts = useMemo(
() => posts.filter(p => !LIVE_SOURCES.has(p.source || '')),
[posts],
swrFetch(
key,
3 * 60_000,
() => getPostsPage(
ARCHIVE_PAGE_SIZE,
archivePage,
undefined,
{
archiveOnly: true,
sourceIn: src === 'all' ? undefined : [src],
},
),
fresh => {
setPosts(fresh.items)
setTotalPosts(fresh.total)
setSourceCounts(fresh.source_counts)
},
)
const sources = useMemo(() => {
const m: Record<string, number> = {}
for (const p of archivePosts) m[p.source || '?'] = (m[p.source || '?'] || 0) + 1
return Object.entries(m).sort((a, b) => b[1] - a[1])
}, [archivePosts])
const filtered = useMemo(
() => src === 'all' ? archivePosts : archivePosts.filter(p => p.source === src),
[archivePosts, src],
.then(r => {
setPosts(r.items)
setTotalPosts(r.total)
setSourceCounts(r.source_counts)
})
.catch(async e => {
const detail = e instanceof Error ? e.message : 'Failed to load archive'
if (!detail.includes('404')) {
setLoadErr(detail)
return
}
try {
const legacyPosts = await swrFetch(
'archive-legacy-500',
3 * 60_000,
() => getPosts(500, 1),
)
const archiveTotalPages = Math.max(1, Math.ceil(filtered.length / ARCHIVE_PAGE_SIZE))
const fallback = buildArchiveFallbackResponse(legacyPosts, archivePage, ARCHIVE_PAGE_SIZE, src)
setPosts(fallback.items)
setTotalPosts(fallback.total)
setSourceCounts(fallback.source_counts)
setLoadErr('')
} catch (legacyErr) {
setLoadErr(legacyErr instanceof Error ? legacyErr.message : detail)
}
})
.finally(() => setLoading(false))
}, [archivePage, posts.length, src])
const archiveTotalPages = Math.max(1, Math.ceil(totalPosts / ARCHIVE_PAGE_SIZE))
const archiveSafePage = Math.min(archivePage, archiveTotalPages)
const archivePageItems = filtered.slice((archiveSafePage - 1) * ARCHIVE_PAGE_SIZE, archiveSafePage * ARCHIVE_PAGE_SIZE)
const allSourcesCount = sourceCounts.reduce((sum, item) => sum + item.count, 0)
const selectedCount = src === 'all'
? totalPosts
: sourceCounts.find(s => s.source === src)?.count ?? totalPosts
const sourceTabs: [string, number][] = [
['all', allSourcesCount],
...sourceCounts.map(item => [item.source, item.count] as [string, number]),
]
return (
<div className="page">
<div className="page-head">
<div>
<h1 className="page-title">Archive</h1>
<PageHint count={`${archivePosts.length} legacy posts`}>
<PageHint count={`${selectedCount} legacy posts`}>
Signals from retired scanner experiments
(rsi_reversal, sma_reclaim, breakout, test/phase1). Read-only
the bot no longer acts on any of these.
@@ -71,7 +101,7 @@ export default function ArchivePageClient() {
</div>
<div style={{ display: 'flex', gap: 6, flexWrap: 'wrap', marginBottom: 12 }}>
{[['all', archivePosts.length] as [string, number], ...sources].map(([s, n]) => (
{sourceTabs.map(([s, n]) => (
<button
key={s}
onClick={() => { setSrc(s); setArchivePage(1) }}
@@ -87,30 +117,30 @@ export default function ArchivePageClient() {
))}
</div>
{loading && <div style={{ textAlign: 'center', padding: 60, color: 'var(--ink-3)' }}>{isZh ? '加载中…' : 'Loading…'}</div>}
{loading && <div style={{ textAlign: 'center', padding: 60, color: 'var(--ink-3)' }}>Loading</div>}
{!loading && loadErr && (
<div className="card" style={{ padding: 24, textAlign: 'center', color: 'var(--down)' }}>
{isZh ? `无法加载归档:${loadErr}` : `Couldn't load archive — ${loadErr}`}
{`Couldn't load archive — ${loadErr}`}
<div style={{ marginTop: 10 }}>
<button className="btn ghost" style={{ fontSize: 12, padding: '6px 14px' }}
onClick={() => location.reload()}>{isZh ? '重试' : 'Retry'}</button>
onClick={() => location.reload()}>Retry</button>
</div>
</div>
)}
{!loading && !loadErr && filtered.length === 0 && (
{!loading && !loadErr && totalPosts === 0 && (
<div className="card" style={{ padding: 48, textAlign: 'center', color: 'var(--ink-3)' }}>
{isZh ? '没有可显示的历史信号。' : 'No archived signals.'}
No archived signals.
</div>
)}
{!loading && archivePageItems.length > 0 && (
{!loading && posts.length > 0 && (
<>
<div className="post-stream">
{archivePageItems.map(p => <PostRow key={p.id} post={p} />)}
{posts.map(p => <PostRow key={p.id} post={p} />)}
</div>
<Pagination
page={archiveSafePage}
total={archiveTotalPages}
count={filtered.length}
count={totalPosts}
pageSize={ARCHIVE_PAGE_SIZE}
onChange={setArchivePage}
/>
+14 -2
View File
@@ -1,13 +1,25 @@
// Archive is legacy/test data only — not part of the live signal stack.
// noindex keeps it out of search results (duplicate/thin content risk)
// while keeping it accessible to logged-in users for inspection.
export const revalidate = 60 // archive data rarely changes — ISR at 60s keeps server load low
import type { Metadata } from 'next'
import { type PostListResponse } from '@/lib/api'
import { getPosts } from '@/lib/api'
import { buildArchiveFallbackResponse, getInitialPostPage } from '@/lib/postPage'
import ArchivePageClient from './ArchivePageClient'
export const metadata: Metadata = {
robots: { index: false, follow: false },
}
export default function ArchivePage() {
return <ArchivePageClient />
export default async function ArchivePage() {
const initialData: PostListResponse | null = await getInitialPostPage(30, 1, {
filters: { archiveOnly: true },
legacyFallback: async () => {
const legacyItems = await getPosts(500, 1).catch(() => null)
return legacyItems ? buildArchiveFallbackResponse(legacyItems, 1, 30) : null
},
})
return <ArchivePageClient initialData={initialData} />
}
+2 -2
View File
@@ -1,4 +1,4 @@
import { redirect } from 'next/navigation'
import { permanentRedirect } from 'next/navigation'
interface LegacyBtcPageProps {
params: Promise<{ locale: string }>
@@ -6,5 +6,5 @@ interface LegacyBtcPageProps {
export default async function LegacyBtcPage({ params }: LegacyBtcPageProps) {
const { locale } = await params
redirect(`/${locale}/macro`)
permanentRedirect(`/${locale}/macro`)
}
+19 -53
View File
@@ -173,14 +173,14 @@ function getCopy(locale: string): CaseStudiesCopy {
ogDescription:
'Historical cases that show why the Trump, BTC, and KOL engines exist: posts, wallet behavior, price reaction, and evidence.',
heroTitle: 'Case Studies',
heroSubtitle: 'Real events, real positioning, and real price reactions — documented.',
heroSubtitle: 'Real events, real price moves — why these signals are worth tracking.',
intro:
'This is not a performance-claims page. It is an evidence page. Each case answers three questions: what happened, how the market reacted, and why that event supports one of the signal engines.',
'Three documented cases where the signal worked. Not forecasts — history.',
statAsset: 'Asset',
statImpact: 'Price impact',
statImpact: 'Move',
statWindow: 'Window',
evidenceLabel: 'Evidence',
footer: 'These cases illustrate the historical basis for each signal engine. They are not return forecasts.',
evidenceLabel: 'Source',
footer: 'Past events don\'t guarantee future results. These cases show why the signal categories exist.',
footerMethodology: 'Methodology',
footerGlossary: 'Glossary',
cases: [
@@ -188,85 +188,51 @@ function getCopy(locale: string): CaseStudiesCopy {
id: 'strategic-reserve-2025',
date: 'March 2, 2025',
source: 'Trump Truth Social',
title: 'Strategic Crypto Reserve announcement',
summary: 'Trump confirmed a U.S. Strategic Crypto Reserve including BTC, ETH, SOL, XRP, and ADA.',
title: 'Trump announces U.S. Strategic Crypto Reserve — BTC +8%, ETH +10%',
summary: 'Trump posted confirmation of a U.S. Strategic Crypto Reserve including BTC, ETH, SOL, XRP, and ADA. Markets moved within minutes.',
signal: 'LONG',
asset: 'BTC / ETH',
priceImpact: 'BTC +8.2%, ETH +10%+',
impactWindow: '24 hours',
detail:
'This case mattered because the post moved from vague political tone into explicit asset-level policy language. A signal engine should classify that as a high-conviction LONG event, because it names specific assets and ties them to a state-level commitment.',
'The post named specific assets and tied them to a government-level commitment — the clearest possible bullish signal. This is exactly what the Trump signal engine is built to catch: a post that goes from vague political tone to explicit crypto policy in one statement.',
evidence:
'CNBC and Al Jazeera both documented the market response, and exchange plus on-chain data showed clear momentum-driven inflows after the post.',
'CNBC and Al Jazeera documented the market response. Exchange data showed immediate momentum-driven inflows.',
externalUrl:
'https://www.cnbc.com/2025/03/02/trump-announces-strategic-crypto-reserve-including-bitcoin-solana-xrp-and-more.html',
},
{
id: 'whale-6m-perp',
date: 'March 2025',
source: 'On-chain / Truth Social',
title: '$6.8M pre-positioning profit around the reserve post',
summary:
'An anonymous address built a large leveraged BTC/ETH position around the reserve announcement and reportedly closed it the same day for roughly $6.8M profit.',
signal: 'LONG',
asset: 'BTC',
priceImpact: '+$6.8M',
impactWindow: 'Same day',
detail:
'This case highlights two facts at once. First, Trump-linked posts can create enough directional force to matter. Second, speed itself is edge in event-driven trading. Whether this was advance positioning or ultra-fast automation, it validates the post-to-trade-to-PnL chain.',
evidence:
'The trade was documented by Raw Story / NewsBreak, and TIME later referenced the political and regulatory scrutiny around the episode.',
externalUrl:
'https://www.newsbreak.com/raw-story-2096750/4286876592634-that-s-the-maga-playbook-crypto-trade-made-moments-before-trump-post-raises-eyebrows',
},
{
id: 'tariff-china-2025',
date: 'April 2025',
source: 'Trump Truth Social',
title: 'Tariff escalation post triggered a risk-off move',
summary: 'A tariff-escalation post created a short-term macro risk-off setup rather than a bullish crypto reaction.',
title: 'Tariff escalation post — BTC -4% in 4 hours',
summary: 'A tariff-escalation post compressed risk appetite fast. BTC dropped 4.1% in 4 hours — no crypto-specific news, just macro sentiment repricing.',
signal: 'SHORT',
asset: 'BTC',
priceImpact: 'BTC -4.1%',
impactWindow: '4 hours',
detail:
'Not every Trump post is bullish for crypto. Posts framed around trade conflict, tariff escalation, tighter regulation, or macro uncertainty can compress risk appetite quickly. This case supports the need for a real SHORT branch in the signal engine.',
'Not every Trump post is bullish for crypto. Trade conflict, tariffs, and macro uncertainty posts can hit crypto just as hard as equity markets. This is why the signal engine has a real SHORT branch — and why noise filtering matters.',
evidence:
'CoinDesk has documented multiple instances of Trump statements moving BTC. This post fits that broader historical pattern of immediate sentiment repricing.',
'CoinDesk has documented multiple Trump statements that moved BTC in both directions.',
externalUrl:
'https://www.coindesk.com/markets/2026/04/20/five-times-president-trump-made-a-statement-that-moved-bitcoin-and-why-it-might-happen-again-this-week',
},
{
id: 'kol-divergence-example',
date: 'Illustrative composite',
source: 'KOL post + on-chain wallet',
title: 'Publicly bullish on ETH, privately reducing ETH',
date: 'Composite example',
source: 'KOL post + tracked wallet',
title: 'KOL bullish on ETH in public, selling ETH on-chain',
summary:
'A tracked KOL published a bullish ETH thesis, then reduced roughly $180k of ETH exposure within five days. That is classic talks-vs-trades divergence.',
'A tracked KOL published a bullish ETH thesis. Within 5 days, their wallet reduced ~$180k of ETH exposure. Public pitch said buy — the wallet said sell.',
signal: 'DIVERGENCE',
asset: 'ETH',
priceImpact: 'N/A',
impactWindow: '±7 days',
detail:
'This example is not about a single post moving price. It is about the information gap between public narrative and real positioning. For research-heavy users, that gap is often more valuable than a simple bullish or bearish statement.',
'Words are free. Wallet moves cost money. When a KOL\'s on-chain behavior contradicts their public call, the wallet is usually telling the truth. This is why the KOL module tracks both — and why divergence is the highest-conviction category.',
evidence:
'The divergence classification comes from the platforms cross-signal logic, which is documented in full on the Methodology page.',
},
{
id: 'btc-bottom-nov-2022',
date: 'November 2022',
source: 'Historical BTC macro-bottom reference',
title: 'The $15.5k FTX washout zone',
summary:
'After the FTX collapse, BTC entered the $15.5k region and later recovered toward $69k within roughly 18 months. This is the kind of regime the BTC macro-bottom engine is built to identify.',
signal: 'LONG',
asset: 'BTC',
priceImpact: '+345%',
impactWindow: '18 months',
detail:
'The current live BTC engine is not trying to replay an old premium-data model. It is trying to locate the same market structure with AHR999, the 200-week moving average, and Pi Cycle Bottom: deep value, long-cycle support, and emotional washout lining up together.',
evidence:
'Public price archives and long-range market charts consistently mark the FTX washout zone as the core bottom region of that bear market.',
'Divergence detection logic is documented on the Methodology page.',
},
],
}
+640 -308
View File
File diff suppressed because it is too large Load Diff
+42 -41
View File
@@ -171,104 +171,105 @@ function getCopy(locale: string): GlossaryCopy {
],
ogTitle: 'Crypto Signals Glossary | Trump Alpha',
ogDescription:
'Clear definitions of Trump Alphas core terms, optimized for search, AI retrieval, and fast reference.',
'Clear definitions of Trump Alpha\'s core terms, optimized for search, AI retrieval, and fast reference.',
heroTitle: 'Glossary',
heroSubtitle: 'Every term on the platform, defined precisely.',
intro:
'Definitions for all the metrics, signal terms, and trading concepts you\'ll encounter on this platform.',
'Quick definitions for the terms you\'ll encounter on this platform.',
terms: [
{
term: 'AHR999',
category: 'Macro-bottom metric',
category: 'Macro-bottom signal',
definition:
'AHR999 is a Bitcoin valuation indicator popular in Chinese crypto research. It combines long-term trend and cost-basis style anchors to estimate whether BTC is trading in a deep-value regime. In Trump Alpha, AHR999 below 0.45 counts as one classic bottom signal.',
extra: 'It is one of the three inputs in the live BTC 2-of-3 macro-bottom scanner.',
'A Bitcoin valuation score. Below 0.45 = BTC is historically cheap and in a potential bottom zone. Above 1.2 = overvalued, bottom thesis is off. One of three conditions in the BTC bottom scanner.',
},
{
term: 'Pi Cycle Bottom',
category: 'Macro-bottom metric',
category: 'Macro-bottom signal',
definition:
'Pi Cycle Bottom is a Bitcoin bottom framework based on long-cycle moving-average relationships. In Trump Alpha, the condition is satisfied when the 150-day EMA falls below the 471-day SMA multiplied by 0.745.',
extra: 'It is one of the three core inputs in the BTC macro-bottom scanner.',
'A long-term moving-average signal that has historically aligned with Bitcoin cycle lows. Fires when the 150-day EMA crosses below the 471-day SMA × 0.745. Binary — either confirmed or not.',
},
{
term: '200-week Moving Average',
category: 'Macro-bottom metric',
category: 'Macro-bottom signal',
definition:
'The 200-week moving average is one of Bitcoins most widely watched long-term trend anchors. Many historical bear-market lows formed near this zone. Trump Alpha treats price proximity to the 200-week MA as part of BTC bottom confluence.',
'BTC\'s most-watched long-term support level. Every major bear-market low in history formed at or near it. The scanner counts price ≤ 200WMA × 1.05 as a bottom vote.',
},
{
term: 'KOL',
abbr: 'Key Opinion Leader',
category: 'Platform term',
definition:
'In crypto, a KOL is an analyst, fund manager, host, or creator whose public views consistently influence market narrative or retail positioning. Trump Alpha emphasizes long-form KOL sources, not only short social fragments.',
'An analyst, fund manager, podcast host, or creator whose calls move crypto narrative. The platform tracks 25 KOLs — Arthur Hayes, Delphi, Bankless, and others — cross-checking what they say publicly against what their wallets actually do.',
},
{
term: 'Talks-vs-Trades Divergence',
category: 'Platform term',
definition:
'Talks-vs-trades divergence happens when a KOLs public stance and wallet behavior point in opposite directions on the same asset. Example: a KOL publishes a bullish ETH thesis while their wallet reduces ETH exposure that same week. Trump Alpha treats the wallet move as the higher-priority truth signal.',
extra: 'This is one of the platforms highest-information signals because it separates narrative from actual positioning.',
'When a KOL\'s public call and their wallet move in opposite directions on the same asset. Example: publicly bullish ETH while quietly reducing ETH on-chain. The wallet is treated as the real signal — it\'s harder to fake than words.',
extra: 'Highest-conviction signal category on the platform.',
},
{
term: 'Conviction Score',
term: 'Aligned',
category: 'Platform term',
definition:
'Conviction Score is the AI-generated strength score assigned to each extracted KOL view, typically ranging from 0.0 to 1.0. Higher values imply clearer language, stronger commitment, and better evidence of timing or sizing intent.',
'A KOL\'s public call and their tracked wallet activity agree — e.g., bullish on BTC and the wallet is adding BTC. Reinforces the signal.',
},
{
term: 'Mismatch',
category: 'Platform term',
definition:
'A KOL\'s public call contradicts their wallet move. Bullish in public, selling on-chain = mismatch. This is the divergence signal you actually want to act on.',
},
{
term: 'Paper mode',
category: 'Platform term',
definition:
'Simulated trading — the bot runs through all its logic and tracks positions, but no real orders are sent to Hyperliquid. Use it to see how the bot would have performed before risking real money.',
},
{
term: '/adopt',
category: 'Platform term',
definition:
'A Telegram bot command. When a Macro Vibes signal fires, you open the position yourself on Hyperliquid, then send /adopt in the bot. The bot then takes over managing the exit — stop ladder, partial de-risk, pyramiding — without you having to watch it.',
},
{
term: 'AI Confidence',
category: 'Platform term',
definition:
'A percentage score (0100%) the AI assigns to each Trump post signal. Higher = the post language is clearer and more explicitly directional. The default threshold is 70% — signals below this are not traded.',
},
{
term: 'Funding Rate',
category: 'Derivatives term',
definition:
'Funding rate is the periodic payment mechanism used by perpetual futures to keep contract pricing anchored to spot. If longs pay shorts, the market is long-crowded. If shorts pay longs, the market is short-crowded. Extreme readings often precede liquidation-driven reversals.',
'The periodic payment between long and short traders on a perp exchange, designed to keep the contract price close to spot. Extreme positive funding = crowded longs. Extreme negative = crowded shorts. Extreme readings often precede sharp reversals when the crowded side gets squeezed.',
},
{
term: 'Isolated Margin',
category: 'Trading term',
definition:
'Isolated margin means each trade uses its own dedicated margin rather than sharing risk with the rest of the account. If one position is liquidated, it does not automatically cascade into other positions.',
extra: 'Trump Alphas execution layer is designed around isolated margin.',
'Each trade uses only its own dedicated margin — if it gets liquidated, it doesn\'t touch your other positions. Trump Alpha always uses isolated margin so one bad trade can\'t wipe the account.',
},
{
term: 'TP / SL',
abbr: 'Take-Profit / Stop-Loss',
category: 'Trading term',
definition:
'TP and SL are conditional exit orders for profit-taking and loss control. Trump Alphas auto-trader attaches both at entry rather than after the position is already open.',
},
{
term: 'UTXO',
abbr: 'Unspent Transaction Output',
category: 'Bitcoin term',
definition:
'UTXO is the fundamental accounting unit of the Bitcoin network. Trump Alphas live Macro Vibes module no longer relies directly on UTXO-spend behavior, but the concept still matters for interpreting classic on-chain research.',
'Automatic exit orders placed at entry. TP closes the trade in profit at your target. SL closes it to cut losses. Trump Alpha attaches both the moment a trade opens.',
},
{
term: 'Perpetual Future',
abbr: 'Perp',
category: 'Derivatives term',
definition:
'A perp is a futures contract with no expiry date. It stays open until the trader closes it or gets liquidated, while funding rate and mark-price mechanisms help keep it close to spot. Hyperliquid is one example of a perp venue.',
},
{
term: 'Substack Signal',
category: 'Platform term',
definition:
'A Substack signal is an extracted asset view taken from a KOLs long-form essay, newsletter, or blog post. These sources usually contain fuller reasoning than short posts and therefore produce more retrieval-friendly signal data.',
'A futures contract with no expiry. You stay in the trade until you close it or get liquidated. Trump Alpha executes on Hyperliquid perps.',
},
{
term: 'Capitulation',
category: 'Market term',
definition:
'Capitulation is the stage of a drawdown when holders finally give up and sell into weakness. It often appears near the end of a bear market and is one of the environments the BTC bottom scanner is designed to detect.',
},
{
term: 'EMA',
abbr: 'Exponential Moving Average',
category: 'Technical term',
definition:
'EMA is a moving average that gives more weight to recent price data than older data. Trump Alpha uses the 150-day EMA inside the Pi Cycle Bottom condition.',
'The phase near a bear market bottom where panicked holders give up and sell en masse. Creates the washout conditions that the BTC macro-bottom scanner is designed to detect.',
},
],
footerLead: 'Missing a term?',
+220 -165
View File
@@ -1,6 +1,6 @@
'use client'
import { useEffect, useMemo, useState } from 'react'
import { useEffect, useMemo, useRef, useState } from 'react'
import { createPortal } from 'react-dom'
import { useLocale } from 'next-intl'
import type {
@@ -42,8 +42,8 @@ function actionLabel(action: KolTicker['action'], isZh: boolean) {
}
function windowLabel(days: number, isZh: boolean) {
if (days === 1) return isZh ? '今日' : 'Today'
return isZh ? `${days}` : `Last ${days}d`
if (days === 1) return 'Today'
return `Last ${days}d`
}
function changeLabel(changeType: KolHoldingChange['change_type'], isZh: boolean) {
@@ -100,6 +100,7 @@ function chainActionLabel(action: string, isZh: boolean) {
function sourceLabel(source: string, isZh: boolean) {
if (source === 'substack') return 'Substack'
if (source === 'blog') return 'Blog'
if (source === 'podcast') return 'Podcast'
if (source === 'twitter') return 'X'
return source
@@ -138,19 +139,20 @@ function DigestWidget({
activeTicker,
isZh,
initialDigest = null,
days,
}: {
onTickerClick: (ticker: string) => void
activeTicker?: string | null
isZh: boolean
initialDigest?: KolDigest | null
days: number
}) {
const [days, setDays] = useState<number>(7)
const [data, setData] = useState<KolDigest | null>(initialDigest)
const [loading, setLoading] = useState(initialDigest === null)
const [err, setErr] = useState('')
useEffect(() => {
if (initialDigest === null || days !== (initialDigest?.window_days ?? 7)) {
if (initialDigest === null || days !== (initialDigest?.window_days ?? 30)) {
setLoading(true)
}
swrFetch(
@@ -160,64 +162,34 @@ function DigestWidget({
fresh => setData(fresh),
)
.then(d => { setData(d); setErr('') })
.catch(e => setErr(e instanceof Error ? e.message : (isZh ? '加载失败' : 'Failed to load digest')))
.catch(e => setErr(e instanceof Error ? e.message : ('Failed to load digest')))
.finally(() => setLoading(false))
}, [days, initialDigest, isZh])
return (
<div style={{
marginBottom: 16, padding: 'clamp(12px, 3vw, 18px)',
borderRadius: 12, background: 'var(--surface)',
border: '1px solid var(--line)',
}}>
<div style={{
display: 'flex', justifyContent: 'space-between',
alignItems: 'center', flexWrap: 'wrap', gap: 8, marginBottom: 12,
}}>
<div>
<div style={{ fontSize: 10, color: 'var(--ink-3)',
letterSpacing: 1, textTransform: 'uppercase',
marginBottom: 2 }}>
What KOLs are pushing now
<div style={{ marginBottom: 10 }}>
{/* Compact meta line — no header label needed, context is obvious */}
{data && !loading && (
<div style={{ fontSize: 12, color: 'var(--ink-4)', marginBottom: 8 }}>
{data.post_count} posts · {data.ticker_count} assets
</div>
<div style={{ fontSize: 13, color: 'var(--ink-2)' }}>
{data
? `${data.post_count} posts analysed · ${data.ticker_count} assets with repeat mentions`
: 'Loading…'}
</div>
</div>
<div className="nav-tabs" style={{ background: 'var(--bg-sunk)' }}>
{WINDOW_OPTIONS.map(daysOption => (
<button
key={daysOption}
onClick={() => setDays(daysOption)}
className={`nav-tab ${days === daysOption ? 'active' : ''}`}
style={{ border: 'none', cursor: 'pointer', fontSize: 12 }}
>
{windowLabel(daysOption, isZh)}
</button>
))}
</div>
</div>
)}
{loading && (
<div style={{ padding: 16, textAlign: 'center', color: 'var(--ink-3)',
fontSize: 12 }}>Loading</div>
<div style={{ padding: '8px 0', color: 'var(--ink-3)', fontSize: 12 }}>Loading</div>
)}
{err && (
<div style={{ padding: 12, color: '#dc2626', fontSize: 12 }}>{err}</div>
)}
{!loading && !err && data && data.tickers.length === 0 && (
<div style={{ padding: 16, textAlign: 'center', color: 'var(--ink-3)',
fontSize: 13 }}>
No actionable calls in this window. Try a longer range.
<div style={{ padding: '8px 0', color: 'var(--ink-3)', fontSize: 13 }}>
No repeat mentions in this window.
</div>
)}
{!loading && !err && data && data.tickers.length > 0 && (
<div style={{
display: 'grid',
gridTemplateColumns: 'repeat(auto-fit, minmax(190px, 1fr))',
gap: 10,
gridTemplateColumns: 'repeat(auto-fit, minmax(170px, 1fr))',
gap: 8,
}}>
{data.tickers.map(t => <DigestTickerChip
key={t.ticker}
@@ -267,7 +239,7 @@ function DigestTickerChip({
aria-pressed={active}
>
<div style={{ display: 'flex', alignItems: 'center', gap: 8, width: '100%' }}>
<strong style={{ fontSize: 18, color: 'var(--ink-1)' }}>
<strong style={{ fontSize: 18, color: 'var(--ink)' }}>
{t.ticker}
</strong>
{active && (
@@ -294,11 +266,10 @@ function DigestTickerChip({
{actionLabel}
</span>
</div>
<div style={{ fontSize: 12, color: 'var(--ink-2)', fontWeight: 600 }}>
{digestSideCopy(t.side)}
</div>
{/* Compact: KOL count + handles in two lines, no "Bullish flow" copy
(Long/Short label already conveys direction). */}
<div style={{ fontSize: 12, color: 'var(--ink-3)' }}>
{t.kol_count} KOL{t.kol_count !== 1 ? 's' : ''} · {(t.max_conviction * 100).toFixed(0)}% max conviction
{t.kol_count} KOL{t.kol_count !== 1 ? 's' : ''} · {(t.max_conviction * 100).toFixed(0)}%
</div>
<div style={{
fontSize: 11, color: 'var(--ink-3)',
@@ -330,9 +301,11 @@ function WalletCheckWidget({
initialChanges = null,
initialItems = null,
tickerFilter = null,
days,
}: {
isZh: boolean
dateLocale: string
days: number
initialDigest?: KolDigest | null
initialChanges?: KolHoldingChange[] | null
initialItems?: KolDivergence[] | null
@@ -344,41 +317,48 @@ function WalletCheckWidget({
const [loading, setLoading] = useState(
initialDigest === null || initialChanges === null || initialItems === null,
)
const [days, setDays] = useState(7)
// `days` now comes from the parent — no local state needed.
// genRef lets in-flight fetches detect they were superseded by a newer
// days/filter change before writing back to state.
const walletCheckGenRef = useRef(0)
useEffect(() => {
const gen = ++walletCheckGenRef.current
setLoading(true)
Promise.all([
swrFetch(
`kol-digest-${days}`,
15 * 60_000,
() => getKolDigest(days),
fresh => setDigest(fresh),
fresh => { if (gen === walletCheckGenRef.current) setDigest(fresh) },
),
swrFetch(
`kol-changes-${days}`,
30 * 60_000,
() => getKolChanges({ days }),
fresh => setChanges(fresh.changes),
fresh => { if (gen === walletCheckGenRef.current) setChanges(fresh.changes) },
),
swrFetch(
`kol-divergence-all-${days}`,
30 * 60_000,
() => getKolDivergence({ days }),
fresh => setItems(fresh.items),
fresh => { if (gen === walletCheckGenRef.current) setItems(fresh.items) },
),
])
.then(([nextDigest, nextChanges, nextItems]) => {
if (gen !== walletCheckGenRef.current) return
setDigest(nextDigest)
setChanges(nextChanges.changes)
setItems(nextItems.items)
})
.catch(() => {
if (gen !== walletCheckGenRef.current) return
setDigest(null)
setChanges([])
setItems([])
})
.finally(() => setLoading(false))
.finally(() => { if (gen === walletCheckGenRef.current) setLoading(false) })
}, [days])
const rows = useMemo(() => {
@@ -458,43 +438,21 @@ function WalletCheckWidget({
borderRadius: 12, background: 'var(--surface)',
border: '1px solid var(--line)',
}}>
<div style={{
display: 'flex', justifyContent: 'space-between',
alignItems: 'flex-start', flexWrap: 'wrap', gap: 8, marginBottom: 12,
}}>
<div>
<div style={{ fontSize: 10, color: 'var(--ink-3)', letterSpacing: 1,
textTransform: 'uppercase', marginBottom: 2 }}>
Talks vs wallets
</div>
<div style={{ fontSize: 13, color: 'var(--ink-2)' }}>
{loading
? 'Loading…'
: rows.length === 0
? 'No overlapping talk and wallet evidence in this window.'
: `${totalAligned} aligned · ${totalMismatch} mismatched across the assets KOLs are pushing`}
</div>
</div>
<div className="nav-tabs" style={{ background: 'var(--bg-sunk)' }}>
{([1, 7, 30] as const).map(d => (
<button
key={d}
onClick={() => setDays(d)}
className={`nav-tab ${days === d ? 'active' : ''}`}
style={{ border: 'none', cursor: 'pointer', fontSize: 12 }}
>
{windowLabel(d, isZh)}
</button>
))}
</div>
{/* Compact summary — no uppercase header, no redundant label */}
{!loading && rows.length > 0 && (
<div style={{ fontSize: 12, color: 'var(--ink-4)', marginBottom: 10 }}>
{totalAligned > 0 && <span style={{ color: '#22c55e', marginRight: 8 }}> {totalAligned} aligned</span>}
{totalMismatch > 0 && <span style={{ color: '#f59e0b' }}> {totalMismatch} mismatch</span>}
{totalAligned === 0 && totalMismatch === 0 && 'Wallet evidence pending'}
</div>
)}
{!loading && rows.length === 0 && (
<div style={{
padding: '12px 16px', borderRadius: 8, background: 'var(--bg-sunk)',
fontSize: 12, color: 'var(--ink-3)', lineHeight: 1.6,
}}>
When KOLs call an asset, do tracked wallets back it up? No overlap yet in this window widen the range or check back after the next feed run.
No wallet overlap for this window try a wider range.
</div>
)}
@@ -521,7 +479,7 @@ function WalletCheckWidget({
{row.verdict.label}
</span>
</div>
<div style={{ fontSize: 13, color: 'var(--ink-1)', fontWeight: 600, marginBottom: 4 }}>
<div style={{ fontSize: 13, color: 'var(--ink)', fontWeight: 600, marginBottom: 4 }}>
{row.talkLine}
</div>
<div style={{ fontSize: 12, color: 'var(--ink-3)', whiteSpace: 'nowrap', overflow: 'hidden', textOverflow: 'ellipsis' }}>
@@ -533,10 +491,8 @@ function WalletCheckWidget({
</div>
<div style={{ minWidth: 0 }}>
<div style={{ fontSize: 11, color: 'var(--ink-3)', textTransform: 'uppercase', letterSpacing: 0.8, marginBottom: 5 }}>
Wallet evidence
</div>
<div style={{ fontSize: 13, color: 'var(--ink-1)', fontWeight: 600, marginBottom: 4 }}>
{/* No "WALLET EVIDENCE" label — context is clear from layout */}
<div style={{ fontSize: 13, color: 'var(--ink)', fontWeight: 600, marginBottom: 4 }}>
{row.latestMatch
? `@${row.latestMatch.handle} ${chainActionLabel(row.latestMatch.onchain_action, isZh).toLowerCase()}`
: row.latestChange
@@ -544,9 +500,13 @@ function WalletCheckWidget({
: 'No tracked move yet'}
</div>
<div style={{ fontSize: 12, color: 'var(--ink-3)', lineHeight: 1.5 }}>
{row.latestMatch
? `${row.verdict.note} ${row.latestMatch.usd_after ? `Size ${formatShortUsd(row.latestMatch.usd_after)}.` : ''}`
: row.verdict.note}
{/* Drop boilerplate "Wallet action supports/disagrees the public pitch."
the verdict badge already says Aligned / Mismatch. Just show the size. */}
{row.latestMatch?.usd_after
? `Size ${formatShortUsd(row.latestMatch.usd_after)}`
: row.verdict.label === 'No wallet proof'
? 'No tracked wallet move in this window'
: ''}
</div>
{(row.divergenceCount > 0 || row.alignmentCount > 0) && (
<div style={{ display: 'flex', gap: 8, flexWrap: 'wrap', marginTop: 6 }}>
@@ -660,7 +620,7 @@ function PostDetail({
margin: 0, fontSize: 'clamp(16px, 4.5vw, 22px)',
lineHeight: 1.3, wordBreak: 'break-word',
}}>
{post.title || (isZh ? '(无标题)' : '(Untitled)')}
{post.title || post.summary || (post.source === 'twitter' ? '(Tweet)' : '(Untitled)')}
</h2>
</div>
@@ -679,7 +639,7 @@ function PostDetail({
whiteSpace: 'nowrap',
}}
>
{isZh ? `查看原帖 ${postSourceLabel}` : `Open original ${postSourceLabel}`}
{`Open original ${postSourceLabel}`}
</a>
)}
<button
@@ -703,7 +663,7 @@ function PostDetail({
}}>
<div style={{ fontSize: 10, color: 'var(--ink-3)', marginBottom: 4,
letterSpacing: 1, textTransform: 'uppercase' }}>
{isZh ? 'AI 摘要' : 'AI summary'}
{'AI summary'}
</div>
{post.summary}
</div>
@@ -714,7 +674,7 @@ function PostDetail({
<div style={{ margin: '12px 0' }}>
<div style={{ fontSize: 10, color: 'var(--ink-3)', marginBottom: 6,
letterSpacing: 1, textTransform: 'uppercase' }}>
{isZh ? '提取标的' : 'Extracted assets'}
{'Extracted assets'}
</div>
<div style={{ display: 'flex', flexDirection: 'column', gap: 8 }}>
{post.tickers.map((t, i) => (
@@ -729,7 +689,7 @@ function PostDetail({
{actionLabel(t.action, isZh)}
</span>
<span style={{ fontSize: 11, color: 'var(--ink-3)' }}>
{isZh ? '信心分' : 'Conviction'} {(t.conviction * 100).toFixed(0)}%
{'Conviction'} {(t.conviction * 100).toFixed(0)}%
</span>
</div>
<div style={{ fontSize: 12, color: 'var(--ink-2)',
@@ -748,7 +708,7 @@ function PostDetail({
}}>
<div style={{ fontSize: 10, color: 'var(--ink-3)', marginBottom: 8,
letterSpacing: 1, textTransform: 'uppercase' }}>
{isZh ? '原文摘录' : 'Source excerpt'}
{'Source excerpt'}
</div>
<div style={{
whiteSpace: 'pre-wrap', fontSize: 13, lineHeight: 1.7,
@@ -767,8 +727,12 @@ function PostDetail({
return createPortal(node, document.body)
}
type SourceFilter = 'all' | 'substack' | 'blog' | 'podcast' | 'twitter'
const KOL_SERVER_PAGE_SIZE = 50
interface KolPageProps {
initialPosts?: KolPostSummary[] | null
initialTotal?: number
initialDigest?: KolDigest | null
initialChanges?: KolHoldingChange[] | null
initialDivergence?: KolDivergence[] | null
@@ -776,78 +740,142 @@ interface KolPageProps {
export default function KolPage({
initialPosts = null,
initialTotal = 0,
initialDigest = null,
initialChanges = null,
initialDivergence = null,
}: KolPageProps) {
const locale = useLocale()
const isZh = false // i18n shelved — Chinese branches kept as dead code for future revival; see messages/zh.json
const dateLocale = isZh ? 'zh-CN' : 'en-US'
const KOL_PAGE_SIZE = 20
const dateLocale = 'en-US'
const isZh = false // i18n shelved — passed to helper fns that still take the param
const [posts, setPosts] = useState<KolPostSummary[]>(initialPosts ?? [])
const [serverTotal, setServerTotal] = useState(initialTotal)
const [loading, setLoading] = useState(initialPosts === null)
const [err, setErr] = useState('')
const [openPost, setOpenPost] = useState<KolPostDetail | null>(null)
const [handleFilter, setHandleFilter] = useState<string>('all')
const [sourceFilter, setSourceFilter] = useState<SourceFilter>('all')
const [signalsOnly, setSignalsOnly] = useState(false)
const [tickerFilter, setTickerFilter] = useState<string | null>(null)
const [kolPage, setKolPage] = useState(1)
const [serverPage, setServerPage] = useState(1)
// Unified time window — controls both DigestWidget and WalletCheckWidget.
// Default 30d, not 7d: KOL ingestion is daily and sparse, so a 7d window is
// frequently empty (e.g. 7d=0 while 30d=196) and the first paint showed
// "No data yet" for modules that actually have data.
const [kolDays, setKolDays] = useState(30)
const postsGenRef = useRef(0)
useEffect(() => {
const gen = ++postsGenRef.current
setLoading(true)
const src = sourceFilter === 'all' ? undefined : sourceFilter
const cacheKey = `kol-posts-${sourceFilter}-${signalsOnly}-${serverPage}-${tickerFilter ?? ''}-${kolDays}`
swrFetch(
'kol-posts-100',
cacheKey,
15 * 60_000, // 15 min TTL — KOL feed is ingested daily
() => getKolPosts({ limit: 100 }),
fresh => setPosts(fresh.items),
() => getKolPosts({
limit: KOL_SERVER_PAGE_SIZE, page: serverPage, source: src, signalsOnly,
ticker: tickerFilter ?? undefined, days: kolDays,
}),
fresh => { if (gen === postsGenRef.current) { setPosts(fresh.items); setServerTotal(fresh.total ?? 0) } },
)
.then(r => { setPosts(r.items); setErr('') })
.catch(e => setErr(e instanceof Error ? e.message : (isZh ? '加载失败' : 'Failed to load posts')))
.finally(() => setLoading(false))
}, [isZh])
.then(r => {
if (gen !== postsGenRef.current) return
setPosts(r.items); setServerTotal(r.total ?? 0); setErr('')
})
.catch(e => { if (gen === postsGenRef.current) setErr(e instanceof Error ? e.message : ('Failed to load posts')) })
.finally(() => { if (gen === postsGenRef.current) setLoading(false) })
}, [sourceFilter, signalsOnly, serverPage, tickerFilter, kolDays])
const handles = useMemo(() => {
const set = new Set(posts.map(p => p.kol_handle))
return ['all', ...Array.from(set)]
}, [posts])
// posts are already filtered server-side; no client-side re-filter needed
const filtered = posts
const filtered = useMemo(() => {
let out = handleFilter === 'all' ? posts : posts.filter(p => p.kol_handle === handleFilter)
if (tickerFilter) {
out = out.filter(p => p.tickers.some(t => t.ticker === tickerFilter))
}
return out
}, [posts, handleFilter, tickerFilter])
const kolTotalPages = Math.max(1, Math.ceil(filtered.length / KOL_PAGE_SIZE))
const kolSafePage = Math.min(kolPage, kolTotalPages)
const kolPageItems = filtered.slice((kolSafePage - 1) * KOL_PAGE_SIZE, kolSafePage * KOL_PAGE_SIZE)
const totalServerPages = Math.max(1, Math.ceil(serverTotal / KOL_SERVER_PAGE_SIZE))
async function openDetail(id: number) {
try {
const detail = await getKolPost(id)
setOpenPost(detail)
} catch (e) {
setErr(e instanceof Error ? e.message : (isZh ? '详情加载失败' : 'Failed to load detail'))
setErr(e instanceof Error ? e.message : ('Failed to load detail'))
}
}
function changeSource(src: SourceFilter) {
setSourceFilter(src)
setServerPage(1)
setTickerFilter(null)
}
return (
<div className="page">
<div className="page-head">
<div>
<h1 className="page-title">{isZh ? 'KOL 信号' : 'KOL Signals'}</h1>
<PageHint count={`${posts.length} posts`}>
Which assets KOLs are pushing right now and whether tracked wallets back it up or call their bluff.
<h1 className="page-title">{'KOL Signals'}</h1>
<PageHint count={`${serverTotal} posts`}>
Arthur Hayes, Delphi, Bankless, and 22 more their public calls vs what their wallets actually do.
</PageHint>
</div>
{/* Single time filter controlling both widgets */}
<div className="nav-tabs" style={{ background: 'var(--bg-sunk)', alignSelf: 'flex-start' }}>
{WINDOW_OPTIONS.map(d => (
<button
key={d}
onClick={() => { setKolDays(d); setServerPage(1) }}
className={`nav-tab ${kolDays === d ? 'active' : ''}`}
style={{ border: 'none', cursor: 'pointer', fontSize: 12 }}
>
{windowLabel(d, isZh)}
</button>
))}
</div>
</div>
{/* Source filter — All / Substack / X + Signals only toggle */}
<div style={{ display: 'flex', alignItems: 'center', gap: 6, marginBottom: 12, flexWrap: 'wrap' }}>
{(['all', 'substack', 'blog', 'podcast', 'twitter'] as SourceFilter[]).map(src => {
const label = src === 'all' ? 'All' : src === 'substack' ? 'Substack' : src === 'blog' ? 'Blog' : src === 'podcast' ? 'Podcast' : 'X (Twitter)'
const active = sourceFilter === src
return (
<button
key={src}
onClick={() => changeSource(src)}
style={{
padding: '4px 12px', borderRadius: 6, fontSize: 12, fontWeight: 600,
cursor: 'pointer', border: '1px solid var(--line)',
background: active ? 'var(--amber)' : 'var(--surface)',
color: active ? '#000' : 'var(--ink-2)',
transition: 'background 0.15s, color 0.15s',
}}
>
{label}
</button>
)
})}
<button
onClick={() => { setSignalsOnly(v => !v); setServerPage(1) }}
title="Exclude noise posts (short tweets, gm, RT). Long-form and directional posts are kept."
style={{
marginLeft: 8,
padding: '4px 12px', borderRadius: 6, fontSize: 12, fontWeight: 600,
cursor: 'pointer',
border: `1px solid ${signalsOnly ? '#16a34a88' : 'var(--line)'}`,
background: signalsOnly ? '#16a34a22' : 'var(--surface)',
color: signalsOnly ? '#16a34a' : 'var(--ink-3)',
transition: 'background 0.15s, color 0.15s, border-color 0.15s',
}}
>
{signalsOnly ? '✓ Signals only' : 'Signals only'}
</button>
</div>
<DigestWidget
isZh={isZh}
initialDigest={initialDigest}
activeTicker={tickerFilter}
days={kolDays}
onTickerClick={(sym) => {
setTickerFilter(prev => prev === sym ? null : sym)
setKolPage(1)
setServerPage(1)
}}
/>
@@ -858,6 +886,7 @@ export default function KolPage({
initialChanges={initialChanges}
initialItems={initialDivergence}
tickerFilter={tickerFilter}
days={kolDays}
/>
{tickerFilter && (
@@ -865,47 +894,38 @@ export default function KolPage({
display: 'flex', alignItems: 'center', gap: 8,
marginBottom: 12, fontSize: 12,
}}>
<span style={{ color: 'var(--ink-3)' }}>{isZh ? '当前筛选标的:' : 'Filtered asset:'}</span>
<span style={{ color: 'var(--ink-3)' }}>{'Filtered asset:'}</span>
<strong>{tickerFilter}</strong>
<button
onClick={() => { setTickerFilter(null); setKolPage(1) }}
onClick={() => { setTickerFilter(null); setServerPage(1) }}
style={{
background: 'var(--bg-sunk)', border: '1px solid var(--line)',
borderRadius: 4, padding: '2px 8px',
cursor: 'pointer', fontSize: 11, color: 'var(--ink-2)',
}}
>{isZh ? '清除 ✕' : 'Clear ✕'}</button>
>{'Clear ✕'}</button>
</div>
)}
{handles.length > 2 && (
<div className="nav-tabs" style={{ background: 'var(--bg-sunk)', marginBottom: 12 }}>
{handles.map(h => (
<button
key={h}
onClick={() => { setHandleFilter(h); setKolPage(1) }}
className={`nav-tab ${handleFilter === h ? 'active' : ''}`}
style={{ border: 'none', cursor: 'pointer' }}
>
{h === 'all' ? (isZh ? `全部 (${posts.length})` : `All (${posts.length})`) : `@${h}`}
</button>
))}
{/* KOL handle filter removed 25 handles as a horizontal tab bar
overflows on every screen size and most users filter by asset (ticker),
not by person. Handle is visible on each post card. */}
<div style={{ margin: '12px 0 4px', fontSize: 11, fontWeight: 600, letterSpacing: '0.06em', textTransform: 'uppercase', color: 'var(--ink-4)' }}>
All posts · paginated feed
</div>
)}
{loading && <KolPostsSkeleton />}
{err && <div style={{ padding: 20, color: '#dc2626' }}>{isZh ? `错误:${err}` : `Error: ${err}`}</div>}
{err && <div style={{ padding: 20, color: '#dc2626' }}>{`Error: ${err}`}</div>}
{!loading && !err && (
<div style={{ display: 'flex', flexDirection: 'column', gap: 10 }}>
{filtered.length === 0 && (
<div style={{ padding: 40, textAlign: 'center', color: 'var(--ink-3)' }}>
{isZh
? '当前没有数据,等待下一轮抓取任务(每天 01:15 UTC)。'
: 'No data yet. Wait for the next feed ingestion run (daily 01:15 UTC).'}
{'No data yet. Wait for the next feed ingestion run (daily 01:15 UTC).'}
</div>
)}
{kolPageItems.map(p => (
{filtered.map(p => (
<div
key={p.id}
onClick={() => openDetail(p.id)}
@@ -927,10 +947,44 @@ export default function KolPage({
@{p.kol_handle} · {sourceLabel(p.source, isZh)} · {new Date(p.published_at).toLocaleDateString(dateLocale)}
</div>
<div style={{ display: 'flex', alignItems: 'center', gap: 8, flexShrink: 0 }}>
{p.tier === 'trade_signal' && (
<span style={{
fontSize: 10, fontWeight: 700, letterSpacing: '0.04em',
padding: '2px 6px', borderRadius: 4,
background: '#16a34a22', color: '#16a34a',
border: '1px solid #16a34a44',
whiteSpace: 'nowrap',
}}>
SIGNAL
</span>
)}
{p.tier === 'directional' && (
<span style={{
fontSize: 10, fontWeight: 700, letterSpacing: '0.04em',
padding: '2px 6px', borderRadius: 4,
background: '#f59e0b22', color: '#f59e0b',
border: '1px solid #f59e0b44',
whiteSpace: 'nowrap',
}}>
VIEW
</span>
)}
{p.talks_vs_trades_flag && (
<span title="Public stance contradicts revealed position in this post"
style={{
fontSize: 10, fontWeight: 700,
padding: '2px 6px', borderRadius: 4,
background: '#ef444422', color: '#ef4444',
border: '1px solid #ef444444',
whiteSpace: 'nowrap',
}}>
FLIP
</span>
)}
<span style={{ fontSize: 11, color: 'var(--ink-3)' }}>
{p.analyzed_at
? (isZh ? '✓ 已分析' : '✓ Analyzed')
: (isZh ? '⏳ 待分析' : '⏳ Pending')}
? ('✓ Analyzed')
: ('⏳ Pending')}
</span>
{p.url && (
<a
@@ -946,16 +1000,17 @@ export default function KolPage({
whiteSpace: 'nowrap',
}}
>
{isZh ? '原帖 ↗' : 'Source ↗'}
{'Source ↗'}
</a>
)}
</div>
</div>
<div style={{ fontSize: 16, fontWeight: 600, marginBottom: 6,
wordBreak: 'break-word' }}>
{p.title || (isZh ? '(无标题)' : '(Untitled)')}
{p.title || p.summary || (p.source === 'twitter' ? '(Tweet)' : '(Untitled)')}
</div>
{p.summary && (
{/* Only show summary as a separate line when there's a real title above it */}
{p.title && p.summary && (
<div style={{ fontSize: 13, color: 'var(--ink-2)', lineHeight: 1.5,
marginBottom: 8 }}>
{p.summary}
@@ -966,11 +1021,11 @@ export default function KolPage({
))}
<Pagination
page={kolSafePage}
total={kolTotalPages}
count={filtered.length}
pageSize={KOL_PAGE_SIZE}
onChange={setKolPage}
page={serverPage}
total={totalServerPages}
count={serverTotal}
pageSize={KOL_SERVER_PAGE_SIZE}
onChange={setServerPage}
scrollTop={false}
/>
</div>
+27
View File
@@ -0,0 +1,27 @@
/** Instant skeleton while KolPage fetches posts and digest. */
export default function KolLoading() {
return (
<div className="page">
<div className="page-head" style={{ marginBottom: 24 }}>
<div>
<div className="skeleton sk-title" style={{ width: 140, marginBottom: 8 }} />
<div className="skeleton sk-line" style={{ width: 260 }} />
</div>
</div>
{Array.from({ length: 6 }).map((_, i) => (
<div key={i} className="skeleton-card" style={{ marginBottom: 10, padding: 18 }}>
<div style={{ display: 'flex', gap: 12, alignItems: 'center', marginBottom: 10 }}>
<div className="skeleton" style={{ width: 36, height: 36, borderRadius: '50%', flexShrink: 0 }} />
<div style={{ flex: 1 }}>
<div className="skeleton sk-line" style={{ width: 120, marginBottom: 6 }} />
<div className="skeleton sk-line-sm" style={{ width: 80 }} />
</div>
<div className="skeleton sk-line" style={{ width: 60 }} />
</div>
<div className="skeleton sk-line sk-w-full" style={{ marginBottom: 6 }} />
<div className="skeleton sk-line sk-w-3q" />
</div>
))}
</div>
)
}
+12 -8
View File
@@ -19,8 +19,8 @@ export async function generateMetadata({
return {
title: isZh ? 'KOL 信号与言行偏离追踪' : 'KOL Signals & Talks-vs-Trades Divergence',
description: isZh
? '从 15 个加密 KOL 信息源中提取可执行观点,覆盖 Arthur Hayes、Delphi Digital、Bankless、Empire、Unchained 等,并追踪“说法”和链上仓位是否一致。'
: 'AI-extracted crypto signals from 19 KOL feeds: Arthur Hayes, Delphi Digital, Bankless, Empire, Unchained and more. Includes talks-vs-trades divergence — when KOL wallets contradict their public posts.',
? '从 25 个加密 KOL 信息源中提取可执行观点,覆盖 Arthur Hayes、Delphi Digital、Bankless、Empire、Unchained 等,并追踪“说法”和链上仓位是否一致。'
: 'AI-extracted crypto signals from 25 KOL feeds: Arthur Hayes, Delphi Digital, Bankless, Empire, Unchained and more. Includes talks-vs-trades divergence — when KOL wallets contradict their public posts.',
keywords: isZh
? [
'KOL 加密信号',
@@ -48,7 +48,7 @@ export async function generateMetadata({
title: isZh ? 'KOL 信号与言行偏离 | Trump Alpha' : 'KOL Signals & Talks-vs-Trades | Trump Alpha',
description: isZh
? '每天分析 KOL 长文、播客和公开观点,再与链上仓位交叉验证,找出真正有信息增量的观点与偏离。'
: '19 KOL feeds (Hayes, Bankless, Empire…) AI-scored daily. Plus talks-vs-trades: when their wallets contradict their words.',
: '25 KOL feeds (Hayes, Bankless, Empire…) AI-scored daily. Plus talks-vs-trades: when their wallets contradict their words.',
},
alternates: {
canonical: `${siteUrl}/en/kol`,
@@ -60,7 +60,7 @@ export async function generateMetadata({
}
}
// GEO: the KOL talks-vs-trades feed is a dataset cross-referencing 19 crypto
// GEO: the KOL talks-vs-trades feed is a dataset cross-referencing 25 crypto
// KOLs' public statements against their on-chain wallet behaviour.
const kolDataset = {
'@context': 'https://schema.org',
@@ -68,7 +68,7 @@ const kolDataset = {
'@id': `${siteUrl}/en/kol#dataset`,
name: 'Crypto KOL talks-vs-trades divergence dataset',
description:
'Daily cross-reference of 19 crypto KOLs\' public statements (Substack / podcast) against their on-chain Ethereum wallet activity, flagging divergence when public stance and real positioning disagree within a ±7-day window.',
'Daily cross-reference of 25 crypto KOLs\' public statements (Substack / podcast) against their on-chain Ethereum wallet activity, flagging divergence when public stance and real positioning disagree within a ±7-day window.',
url: `${siteUrl}/en/kol`,
keywords: ['crypto KOL', 'on-chain', 'divergence', 'wallet tracking', 'sentiment'],
isAccessibleForFree: true,
@@ -80,10 +80,13 @@ const kolDataset = {
}
export default async function KolPage() {
// days=30 must match the client default (KolPageClient kolDays=30) so the
// SSR payload and first client render agree — otherwise content flashes on
// mount. 7d is frequently empty while 30d has data.
const [posts, digest, changes, divergence] = await Promise.all([
getKolPosts({ limit: 100 }).catch(() => null),
getKolDigest(7).catch(() => null),
getKolChanges({ days: 7 }).catch(() => null),
getKolPosts({ limit: 50, page: 1, days: 30 }).catch(() => null),
getKolDigest(30).catch(() => null),
getKolChanges({ days: 30 }).catch(() => null),
getKolDivergence({ days: 30 }).catch(() => null),
])
@@ -96,6 +99,7 @@ export default async function KolPage() {
<Breadcrumbs items={[{ name: 'KOL talks-vs-trades', path: '/en/kol' }]} />
<KolPageClient
initialPosts={posts?.items ?? null}
initialTotal={posts?.total ?? 0}
initialDigest={digest}
initialChanges={changes?.changes ?? null}
initialDivergence={divergence?.items ?? null}
+2
View File
@@ -6,6 +6,7 @@ import Link from 'next/link'
import { locales } from '@/i18n'
import Providers from './Providers'
import Navbar from '@/components/nav/Navbar'
import TradeAlertBanner from '@/components/ui/TradeAlertBanner'
const siteUrl = process.env.NEXT_PUBLIC_SITE_URL || 'https://trumpsignal.com'
@@ -46,6 +47,7 @@ export default async function LocaleLayout({ children, params }: LayoutProps) {
<NextIntlClientProvider messages={messages}>
<Providers>
<Navbar />
<TradeAlertBanner />
<main>{children}</main>
<footer style={{
borderTop: '1px solid var(--line)',
+30 -39
View File
@@ -9,7 +9,7 @@ import { swrFetch } from '@/lib/cache'
import PostRow from '@/components/dashboard/PostCards'
import SystemControl from '@/components/signals/SystemControl'
import InfoTip from '@/components/ui/InfoTip'
import PageHint from '@/components/ui/PageHint'
import SignalMonitor from '@/components/dashboard/SignalMonitor'
// MacroPanel is 631 lines with heavy indicator math — split it out.
const MacroPanel = dynamic(() => import('@/components/btc/MacroPanel'), {
@@ -84,23 +84,29 @@ export default function MacroVibesPage({
<div className="page">
<div className="page-head">
<div>
<h1 className="page-title">{isZh ? '宏观氛围' : 'Macro Vibes'}</h1>
{/* PageHint: brand tagline for the page same across both tabs so
the "what is this page" answer doesn't shift under the user when
they click between Bottom / Funding. Tab-specific notes live in
the section-hint card right below the tab bar. */}
<PageHint>
Macro vibes for crypto. Read what&apos;s about to happen before price prints it.
</PageHint>
<div style={{ display: 'flex', alignItems: 'center', gap: 8, flexWrap: 'wrap' }}>
<h1 className="page-title" style={{ margin: 0 }}>{isZh ? '宏观氛围' : 'Macro Vibes'}</h1>
<span style={{
display: 'inline-flex', alignItems: 'center', gap: 4,
padding: '2px 8px', borderRadius: 6, fontSize: 11, fontWeight: 700,
background: 'var(--bg-sunk)',
color: 'var(--ink-3)', border: '1px solid var(--line)',
letterSpacing: '0.04em',
}}>
{isZh ? '手动开仓 · Bot 托管' : 'You open · bot manages'}
</span>
</div>
</div>
<span className="chip"><span className="live-dot" />Live</span>
</div>
<SystemControl system="btc" />
<div className="nav-tabs" style={{
background: 'var(--bg-sunk)', marginTop: 16, marginBottom: 12,
}}>
{/* Tabs + inline description on the same row avoids a separate
"section hint" block that adds a third layer before the data. */}
<div style={{ display: 'flex', alignItems: 'center', gap: 16,
flexWrap: 'wrap', marginTop: 14, marginBottom: 14 }}>
<div className="nav-tabs" style={{ background: 'var(--bg-sunk)', flexShrink: 0 }}>
<button
onClick={() => setTab('bottom')}
className={`nav-tab ${tab === 'bottom' ? 'active' : ''}`}
@@ -116,38 +122,25 @@ export default function MacroVibesPage({
{isZh ? '资金费率反转' : 'Funding Reversal'}
</button>
</div>
{/* Always-visible per-tab explanation. Was hidden behind a hover
tooltip on the tab button users couldn't tell what they were
about to look at until they explicitly hovered. */}
{tab === 'bottom' && (
<div className="section-hint">
Fires when <strong>2 of 3</strong> classic bottom signals agree:{' '}
<strong>AHR999 &lt; 0.45</strong> · <strong>price 200-week MA</strong> · <strong>Pi Cycle Bottom</strong>.
{' '}Long-only · 24 fires per cycle · trailing-stop exit · max hold ~18 months.
<span style={{ fontSize: 12, color: 'var(--ink-3)', lineHeight: 1.4 }}>
{tab === 'bottom'
? <><strong style={{ color: 'var(--ink-2)' }}>2 of 3:</strong> AHR999 &lt; 0.45 · 200w MA · Pi Cycle Bottom long-only, rare.</>
: <>Fades crowded perps when 30d cumulative funding crosses <strong>±3%</strong> and cools. Hourly.</>}
</span>
</div>
)}
{/* Macro indicator panel only relevant on the Macro Bottom tab where
users are reasoning about the broader risk regime. The Funding tab
has its own live funding panel below. */}
{tab === 'bottom' && <MacroPanel />}
{tab === 'funding' && (
<div className="section-hint">
Mean-reversion against crowded perp positioning. When 30-day cumulative funding crosses{' '}
<strong>±3%</strong> and recent cycles start cooling, the scanner fades the crowded side.
Checked hourly.
</div>
)}
{/* Old plain-text per-tab description removed the same content
now lives in the section-hint block above the tab content. */}
{tab === 'funding' && (
<>
<FundingPanel
isZh={isZh}
initialSnapshot={initialFundingSnapshot}
/>
<SignalMonitor />
</>
)}
<div style={{ display: 'flex', gap: 6, flexWrap: 'wrap', margin: '16px 0 12px' }}>
@@ -179,13 +172,11 @@ export default function MacroVibesPage({
)}
{!loading && !loadErr && filtered.length === 0 && (
<div className="card" style={{ padding: 48, textAlign: 'center', color: 'var(--ink-3)' }}>
{tab === 'bottom' ? 'No bottom signals yet.' : 'No funding signals yet.'}
<div style={{ fontSize: 12, marginTop: 6 }}>
{tab === 'bottom'
? 'No macro-bottom signals yet.'
: 'No funding-reversal signals yet.'}
<div style={{ fontSize: 12, marginTop: 8 }}>
{tab === 'bottom'
? 'This scanner is intentionally rare — only fires at genuine macro bottoms (daily 00:45 UTC).'
: 'Fires when 30-day cumulative funding exceeds ±3% AND starts mean-reverting. See the live panel above for current state.'}
? 'Intentionally rare — fires only at genuine cycle bottoms.'
: 'Check the live panel above for current funding state.'}
</div>
</div>
)}
+29
View File
@@ -0,0 +1,29 @@
/** Instant skeleton while MacroVibesPage fetches indicator data. */
export default function MacroLoading() {
return (
<div className="page">
<div className="page-head" style={{ marginBottom: 24 }}>
<div>
<div className="skeleton sk-title" style={{ width: 160, marginBottom: 8 }} />
<div className="skeleton sk-line" style={{ width: 300 }} />
</div>
</div>
{/* Composite score card */}
<div className="skeleton-card" style={{ marginBottom: 16, padding: 24 }}>
<div className="skeleton sk-line" style={{ width: 120, marginBottom: 16 }} />
<div className="skeleton" style={{ height: 48, width: 200, marginBottom: 16 }} />
<div className="skeleton" style={{ height: 24, width: '100%', borderRadius: 12 }} />
</div>
{/* 8-indicator grid */}
<div style={{ display: 'grid', gridTemplateColumns: 'repeat(2, 1fr)', gap: 12 }}>
{Array.from({ length: 8 }).map((_, i) => (
<div key={i} className="skeleton-card" style={{ padding: 20 }}>
<div className="skeleton sk-line sk-w-half" style={{ marginBottom: 12 }} />
<div className="skeleton" style={{ height: 36, width: 100, marginBottom: 8 }} />
<div className="skeleton sk-line-sm sk-w-3q" />
</div>
))}
</div>
</div>
)
}
+4 -1
View File
@@ -64,7 +64,10 @@ export async function generateMetadata({
export default async function MacroVibesPage() {
const [posts, fundingSnapshot] = await Promise.all([
getPosts(500, 1).catch(() => null),
// The default tab is the bottom-reversal view. Fetch only the source this
// page actually renders on first paint instead of hydrating with the
// latest global post firehose and filtering it client-side.
getPosts(200, 1, 'btc_bottom_reversal').catch(() => null),
getFundingSnapshot().catch(() => null),
])
+4 -2
View File
@@ -19,7 +19,7 @@ export async function generateMetadata({ params }: OverviewPageProps): Promise<M
: 'Trump Alpha — Live Crypto Signal Desk'
const description = isZh
? 'Endorphin 研究台追踪四个先于市场共识的信号:Trump 帖子、BTC 宏观底部、资金费率极值,以及 KOL 言行偏离。每个信号公开且带时间戳。'
: 'Endorphin tracks four signals that move crypto before the crowd: Trump posts, BTC macro bottoms, funding-rate extremes, and what KOLs do vs say. Public and timestamped.'
: 'Endorphin tracks six signals that move crypto before the crowd: Trump posts, BTC macro bottoms, funding-rate extremes, KOL long-form calls, talks-vs-trades divergence, and the Breakout Monitor. Public and timestamped.'
const path = `${siteUrl}/${locale}`
return {
@@ -47,7 +47,9 @@ export async function generateMetadata({ params }: OverviewPageProps): Promise<M
}
export default async function OverviewPage() {
const posts = await getPosts(500, 1).catch(() => [])
// The overview only renders a small curated slice on first paint; pulling
// 500 posts here bloats the server payload without improving the initial UI.
const posts = await getPosts(80, 1).catch(() => [])
return (
<DashboardClient
+10 -156
View File
@@ -1,183 +1,37 @@
'use client'
import { useState, useEffect } from 'react'
import dynamic from 'next/dynamic'
import Link from 'next/link'
import { usePathname } from 'next/navigation'
import { useLocale } from 'next-intl'
import { useAccount } from 'wagmi'
import TelegramCard from '@/components/telegram/TelegramCard'
import PageHint from '@/components/ui/PageHint'
// BotConfigPanel is 867 lines and only needed after wallet connect — lazy load it.
import TelegramCard from '@/components/telegram/TelegramCard'
// BotConfigPanel is heavy and only needed after wallet connect — lazy load it.
const BotConfigPanel = dynamic(() => import('@/components/trades/BotConfigPanel'), {
ssr: false,
loading: () => <div style={{ height: 200, background: 'var(--bg-sunk)', borderRadius: 12, marginBottom: 16 }} />,
})
/**
* Settings page the home for all configuration.
*
* Previously the BotConfigPanel lived on /trades (alongside the trade history),
* and /settings was just a redirect card. That made /trades double-duty
* (configure AND view results) and /settings feel like a dead end. We swap:
* - /settings all configuration (bot, exchange key, subscription)
* - /trades pure execution view (open positions + history)
* Legal links stay here since this is the "everything else" page.
*/
export default function SettingsClient() {
const localeIntl = useLocale()
const isZh = false // i18n shelved — Chinese branches kept as dead code for future revival; see messages/zh.json
const { address, isConnected } = useAccount()
const [mounted, setMounted] = useState(false)
const pathname = usePathname()
useEffect(() => { setMounted(true) }, [])
const locale = pathname.split('/')[1] || 'en'
const href = (path: string) => `/${locale}${path}`
const walletLabel = mounted && isConnected && address
? `${address.slice(0, 6)}${address.slice(-4)}`
: 'Not connected'
return (
<>
<div className="settings-control-center">
<div>
<div className="settings-control-kicker">Control center</div>
<div className="settings-control-title">One place to arm, limit, and verify the bot</div>
<div className="settings-control-copy">
Arm the bot, set per-system risk limits, and configure Telegram alerts all in one place.
</div>
</div>
<div className="settings-control-meta">
<div className="settings-meta-card">
<span className="settings-meta-label">Wallet</span>
<strong className="mono">{walletLabel}</strong>
</div>
<div className="settings-meta-card">
<span className="settings-meta-label">Private data</span>
<strong>{mounted && isConnected ? 'Ready to unlock' : 'Connect first'}</strong>
</div>
<div className="settings-meta-card">
<span className="settings-meta-label">Main actions</span>
<strong>Load settings, save limits, link API</strong>
</div>
</div>
</div>
<div className="settings-scope-intro">
<PageHint>
Your account&apos;s full control surface subscription, Hyperliquid API key, risk limits, and alert delivery.
</PageHint>
<div style={{ fontSize: 12, color: 'var(--ink-3)', marginTop: 8 }}>
Trump drives entries · Macro Vibes manages BTC · Global limits apply to both.
</div>
</div>
<div className="settings-scope-grid" style={{ marginBottom: 16 }}>
<section id="trump-settings" className="settings-scope-card trump">
<div className="settings-scope-eyebrow">Trump Signal</div>
<div className="settings-scope-title">Event-driven entry settings</div>
<div className="settings-scope-copy">
Position size, Trump leverage, and minimum AI confidence used when a Truth Social post becomes actionable.
</div>
<a href="#config-trump" className="settings-scope-link">Configure Trump </a>
</section>
<section id="macro-settings" className="settings-scope-card btc">
<div className="settings-scope-eyebrow">Macro Vibes</div>
<div className="settings-scope-title">BTC manage-only settings</div>
<div className="settings-scope-copy">
Strategy mode, BTC leverage, and de-risk targets for the Macro Vibes system.
</div>
<a href="#config-macro" className="settings-scope-link">Configure Macro Vibes </a>
</section>
<section id="global-settings" className="settings-scope-card global">
<div className="settings-scope-eyebrow">Global</div>
<div className="settings-scope-title">Account-wide execution controls</div>
<div className="settings-scope-copy">
Subscription plan, Hyperliquid API key, trading schedule, and guardrails that apply to both systems.
</div>
<a href="#config-global" className="settings-scope-link">Configure global </a>
</section>
</div>
{/* Account card — quick "who am I logged in as" */}
<div className="card" style={{ padding: 20, marginBottom: 16 }}>
<div style={{ fontSize: 11, fontWeight: 600, letterSpacing: '0.06em',
textTransform: 'uppercase', color: 'var(--ink-3)', marginBottom: 8 }}>
{isZh ? '账户' : 'Account'}
</div>
<div style={{ display: 'flex', alignItems: 'center', gap: 12 }}>
<div style={{
width: 32, height: 32, borderRadius: 8,
background: mounted && isConnected ? 'var(--up-soft)' : 'var(--bg-sunk)',
display: 'flex', alignItems: 'center', justifyContent: 'center',
color: mounted && isConnected ? 'var(--up)' : 'var(--ink-4)', fontSize: 14,
}}>
{mounted && isConnected ? '✓' : '○'}
</div>
<div>
<div style={{ fontSize: 13, fontWeight: 500 }}>
{mounted && isConnected && address
? <span className="mono">{address.slice(0, 10)}{address.slice(-8)}</span>
: (isZh ? '未连接' : 'Not connected')}
</div>
<div style={{ fontSize: 11, color: 'var(--ink-4)' }}>
{mounted && isConnected ? (isZh ? '钱包是下方所有配置的身份入口' : 'Wallet is the access key for everything below') : (isZh ? '连接钱包后才能配置机器人' : 'Connect a wallet to configure the bot')}
</div>
</div>
</div>
</div>
<div id="bot-config" className="settings-section-shell">
<div className="settings-section-head">
<div>
<div className="settings-section-kicker">Execution setup</div>
<div className="settings-section-title">Trading permissions and risk controls</div>
</div>
<div className="settings-section-note">
Load once, then adjust by module without leaving the page.
</div>
</div>
{/* The full bot config UI (subscribe, HL key, risk settings, schedule) */}
<div id="bot-config">
<BotConfigPanel />
</div>
<div className="settings-section-shell">
<div className="settings-section-head">
<div>
<div className="settings-section-kicker">Delivery</div>
<div className="settings-section-title">Telegram alerts</div>
</div>
<div className="settings-section-note">
Set up Telegram alerts once the bot is live.
</div>
</div>
<div style={{ marginTop: 8 }}>
<TelegramCard />
</div>
<div className="settings-section-shell">
<div className="settings-section-head">
<div>
<div className="settings-section-kicker">Support</div>
<div className="settings-section-title">Legal and contact</div>
</div>
</div>
{/* Legal & support */}
<div className="card" style={{ padding: 20 }}>
<div style={{ fontSize: 11, fontWeight: 600, letterSpacing: '0.06em',
textTransform: 'uppercase', color: 'var(--ink-3)', marginBottom: 12 }}>
{isZh ? '法律与支持' : 'Legal & support'}
</div>
<div style={{ display: 'flex', flexDirection: 'column', gap: 8 }}>
<Link href={href('/privacy')} style={{ fontSize: 13, color: 'var(--ink-2)', textDecoration: 'none' }}>{isZh ? '隐私政策 →' : 'Privacy Policy →'}</Link>
<Link href={href('/terms')} style={{ fontSize: 13, color: 'var(--ink-2)', textDecoration: 'none' }}>{isZh ? '服务条款 →' : 'Terms of Service →'}</Link>
<Link href={href('/contact')} style={{ fontSize: 13, color: 'var(--ink-2)', textDecoration: 'none' }}>{isZh ? '联系我们 →' : 'Contact Us →'}</Link>
</div>
<div className="card" style={{ padding: '14px 20px', marginTop: 8 }}>
<div style={{ display: 'flex', gap: 20, flexWrap: 'wrap' }}>
<Link href={href('/privacy')} style={{ fontSize: 13, color: 'var(--ink-3)', textDecoration: 'none' }}>Privacy Policy </Link>
<Link href={href('/terms')} style={{ fontSize: 13, color: 'var(--ink-3)', textDecoration: 'none' }}>Terms </Link>
<Link href={href('/contact')} style={{ fontSize: 13, color: 'var(--ink-3)', textDecoration: 'none' }}>Contact </Link>
</div>
</div>
</>
+26
View File
@@ -0,0 +1,26 @@
/** Instant skeleton while SettingsPage loads. */
export default function SettingsLoading() {
return (
<div className="page">
<div className="page-head" style={{ marginBottom: 24 }}>
<div className="skeleton sk-title" style={{ width: 120, marginBottom: 8 }} />
</div>
{Array.from({ length: 3 }).map((_, i) => (
<div key={i} className="skeleton-card" style={{ marginBottom: 14, padding: 24 }}>
<div className="skeleton sk-line" style={{ width: 160, marginBottom: 18 }} />
<div style={{ display: 'flex', flexDirection: 'column', gap: 14 }}>
{Array.from({ length: 3 }).map((_, j) => (
<div key={j} style={{ display: 'flex', justifyContent: 'space-between', alignItems: 'center' }}>
<div>
<div className="skeleton sk-line" style={{ width: 140, marginBottom: 6 }} />
<div className="skeleton sk-line-sm" style={{ width: 200 }} />
</div>
<div className="skeleton" style={{ width: 72, height: 32, borderRadius: 8 }} />
</div>
))}
</div>
</div>
))}
</div>
)
}
+67 -21
View File
@@ -5,8 +5,8 @@ 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 type { BotTrade } from '@/types'
import { getTrades, getUserPublic } from '@/lib/api'
import { useDashboardStore } from '@/store/dashboard'
import { getCachedViewEnvelope, getOrCreateViewEnvelope, type SignedEnvelope } from '@/lib/signedRequest'
import TradeTable from '@/components/trades/TradeTable'
@@ -18,13 +18,13 @@ export default function TradesPageClient() {
const isZh = false // i18n shelved — Chinese branches kept as dead code for future revival; see messages/zh.json
const { address, isConnected } = useAccount()
const { signMessageAsync } = useSignMessage()
const { isSubscribed, hlApiKeySet } = useDashboardStore()
const { isSubscribed, hlApiKeySet, paperMode,
setSubscribed, setHlApiKeySet, setPaperMode, setBotReadiness } = useDashboardStore()
const pathname = usePathname()
const locale = pathname.split('/')[1] || 'en'
const [mounted, setMounted] = useState(false)
const [trades, setTrades] = useState<BotTrade[]>([])
const [posts, setPosts] = useState<TrumpPost[]>([])
const [loading, setLoading] = useState(true)
const [loadErr, setLoadErr] = useState('')
const [needsUnlock, setNeedsUnlock] = useState(false)
@@ -37,41 +37,77 @@ export default function TradesPageClient() {
return () => { aliveRef.current = false }
}, [])
// genRef guards loadAll against stale-closure wallet-switch races.
// `snapAddr !== address` inside an async function compares two copies of
// the same closure-captured value — it's always equal even when the wallet
// has changed, so the check is a no-op. genRef is a mutable ref that every
// closure can read, so `gen !== genRef.current` correctly detects staleness.
const genRef = useRef(0)
useEffect(() => { genRef.current++ }, [address])
// B41: TradesPageClient can be the entry point (direct navigation to /trades)
// without DashboardClient or BotConfigPanel ever running. In that case the
// Zustand store has isSubscribed=false (initial default), causing the
// "Bot not configured" banner to appear for valid subscribers.
// Fix: fetch /user/{wallet}/public here too — it's lightweight, unauthenticated,
// and idempotent with the same fetch DashboardClient does.
useEffect(() => {
if (!address || !isConnected) return
let cancelled = false
const snap = address
getUserPublic(snap.toLowerCase())
.then(u => {
if (cancelled || snap !== address) return
setSubscribed(u.active)
setHlApiKeySet(u.hl_api_key_set)
setBotReadiness(u.hl_api_key_set ? 'saved' : 'unknown')
setPaperMode(!!u.paper_mode)
})
.catch(() => {})
return () => { cancelled = true }
// eslint-disable-next-line react-hooks/exhaustive-deps
}, [address, isConnected])
// Load public posts always; load private trades only if we have a view
// envelope. `forcedEnv` lets the in-page Unlock button pass a freshly-minted
// one so the user never has to detour through the Settings page first.
async function loadAll(forcedEnv?: SignedEnvelope) {
if (!address || !isConnected) {
setTrades([]); setPosts([]); setLoading(false); setLoadErr(''); setNeedsUnlock(false)
setTrades([]); setLoading(false); setLoadErr(''); setNeedsUnlock(false)
return
}
const gen = genRef.current
const snapAddr = address // for API calls only — NOT for stale detection
setLoading(true)
const env = forcedEnv
?? getCachedViewEnvelope('view_trades', address)
?? getCachedViewEnvelope('view_user', address)
?? getCachedViewEnvelope('view_trades', snapAddr)
?? getCachedViewEnvelope('view_user', snapAddr)
let failed = false
try {
const [t, p] = await Promise.all([
env
? getTrades(address, env, 100, 1).catch(e => {
const t = env
? await getTrades(snapAddr, env, 500, 1).catch(e => {
failed = true
setLoadErr(e instanceof Error ? e.message : 'Failed to load trades')
return [] as BotTrade[]
})
: Promise.resolve([] as BotTrade[]),
getPosts(500, 1).catch(() => [] as TrumpPost[]),
])
if (!aliveRef.current) return
: []
// Use genRef — NOT `snapAddr !== address` (stale closure: both are the
// same closed-over value and the comparison is always false).
if (!aliveRef.current || gen !== genRef.current) return
setTrades(t)
setPosts(p)
setNeedsUnlock(!env)
if (env && !failed) setLoadErr('')
} finally {
if (aliveRef.current) setLoading(false)
if (aliveRef.current && gen === genRef.current) setLoading(false)
}
}
useEffect(() => {
// B27/B35: clear stale previous-wallet data BEFORE the async fetch so the
// UI never briefly shows another wallet's private trades.
setTrades([])
setNeedsUnlock(false)
setLoadErr('')
// On navigation we only use a cached envelope — never auto-popup the
// wallet. If none is cached the user unlocks explicitly via the button.
void loadAll()
@@ -84,8 +120,12 @@ export default function TradesPageClient() {
setUnlocking(true)
setLoadErr('')
try {
// view_user is a superset accepted by /trades, /positions/open,
// /positions/today — one signature unlocks everything on this page.
// Previously view_trades was used here, but that left OpenPositions
// locked (it requires view_positions or view_user).
const env = await getOrCreateViewEnvelope({
action: 'view_trades', wallet: address, signMessageAsync,
action: 'view_user', wallet: address, signMessageAsync,
})
await loadAll(env)
} catch (e) {
@@ -97,7 +137,14 @@ export default function TradesPageClient() {
}
}
const needsSetup = mounted && isConnected && (!isSubscribed || !hlApiKeySet)
// B40: paper users have no HL key but the bot IS configured for them — don't
// show "Bot not configured" just because hlApiKeySet is false.
// B41: on cold start (navigating directly to /trades), isSubscribed starts
// false in the store until DashboardClient or BotConfigPanel fetches
// /user/public. Guard with !loading so the banner only appears once
// the page has confirmed the wallet is genuinely unconfigured.
const needsSetup = mounted && isConnected && !loading &&
(!isSubscribed || (!hlApiKeySet && !paperMode))
return (
<div className="page">
@@ -105,8 +152,7 @@ export default function TradesPageClient() {
<div>
<h1 className="page-title">{isZh ? '交易执行' : 'Trades'}</h1>
<PageHint>
What the bot actually did with your money currently-open positions
on top, closed-trade history with realized P&amp;L below.
Open positions above · closed trade history with realized P&amp;L below.
</PageHint>
</div>
</div>
@@ -163,7 +209,7 @@ export default function TradesPageClient() {
</div>
)}
<TradeTable trades={trades} posts={posts} loading={loading} />
<TradeTable trades={trades} loading={loading} locked={needsUnlock} />
</div>
)
}
+4 -3
View File
@@ -34,10 +34,11 @@ const tradesDataset = {
'@id': `${siteUrl}/en/trades#dataset`,
name: 'Trump Alpha trade execution history',
description:
'Record of every signal-triggered trade: asset, direction, entry and exit price, realised P&L, hold time, and the source signal that triggered it. Public and timestamped.',
'Per-wallet record of signal-triggered trades: asset, direction, entry and exit price, realised P&L, hold time, and the triggering signal. Private to each wallet owner — wallet signature required to view.',
url: `${siteUrl}/en/trades`,
keywords: ['crypto trading track record', 'Hyperliquid', 'P&L', 'backtest', 'signal performance'],
isAccessibleForFree: true,
keywords: ['crypto trading track record', 'Hyperliquid', 'P&L', 'signal performance'],
// Data is private (wallet-signed access), not freely accessible to the public
isAccessibleForFree: false,
creator: { '@type': 'Organization', name: 'Endorphin', url: siteUrl },
publisher: { '@id': `${siteUrl}/#org` },
license: `${siteUrl}/en/terms`,
+171 -54
View File
@@ -1,10 +1,9 @@
'use client'
import { useState, useEffect, useMemo } from 'react'
import { useLocale } from 'next-intl'
import { useState, useEffect, useMemo, useRef } from 'react'
import type { TrumpPost } from '@/types'
import { getPosts } from '@/lib/api'
import { swrFetch } from '@/lib/cache'
import { getPosts, getPostsPage, type PostListResponse } from '@/lib/api'
import { hasCached, swrFetch } from '@/lib/cache'
import PostRow, { isAiScored } from '@/components/dashboard/PostCards'
import SystemControl from '@/components/signals/SystemControl'
import PageHint from '@/components/ui/PageHint'
@@ -18,62 +17,147 @@ type SentimentFilter = (typeof SENTIMENTS)[number]
type SignalFilter = 'all' | 'actionable' | 'buy' | 'short'
interface TrumpSignalPageProps {
initialPosts?: TrumpPost[] | null
initialData?: PostListResponse | null
}
export default function TrumpSignalPage({ initialPosts = null }: TrumpSignalPageProps) {
const locale = useLocale()
const isZh = false
const [posts, setPosts] = useState<TrumpPost[]>(initialPosts ?? [])
const [loading, setLoading] = useState(initialPosts === null)
const EMPTY_COUNTS: PostListResponse['counts'] = {
all: 0,
actionable: 0,
buy: 0,
short: 0,
off_topic: 0,
}
function matchesBaseFilters(post: TrumpPost, sentFilter: SentimentFilter, hideNoise: boolean) {
if (hideNoise && !isAiScored(post)) return false
if (sentFilter !== 'all' && post.sentiment !== sentFilter) return false
return true
}
function matchesSignalFilter(post: TrumpPost, sigFilter: SignalFilter) {
if (sigFilter === 'actionable') return post.signal === 'buy' || post.signal === 'short'
if (sigFilter === 'buy') return post.signal === 'buy'
if (sigFilter === 'short') return post.signal === 'short'
return true
}
function buildLocalCounts(
posts: TrumpPost[],
sentFilter: SentimentFilter,
hideNoise: boolean,
): PostListResponse['counts'] {
const sentimentScoped = posts.filter(p => sentFilter === 'all' || p.sentiment === sentFilter)
const base = sentimentScoped.filter(p => matchesBaseFilters(p, sentFilter, hideNoise))
return {
all: base.length,
actionable: base.filter(p => p.signal === 'buy' || p.signal === 'short').length,
buy: base.filter(p => p.signal === 'buy').length,
short: base.filter(p => p.signal === 'short').length,
off_topic: sentimentScoped.filter(p => !isAiScored(p)).length,
}
}
export default function TrumpSignalPage({ initialData = null }: TrumpSignalPageProps) {
const [posts, setPosts] = useState<TrumpPost[]>(initialData?.items ?? [])
const [totalPosts, setTotalPosts] = useState(initialData?.total ?? 0)
const [counts, setCounts] = useState<PostListResponse['counts']>(initialData?.counts ?? EMPTY_COUNTS)
const [loading, setLoading] = useState(initialData === null)
const [loadErr, setLoadErr] = useState('')
const [sentFilter, setSentFilter] = useState<SentimentFilter>('all')
const [sigFilter, setSigFilter] = useState<SignalFilter>('all')
const [hideNoise, setHideNoise] = useState(false)
const [page, setPage] = useState(1)
const [serverPaging, setServerPaging] = useState(true)
// Tracks whether we already have any rows on screen, WITHOUT putting
// posts.length in the effect deps (which would re-run the effect on every
// setPosts and fire a redundant fetch). Updated after each load below.
const hasRowsRef = useRef((initialData?.items?.length ?? 0) > 0)
useEffect(() => {
const filters = {
// Don't apply the sentiment bias when a directional signal filter is
// active — Buy/Short/Actionable already imply direction, and combining
// them with a sentiment filter produces confusing empty results.
// sentFilter is intentionally NOT reset when the user switches tabs so
// their preference is preserved if they switch back to 'all'.
sentiment: sentFilter === 'all' || sigFilter !== 'all' ? undefined : sentFilter,
signal: sigFilter === 'all' ? undefined : sigFilter,
aiScoredOnly: hideNoise,
} as const
// sentFilter only participates in the key when sigFilter is 'all' — it's
// ignored by the query otherwise, so caching it in the key would create
// phantom cache entries that never match on the way back.
const effectiveSent = sigFilter === 'all' ? sentFilter : 'all'
const key = `posts-truth-page-${page}-sent-${effectiveSent}-sig-${sigFilter}-noise-${hideNoise ? '1' : '0'}`
const legacyKey = 'posts-truth-legacy-500'
setLoadErr('')
setLoading(!hasRowsRef.current && !hasCached(key) && !hasCached(legacyKey))
swrFetch(
'posts-500',
key,
3 * 60_000,
() => getPosts(500, 1),
fresh => setPosts(fresh),
() => getPostsPage(PAGE_SIZE, page, 'truth', filters),
fresh => {
setPosts(fresh.items)
setTotalPosts(fresh.total)
setCounts(fresh.counts)
hasRowsRef.current = fresh.items.length > 0
},
)
.then(p => { setPosts(p); setLoadErr('') })
.catch(e => setLoadErr(e instanceof Error ? e.message : 'Failed to load posts'))
.then(r => {
setPosts(r.items)
setTotalPosts(r.total)
setCounts(r.counts)
setServerPaging(true)
setLoadErr('')
hasRowsRef.current = r.items.length > 0
})
.catch(async e => {
const detail = e instanceof Error ? e.message : 'Failed to load posts'
if (!detail.includes('404')) {
setLoadErr(detail)
return
}
try {
// Legacy fallback (old backend without /posts-paged). Pull the
// largest window the /posts endpoint allows (le=500) so client-side
// pagination below has the full set to slice — 200 silently dropped
// older matching posts once the truth feed grew past one page.
const legacyPosts = await swrFetch(
legacyKey,
3 * 60_000,
() => getPosts(500, 1, 'truth'),
)
const localCounts = buildLocalCounts(legacyPosts, sentFilter, hideNoise)
setPosts(legacyPosts)
setTotalPosts(localCounts.all)
setCounts(localCounts)
setServerPaging(false)
setLoadErr('')
hasRowsRef.current = legacyPosts.length > 0
} catch (legacyErr) {
setLoadErr(legacyErr instanceof Error ? legacyErr.message : detail)
}
})
.finally(() => setLoading(false))
}, [])
}, [page, sentFilter, sigFilter, hideNoise])
const trumpPosts = useMemo(
() => posts.filter(p => (p.source || '') === 'truth'),
[posts],
const filtered = useMemo(
() => serverPaging
? posts
: posts.filter(p => matchesBaseFilters(p, sentFilter, hideNoise) && matchesSignalFilter(p, sigFilter)),
[hideNoise, posts, sentFilter, serverPaging, sigFilter],
)
const noiseCount = useMemo(
() => trumpPosts.filter(p => !isAiScored(p)).length,
[trumpPosts],
)
const filtered = useMemo(() => trumpPosts.filter(p => {
if (hideNoise && !isAiScored(p)) return false
if (sentFilter !== 'all' && p.sentiment !== sentFilter) return false
if (sigFilter === 'actionable' && p.signal !== 'buy' && p.signal !== 'short') return false
if (sigFilter === 'buy' && p.signal !== 'buy') return false
if (sigFilter === 'short' && p.signal !== 'short') return false
return true
}), [trumpPosts, sentFilter, sigFilter, hideNoise])
const totalPages = Math.max(1, Math.ceil(filtered.length / PAGE_SIZE))
const noiseCount = counts.off_topic
const totalPages = Math.max(1, Math.ceil(totalPosts / PAGE_SIZE))
const safePage = Math.min(page, totalPages)
const pageItems = filtered.slice((safePage - 1) * PAGE_SIZE, safePage * PAGE_SIZE)
const sigCounts = useMemo(() => ({
all: trumpPosts.length,
actionable: trumpPosts.filter(p => p.signal === 'buy' || p.signal === 'short').length,
buy: trumpPosts.filter(p => p.signal === 'buy').length,
short: trumpPosts.filter(p => p.signal === 'short').length,
}), [trumpPosts])
const pageItems = serverPaging
? posts
: filtered.slice((safePage - 1) * PAGE_SIZE, safePage * PAGE_SIZE)
const signalLabels: Record<SignalFilter, string> = {
all: 'All', actionable: 'Actionable', buy: 'Buy', short: 'Short',
@@ -86,10 +170,25 @@ export default function TrumpSignalPage({ initialPosts = null }: TrumpSignalPage
<div className="page">
<div className="page-head">
<div>
<h1 className="page-title"> Trump Signal</h1>
<PageHint count={`${sigCounts.actionable} actionable / ${trumpPosts.length} posts`}>
Watches Trump's Truth Social posts in real time, AI-scores each one,
and only fires a trade when conviction is high enough to move the market.
<div style={{ display: 'flex', alignItems: 'center', gap: 8, flexWrap: 'wrap' }}>
<h1 className="page-title" style={{ margin: 0 }}>Trump Signal</h1>
<span style={{
display: 'inline-flex', alignItems: 'center', gap: 4,
padding: '2px 8px', borderRadius: 6, fontSize: 11, fontWeight: 700,
background: 'color-mix(in oklab, var(--up) 12%, transparent)',
color: 'var(--up)', border: '1px solid color-mix(in oklab, var(--up) 25%, transparent)',
letterSpacing: '0.04em',
}}>
Auto-trade
</span>
</div>
<PageHint count={
sigFilter === 'buy' ? `${counts.buy} buy signals`
: sigFilter === 'short' ? `${counts.short} short signals`
: sigFilter === 'actionable' ? `${counts.actionable} actionable signals`
: `${counts.actionable} actionable / ${counts.all} posts`
}>
Every Truth Social post scored in &lt;3s. Trades only when conviction clears the threshold.
</PageHint>
</div>
<span className="chip"><span className="live-dot" />Live</span>
@@ -112,19 +211,36 @@ export default function TrumpSignalPage({ initialPosts = null }: TrumpSignalPage
<button
key={f.key}
className={`nav-tab ${sigFilter === f.key ? 'active' : ''}`}
onClick={() => { setSigFilter(f.key); setPage(1) }}
onClick={() => {
setSigFilter(f.key)
setPage(1)
// sentFilter is intentionally NOT reset here — the user's
// bias preference is preserved so it's still active when
// they switch back to 'all'. The query layer ignores
// sentFilter whenever sigFilter is directional.
}}
>
{f.key === 'actionable' ? '🔥 ' : ''}
{signalLabels[f.key]}
<span style={{ color: 'var(--ink-4)', marginLeft: 4 }}>{sigCounts[f.key]}</span>
{signalLabels[f.key]}{' '}
<span style={{ color: 'var(--ink-4)' }}>{counts[f.key]}</span>
</button>
))}
</div>
{/* Sentiment filter */}
{/* Sentiment + noise filters hidden when a directional filter is
already active (actionable / buy / short), because:
- "buy" already implies bullish direction
- "short" already implies bearish direction
- "actionable" = buy short sentiment adds no further info
Showing them would create confusing combinations (e.g. Buy + Bearish
returns 0 results with no explanation). */}
{sigFilter === 'all' && (
<div style={{ display: 'flex', gap: 6, flexWrap: 'wrap', alignItems: 'center' }}>
{/* One-click collapse of off-topic (non-crypto, un-scored) posts. */}
{noiseCount > 0 && (
{/* One-click collapse of off-topic (non-crypto, un-scored) posts.
Hidden when a sentiment filter is active Bullish/Bearish/Neutral
results are all AI-scored by definition, so there are no off-topic
posts to hide and the button would be meaningless. */}
{(noiseCount > 0 || hideNoise) && sentFilter === 'all' && (
<button
onClick={() => { setHideNoise(v => !v); setPage(1) }}
title={`Show only crypto-relevant posts — hides ${noiseCount} off-topic Trump posts`}
@@ -162,6 +278,7 @@ export default function TrumpSignalPage({ initialPosts = null }: TrumpSignalPage
</button>
))}
</div>
)}
</div>
{loading && <TrumpSkeleton />}
@@ -176,7 +293,7 @@ export default function TrumpSignalPage({ initialPosts = null }: TrumpSignalPage
</div>
)}
{!loading && !loadErr && filtered.length === 0 && (
{!loading && !loadErr && totalPosts === 0 && (
<div className="card" style={{ padding: 48, textAlign: 'center', color: 'var(--ink-3)' }}>
No Trump signals match the current filter.
</div>
@@ -191,7 +308,7 @@ export default function TrumpSignalPage({ initialPosts = null }: TrumpSignalPage
<Pagination
page={safePage}
total={totalPages}
count={filtered.length}
count={totalPosts}
pageSize={PAGE_SIZE}
onChange={setPage}
/>
+7 -3
View File
@@ -1,7 +1,8 @@
import { getPosts } from '@/lib/api'
import { type PostListResponse } from '@/lib/api'
import type { Metadata } from 'next'
import TrumpPageClient from './TrumpPageClient'
import Breadcrumbs from '@/components/seo/Breadcrumbs'
import { getInitialPostPage } from '@/lib/postPage'
const siteUrl = process.env.NEXT_PUBLIC_SITE_URL || 'https://trumpsignal.com'
export const revalidate = 30
@@ -75,7 +76,10 @@ const trumpDataset = {
}
export default async function TrumpPage() {
const posts = await getPosts(500, 1).catch(() => null)
const initialData: PostListResponse | null = await getInitialPostPage(30, 1, {
source: 'truth',
legacyFallbackSource: 'truth',
})
return (
<>
@@ -84,7 +88,7 @@ export default async function TrumpPage() {
dangerouslySetInnerHTML={{ __html: JSON.stringify(trumpDataset) }}
/>
<Breadcrumbs items={[{ name: 'Trump signals', path: '/en/trump' }]} />
<TrumpPageClient initialPosts={posts} />
<TrumpPageClient initialData={initialData} />
</>
)
}
+116 -65
View File
@@ -127,17 +127,20 @@
}
.lp-nav-cta {
display: inline-flex; align-items: center; gap: 8px;
padding: 9px 16px;
font-size: 13px; font-weight: 600;
padding: 9px 18px;
font-size: 13px; font-weight: 700;
color: #0a0907;
background: var(--lp-amber);
background: linear-gradient(135deg, #ffd88a, var(--lp-amber) 55%, #ff9a4d);
border-radius: 999px;
text-decoration: none;
transition: transform 0.15s ease, box-shadow 0.15s ease;
box-shadow: 0 4px 16px var(--lp-amber-glow), inset 0 1px 0 rgba(255,255,255,0.3);
letter-spacing: -0.01em;
}
.lp-nav-cta:hover {
transform: translateY(-1px);
box-shadow: 0 10px 30px var(--lp-amber-glow);
box-shadow: 0 10px 30px var(--lp-amber-glow), inset 0 1px 0 rgba(255,255,255,0.3);
filter: brightness(1.06);
}
/* ---------- Hero ---------- */
@@ -175,15 +178,16 @@
.lp-live-badge {
display: inline-flex; align-items: center; gap: 8px;
margin: 0 0 22px;
padding: 5px 12px 5px 9px;
padding: 6px 14px 6px 10px;
font-size: 11px; font-weight: 700;
color: var(--lp-ink-3);
background: rgba(255, 255, 255, 0.04);
border: 1px solid rgba(255, 255, 255, 0.10);
border-radius: 6px;
letter-spacing: 0.08em;
color: var(--lp-ink-2);
background: rgba(255, 255, 255, 0.05);
border: 1px solid rgba(255, 255, 255, 0.12);
border-radius: 8px;
letter-spacing: 0.09em;
text-transform: uppercase;
animation: lp-fade-up 0.7s ease both;
box-shadow: inset 0 1px 0 rgba(255,255,255,0.06);
}
.lp-live-dot {
width: 8px; height: 8px; border-radius: 50%;
@@ -338,16 +342,17 @@
.lp-eyebrow {
font-size: 11px;
font-weight: 700;
letter-spacing: 0.14em;
letter-spacing: 0.16em;
text-transform: uppercase;
color: var(--lp-amber);
margin-bottom: 12px;
text-shadow: 0 0 20px rgba(245,165,36,0.35);
}
.lp-h2 {
font-size: clamp(26px, 3.8vw, 48px);
font-size: clamp(26px, 3.8vw, 52px);
font-weight: 800;
letter-spacing: -0.03em;
line-height: 1.1;
letter-spacing: -0.035em;
line-height: 1.08;
margin: 0 0 16px;
}
.lp-lead {
@@ -410,9 +415,10 @@
.lp-step-num {
font-family: 'Geist Mono', monospace;
font-size: 12px;
color: var(--lp-ink-4);
color: var(--lp-amber);
letter-spacing: 0.1em;
margin-bottom: 20px;
opacity: 0.7;
}
.lp-step-icon {
width: 52px; height: 52px;
@@ -425,13 +431,13 @@
}
.lp-step h3 {
font-size: 20px;
font-weight: 600;
font-weight: 700;
margin: 0 0 10px;
letter-spacing: -0.01em;
letter-spacing: -0.02em;
}
.lp-step p {
font-size: 15px;
line-height: 1.6;
line-height: 1.62;
color: var(--lp-ink-3);
margin: 0;
}
@@ -450,30 +456,47 @@
background: var(--lp-surface);
border: 1px solid var(--lp-line);
border-radius: 16px;
transition: all 0.2s ease;
transition: transform 0.22s ease, border-color 0.22s ease, background 0.22s ease;
position: relative;
overflow: hidden;
}
.lp-feat::before {
content: '';
position: absolute;
inset: 0;
border-radius: inherit;
padding: 1px;
background: linear-gradient(135deg, rgba(245,165,36,0.4), transparent 55%);
-webkit-mask: linear-gradient(#000 0 0) content-box, linear-gradient(#000 0 0);
-webkit-mask-composite: xor;
mask-composite: exclude;
opacity: 0;
transition: opacity 0.28s ease;
}
.lp-feat:hover {
background: var(--lp-surface-2);
border-color: var(--lp-line-2);
transform: translateY(-2px);
border-color: rgba(245,165,36,0.22);
transform: translateY(-3px);
}
.lp-feat:hover::before { opacity: 1; }
.lp-feat-icon {
width: 36px; height: 36px;
border-radius: 10px;
width: 40px; height: 40px;
border-radius: 11px;
display: grid; place-items: center;
margin-bottom: 16px;
background: rgba(245,165,36,0.1);
background: linear-gradient(135deg, rgba(245,165,36,0.18), rgba(245,165,36,0.06));
border: 1px solid rgba(245,165,36,0.18);
color: var(--lp-amber);
}
.lp-feat h4 {
font-size: 16px;
font-weight: 600;
font-weight: 700;
margin: 0 0 8px;
letter-spacing: -0.01em;
letter-spacing: -0.015em;
}
.lp-feat p {
font-size: 14px;
line-height: 1.55;
line-height: 1.58;
color: var(--lp-ink-3);
margin: 0;
}
@@ -575,7 +598,7 @@
/* ---------- Final CTA ---------- */
.lp-cta-final {
padding: 88px 0 96px;
padding: 96px 0 104px;
text-align: center;
position: relative;
}
@@ -583,10 +606,10 @@
content: '';
position: absolute;
left: 50%; top: 50%;
width: 700px; height: 700px;
background: radial-gradient(circle, rgba(245,165,36,0.18), transparent 60%);
width: 800px; height: 700px;
background: radial-gradient(ellipse, rgba(245,165,36,0.22) 0%, rgba(239,68,68,0.10) 45%, transparent 70%);
transform: translate(-50%, -50%);
filter: blur(80px);
filter: blur(90px);
pointer-events: none;
z-index: -1;
}
@@ -646,23 +669,25 @@
}
.lp-stat-val {
font-family: 'Geist', sans-serif;
font-size: 34px;
font-weight: 700;
letter-spacing: -0.02em;
font-size: 38px;
font-weight: 800;
letter-spacing: -0.03em;
line-height: 1;
color: var(--lp-ink);
margin-bottom: 8px;
}
.lp-stat-val .suffix {
font-size: 18px;
font-size: 20px;
color: var(--lp-amber);
margin-left: 2px;
margin-left: 3px;
font-weight: 700;
}
.lp-stat-lbl {
font-size: 12px;
font-size: 11px;
color: var(--lp-ink-3);
text-transform: uppercase;
letter-spacing: 0.08em;
letter-spacing: 0.1em;
font-weight: 600;
}
.lp-stat-sub {
font-size: 11px;
@@ -681,17 +706,18 @@
.lp-post-card {
padding: 24px;
background: linear-gradient(180deg, rgba(255,255,255,0.04), rgba(255,255,255,0.01));
background: linear-gradient(180deg, rgba(255,255,255,0.045), rgba(255,255,255,0.01));
border: 1px solid var(--lp-line);
border-radius: 16px;
display: flex;
gap: 18px;
align-items: flex-start;
transition: all 0.25s ease;
transition: transform 0.22s ease, border-color 0.22s ease;
box-shadow: inset 0 1px 0 rgba(255,255,255,0.05);
}
.lp-post-card:hover {
border-color: var(--lp-line-2);
transform: translateY(-2px);
border-color: rgba(245,165,36,0.2);
transform: translateY(-3px);
}
.lp-post-kind {
width: 44px; height: 44px; flex-shrink: 0;
@@ -891,11 +917,12 @@
grid-template-columns: repeat(5, 1fr);
gap: 0;
margin-top: 48px;
padding: 32px 16px;
background: linear-gradient(180deg, rgba(255,255,255,0.03), rgba(255,255,255,0.005));
padding: 36px 20px;
background: linear-gradient(180deg, rgba(255,255,255,0.04), rgba(255,255,255,0.01));
border: 1px solid var(--lp-line);
border-radius: 20px;
position: relative;
box-shadow: inset 0 1px 0 rgba(255,255,255,0.05);
}
@media (max-width: 880px) { .lp-flow { grid-template-columns: 1fr; gap: 20px; } }
@@ -907,11 +934,12 @@
.lp-flow-step:not(:last-child)::after {
content: '→';
position: absolute;
right: -8px;
top: 28px;
font-size: 20px;
right: -10px;
top: 26px;
font-size: 22px;
color: var(--lp-amber);
opacity: 0.6;
opacity: 0.7;
text-shadow: 0 0 14px rgba(245,165,36,0.5);
}
@media (max-width: 880px) {
.lp-flow-step:not(:last-child)::after { display: none; }
@@ -919,15 +947,16 @@
.lp-flow-badge {
display: inline-flex; align-items: center; justify-content: center;
width: 56px; height: 56px;
width: 58px; height: 58px;
border-radius: 16px;
background: linear-gradient(135deg, rgba(245,165,36,0.2), rgba(245,165,36,0.05));
border: 1px solid rgba(245,165,36,0.3);
background: linear-gradient(135deg, rgba(245,165,36,0.22), rgba(245,165,36,0.06));
border: 1px solid rgba(245,165,36,0.35);
color: var(--lp-amber);
font-weight: 700; font-size: 18px;
font-weight: 800; font-size: 18px;
font-family: 'Geist Mono', monospace;
margin-bottom: 14px;
position: relative;
box-shadow: inset 0 1px 0 rgba(255,255,255,0.1);
}
.lp-flow-badge::before {
content: '';
@@ -938,10 +967,11 @@
z-index: -1;
}
.lp-flow-step h5 {
font-size: 14px; font-weight: 600; margin: 0 0 6px;
font-size: 14px; font-weight: 700; margin: 0 0 6px;
letter-spacing: -0.01em;
}
.lp-flow-step p {
font-size: 12px; line-height: 1.5;
font-size: 12px; line-height: 1.55;
color: var(--lp-ink-3); margin: 0;
}
.lp-flow-time {
@@ -969,11 +999,12 @@
background: var(--lp-surface);
border: 1px solid var(--lp-line);
border-radius: 14px;
transition: all 0.2s ease;
transition: transform 0.2s ease, border-color 0.2s ease, background 0.2s ease;
}
.lp-faq-item:hover {
background: var(--lp-surface-2);
border-color: var(--lp-line-2);
border-color: rgba(245,165,36,0.2);
transform: translateY(-2px);
}
.lp-faq-q {
display: flex; align-items: flex-start; gap: 10px;
@@ -1686,12 +1717,18 @@
animation: lp-fade-up 0.9s 0.55s ease both;
}
.lp-engine-chip {
font-size: 11px; font-weight: 600;
padding: 4px 10px; border-radius: 5px;
font-size: 11px; font-weight: 700;
padding: 5px 11px; border-radius: 6px;
font-family: 'Geist Mono', monospace;
letter-spacing: 0.04em;
letter-spacing: 0.05em;
border: 1px solid;
white-space: nowrap;
box-shadow: inset 0 1px 0 rgba(255,255,255,0.06);
transition: opacity 0.15s ease, transform 0.15s ease;
}
.lp-engine-chip:hover {
opacity: 0.85;
transform: translateY(-1px);
}
.lp-engine-chip.trump { color: var(--lp-amber); background: rgba(245,165,36,0.10); border-color: rgba(245,165,36,0.28); }
.lp-engine-chip.macro { color: var(--lp-green); background: rgba(31,219,99,0.09); border-color: rgba(31,219,99,0.25); }
@@ -1715,12 +1752,12 @@
}
.lp-livefeed-head {
display: flex; align-items: center; gap: 8px;
padding: 11px 16px;
padding: 12px 16px;
border-bottom: 1px solid rgba(255,255,255,0.07);
font-size: 10px; font-weight: 700;
letter-spacing: 0.12em; text-transform: uppercase;
color: var(--lp-ink-3);
background: rgba(255,255,255,0.015);
letter-spacing: 0.13em; text-transform: uppercase;
color: var(--lp-ink-2);
background: linear-gradient(180deg, rgba(255,255,255,0.03), rgba(255,255,255,0.01));
}
.lp-livefeed-dot {
width: 7px; height: 7px; border-radius: 50%;
@@ -1968,10 +2005,11 @@
padding-top: 12px; border-top: 1px solid var(--lp-line);
}
.lp-pillar-metric {
font-size: 22px; font-weight: 700;
font-size: 26px; font-weight: 800;
color: var(--lp-amber);
font-family: 'Geist Mono', ui-monospace, monospace;
line-height: 1;
letter-spacing: -0.02em;
}
.lp-pillar-metric-lbl {
font-size: 11px; color: var(--lp-ink-4);
@@ -1985,10 +2023,21 @@
/* reduce motion respect */
@media (prefers-reduced-motion: reduce) {
/* Catch-all: neutralise all 14 infinite animations (lp-scroll marquee,
lp-float blobs, lp-ping/lp-pulse dots, lp-blink cursor, ) plus every
entrance animation. 0.01ms keeps onAnimationEnd handlers firing. */
*, *::before, *::after {
animation-duration: 0.01ms !important;
animation-iteration-count: 1 !important;
transition-duration: 0.01ms !important;
scroll-behavior: auto !important;
}
.lp-noise,
.lp-pillar-edge { animation: none !important; }
.lp-pillar { transform: none !important; transition: none; }
.lp-spotlight { display: none; }
/* Marquee: park at origin instead of mid-translate(-50%). */
.lp-ticker-track { animation: none !important; transform: none !important; }
}
/* ── FAQ ──────────────────────────────────────────────── */
@@ -2006,7 +2055,9 @@
background: var(--lp-surface);
transition: border-color 0.2s;
}
.lp-faq-item:hover { border-color: var(--lp-line-2); }
.lp-faq-item:hover {
border-color: rgba(245,165,36,0.28);
}
.lp-faq-q {
width: 100%;
display: flex;
+6 -6
View File
@@ -5,7 +5,7 @@ import './[locale]/globals.css'
const siteTitle = 'Trump Alpha'
const siteTagline = 'The crypto signals that move price before the crowd'
const siteDescription = "Endorphin is a crypto research desk tracking four signals that move markets before consensus catches up — Trump's posts, BTC macro bottoms, funding-rate extremes, and what KOLs do versus what they say. Every signal is public and timestamped."
const siteDescription = "Endorphin is a crypto research desk tracking six signals that move markets before consensus catches up — Trump's posts, BTC macro bottoms, funding-rate extremes, KOL long-form calls, talks-vs-trades divergence, and the Breakout Monitor. Every signal is public and timestamped."
const siteUrl = process.env.NEXT_PUBLIC_SITE_URL
export const metadata: Metadata = {
@@ -283,7 +283,7 @@ const jsonLd = {
name: 'What is Trump Alpha?',
acceptedAnswer: {
'@type': 'Answer',
text: 'Trump Alpha is an AI-powered crypto intelligence dashboard that monitors four signal sources: Trump Truth Social posts, BTC macro-bottom confluence signals, KOL Substack and podcast essays, and talks-vs-trades divergence between public commentary and on-chain behavior.',
text: 'Trump Alpha is an AI-powered crypto intelligence dashboard that monitors six signal sources: Trump Truth Social posts, BTC macro-bottom confluence signals, KOL Substack and podcast essays, talks-vs-trades divergence between public commentary and on-chain behavior, a funding-rate reversal trigger, and a real-time breakout monitor for ETH and LINK.',
},
},
{
@@ -315,7 +315,7 @@ const jsonLd = {
name: 'Which KOLs does Trump Alpha track?',
acceptedAnswer: {
'@type': 'Answer',
text: 'Trump Alpha tracks 19 KOL feeds including Arthur Hayes (BitMEX), Delphi Digital, Dragonfly Capital, Pomp, and major crypto podcasts (Empire, Bankless, Unchained, 0xResearch, Lightspeed). Posts and episodes are processed daily; AI extracts ticker calls, direction (bullish/bearish/buy/sell), and conviction scores.',
text: 'Trump Alpha tracks 25 KOL feeds including Arthur Hayes (BitMEX), Delphi Digital, Pomp, and major crypto podcasts (Empire, Bankless, Unchained, 0xResearch, Lightspeed). Posts and episodes are processed daily; AI extracts ticker calls, direction (bullish/bearish/buy/sell), and conviction scores.',
},
},
{
@@ -323,7 +323,7 @@ const jsonLd = {
name: 'Is Trump Alpha free?',
acceptedAnswer: {
'@type': 'Answer',
text: 'Yes. All four signal dashboards (Trump, Macro Vibes, KOL, talks-vs-trades) are free to read. The optional Hyperliquid auto-trader requires your own Hyperliquid account and API key. Trump Alpha never takes custody of your funds — your API key can open and close positions but cannot withdraw.',
text: 'Yes. All six signal dashboards are free to read. The optional Hyperliquid auto-trader requires a subscription, your own Hyperliquid account, and an API key. Trump Alpha never takes custody of your funds — your API key can open and close positions but cannot withdraw.',
},
},
{
@@ -380,7 +380,7 @@ const jsonLd = {
name: 'What crypto signals do KOL newsletters give?',
acceptedAnswer: {
'@type': 'Answer',
text: 'Trump Alpha ingests 19 crypto KOL newsletters, blogs, and podcast feeds daily — including Arthur Hayes, Delphi Digital, Dragonfly Capital, Bankless, and Unchained. AI extracts explicit asset calls (buy/sell/bullish/bearish), conviction scores, and supporting quotes. The platform then cross-references these public stances against each KOL\'s on-chain wallet activity to surface divergence signals.',
text: 'Trump Alpha ingests 25 crypto KOL newsletters, blogs, and podcast feeds daily — including Arthur Hayes, Delphi Digital, Bankless, and Unchained. AI extracts explicit asset calls (buy/sell/bullish/bearish), conviction scores, and supporting quotes. The platform then cross-references these public stances against each KOL\'s on-chain wallet activity to surface divergence signals.',
},
},
{
@@ -429,7 +429,7 @@ export default async function RootLayout({ children }: { children: React.ReactNo
}
return (
<html lang={locale === 'zh' ? 'zh-CN' : 'en'}>
<html lang={locale === 'zh' ? 'zh-CN' : 'en-US'}>
<head>
<script
type="application/ld+json"
+1 -1
View File
@@ -153,7 +153,7 @@ export default function OGImage() {
>
{[
{ v: '<3s', l: 'post → position' },
{ v: '19', l: 'KOL feeds' },
{ v: '25', l: 'KOL feeds' },
{ v: '$0', l: 'platform fee' },
].map((s) => (
<div key={s.l} style={{ display: 'flex', gap: 10, alignItems: 'baseline' }}>
+7 -7
View File
@@ -354,8 +354,8 @@ export default function LandingPage() {
<PillarCard
tag="Daily · narrative"
title="KOL Signal"
desc="19 crypto KOL feeds (Hayes, Delphi, Bankless…). AI extracts which tokens they called and how convicted they were."
metric="15"
desc="25 crypto KOL feeds (Hayes, Delphi, Bankless…). AI extracts which tokens they called and how convicted they were."
metric="25"
metricLabel="live feeds"
href="/en/kol"
/>
@@ -621,8 +621,8 @@ export default function LandingPage() {
<div className="lp-reveal" style={{ maxWidth: 680 }}>
<div className="lp-eyebrow">How it compares</div>
<h2 className="lp-h2">
Free. Non-custodial.<br />
<span className="grad">No subscription.</span>
Free to read. Non-custodial.<br />
<span className="grad">Auto-trade is opt-in.</span>
</h2>
</div>
<div className="lp-compare-wrap lp-reveal">
@@ -638,7 +638,7 @@ export default function LandingPage() {
<tbody>
<CompRow f="Trump post → trade latency" us="<3 seconds" them="manual / N/A" manual="minuteshours" />
<CompRow f="BTC macro-bottom signal" us="✓ 2-of-3 confluence" them="paid tier" manual="✗" />
<CompRow f="KOL feed ingestion" us="19 feeds daily" them="limited / paid" manual="slow" />
<CompRow f="KOL feed ingestion" us="25 feeds daily" them="limited / paid" manual="slow" />
<CompRow f="Talks-vs-trades divergence" us="✓ built-in" them="✗" manual="✗" />
<CompRow f="Auto-trader integration" us="✓ Hyperliquid" them="✗" manual="✗" />
<CompRow f="Price" us="Free" them="$49$299/mo" manual="time cost" />
@@ -661,8 +661,8 @@ export default function LandingPage() {
<strong>Trump Alpha</strong> is an AI-powered crypto intelligence dashboard that
aggregates six uncorrelated signal sources into one live feed Trump Truth Social
posts, BTC macro-bottom confluence (AHR999 + 200-week MA + Pi Cycle Bottom),
19 KOL narrative feeds, talks-vs-trades divergence, and a
Hyperliquid auto-trader. All signal reading is free. No custody. No subscription.
25 KOL narrative feeds, talks-vs-trades divergence, and a
Hyperliquid auto-trader. All signal reading is free and public. No custody. Auto-trading requires a subscription and your own HL API key.
</p>
<p className="lp-lead" style={{ marginBottom: 0, fontSize: 15 }}>
<Link href="/en/methodology" style={{ color: 'var(--lp-amber)', textDecoration: 'none' }}>Signal methodology</Link>
+3 -3
View File
@@ -457,7 +457,7 @@ export default function MacroPanel() {
label="Altcoin Season"
value={ind.altcoin_season_index == null ? '—' : ind.altcoin_season_index.toFixed(0) + ' / 100'}
tone={toneAltseason(ind.altcoin_season_index)}
hint="% of top-50 alts that beat BTC over the last 30 days. < 25 = Bitcoin season, 2560 = mixed, 6075 = alt strength building, ≥ 75 = altseason."
hint="% of top-50 alts that beat BTC over the last 90 days (blockchaincenter.net formula). < 25 = Bitcoin season, 2560 = mixed, 6075 = alt strength building, ≥ 75 = altseason."
summary={altSay}
activeIndex={altActive}
thresholds={[
@@ -466,8 +466,8 @@ export default function MacroPanel() {
{ label: '6075 alt strength', tone: 'up' },
{ label: '≥ 75 altseason', tone: 'up' },
]}
chartHref="https://www.coinglass.com/en/pro/i/alt-coin-season"
chartLabel="CoinGlass"
chartHref="https://www.blockchaincenter.net/altcoin-season-index/"
chartLabel="BlockchainCenter"
/>
<MetricCard
rank={3}
-296
View File
@@ -1,296 +0,0 @@
'use client'
import { useEffect, useState } from 'react'
import { useAccount, useConnect, useSignMessage } from 'wagmi'
import type { BotPerformance } from '@/types'
import { useDashboardStore } from '@/store/dashboard'
import { getUserPublic, setHlApiKey, subscribe } from '@/lib/api'
import { signRequest } from '@/lib/signedRequest'
import { isUserRejection, walletErrorLabel } from '@/lib/walletError'
import { getFirstReadyConnector, walletConnectErrorLabel } from '@/lib/walletConnect'
// Action names must match backend/app/api/{user,subscribe}.py
const ACTION_SET_API_KEY = 'set_hl_api_key'
const ACTION_SUBSCRIBE = 'subscribe'
interface Props {
performance?: BotPerformance | null
}
type SaveState = 'idle' | 'signing' | 'saving' | 'success' | 'error'
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 BotPanel({ performance }: Props) {
const { isSubscribed, hlApiKeySet, hlApiKeyMasked, botReadiness, setBotReadiness, setHlApiKeySet, setSubscribed } = useDashboardStore()
const { address, isConnected } = useAccount()
const { connectAsync, connectors } = useConnect()
const { signMessageAsync } = useSignMessage()
const [mounted, setMounted] = useState(false)
const [apiKey, setApiKey] = useState('')
const [saveState, setSaveState] = useState<SaveState>('idle')
const [errorMsg, setErrorMsg] = useState('')
const [subState, setSubState] = useState<'idle' | 'signing' | 'saving' | 'error'>('idle')
const [subError, setSubError] = useState('')
const [connectError, setConnectError] = useState('')
useEffect(() => { setMounted(true) }, [])
useEffect(() => {
if (!isConnected || !address) {
setSubscribed(false)
setHlApiKeySet(false)
setBotReadiness('unknown')
return
}
setSubscribed(false)
setHlApiKeySet(false)
setBotReadiness('unknown')
getUserPublic(address.toLowerCase())
.then((user) => {
setSubscribed(user.active)
setHlApiKeySet(user.hl_api_key_set)
setBotReadiness(user.hl_api_key_set ? 'saved' : 'unknown')
})
.catch(() => {})
}, [address, isConnected, setHlApiKeySet, setSubscribed, setBotReadiness])
async function refreshUserState(wallet: string) {
const pub = await getUserPublic(wallet.toLowerCase())
setSubscribed(pub.active)
setHlApiKeySet(pub.hl_api_key_set)
setBotReadiness(pub.hl_api_key_set ? 'saved' : 'unknown')
return pub
}
async function handleSubscribe() {
if (!address) return
setSubError('')
try {
setSubState('signing')
const env = await signRequest({
action: ACTION_SUBSCRIBE,
wallet: address,
body: null,
signMessageAsync,
})
setSubState('saving')
await subscribe(env)
await refreshUserState(address)
setSubState('idle')
} catch (err: unknown) {
setSubError(walletErrorLabel(err, 'Signature cancelled', 120))
setSubState('error')
}
}
async function handleSaveKey() {
if (!address || !apiKey.trim()) return
if (!apiKey.trim().startsWith('0x') || apiKey.trim().length !== 66) {
setErrorMsg('Key must start with 0x and be 66 characters')
setSaveState('error')
return
}
setErrorMsg('')
try {
setSaveState('signing')
const trimmed = apiKey.trim()
const env = await signRequest({
action: ACTION_SET_API_KEY,
wallet: address,
body: { api_key: trimmed },
signMessageAsync,
})
setSaveState('saving')
const res = await setHlApiKey(env, trimmed)
const pub = await refreshUserState(address)
setHlApiKeySet(pub.hl_api_key_set, res.masked_key)
setApiKey('')
setSaveState('success')
} catch (err: unknown) {
if (isUserRejection(err)) {
setErrorMsg('Signature cancelled')
} else {
setErrorMsg(walletErrorLabel(err, 'Signature cancelled', 120))
}
setSaveState('error')
}
}
const saveLabel =
saveState === 'signing' ? 'Waiting for signature…'
: saveState === 'saving' ? 'Saving…'
: saveState === 'success' ? '✓ Saved'
: 'Save key'
async function handleConnectWallet() {
setConnectError('')
try {
const connector = await getFirstReadyConnector(connectors)
if (!connector) {
setConnectError('No wallet connector is available right now.')
return
}
await connectAsync({ connector })
} catch (err: unknown) {
setConnectError(walletConnectErrorLabel(err))
}
}
return (
<>
{/* Bot status card — dark design */}
<div className="bot-status">
<div className="bot-head">
<h3>
<span style={{ width: 8, height: 8, borderRadius: 999, background: botReadiness === 'ready' ? 'var(--amber)' : hlApiKeySet ? 'var(--up)' : isSubscribed ? 'var(--up)' : 'oklch(70% 0.01 85)', display: 'inline-block' }} />
Auto-trader
</h3>
<span style={{ fontSize: 11, opacity: 0.7, textTransform: 'uppercase', letterSpacing: '0.08em' }}>30 days</span>
</div>
<div className="bot-stats">
<div className="bot-stat">
<div className="k">Net P&amp;L</div>
<div className="v amber">
{performance ? (performance.net_pnl_usd >= 0 ? '+$' : '-$') + Math.abs(performance.net_pnl_usd).toLocaleString('en-US', { maximumFractionDigits: 0 }) : '—'}
</div>
</div>
<div className="bot-stat">
<div className="k">Win rate</div>
<div className="v up">
{performance ? (performance.win_rate * 100).toFixed(1) + '%' : '—'}
</div>
</div>
<div className="bot-stat">
<div className="k">Trades</div>
<div className="v">{performance?.total_trades ?? '—'}</div>
</div>
<div className="bot-stat">
<div className="k">Avg hold</div>
<div className="v">{performance ? fmtHold(performance.avg_hold_seconds) : '—'}</div>
</div>
</div>
<div className="bot-cta">
{(!mounted || !isConnected) && (
<>
<button className="btn amber" style={{ width: '100%' }}
onClick={() => { void handleConnectWallet() }}>
Connect wallet
</button>
{connectError && (
<p style={{ fontSize: 11, color: 'var(--down)', marginTop: 6, textAlign: 'center' }}>{connectError}</p>
)}
</>
)}
{mounted && isConnected && !isSubscribed && (
<div style={{ width: '100%' }}>
<button
className="btn amber"
style={{ width: '100%' }}
onClick={handleSubscribe}
disabled={subState === 'signing' || subState === 'saving'}
>
{subState === 'signing' ? 'Waiting for signature…' : subState === 'saving' ? 'Activating…' : 'Start trading'}
</button>
{subState === 'error' && subError && (
<p style={{ fontSize: 11, color: 'var(--down)', marginTop: 6, textAlign: 'center' }}>{subError}</p>
)}
</div>
)}
{mounted && isConnected && isSubscribed && !hlApiKeySet && (
<div style={{ width: '100%', textAlign: 'center', fontSize: 12, color: 'oklch(75% 0.01 85)', padding: '6px 0' }}>
Paste your Hyperliquid API key below to finish setup
</div>
)}
{mounted && isConnected && isSubscribed && hlApiKeySet && (
<div style={{ width: '100%', textAlign: 'center', fontSize: 12, color: 'var(--amber)', padding: '6px 0', fontWeight: 500 }}>
Setup saved · verification still depends on backend
</div>
)}
</div>
</div>
{/* HL API Key card — only when subscribed */}
{mounted && isConnected && isSubscribed && (
<div className="card" style={{ padding: 20 }}>
<div className="section-title">
<h2 style={{ fontSize: 14 }}>Hyperliquid API key</h2>
{hlApiKeySet && <span style={{ fontSize: 11, color: 'var(--up)', fontWeight: 500 }}> Connected</span>}
</div>
{hlApiKeySet && !apiKey && (
<div className="row between" style={{ padding: '10px 12px', background: 'var(--bg-sunk)', borderRadius: 'var(--r-sm)', border: '1px solid var(--line)', marginBottom: 12 }}>
<span style={{ fontSize: 12, color: 'var(--up)', fontFamily: 'var(--mono)' }}>
{hlApiKeyMasked ?? '···'}
</span>
<button
style={{ fontSize: 11, color: 'var(--ink-3)' }}
onClick={() => { setSaveState('idle'); setApiKey(' ') }}
>
Update
</button>
</div>
)}
{(!hlApiKeySet || apiKey) && (
<>
<div className="field" style={{ marginBottom: 12 }}>
<label>API wallet private key</label>
<input
value={apiKey.trim() === '' && hlApiKeySet ? '' : apiKey}
onChange={(e) => {
setApiKey(e.target.value)
if (saveState === 'error' || saveState === 'success') setSaveState('idle')
}}
placeholder="0x…"
/>
<div className="hint">
From{' '}
<a href="https://app.hyperliquid.xyz/API" target="_blank" rel="noopener noreferrer" style={{ color: 'var(--amber-ink)' }}>
app.hyperliquid.xyz/API
</a>
</div>
</div>
{saveState === 'error' && errorMsg && (
<p style={{ fontSize: 11, color: 'var(--down)', marginBottom: 8 }}>{errorMsg}</p>
)}
<button
className={`btn ${saveState === 'success' ? 'ghost' : 'amber'}`}
style={{ width: '100%' }}
onClick={handleSaveKey}
disabled={saveState === 'signing' || saveState === 'saving' || !apiKey.trim()}
>
{saveLabel}
</button>
</>
)}
{!hlApiKeySet && (
<details style={{ marginTop: 12 }}>
<summary style={{ fontSize: 11, color: 'var(--ink-3)', cursor: 'pointer' }}>
How to get your API key
</summary>
<ol style={{ marginTop: 8, fontSize: 11, color: 'var(--ink-3)', paddingLeft: 16, lineHeight: 1.7 }}>
<li>Deposit USDC at app.hyperliquid.xyz</li>
<li>Go to app.hyperliquid.xyz/API</li>
<li>Click <strong>Generate API Wallet</strong></li>
<li>Sign with MetaMask (no gas)</li>
<li>Copy the private key paste above</li>
</ol>
</details>
)}
</div>
)}
</>
)
}
+1 -1
View File
@@ -417,7 +417,7 @@ export default function ChartPanel({ posts = [], candles = [], externalSelectedI
}
}, [candles, posts, externalSelectedId, asset])
useEffect(() => { fittedRef.current = false }, [timeframe])
useEffect(() => { fittedRef.current = false }, [timeframe, asset])
// Live-tick the rightmost candle so the chart feels alive between REST polls.
// lightweight-charts' `series.update()` either appends a new bar (newer time)
+20 -16
View File
@@ -66,16 +66,18 @@ function LocalDateTime({ iso, opts }: { iso: string; opts?: Intl.DateTimeFormatO
// When adding a new scanner source, register it here too — otherwise it
// falls through to the generic "first letter" fallback which has no title
// or accent colour.
const SOURCE_DISPLAY: Record<string, { glyph: string; cls: string; title: string }> = {
truth: { glyph: 'T', cls: 'truth', title: 'Trump · Truth Social' },
breakout: { glyph: '▲', cls: 'breakout', title: 'VCP / breakout scanner' },
vcp_breakout: { glyph: '▲', cls: 'breakout', title: 'VCP / breakout scanner' },
reversal: { glyph: '⇋', cls: 'reversal', title: 'Reversal scanner' },
btc_bottom_reversal: { glyph: '₿', cls: 'reversal', title: 'BTC · Macro Bottom Reversal' },
funding_reversal: { glyph: 'ƒ', cls: 'reversal', title: 'BTC · Funding Rate Reversal' },
kol_divergence: { glyph: '⚖', cls: 'whale', title: 'KOL · Talks vs Trades Divergence' },
whale: { glyph: '🐋', cls: 'whale', title: 'On-chain whale alert' },
manual: { glyph: '', cls: 'manual', title: 'Manual entry' },
export const SOURCE_DISPLAY: Record<string, { glyph: string; cls: string; title: string; label: string }> = {
truth: { glyph: 'T', cls: 'truth', title: 'Trump · Truth Social', label: '@realDonaldTrump' },
breakout: { glyph: '▲', cls: 'breakout', title: 'VCP / breakout scanner', label: 'Breakout scanner' },
vcp_breakout: { glyph: '▲', cls: 'breakout', title: 'VCP / breakout scanner', label: 'Breakout scanner' },
reversal: { glyph: '⇋', cls: 'reversal', title: 'Reversal scanner', label: 'Reversal scanner' },
btc_bottom_reversal: { glyph: '₿', cls: 'reversal', title: 'BTC Macro Bottom scanner', label: 'BTC Macro Bottom' },
funding_reversal: { glyph: 'ƒ', cls: 'reversal', title: 'BTC Funding Rate Reversal scanner', label: 'Funding Reversal' },
kol_divergence: { glyph: '⚖', cls: 'whale', title: 'KOL Talks-vs-Trades Divergence', label: 'KOL Divergence' },
sma_reclaim: { glyph: '', cls: 'breakout', title: 'SMA reclaim scanner', label: 'SMA Reclaim' },
rsi_reversal: { glyph: '', cls: 'reversal', title: 'RSI reversal scanner', label: 'RSI Reversal' },
whale: { glyph: '🐋', cls: 'whale', title: 'On-chain whale alert', label: 'Whale alert' },
manual: { glyph: '✋', cls: 'manual', title: 'Manual entry', label: 'Manual' },
}
function SourceIcon({ source }: { source: string }) {
@@ -119,7 +121,7 @@ const PostRow = memo(function PostRow({ post, selected, onClick }: PostRowProps)
return (
<div
className={`post-row ${selected ? 'selected' : ''} ${aiScored ? '' : 'noise'}`}
className={`post-row ${selected ? 'selected' : ''} ${aiScored ? '' : 'noise'} ${post.signal === 'buy' ? 'signal-buy' : post.signal === 'short' ? 'signal-short' : ''}`}
onClick={handleClick}
>
{/* ── main row ── */}
@@ -130,7 +132,7 @@ const PostRow = memo(function PostRow({ post, selected, onClick }: PostRowProps)
{/* Author label depends on source non-Trump signals come from
technical scanners or external modules, not @realDonaldTrump. */}
<span className="mono" style={{ color: 'var(--ink-2)', fontWeight: 500 }}>
{post.source === 'truth' ? '@realDonaldTrump' : post.source}
{SOURCE_DISPLAY[post.source?.toLowerCase?.()]?.label ?? post.source ?? 'Signal'}
</span>
<span>·</span>
<TimeAgo iso={post.published_at} suffix=" ago" />
@@ -186,7 +188,7 @@ const PostRow = memo(function PostRow({ post, selected, onClick }: PostRowProps)
<div className="impact-mini">
{impact ? (
<>
<span className="tf">1h peak</span>
<span className="tf">1h move</span>
<span className={`delta ${impact.m1h == null ? '' : impact.m1h >= 0 ? 'up' : 'down'}`}>
{impact.m1h == null ? '…' : fmtPct(impact.m1h)}
</span>
@@ -246,7 +248,7 @@ const PostRow = memo(function PostRow({ post, selected, onClick }: PostRowProps)
</span>
{post.expected_move_pct != null && (
<span style={{ fontSize: 11, color: 'var(--ink-3)' }}>
{`AI expects ~${post.expected_move_pct}% in 1h`}
{`model projection ~${post.expected_move_pct}% · 1h`}
</span>
)}
{post.category && (
@@ -260,7 +262,9 @@ const PostRow = memo(function PostRow({ post, selected, onClick }: PostRowProps)
{/* AI reasoning */}
{post.ai_reasoning && (
<div>
<div className="ai-reasoning-label">AI reasoning</div>
<div className="ai-reasoning-label">
{post.signal === 'buy' || post.signal === 'short' ? 'Why this signal fired' : 'Why this was filtered out'}
</div>
<div className="ai-reasoning-card">
{post.ai_reasoning}
</div>
@@ -270,7 +274,7 @@ const PostRow = memo(function PostRow({ post, selected, onClick }: PostRowProps)
{/* Price impact — peak move in signal direction per window */}
{impact && (
<div>
<div className="tiny" style={{ marginBottom: 8 }}>{`Peak move · ${impact.asset}`}</div>
<div className="tiny" style={{ marginBottom: 8 }}>{`Price moved · ${impact.asset} · after signal`}</div>
<div style={{ display: 'grid', gridTemplateColumns: '1fr 1fr 1fr', gap: 8 }}>
{(['m5', 'm15', 'm1h'] as const).map(key => {
const label = key === 'm5' ? '5m' : key === 'm15' ? '15m' : '1h'
+14 -95
View File
@@ -1,7 +1,6 @@
'use client'
import { useState, useEffect, useCallback } from 'react'
import { useLocale } from 'next-intl'
import { useState, useEffect } from 'react'
import { useWsSubscribe } from '@/lib/wsContext'
const API_BASE = '/api/proxy/api'
@@ -30,72 +29,12 @@ function timeAgo(iso: string) {
return `${Math.round(diff / 3600)}h ago`
}
// ── iOS-style toggle switch ───────────────────────────────────────────────────
function ToggleSwitch({ on, loading, onToggle }: {
on: boolean
loading: boolean
onToggle: () => void
}) {
return (
<button
onClick={onToggle}
disabled={loading}
title={on ? 'Click to disable' : 'Click to enable'}
style={{
display: 'flex',
alignItems: 'center',
gap: 8,
background: 'none',
border: 'none',
cursor: loading ? 'not-allowed' : 'pointer',
padding: 0,
opacity: loading ? 0.5 : 1,
}}
>
{/* Switch track */}
<div style={{
width: 44,
height: 26,
borderRadius: 13,
background: on ? '#22c55e' : 'var(--ink-4)',
position: 'relative',
transition: 'background 0.2s',
flexShrink: 0,
opacity: on ? 1 : 0.5,
}}>
{/* Thumb */}
<div style={{
width: 18,
height: 18,
borderRadius: '50%',
background: '#fff',
position: 'absolute',
top: 2,
left: on ? 20 : 2,
transition: 'left 0.2s',
boxShadow: '0 1px 3px rgba(0,0,0,0.3)',
}} />
</div>
<span style={{
fontSize: 12,
fontWeight: 600,
color: on ? '#22c55e' : 'var(--ink-3)',
letterSpacing: '0.05em',
minWidth: 24,
}}>
{on ? 'ON' : 'OFF'}
</span>
</button>
)
}
// ── Main component ────────────────────────────────────────────────────────────
// Display-only: toggle is operator-only (requires X-Ingest-Key) so the
// on/off switch is intentionally absent from the user-facing UI.
export default function SignalMonitor() {
const locale = useLocale()
const isZh = false // i18n shelved — Chinese branches kept as dead code for future revival; see messages/zh.json
const [enabled, setEnabledState] = useState(false)
const [loading, setLoading] = useState(false)
const [backendOk, setBackendOk] = useState<boolean | null>(null)
const [signals, setSignals] = useState<SignalAlert[]>([])
const [btcTrend, setBtcTrend] = useState<string | null>(null)
const [lastScan, setLastScan] = useState<Date | null>(null)
@@ -104,8 +43,8 @@ export default function SignalMonitor() {
useEffect(() => {
fetch(`${API_BASE}/signal/status`)
.then(r => { if (!r.ok) throw new Error(); return r.json() })
.then(d => { setEnabledState(d.enabled); setBackendOk(true) })
.catch(() => setBackendOk(false))
.then(d => { setEnabledState(d.enabled) })
.catch(() => {})
fetch(`${API_BASE}/signal/history?limit=20`)
.then(r => r.json())
@@ -128,22 +67,6 @@ export default function SignalMonitor() {
setSignals(prev => [alert, ...prev].slice(0, 50))
})
// ── Toggle ───────────────────────────────────────────────────────────────
const toggle = useCallback(async () => {
setLoading(true)
try {
const next = !enabled
const r = await fetch(`${API_BASE}/signal/toggle?enabled=${next}`, { method: 'POST' })
if (!r.ok) throw new Error()
const d = await r.json()
setEnabledState(d.enabled)
setBackendOk(true)
} catch {
setBackendOk(false)
}
setLoading(false)
}, [enabled])
// ── Render ───────────────────────────────────────────────────────────────
const btcUp = btcTrend?.includes('↑')
@@ -160,20 +83,16 @@ export default function SignalMonitor() {
{isZh ? 'ETH · LINK · 5 分钟扫描' : 'ETH · LINK · 5m scan'}
</div>
</div>
<ToggleSwitch on={enabled} loading={loading} onToggle={toggle} />
</div>
{/* Backend offline warning */}
{backendOk === false && (
{/* Enabled status dot — display-only; toggle is operator-only (X-Ingest-Key) */}
<div style={{ display: 'flex', alignItems: 'center', gap: 6, fontSize: 11, color: enabled ? '#22c55e' : 'var(--ink-3)' }}>
<div style={{
fontSize: 11, color: '#f59e0b',
padding: '6px 10px', borderRadius: 6,
background: 'rgba(245,158,11,0.1)',
marginBottom: 12,
}}>
{isZh ? '后端离线,开关暂时不可用' : "Backend offline — toggle won't work"}
width: 7, height: 7, borderRadius: '50%',
background: enabled ? '#22c55e' : 'var(--ink-4)',
boxShadow: enabled ? '0 0 0 2px rgba(34,197,94,0.25)' : 'none',
}} />
{enabled ? (isZh ? '监控中' : 'Active') : (isZh ? '已暂停' : 'Paused')}
</div>
</div>
)}
{/* Status row: BTC trend + last scan */}
<div style={{
@@ -208,7 +127,7 @@ export default function SignalMonitor() {
}}>
{enabled
? (isZh ? '· 正在等待信号…' : '· Watching for signals…')
: (isZh ? 打开开关后开始监控' : Enable the toggle to start watching')}
: (isZh ? 暂无历史信号' : No signals yet')}
</div>
) : (
<div style={{ display: 'flex', flexDirection: 'column', gap: 8 }}>
+23 -2
View File
@@ -6,6 +6,8 @@ import { usePathname } from 'next/navigation'
import { useAccount, useConnect, useDisconnect } from 'wagmi'
import { useTranslations } from 'next-intl'
import { getFirstReadyConnector, walletConnectErrorLabel } from '@/lib/walletConnect'
import { needsMobileWallet } from '@/lib/mobileWallet'
import MobileWalletSheet from '@/components/wallet/MobileWalletSheet'
// i18n shelved — LanguageSwitch hidden but kept on disk for future revival.
// import LanguageSwitch from './LanguageSwitch'
@@ -31,7 +33,12 @@ function ThemeToggle() {
}
return (
<button className="icon-btn theme-toggle" onClick={toggle}>
<button
className="icon-btn theme-toggle"
onClick={toggle}
aria-label={theme === 'dark' ? 'Switch to light mode' : 'Switch to dark mode'}
title={theme === 'dark' ? 'Switch to light mode' : 'Switch to dark mode'}
>
{theme === 'dark' ? (
<svg width="16" height="16" viewBox="0 0 24 24" fill="none">
<circle cx="12" cy="12" r="4" stroke="currentColor" strokeWidth="2" />
@@ -56,6 +63,7 @@ export default function Navbar() {
const [walletMenuOpen, setWalletMenuOpen] = useState(false)
const [copied, setCopied] = useState(false)
const [connectError, setConnectError] = useState('')
const [mobileSheetOpen, setMobileSheetOpen] = useState(false)
async function copyAddress(addr: string) {
let ok = false
@@ -89,10 +97,20 @@ export default function Navbar() {
async function handleConnectWallet() {
setConnectError('')
// On mobile without an injected provider, show the wallet deep-link sheet
// instead of throwing "No wallet found". This lets users open the dApp
// inside MetaMask / Trust / Coinbase without a confusing error.
if (needsMobileWallet()) {
setMobileSheetOpen(true)
return
}
try {
const connector = await getFirstReadyConnector(connectors)
if (!connector) {
setConnectError('No wallet connector is available right now.')
// Desktop with no extension — give a helpful hint instead of raw error.
setConnectError('No wallet extension found. Install MetaMask or another browser wallet.')
return
}
await connectAsync({ connector })
@@ -124,6 +142,8 @@ export default function Navbar() {
const shortAddr = address ? `${address.slice(0, 6)}${address.slice(-4)}` : null
return (
<>
<MobileWalletSheet open={mobileSheetOpen} onClose={() => setMobileSheetOpen(false)} />
<nav className="nav">
<Link href={`/${locale}`} className="brand" style={{ textDecoration: 'none', color: 'inherit' }}>
<BrandMark />
@@ -204,5 +224,6 @@ export default function Navbar() {
</div>
</div>
</nav>
</>
)
}
+85
View File
@@ -0,0 +1,85 @@
'use client'
/**
* Ticker horizontal scrolling price tape under the navbar, the way a crypto
* terminal shows a running market strip. Driven by the shared WebSocket price
* feed (no new socket). Each asset cell flashes green/red on a price change and
* shows the live last price.
*
* Behaviour notes:
* - The strip is duplicated once and translated -50% in a CSS marquee so the
* loop is seamless (`ticker-marquee` keyframe in globals.css).
* - prefers-reduced-motion disables the scroll (CSS), so the tape becomes a
* static, readable row instead of moving.
* - The animation is paused on hover so a user can read a specific price.
* - Assets with no tick yet render "—" rather than a stale zero.
*/
import { useRef, useState } from 'react'
import { useWsSubscribe } from '@/lib/wsContext'
// Assets the backend streams (see binance ASSET_MAP + hl_price_feed). Order is
// the display order in the tape.
const ASSETS = ['BTC', 'ETH', 'SOL', 'BNB', 'DOGE', 'LINK', 'AAVE', 'TRUMP', 'HYPE'] as const
interface Cell {
price: number | null
dir: 'up' | 'down' | null
}
function fmtPrice(p: number): string {
if (p >= 1000) return '$' + p.toLocaleString('en-US', { maximumFractionDigits: 0 })
if (p >= 1) return '$' + p.toLocaleString('en-US', { maximumFractionDigits: 2 })
return '$' + p.toLocaleString('en-US', { maximumFractionDigits: 4 })
}
export default function Ticker() {
const [cells, setCells] = useState<Record<string, Cell>>({})
// Per-asset flash-clear timers so a fast stream doesn't leak setTimeouts.
const timers = useRef<Record<string, ReturnType<typeof setTimeout>>>({})
useWsSubscribe('price', (msg) => {
const m = msg as { asset?: string; price?: number }
if (!m.asset || typeof m.price !== 'number') return
const asset = m.asset.toUpperCase()
if (!ASSETS.includes(asset as (typeof ASSETS)[number])) return
setCells((prev) => {
const old = prev[asset]
const dir: Cell['dir'] =
old?.price != null && m.price !== old.price
? (m.price! > old.price ? 'up' : 'down')
: old?.dir ?? null
return { ...prev, [asset]: { price: m.price!, dir } }
})
// Clear the flash after 600ms.
clearTimeout(timers.current[asset])
timers.current[asset] = setTimeout(() => {
setCells((prev) => (prev[asset] ? { ...prev, [asset]: { ...prev[asset], dir: null } } : prev))
}, 600)
})
const strip = ASSETS.map((a) => {
const c = cells[a]
return (
<span key={a} className={`ticker-cell ${c?.dir ? `tick-flash-${c.dir}` : ''}`}>
<span className="ticker-sym">{a}</span>
<span className="ticker-px">{c?.price != null ? fmtPrice(c.price) : '—'}</span>
<span className={`ticker-arrow ${c?.dir ?? ''}`} aria-hidden>
{c?.dir === 'up' ? '▲' : c?.dir === 'down' ? '▼' : ''}
</span>
</span>
)
})
return (
<div className="ticker" role="region" aria-label="Live market prices">
<div className="ticker-track">
{strip}
{/* duplicate for seamless loop */}
<span aria-hidden style={{ display: 'contents' }}>{strip}</span>
</div>
</div>
)
}
+72 -20
View File
@@ -12,6 +12,7 @@
*/
import { useEffect, useState } from 'react'
import Link from 'next/link'
import { useLocale } from 'next-intl'
import { useAccount, useSignMessage } from 'wagmi'
import {
@@ -22,7 +23,7 @@ import {
type OpenPosition,
type TodayStats,
} from '@/lib/api'
import { getCachedViewEnvelope, signRequest } from '@/lib/signedRequest'
import { getCachedViewEnvelope, getOrCreateViewEnvelope, signRequest, type SignedEnvelope } from '@/lib/signedRequest'
import { isUserRejection, walletErrorLabel } from '@/lib/walletError'
const POLL_MS = 15_000
@@ -85,7 +86,7 @@ function PositionRow({ p, onClose, onToggleGrow, growBusy, isZh }: {
</span>
{/* Entry → Current */}
<div className="mono" style={{ fontSize: 12 }}>
<div style={{ color: 'var(--ink-3)', fontSize: 10 }}>entry mark</div>
<div style={{ color: 'var(--ink-3)', fontSize: 10 }}>entry / current price</div>
<div>
{fmtMoney(p.entry_price)}
<span style={{ color: 'var(--ink-4)' }}> </span>
@@ -102,10 +103,10 @@ function PositionRow({ p, onClose, onToggleGrow, growBusy, isZh }: {
{((p.derisk_steps ?? 0) > 0 || (p.addon_steps ?? 0) > 0) && (
<div style={{ fontSize: 9, marginTop: 2 }}>
{(p.addon_steps ?? 0) > 0 && (
<span style={{ color: 'var(--up)' }}>{`⬆ pyramided ×${p.addon_steps} `}</span>
<span style={{ color: 'var(--up)' }}>{`↑ scaled in ×${p.addon_steps} `}</span>
)}
{(p.derisk_steps ?? 0) > 0 && (
<span style={{ color: 'var(--down)' }}>{`⬇ de-risked ×${p.derisk_steps}`}</span>
<span style={{ color: 'var(--down)' }}>{`↓ trimmed ×${p.derisk_steps}`}</span>
)}
</div>
)}
@@ -114,8 +115,8 @@ function PositionRow({ p, onClose, onToggleGrow, growBusy, isZh }: {
onClick={() => onToggleGrow(p)}
disabled={growBusy}
title={p.grow_mode
? (isZh ? 'Grow 已开启:趋势确认后会继续顺势加仓。点击关闭。' : 'Grow ON — scales INTO this winner on confirmed trend. Click to turn off.')
: (isZh ? 'Grow 已关闭:仅持有并做保护性降风险。点击后允许顺势加仓。' : 'Grow OFF — hold + protective de-risk only. Click to let it pyramid.')}
? (isZh ? '加仓已开启:趋势确认后自动追加仓。点击关闭。' : 'Scale-in ON — bot adds to this position when trend is confirmed. Click to turn off.')
: (isZh ? '加仓已关闭:仅持有并做保护性仓。' : 'Scale-in OFF — hold + protective trim only. Click to allow adding.')}
style={{
marginTop: 4, fontSize: 9, fontWeight: 700, padding: '2px 7px',
borderRadius: 999, cursor: growBusy ? 'wait' : 'pointer',
@@ -124,7 +125,7 @@ function PositionRow({ p, onClose, onToggleGrow, growBusy, isZh }: {
color: p.grow_mode ? '#fff' : 'var(--ink-3)',
}}
>
{p.grow_mode ? '⬆ Grow ON' : 'Grow OFF'}
{p.grow_mode ? '↑ Scale-in ON' : 'Scale-in OFF'}
</button>
</div>
{/* Hold time */}
@@ -141,7 +142,7 @@ function PositionRow({ p, onClose, onToggleGrow, growBusy, isZh }: {
</div>
{p.realized_usd != null && p.realized_usd !== 0 && (
<div style={{ fontSize: 10, color: 'var(--ink-3)', marginTop: 1 }}>
locked in {fmtMoney(p.realized_usd, { sign: true })}
banked {fmtMoney(p.realized_usd, { sign: true })} from partial close
</div>
)}
</div>
@@ -172,6 +173,7 @@ export default function OpenPositions() {
const [today, setToday] = useState<TodayStats | null>(null)
const [err, setErr] = useState<string | null>(null)
const [needsUnlock, setNeedsUnlock] = useState(false)
const [unlocking, setUnlocking] = useState(false)
// Close-confirmation modal state
const [closing, setClosing] = useState<OpenPosition | null>(null)
const [closeState, setCloseState] = useState<'idle'|'signing'|'closing'|'err'>('idle')
@@ -212,10 +214,11 @@ export default function OpenPositions() {
}
useEffect(() => {
if (!isConnected || !address) {
// B39: wipe stale data from the previous wallet immediately — don't wait
// for the async fetch to complete before the UI shows a clean slate.
setPositions(null); setToday(null); setNeedsUnlock(false); setErr(null)
return
}
if (!isConnected || !address) return
let cancelled = false
// Only reuse a cached envelope here. Open positions should never trigger
@@ -253,6 +256,31 @@ export default function OpenPositions() {
// eslint-disable-next-line react-hooks/exhaustive-deps
}, [address, isConnected])
// In-page unlock: mint a view_user envelope (one signature) right here and
// load positions immediately — no detour to the Settings page. view_user is
// a superset accepted by /positions/open and /positions/today.
async function handleUnlock() {
if (!address || unlocking) return
setUnlocking(true); setErr(null)
try {
const env = await getOrCreateViewEnvelope({
action: 'view_user', wallet: address, signMessageAsync,
})
const [p, t] = await Promise.all([
getOpenPositions(address, env),
getTodayStats(address, env),
])
setPositions(p.positions); setToday(t); setNeedsUnlock(false); setErr(null)
} catch (e: unknown) {
// User-cancelled signature is benign — keep the unlock CTA visible.
if (!isUserRejection(e)) {
setErr(e instanceof Error ? e.message.slice(0, 80) : (isZh ? '解锁失败' : 'unlock failed'))
}
} finally {
setUnlocking(false)
}
}
// Trigger close. Two-step: opens modal, user confirms, we sign + POST.
async function confirmCloseTrade() {
if (!address || !closing) return
@@ -293,15 +321,39 @@ export default function OpenPositions() {
Open positions
</div>
<div style={{ fontSize: 14, fontWeight: 600, color: 'var(--ink)' }}>
Sign in once to view open positions
Sign in to see open positions
</div>
<div style={{ fontSize: 12, color: 'var(--ink-3)', marginTop: 4, lineHeight: 1.6 }}>
Go to the <strong>Settings page</strong> and click <em>Sign in to view your settings</em>. After signing, your open positions will appear here automatically.
Sign once on this device to unlock your positions (valid for a few
minutes, no transaction, no gas).
</div>
<div style={{ display: 'flex', alignItems: 'center', gap: 10, marginTop: 10, flexWrap: 'wrap' }}>
<button className="btn amber" style={{ fontSize: 13, padding: '8px 16px' }}
disabled={unlocking} onClick={handleUnlock}>
{unlocking ? 'Waiting for signature…' : 'Unlock positions'}
</button>
<Link href={`/${locale}/settings`} style={{ fontSize: 12, color: 'var(--ink-3)', textDecoration: 'none' }}>
or go to Settings
</Link>
</div>
{err && (
<div style={{ fontSize: 11, color: 'var(--down)', marginTop: 8 }}> {err}</div>
)}
</div>
)
}
if (positions === null && today === null) return null
// When the first load fails, positions and today are still null but err is set.
// Without this guard the component returns null (blank), swallowing the error.
if (positions === null && today === null) {
if (err) {
return (
<div className="card" style={{ padding: '12px 16px', marginBottom: 16, fontSize: 12, color: 'var(--down)' }}>
Could not load positions {err}
</div>
)
}
return null
}
const totalUnrealized = (positions ?? []).reduce(
(s, p) => s + (p.unrealized_usd ?? 0), 0,
@@ -363,7 +415,7 @@ export default function OpenPositions() {
</div>
{today != null && (today.open_realized_usd ?? 0) !== 0 && (
<div style={{ fontSize: 10, color: 'var(--ink-3)', marginTop: 1 }}>
{`incl. ${fmtMoney(today.open_realized_usd, { sign: true })} locked in on open trades`}
{`incl. ${fmtMoney(today.open_realized_usd, { sign: true })} banked from partial closes`}
</div>
)}
</div>
@@ -447,8 +499,8 @@ export default function OpenPositions() {
</div>
<div style={{ fontSize: 12, color: 'var(--ink-3)', marginBottom: 16 }}>
{closing.is_paper
? (isZh ? '这是模拟交易,平仓只做本地记录,不会调用 Hyperliquid。' : 'Paper trade — synthetic close, no Hyperliquid call.')
: (isZh ? '会向 Hyperliquid 发送 IOC 市价单。已实现盈亏将立即确认。' : 'Sends an IOC market order to Hyperliquid. Realised PnL is permanent.')}
? (isZh ? '这是模拟交易,平仓只做本地记录,不会动用真实资金。' : 'Paper trade — simulated close, no real funds involved.')
: (isZh ? '立即按市价在 Hyperliquid 上平仓。盈亏将立即结算,无法撤销。' : 'Closes at market price on Hyperliquid right now. The profit or loss becomes final and cannot be undone.')}
</div>
<div style={{
background: 'var(--bg-sunk)', borderRadius: 8, padding: 14, marginBottom: 16,
@@ -458,17 +510,17 @@ export default function OpenPositions() {
<span className="mono">{fmtMoney(closing.entry_price)}</span>
</div>
<div style={{ display: 'flex', justifyContent: 'space-between', fontSize: 12, marginBottom: 6 }}>
<span style={{ color: 'var(--ink-3)' }}>{isZh ? '现价' : 'Mark'}</span>
<span style={{ color: 'var(--ink-3)' }}>{isZh ? '现价' : 'Current price'}</span>
<span className="mono">{closing.current_price != null ? fmtMoney(closing.current_price) : (isZh ? '暂无' : 'n/a')}</span>
</div>
{closing.realized_usd != null && closing.realized_usd !== 0 && (
<div style={{ display: 'flex', justifyContent: 'space-between', fontSize: 12, marginBottom: 6, color: 'var(--ink-3)' }}>
<span>{isZh ? '已锁定(降风险' : 'Locked in (de-risked)'}</span>
<span>{isZh ? '已落袋(之前减仓' : 'Already banked'}</span>
<span className="mono">{fmtMoney(closing.realized_usd, { sign: true })}</span>
</div>
)}
<div style={{ display: 'flex', justifyContent: 'space-between', fontSize: 13, fontWeight: 600, marginTop: 8, paddingTop: 8, borderTop: '1px solid var(--line)' }}>
<span>{isZh ? '当前未平部分预估盈亏' : 'Est. PnL on open portion'}</span>
<span>{isZh ? '平仓后将结算' : 'You\'ll get if you close now'}</span>
<span style={{
color: (closing.unrealized_usd ?? 0) > 0 ? 'var(--up)'
: (closing.unrealized_usd ?? 0) < 0 ? 'var(--down)' : 'var(--ink-2)',
+58 -53
View File
@@ -1,6 +1,6 @@
'use client'
import Link from 'next/link'
import { useState, useEffect, useCallback } from 'react'
import { useState, useEffect, useCallback, useRef } from 'react'
import { useLocale } from 'next-intl'
import { useAccount, useSignMessage } from 'wagmi'
import { getUserPublic, setAutoTrade, type UserPublic } from '@/lib/api'
@@ -25,8 +25,8 @@ import { confirmSign } from '@/components/wallet/SignConfirmSheet'
*/
const SYS = {
trump: { idx: '', name: 'Trump', accent: '#b45309', soft: 'rgba(180,83,9,0.08)' },
btc: { idx: '', name: 'Macro Vibes', accent: '#16a34a', soft: 'rgba(22,163,74,0.08)' },
trump: { idx: '', name: 'Trump Signal', accent: '#b45309', soft: 'rgba(180,83,9,0.08)' },
btc: { idx: '', name: 'Macro Vibes', accent: '#16a34a', soft: 'rgba(22,163,74,0.08)' },
} as const
const ROW: React.CSSProperties = {
@@ -49,9 +49,18 @@ export default function SystemControl({ system }: { system: 'trump' | 'btc' }) {
useEffect(() => { setMounted(true) }, [])
// Generation counter: each address change increments it so any in-flight
// refresh from the previous address can detect it's stale.
// `snap !== address` inside a useCallback is a stale-closure trap — both
// refer to the same closed-over value so the check is always false.
const genRef = useRef(0)
useEffect(() => { genRef.current++ }, [address])
const refresh = useCallback(async () => {
if (!address) { setPub(null); return }
const gen = genRef.current
const p = await getUserPublic(address.toLowerCase()).catch(() => null)
if (gen !== genRef.current) return // wallet changed while in-flight
setPub(p)
}, [address])
@@ -71,6 +80,14 @@ export default function SystemControl({ system }: { system: 'trump' | 'btc' }) {
if (busy) return
if (!address) { setErr(isZh ? '请先连接右上角的钱包。' : 'Connect your wallet first (top-right).'); return }
if (!subscribed) { setErr(isZh ? '钱包尚未订阅,请先去设置页完成订阅。' : 'Wallet not subscribed — subscribe on the Settings page first.'); return }
// B51: live users without an HL API key cannot actually execute trades —
// block the toggle so the ON state never silently becomes a no-op.
if (on && !paper && !pub?.hl_api_key_set) {
setErr(isZh
? '未绑定 Hyperliquid API Key。请先在设置页保存 API KeyAuto-Trade 才能真实下单。'
: 'No Hyperliquid API key saved. Add your HL API key on the Settings page before enabling Auto-Trade.')
return
}
if (autoOn === on) return
// Claim the busy slot BEFORE awaiting confirmSign — otherwise a rapid
@@ -141,39 +158,35 @@ export default function SystemControl({ system }: { system: 'trump' | 'btc' }) {
// auto-open and (b) be a confusing second copy of the SAME global switch
// shown on the Trump page. Show the adopt-only flow instead.
if (system === 'btc') {
const linkStyle: React.CSSProperties = {
display: 'inline-flex', alignItems: 'center', gap: 8, padding: '8px 12px',
borderRadius: 999, border: '1px solid var(--line)', background: 'var(--surface)',
fontSize: 12, color: 'var(--ink)', textDecoration: 'none', fontWeight: 700,
boxShadow: 'var(--shadow-1)',
}
// Compact inline strip — signal fires → you open → bot manages.
// No big card; the data panel is the main content. Settings link stays
// for users who want to configure, but the explanation is one line.
return (
<div className="card" style={{ padding: 0, marginBottom: 16, overflow: 'hidden' }}>
<div style={{ padding: '14px 16px', background: s.soft,
borderLeft: `4px solid ${s.accent}` }}>
<div style={{ fontSize: 14, fontWeight: 700, color: s.accent }}>
{s.idx} {s.name} manage-only
</div>
</div>
<div style={{ padding: '16px', fontSize: 13, color: 'var(--ink-2)', lineHeight: 1.6 }}>
<p style={{ margin: '0 0 10px' }}>
<strong>Macro Vibes does not auto-open trades.</strong> When a bottom-reversal
signal fires you get a Telegram alert. You open the position yourself on
Hyperliquid, then hand it to the bot with <code>/adopt</code> the bot then
manages the exit (staged stop ladder, de-risk, pyramid, peak-trail).
</p>
<p style={{ margin: '0 0 12px', color: 'var(--ink-4)', fontSize: 12 }}>
The Auto-Trade switch on the Trump page controls Trump (System&nbsp;1)
auto-opens only it has no effect on Macro Vibes.
</p>
<Link href={settingsHref} style={linkStyle}>
<span style={{ fontSize: 10, letterSpacing: '0.08em', textTransform: 'uppercase',
color: 'var(--ink-4)' }}>Settings</span>
<span>{settingsLabel}</span>
<span aria-hidden="true"></span>
<div style={{
display: 'flex', alignItems: 'center', justifyContent: 'space-between',
gap: 12, flexWrap: 'wrap',
padding: '9px 14px', marginBottom: 14,
borderRadius: 8,
background: s.soft,
borderLeft: `3px solid ${s.accent}`,
}}>
<span style={{ fontSize: 12, color: 'var(--ink-2)', lineHeight: 1.4 }}>
<strong style={{ color: s.accent }}>You open · bot manages exit</strong>
<span style={{ color: 'var(--ink-4)', marginLeft: 8 }}>
Signal Telegram open on Hyperliquid <code style={{ fontSize: 11 }}>/adopt</code>
</span>
</span>
<Link
href={settingsHref}
style={{
fontSize: 11, color: s.accent, textDecoration: 'none',
fontWeight: 700, flexShrink: 0,
opacity: 0.8,
}}
>
{settingsLabel} settings
</Link>
</div>
</div>
)
}
@@ -248,11 +261,18 @@ export default function SystemControl({ system }: { system: 'trump' | 'btc' }) {
netMsg = isZh
? 'Auto-Trade 当前为关闭: Trump 信号仍会显示,但不会自动开仓。'
: 'Auto-Trade is OFF — Trump signals are shown in the feed but NOT traded.'
} else if (pub?.trump_enabled === false) {
// Auto-Trade is ON but the Trump (System-1) gate is OFF, so the backend
// skips every Trump signal (bot_engine: trump_enabled OFF → not traded).
// Without this branch the UI falsely promised "next signal auto-opens".
netMsg = isZh
? 'Auto-Trade 已开启,但 Trump 系统①未启用: 在设置页打开 Trump 开关后才会自动开仓。'
: 'Auto-Trade is ON, but the Trump system is disabled — enable Trump in Settings before signals will trade.'
} else {
netOk = true
netMsg = isZh
? `Auto-Trade 已开启(Trump 系统①): 下一条合格 Trump 信号会自动开出${paper ? '模拟' : '真实'}仓位。`
: `Auto-Trade ON (Trump / System 1) — will open a ${paper ? 'PAPER' : 'LIVE'} trade on the next qualifying Trump signal.`
: `Auto-Trade ON — will open a ${paper ? 'PAPER' : 'LIVE'} trade on the next qualifying Trump signal.`
}
const Pill = ({ active, onClick, children, tone }: {
@@ -278,7 +298,7 @@ export default function SystemControl({ system }: { system: 'trump' | 'btc' }) {
<div style={{ padding: '14px 16px', background: s.soft,
borderLeft: `4px solid ${s.accent}` }}>
<div style={{ fontSize: 14, fontWeight: 700, color: s.accent }}>
{s.idx} {s.name} {isZh ? '控制面板' : '— control'}
{s.name} {isZh ? '控制面板' : '— Auto-Trade'}
</div>
</div>
@@ -288,25 +308,10 @@ export default function SystemControl({ system }: { system: 'trump' | 'btc' }) {
<div>
<div style={{ fontSize: 14, fontWeight: 700 }}>
Auto-Trade <span style={{ fontSize: 10, fontWeight: 600,
color: 'var(--ink-4)', marginLeft: 6 }}>{isZh ? Trump 系统①' : TRUMP (System 1)'}</span>
color: 'var(--ink-4)', marginLeft: 6 }}>{isZh ? 事件交易' : event-driven'}</span>
</div>
<div style={{ fontSize: 11, color: 'var(--ink-4)', marginTop: 3, maxWidth: 480, lineHeight: 1.5 }}>
{isZh ? (
<>
<strong> Trump </strong>
Trump
Macro Vibes Macro manage-only
</>
) : (
<>
<strong>Controls Trump (System 1) auto-opens.</strong> OFF: signals
scanned &amp; shown in the feed, nothing traded. ON: a qualifying
Trump signal auto-opens a trade. Stop-loss / staged de-risk always
protect open positions either way. (Macro Vibes is manage-only and
never auto-opens see its page.)
</>
)}
<div style={{ fontSize: 11, color: 'var(--ink-4)', marginTop: 3 }}>
{isZh ? 'OFF = 只监控信号 · ON = 自动开仓' : 'OFF = monitor only · ON = auto-open on qualifying Trump signals'}
</div>
</div>
<div style={{ display: 'flex', gap: 6 }}>
+32 -15
View File
@@ -1,6 +1,6 @@
'use client'
import { useState, useEffect, useCallback } from 'react'
import { useState, useEffect, useCallback, useRef } from 'react'
import { useLocale } from 'next-intl'
import { useAccount, useSignMessage } from 'wagmi'
import {
@@ -36,19 +36,36 @@ export default function TelegramCard() {
useEffect(() => { setMounted(true) }, [])
// Generation counter guards against stale-closure trap: `snap !== address`
// inside useCallback compares two closed-over copies of the same value and
// is always false. genRef is a mutable ref readable from any closure.
const genRef = useRef(0)
useEffect(() => { genRef.current++ }, [address])
const refresh = useCallback(async () => {
if (!address) {
setLoading(false)
setStatus(null)
return
}
if (!address) { setLoading(false); setStatus(null); return }
const gen = genRef.current
setLoading(true)
try {
const s = await getTelegramStatus(address.toLowerCase())
const { getCachedViewEnvelope } = await import('@/lib/signedRequest')
const cached = getCachedViewEnvelope('view_user', address)
const s = await getTelegramStatus(address.toLowerCase(), cached ?? undefined)
if (gen !== genRef.current) return // wallet changed while in-flight
setStatus(s); setErr('')
} catch (e) {
if (gen !== genRef.current) return
setErr(e instanceof Error ? e.message : 'load failed')
} finally { setLoading(false) }
} finally {
if (gen === genRef.current) setLoading(false)
}
}, [address])
// B32: clear stale status immediately when wallet changes so the previous
// wallet's binding info never flickers in before the new fetch resolves.
useEffect(() => {
setStatus(null)
setCode(null)
setErr('')
}, [address])
useEffect(() => { refresh() }, [refresh])
@@ -112,7 +129,7 @@ export default function TelegramCard() {
Telegram alerts
</div>
<div style={{ fontSize: 12, color: 'var(--ink-3)', lineHeight: 1.6 }}>
Connect your wallet first. After that, you can link Telegram for alert delivery and Pro wallet-bound notifications.
You can get free Telegram alerts without a wallet just open the bot. Connect a wallet here to also get alerts tailored to your own positions.
</div>
</div>
)
@@ -180,8 +197,8 @@ export default function TelegramCard() {
</div>
<div style={{ fontSize: 11, color: 'var(--ink-4)', marginTop: 2 }}>
{status.bound
? (isZh ? '打开机器人调整偏好(/trump /btc /funding /kol /conf /quiet' : 'Open the bot to adjust preferences (/trump /btc /funding /kol /conf /quiet)')
: (isZh ? '打开机器人并发送 /start,无需额外账号' : 'Open the bot and send /start — no account needed')}
? (isZh ? '机器人里可开关各类提醒、设置免打扰时段' : 'Open the bot to choose which alerts you get and set quiet hours')
: (isZh ? '打开机器人并发送 /start,无需额外账号' : 'Open the bot and tap Start — no account needed')}
</div>
</div>
</div>
@@ -197,11 +214,11 @@ export default function TelegramCard() {
</span>
{status.wallet_address ? (
<>
<span style={{ color: 'var(--ink-5)' }}>·</span>
<span style={{ color: 'var(--ink-4)' }}>·</span>
<span style={{ color: 'var(--up)', fontSize: 11 }}>Pro</span>
<span style={{ color: 'var(--ink-5)' }}>·</span>
<span style={{ color: 'var(--ink-4)' }}>·</span>
<span>{isZh ? `已发送 ${status.total_alerts_sent ?? 0} 条提醒` : `${status.total_alerts_sent ?? 0} alerts sent`}</span>
<span style={{ color: 'var(--ink-5)' }}>·</span>
<span style={{ color: 'var(--ink-4)' }}>·</span>
<button className="btn ghost" disabled={busy} onClick={handleUnbind}
style={{ fontSize: 11, color: 'var(--down)', padding: '2px 8px' }}>
{isZh ? '断开钱包绑定' : 'Disconnect wallet'}
@@ -209,7 +226,7 @@ export default function TelegramCard() {
</>
) : (
<>
<span style={{ color: 'var(--ink-5)' }}>·</span>
<span style={{ color: 'var(--ink-4)' }}>·</span>
<span>{isZh ? `已发送 ${status.total_alerts_sent ?? 0} 条提醒` : `${status.total_alerts_sent ?? 0} alerts sent`}</span>
</>
)}
+275 -45
View File
@@ -6,9 +6,11 @@ import { useAccount, useConnect, useSignMessage } from 'wagmi'
import {
getUserPublic,
getUser,
getTelegramStatus,
setUserSettings,
setHlApiKey,
setManualWindow,
setAutoTrade,
subscribe,
type UserSettings,
} from '@/lib/api'
@@ -30,18 +32,27 @@ const DEFAULT_SETTINGS: UserSettings = {
trump_enabled: false, macro_enabled: false,
}
// The backend treats active_from/active_until as a DAILY RECURRING time window
// (it extracts only .time() and compares with the current UTC time). Storing a
// full datetime-local value was misleading — the date part was silently ignored
// so users thought they were setting a date range when they were setting a
// time-of-day schedule. We now use type="time" and store as a fixed-epoch ISO
// so the backend's .time() extraction gives the right HH:MM:SS.
function isoToLocalInput(iso: string | null): string {
if (!iso) return ''
const d = new Date(iso)
if (isNaN(d.getTime())) return ''
const pad = (n: number) => String(n).padStart(2, '0')
return `${d.getFullYear()}-${pad(d.getMonth() + 1)}-${pad(d.getDate())}T${pad(d.getHours())}:${pad(d.getMinutes())}`
// Return just HH:MM for the time input
return `${pad(d.getUTCHours())}:${pad(d.getUTCMinutes())}`
}
function localInputToIso(v: string): string | null {
if (!v) return null
const d = new Date(v)
if (isNaN(d.getTime())) return null
return d.toISOString()
// v is HH:MM from <input type="time">. Store as 2000-01-01T{HH:MM}:00Z so
// the backend's .time() extraction returns the correct UTC time.
const [hh, mm] = v.split(':')
if (!hh || !mm) return null
return `2000-01-01T${hh.padStart(2,'0')}:${mm.padStart(2,'0')}:00Z`
}
export default function BotConfigPanel() {
@@ -51,7 +62,7 @@ export default function BotConfigPanel() {
const { signMessageAsync } = useSignMessage()
const {
isSubscribed, hlApiKeySet, hlApiKeyMasked,
setSubscribed, setBotReadiness, setHlApiKeySet,
setSubscribed, setBotReadiness, setHlApiKeySet, setPaperMode: setPaperModeStore,
} = useDashboardStore()
const [settings, setSettings] = useState<UserSettings>(DEFAULT_SETTINGS)
@@ -75,24 +86,66 @@ export default function BotConfigPanel() {
const [mwErr, setMwErr] = useState('')
const [mwTick, setMwTick] = useState(0)
const [paperMode, setPaperMode] = useState(false)
const [autoTrade, setAutoTrade_] = useState(false)
const [atState, setAtState] = useState<'idle'|'signing'|'saving'|'err'>('idle')
const [showAdvanced, setShowAdvanced] = useState(false)
const [mounted, setMounted] = useState(false)
const [loadState, setLoadState] = useState<'idle'|'loading'|'loaded'|'err'>('idle')
const [loadErr, setLoadErr] = useState('')
const [connectErr, setConnectErr] = useState('')
// Telegram binding state. Macro Vibes (System-2) is manage-only via the
// Telegram /adopt command, so a Macro-only user who hasn't bound Telegram
// cannot actually hand any position to the bot — readiness must reflect that.
// The unauthenticated status call returns only { bound } (no chat_id), which
// is all we need here.
const [tgBound, setTgBound] = useState<boolean | null>(null)
useEffect(() => { setMounted(true) }, [])
useEffect(() => {
if (!address) { setTgBound(null); return }
let cancelled = false
getTelegramStatus(address.toLowerCase())
.then(s => { if (!cancelled) setTgBound(!!s.bound) })
.catch(() => { if (!cancelled) setTgBound(null) })
return () => { cancelled = true }
}, [address])
// B33: when the connected wallet changes, immediately wipe all private
// settings so the previous wallet's config never leaks into the new one.
useEffect(() => {
setSettings(DEFAULT_SETTINGS)
setPaperMode(false)
setAutoTrade_(false)
setTpConfigured(false)
setSlConfigured(false)
setUseBudget(false)
setUseSchedule(false)
setFromLocal('')
setUntilLocal('')
setManualUntil(null)
setApiKey('')
setDirty(false)
setSaveState('idle'); setSaveErr('')
setKeyState('idle'); setKeyErr('')
setSubState('idle'); setSubErr('')
setLoadState('idle'); setLoadErr('')
setConnectErr('')
}, [address])
function applyUserPayload(u: {
active: boolean
hl_api_key_set: boolean
hl_api_key_masked: string | null
paper_mode?: boolean
auto_trade?: boolean
settings: UserSettings
manual_window_until?: string | null
}) {
setSubscribed(u.active)
setPaperMode(!!u.paper_mode)
setPaperModeStore(!!u.paper_mode) // sync to global store for B40/B41
setAutoTrade_(!!u.auto_trade)
setHlApiKeySet(u.hl_api_key_set, u.hl_api_key_masked ?? undefined)
setManualUntil(u.manual_window_until ?? null)
if (u.settings) {
@@ -126,6 +179,7 @@ export default function BotConfigPanel() {
setSubscribed(pub.active)
setHlApiKeySet(pub.hl_api_key_set)
setBotReadiness(pub.hl_api_key_set ? 'saved' : 'unknown')
setAutoTrade_(!!pub.auto_trade)
if (!pub.active) return
const cached = getCachedViewEnvelope('view_user', address)
if (!cached) return
@@ -141,11 +195,8 @@ export default function BotConfigPanel() {
if (!address) return
setLoadErr(''); setLoadState('loading')
try {
const ok = await confirmSign({
label: 'View account settings',
description: 'Read your Trump Alpha subscription state, risk settings, and API key status. The signature is only for identity verification — no on-chain action is performed.',
})
if (!ok) { setLoadState('idle'); return }
// Read-only identity check — go straight to MetaMask, no pre-confirm sheet.
// getOrCreateViewEnvelope caches the result for 4 min so repeat visits are free.
const env = await getOrCreateViewEnvelope({ action: 'view_user', wallet: address, signMessageAsync })
const u = await getUser(address, env)
applyUserPayload(u)
@@ -161,9 +212,34 @@ export default function BotConfigPanel() {
setSubscribed(pub.active)
setHlApiKeySet(pub.hl_api_key_set)
setBotReadiness(pub.hl_api_key_set ? 'saved' : 'unknown')
setAutoTrade_(!!pub.auto_trade)
return pub
}
async function flipAutoTrade(on: boolean) {
if (!address || atState !== 'idle') return
const ok = await confirmSign({
label: on ? 'Enable Auto-Trade' : 'Disable Auto-Trade',
description: on
? 'Bot will open real positions on Hyperliquid when qualifying Trump signals fire. Stop-loss and de-risking remain active.'
: 'Bot stops opening new trades. Risk controls on existing positions keep running.',
danger: on,
})
if (!ok) return
setAtState('signing')
try {
const env = await signRequest({ action: 'set_auto_trade', wallet: address, body: { enabled: on }, signMessageAsync })
setAtState('saving')
const r = await setAutoTrade(env, on)
setAutoTrade_(r.auto_trade)
setAtState('idle')
} catch (e: unknown) {
console.error('set_auto_trade failed', e)
setAtState('err')
setTimeout(() => setAtState('idle'), 3000)
}
}
function updateSettings(patch: Partial<UserSettings>) {
setSettings(s => ({ ...s, ...patch }))
setDirty(true)
@@ -202,7 +278,7 @@ export default function BotConfigPanel() {
if (!address) return
const ok = await confirmSign({
label: 'Save trading settings',
description: 'Settings are saved to the server and apply to all new trades from this point forward. Open positions are not affected.',
description: 'Applied to all new trades going forward. Open positions are not affected.',
})
if (!ok) return
setSaveErr(''); setSaveState('signing')
@@ -213,7 +289,11 @@ export default function BotConfigPanel() {
schedFrom = localInputToIso(fromLocal)
schedUntil = localInputToIso(untilLocal)
if (!schedFrom || !schedUntil) { setSaveErr('Pick both a start and end time'); setSaveState('err'); return }
if (new Date(schedUntil).getTime() <= new Date(schedFrom).getTime()) { setSaveErr('End must be after start'); setSaveState('err'); return }
// Cross-midnight windows (e.g. 22:0002:00) are VALID — the backend's
// _is_in_active_window treats af_t > au_t as a wrap-around window
// (now >= from OR now <= until). Only reject when start === end, which
// would describe a zero-length (or full-day-ambiguous) window.
if (new Date(schedUntil).getTime() === new Date(schedFrom).getTime()) { setSaveErr('Start and end cant be the same time'); setSaveState('err'); return }
}
const tp = settings.take_profit_pct, sl = settings.stop_loss_pct, bd = settings.daily_budget_usd
if (trumpOn) {
@@ -244,7 +324,7 @@ export default function BotConfigPanel() {
}
const ok = await confirmSign({
label: 'Link Hyperliquid API key',
description: 'The API key is stored encrypted on the server and used by the bot to place trades on Hyperliquid for you.',
description: 'Stored encrypted on the server. Used by the bot to open and close positions only — no withdrawal access.',
danger: true,
})
if (!ok) return
@@ -304,7 +384,7 @@ export default function BotConfigPanel() {
if (!address) return
const ok = await confirmSign({
label: 'Switch to live trading',
description: 'Your subscription will change from paper mode to live. For your safety, Auto-Trade is turned OFF on this switch — you must re-enable it explicitly while live. No trade opens immediately; you still need to add a Hyperliquid API key first.',
description: 'Switches to live trading. Auto-Trade is turned OFF automatically — re-enable it explicitly. You still need a Hyperliquid API key before the bot can trade.',
danger: true,
})
if (!ok) return
@@ -360,10 +440,9 @@ export default function BotConfigPanel() {
if (!isSubscribed) {
return (
<div className="card" id="bot-config-panel" style={{ padding: '28px 28px 24px', marginBottom: 28 }}>
<div style={{ fontSize: 15, fontWeight: 600, marginBottom: 4 }}>Set up your trading bot</div>
<div style={{ fontSize: 13, color: 'var(--ink-3)', lineHeight: 1.65, marginBottom: 24 }}>
The bot places trades on Hyperliquid with a trade-only API key it can never withdraw funds.
Start in paper mode to try it safely, or choose Live if you already have a Hyperliquid API key.
<div style={{ fontSize: 15, fontWeight: 600, marginBottom: 4 }}>Set up your bot</div>
<div style={{ fontSize: 13, color: 'var(--ink-3)', lineHeight: 1.55, marginBottom: 24 }}>
Trade-only API key no withdrawals. Try Paper first, or Live if you already have a key.
</div>
{/* Paper / Live choice */}
@@ -421,8 +500,8 @@ export default function BotConfigPanel() {
return (
<div className="card" id="bot-config-panel" style={{ padding: '28px 28px 24px', marginBottom: 28 }}>
<div style={{ fontSize: 15, fontWeight: 600, marginBottom: 4 }}>Sign in to view your settings</div>
<div style={{ fontSize: 13, color: 'var(--ink-3)', lineHeight: 1.65, marginBottom: 20 }}>
Your settings are private and wallet-bound. Sign once to load them the permission is cached for 4 minutes so you won&apos;t be prompted again while you browse.
<div style={{ fontSize: 13, color: 'var(--ink-3)', lineHeight: 1.55, marginBottom: 20 }}>
Settings are wallet-private. Sign once to load cached for 4 min.
</div>
<div style={{ display: 'flex', alignItems: 'center', gap: 12 }}>
<button className="btn amber" style={{ padding: '10px 22px', fontSize: 13 }} onClick={handleLoadSettings} disabled={loadState === 'loading'}>
@@ -442,6 +521,13 @@ export default function BotConfigPanel() {
if (!trumpOn && !macroOn) missingItems.push('enable Trump Signal or Macro Vibes below')
if (trumpOn && !tpConfigured) missingItems.push('set a Trump Signal take-profit %')
if (trumpOn && !slConfigured) missingItems.push('set a Trump Signal stop-loss %')
// Macro Vibes is manage-only through the Telegram /adopt command. If Macro is
// the only enabled system and Telegram isn't bound, the bot can't manage any
// position — so "ready" would be a lie. (tgBound === null = status unknown /
// still loading: don't block on it.)
if (macroOn && !trumpOn && tgBound === false) {
missingItems.push('connect Telegram (Settings → Telegram) so the bot can manage Macro positions via /adopt')
}
const botReady = missingItems.length === 0
// Manual window countdown
@@ -461,6 +547,77 @@ export default function BotConfigPanel() {
return (
<div style={{ marginBottom: 28 }} id="bot-config-panel">
{/* ── Onboarding stepper ─────────────────────────────────────────────── */}
{(!isSubscribed || !(hlApiKeySet || paperMode) || !autoTrade) && (
<div className="card" style={{ padding: '14px 18px 16px', marginBottom: 12 }}>
<div style={{ fontSize: 11, fontWeight: 700, letterSpacing: '0.06em',
textTransform: 'uppercase', color: 'var(--ink-4)', marginBottom: 14 }}>
Setup progress
</div>
{/* Steps row: steps are fixed-width, connectors flex-grow to fill */}
<div style={{ display: 'flex', alignItems: 'flex-start', marginBottom: 14 }}>
{([
{ label: 'Subscribe', done: isSubscribed },
{ label: 'Add HL key', done: hlApiKeySet || paperMode },
{ label: 'Enable Auto-Trade', done: autoTrade },
] as const).map((step, i, arr) => {
const isActive = !step.done && (i === 0 || arr[i - 1].done)
const isLast = i === arr.length - 1
return (
<div key={step.label} style={{
display: 'flex', alignItems: 'flex-start',
flex: isLast ? '0 0 auto' : 1, // last step: natural width; others: expand via connector
minWidth: 0,
}}>
{/* Circle + label — fixed, never stretches */}
<div style={{ display: 'flex', flexDirection: 'column', alignItems: 'center', gap: 6, flexShrink: 0 }}>
<div style={{
width: 24, height: 24, borderRadius: '50%',
fontSize: 11, fontWeight: 700,
display: 'flex', alignItems: 'center', justifyContent: 'center',
background: step.done ? 'var(--up)' : isActive ? 'var(--amber, #f59e0b)' : 'var(--bg-sunk)',
color: step.done ? '#fff' : isActive ? '#000' : 'var(--ink-4)',
border: `2px solid ${step.done ? 'var(--up)' : isActive ? 'var(--amber, #f59e0b)' : 'var(--line)'}`,
boxSizing: 'border-box',
}}>
{step.done ? '✓' : i + 1}
</div>
<div style={{
fontSize: 10, lineHeight: 1.3,
textAlign: isLast ? 'right' : 'center',
fontWeight: isActive ? 600 : 400,
color: step.done ? 'var(--up)' : isActive ? 'var(--ink)' : 'var(--ink-4)',
whiteSpace: 'nowrap',
}}>
{step.label}
</div>
</div>
{/* Connector — takes all remaining space between this and next step */}
{!isLast && (
<div style={{
flex: 1, height: 2, marginTop: 11,
background: step.done ? 'var(--up)' : 'var(--line)',
transition: 'background 0.3s',
}} />
)}
</div>
)
})}
</div>
{/* Bottom progress bar */}
<div style={{ height: 3, borderRadius: 999, background: 'var(--bg-sunk)', overflow: 'hidden' }}>
<div style={{
height: '100%', borderRadius: 999,
background: 'var(--up)',
width: `${Math.round(([isSubscribed, hlApiKeySet || paperMode, autoTrade].filter(Boolean).length / 3) * 100)}%`,
transition: 'width .4s ease',
}} />
</div>
</div>
)}
{/* ── HL API Key ─────────────────────────────────────────────────────── */}
<div className="card" style={{ padding: '16px 20px', marginBottom: 12 }}>
<div style={{ display: 'flex', alignItems: 'center', gap: 14 }}>
@@ -481,7 +638,9 @@ export default function BotConfigPanel() {
? <span style={{ color: 'var(--up)' }}>📝 Paper mode no real money involved. Add an API key below to switch to live.</span>
: hlApiKeySet && !apiKey
? <><span className="mono">{hlApiKeyMasked ?? '···'}</span><span> · trade-only · cannot withdraw</span></>
: 'Generate at app.hyperliquid.xyz/API — paste the private key here. Never your MetaMask key.'}
: <>Don&apos;t have Hyperliquid?{' '}
<a href="https://app.hyperliquid.xyz" target="_blank" rel="noopener noreferrer" style={{ color: 'var(--amber)', textDecoration: 'none' }}>Sign up free </a>
{' '}· Then go to API generate a trade-only key paste below.</>}
</div>
</div>
{/* Paper mode: show upgrade path instead of key input */}
@@ -526,10 +685,74 @@ export default function BotConfigPanel() {
))}
</div>
{keyState === 'err' && <div style={{ fontSize: 12, color: 'var(--down)', marginTop: 8, paddingLeft: 50 }}>{keyErr}</div>}
{keyState === 'ok' && <div style={{ fontSize: 11, color: 'var(--up)', marginTop: 6, paddingLeft: 50 }}>Saved. Run one small test trade to confirm the live path end-to-end.</div>}
{keyState === 'ok' && <div style={{ fontSize: 11, color: 'var(--up)', marginTop: 6, paddingLeft: 50 }}>Saved. Enable Auto-Trade below, then try a paper trade first to confirm the live path works.</div>}
{!paperMode && !hlApiKeySet && (
<div style={{
marginTop: 10, paddingLeft: 50,
display: 'flex', alignItems: 'flex-start', gap: 6,
}}>
<span style={{ fontSize: 13, flexShrink: 0, marginTop: 1 }}></span>
<div style={{ fontSize: 11, color: 'var(--down)', lineHeight: 1.5 }}>
<strong>Do not paste your main wallet private key.</strong>{' '}
This field only accepts a Hyperliquid <em>trade-only API key</em> generate one at{' '}
<a href="https://app.hyperliquid.xyz/API" target="_blank" rel="noopener noreferrer"
style={{ color: 'var(--down)', textDecorationColor: 'var(--down)' }}>
app.hyperliquid.xyz/API
</a>
{' '} &ldquo;Generate API wallet&rdquo;. A trade-only key cannot withdraw funds.
</div>
</div>
)}
{subState === 'err' && subErr && <div style={{ fontSize: 12, color: 'var(--down)', marginTop: 8 }}>{subErr}</div>}
</div>
{/* ── Auto-Trade master switch ───────────────────────────────────────── */}
{isSubscribed && (hlApiKeySet || paperMode) && (
<div className="card" style={{ padding: '14px 20px', marginBottom: 12 }}>
<div style={{ display: 'flex', alignItems: 'center', justifyContent: 'space-between', gap: 12 }}>
<div>
<div style={{ fontSize: 13, fontWeight: 600, marginBottom: 2 }}>Auto-Trade</div>
<div style={{ fontSize: 11, color: 'var(--ink-4)', lineHeight: 1.4 }}>
{autoTrade
? 'ON — bot opens positions automatically when qualifying Trump signals fire.'
: 'OFF — signals are shown but no trades are opened. Turn on when ready to go live.'}
</div>
</div>
<div style={{ display: 'flex', gap: 6, flexShrink: 0 }}>
<button
onClick={() => flipAutoTrade(true)}
disabled={atState !== 'idle'}
style={{
padding: '6px 14px', borderRadius: 6, fontSize: 12, fontWeight: 700, cursor: 'pointer',
border: 'none',
background: autoTrade ? 'var(--up)' : 'var(--bg-sunk)',
color: autoTrade ? '#fff' : 'var(--ink-4)',
opacity: atState !== 'idle' ? 0.5 : 1,
}}
>ON</button>
<button
onClick={() => flipAutoTrade(false)}
disabled={atState !== 'idle'}
style={{
padding: '6px 14px', borderRadius: 6, fontSize: 12, fontWeight: 700, cursor: 'pointer',
border: '1px solid var(--line)',
background: !autoTrade ? 'var(--ink)' : 'transparent',
color: !autoTrade ? 'var(--bg)' : 'var(--ink-4)',
opacity: atState !== 'idle' ? 0.5 : 1,
}}
>OFF</button>
</div>
</div>
{atState !== 'idle' && (
<div style={{ fontSize: 11, marginTop: 8, color: atState === 'err' ? 'var(--down)' : 'var(--ink-4)' }}>
{atState === 'signing' ? 'Waiting for wallet signature…'
: atState === 'saving' ? 'Saving…'
: 'Failed to update — please try again.'}
</div>
)}
</div>
)}
{/* ── Trump Signal ───────────────────────────────────────────────────── */}
<div id="config-trump" className="card" style={{ padding: 0, overflow: 'hidden', marginBottom: 12 }}>
{/* Header */}
@@ -560,7 +783,7 @@ export default function BotConfigPanel() {
<div className="form-row">
<div className="form-row-label">
Per-trade size
<span className="hint">Notional in USD margin ${(settings.position_size_usd / settings.leverage).toFixed(2)} at {settings.leverage}×</span>
<span className="hint">How much to bet per trade. At {settings.leverage}×, HL holds ~${(settings.position_size_usd / settings.leverage).toFixed(0)} as collateral.</span>
</div>
<div className="form-row-control">
<div className="num-field">
@@ -575,7 +798,7 @@ export default function BotConfigPanel() {
<div className="form-row">
<div className="form-row-label">
Leverage
<span className="hint">Event-driven scalp use lower leverage if unsure</span>
<span className="hint">How aggressive the position is. Start low (23×) and increase once you've seen the bot trade live.</span>
</div>
<div className="form-row-control">
<div className="slider-field">
@@ -584,13 +807,18 @@ export default function BotConfigPanel() {
<div className="ticks"><span>1×</span><span>25×</span><span>50×</span></div>
</div>
<span className="slider-readout">{settings.leverage}×</span>
{settings.leverage > 10 && (
<div className="settings-note warn" style={{ marginTop: 6 }}>
{settings.leverage}× is high for event-driven signals. A 1.5% stop-loss at {settings.leverage}× means the trade closes on a {(1.5 / settings.leverage).toFixed(1)}% price move against you. Consider 35× until you see how the bot performs live.
</div>
)}
</div>
</div>
<div className="form-row">
<div className="form-row-label">
Min AI confidence
<span className="hint">Skip signals below this score (0 = take all, 100 = only the highest-conviction)</span>
<span className="hint">Filter out weak signals. Higher = fewer trades, but only the strongest ones.</span>
</div>
<div className="form-row-control">
<div className="slider-field">
@@ -607,7 +835,7 @@ export default function BotConfigPanel() {
<div className="form-row">
<div className="form-row-label">
Take profit <span style={{ color: 'var(--down)' }}>*</span>
<span className="hint">Auto-close when unrealised gain hits this target. Required.</span>
<span className="hint">Bot locks in profit when the position gains this much. Required.</span>
</div>
<div className="form-row-control">
<div className="num-field">
@@ -623,7 +851,7 @@ export default function BotConfigPanel() {
<div className="form-row" style={{ marginBottom: 16 }}>
<div className="form-row-label">
Stop loss <span style={{ color: 'var(--down)' }}>*</span>
<span className="hint">Auto-close when drawdown hits this limit. Required.</span>
<span className="hint">Bot cuts the loss when the position falls this much. Required.</span>
</div>
<div className="form-row-control">
<div className="num-field">
@@ -655,8 +883,8 @@ export default function BotConfigPanel() {
</div>
<div style={{ fontSize: 12, color: 'var(--ink-3)', marginTop: 2 }}>
{macroOn
? 'You open a BTC long on Hyperliquid, then use /adopt in the Telegram bot to hand it to the bot for exit management.'
: 'Disabled — Macro Vibes alerts will not include bot management instructions.'}
? 'When a signal fires: open a BTC long on Hyperliquid → type /adopt in the Telegram bot → bot manages the exit for you.'
: 'Disabled — Macro Vibes alerts sent without bot management. Enable + set up Telegram to activate.'}
</div>
</div>
<Switch on={macroOn} onChange={v => updateSettings({ macro_enabled: v })} tone="up" />
@@ -719,7 +947,7 @@ export default function BotConfigPanel() {
<div className="form-row" style={{ marginBottom: 16 }}>
<div className="form-row-label">
BTC bottom leverage
<span className="hint">Separate from Trump leverage. The bot de-risks in stages before exchange liquidation.</span>
<span className="hint">Higher leverage = less room for BTC to drop before the bot starts reducing the position.</span>
</div>
<div className="form-row-control">
<div className="slider-field">
@@ -729,9 +957,9 @@ export default function BotConfigPanel() {
</div>
<span className="slider-readout">{lev}×</span>
<div className={`settings-note ${risky ? 'warn' : ''}`} style={{ marginTop: 6 }}>
At {lev}× it sheds near {(prot * 0.6).toFixed(0)}%, near {(prot * 0.8).toFixed(0)}%, fully out by {prot.toFixed(0)}%.
Exchange liquidation {liq.toFixed(0)}%.
{risky ? ' Above 2×, a normal correction can push you out early.' : ' Wide enough to survive a normal correction.'}
{risky
? `⚠️ At ${lev}×, BTC only needs to drop ${prot.toFixed(0)}% before the bot fully closes the position. A normal correction can trigger early exits — use lower leverage unless you're comfortable with that.`
: `At ${lev}×, the bot has room for a ${prot.toFixed(0)}% BTC drop before closing. It reduces the position gradually as the drawdown deepens, so you don't lose everything at once.`}
</div>
</div>
</div>
@@ -751,7 +979,7 @@ export default function BotConfigPanel() {
cursor: 'pointer', borderBottom: showAdvanced ? '1px solid var(--line)' : 'none',
}}
>
<span style={{ fontSize: 13, fontWeight: 600, color: 'var(--ink-2)' }}>Advanced</span>
<span style={{ fontSize: 13, fontWeight: 600, color: 'var(--ink-2)' }}>Risk limits &amp; schedule</span>
<span style={{
fontSize: 11, color: 'var(--ink-4)',
display: 'flex', alignItems: 'center', gap: 10,
@@ -770,7 +998,7 @@ export default function BotConfigPanel() {
<div className="form-row">
<div className="form-row-label">
Daily trading cap
<span className="hint">Optional bot stops opening new trades once total notional crosses this limit in a UTC day.</span>
<span className="hint">Daily spending cap bot stops opening new trades once it hits this amount.</span>
</div>
<div className="form-row-control" style={{ flexWrap: 'wrap', gap: 10 }}>
<Switch on={useBudget} onChange={v => { setUseBudget(v); setDirty(true) }} />
@@ -792,7 +1020,7 @@ export default function BotConfigPanel() {
<div className="form-row">
<div className="form-row-label">
Trading schedule
<span className="hint">Bot only accepts signals inside this window. Times in your browser&apos;s local timezone. Leave off to trade anytime.</span>
<span className="hint">Daily recurring UTC window bot only opens new trades within this time range. Overnight windows (e.g. 22:0002:00) are allowed. Leave off for 24/7.</span>
</div>
<div className="form-row-control" style={{ flexWrap: 'wrap' }}>
<Switch on={useSchedule} onChange={v => { setUseSchedule(v); setDirty(true) }} />
@@ -800,25 +1028,26 @@ export default function BotConfigPanel() {
<div style={{ display: 'flex', alignItems: 'center', gap: 10, flexWrap: 'wrap' }}>
<div className="num-field">
<span className="prefix">From</span>
<input type="datetime-local" lang="en-US" value={fromLocal}
onChange={e => { setFromLocal(e.target.value); setDirty(true) }} style={{ width: 190 }} />
<input type="time" value={fromLocal}
onChange={e => { setFromLocal(e.target.value); setDirty(true) }} style={{ width: 110 }} />
</div>
<span style={{ fontSize: 12, color: 'var(--ink-4)' }}></span>
<div className="num-field">
<span className="prefix">Until</span>
<input type="datetime-local" lang="en-US" value={untilLocal}
onChange={e => { setUntilLocal(e.target.value); setDirty(true) }} style={{ width: 190 }} />
<input type="time" value={untilLocal}
onChange={e => { setUntilLocal(e.target.value); setDirty(true) }} style={{ width: 110 }} />
</div>
</div>
)}
</div>
</div>
{/* Manual window */}
{/* Override window — only relevant when a schedule is set */}
{useSchedule && (
<div className="form-row" style={{ marginBottom: 16 }}>
<div className="form-row-label">
Override window
<span className="hint">Open a timed override so the bot accepts signals for the next 124 hours useful for high-conviction catalysts like CPI or FOMC releases.</span>
<span className="hint">Temporarily bypass your schedule. Useful when a high-conviction event (e.g. CPI, FOMC) happens outside your trading hours.</span>
</div>
<div className="form-row-control" style={{ flexWrap: 'wrap', gap: 8 }}>
{armed ? (
@@ -826,20 +1055,21 @@ export default function BotConfigPanel() {
<span style={{ fontSize: 13, fontWeight: 600, color: 'var(--up)' }}> Override active {remainingLabel} remaining</span>
<button className="btn ghost" style={{ padding: '6px 14px', fontSize: 12 }}
onClick={() => handleManualWindow(0)} disabled={mwBusy}>
{mwBusy ? 'Sign…' : 'Cancel override'}
{mwBusy ? 'Sign…' : 'Cancel'}
</button>
</>
) : (
[1, 4, 24].map(h => (
[4, 12, 24].map(h => (
<button key={h} className="btn ghost" style={{ padding: '6px 12px', fontSize: 12 }}
onClick={() => handleManualWindow(h)} disabled={mwBusy}>
{mwBusy && mwState === 'signing' ? 'Sign…' : `Override ${h}h`}
{mwBusy && mwState === 'signing' ? 'Sign…' : `+${h}h`}
</button>
))
)}
{mwState === 'err' && <span style={{ fontSize: 11, color: 'var(--down)', width: '100%' }}>{mwErr}</span>}
</div>
</div>
)}
</div>
)}
+60 -20
View File
@@ -1,8 +1,8 @@
'use client'
import { useState, useMemo } from 'react'
import { useState, useMemo, useEffect } from 'react'
import { useLocale } from 'next-intl'
import type { BotTrade, TrumpPost } from '@/types'
import type { BotTrade } from '@/types'
import Pagination from '@/components/ui/Pagination'
// ── Formatters ────────────────────────────────────────────────────────────────
@@ -16,7 +16,8 @@ function fmtMoney(n: number, opts: { sign?: boolean; decimals?: number } = {}) {
return '$' + s
}
function fmtPct(n: number) { return (n >= 0 ? '+' : '') + n.toFixed(2) + '%' }
function fmtHold(s: number) {
function fmtHold(s: number | null | undefined) {
if (s == null) return '—'
if (s < 60) return s + 's'
const m = Math.floor(s / 60)
if (m < 60) return m + 'm'
@@ -25,17 +26,35 @@ function fmtHold(s: number) {
interface Props {
trades: BotTrade[]
posts: TrumpPost[]
loading: boolean
locked?: boolean // true = waiting for wallet signature, not "no trades"
}
// ASSETS filter is derived dynamically from the trade set (see useMemo below)
// so new assets (TRUMP, BNB, DOGE, LINK, AAVE, ...) appear automatically.
const SIDES = ['all', 'long', 'short'] as const
// Human-readable labels for raw signal-source identifiers. Keeps the trade
// history readable for non-technical users (matches PostCards source labels).
const SOURCE_LABEL: Record<string, string> = {
truth: 'Trump',
btc_bottom_reversal: 'BTC Macro Bottom',
funding_reversal: 'Funding Reversal',
kol_divergence: 'KOL Divergence',
sma_reclaim: 'SMA Reclaim',
rsi_reversal: 'RSI Reversal',
breakout: 'Breakout',
adopted: 'Adopted',
manual: 'Manual',
unknown: 'Unknown',
}
function sourceLabel(src: string): string {
return SOURCE_LABEL[src?.toLowerCase()] ?? src
}
const TRADES_PER_PAGE = 25
export default function TradeTable({ trades, posts, loading }: Props) {
export default function TradeTable({ trades, loading, locked = false }: Props) {
const locale = useLocale()
const isZh = false // i18n shelved — Chinese branches kept as dead code for future revival; see messages/zh.json
const [assetFilter, setAssetFilter] = useState('all')
@@ -63,12 +82,31 @@ export default function TradeTable({ trades, posts, loading }: Props) {
return Array.from(set).sort()
}, [trades])
// Reset filters that no longer apply to the loaded trade set. On a wallet
// switch the trades prop changes but the local filter state persists, so a
// source/asset/side the previous wallet had could stay "stuck" — and when
// the new wallet has a single source the breakdown card (sources.length > 1)
// disappears, removing the only Clear affordance. Clamping here guarantees
// the user always sees their full new history.
useEffect(() => {
if (sourceFilter !== 'all' && !sources.includes(sourceFilter)) setSourceFilter('all')
if (assetFilter !== 'all' && !assets.includes(assetFilter)) setAssetFilter('all')
}, [sources, assets, sourceFilter, assetFilter])
// Per-source PnL aggregate — the critical view for "which module makes money".
// Computed BEFORE the asset/side filter so the source breakdown reflects the
// full universe, not whatever sub-filter is currently applied.
// Apply asset/side/paper filters for the source breakdown so the cards stay
// consistent with the KPI and table rows below. We intentionally do NOT apply
// sourceFilter here — filtering by source would trivially make one card 100%.
const filteredForSources = useMemo(() => trades.filter(t => {
if (assetFilter !== 'all' && t.asset !== assetFilter) return false
if (sideFilter !== 'all' && t.side !== sideFilter) return false
if (hidePaper && t.is_paper) return false
return true
}), [trades, assetFilter, sideFilter, hidePaper])
const perSource = useMemo(() => {
const acc: Record<string, { trades: number; pnl: number; wins: number; paper: number }> = {}
for (const t of trades) {
for (const t of filteredForSources) {
const k = t.trigger_source || 'unknown'
if (!acc[k]) acc[k] = { trades: 0, pnl: 0, wins: 0, paper: 0 }
acc[k].trades += 1
@@ -79,7 +117,7 @@ export default function TradeTable({ trades, posts, loading }: Props) {
if (t.is_paper) acc[k].paper += 1
}
return acc
}, [trades])
}, [filteredForSources])
const filtered = useMemo(() => trades.filter(t => {
if (sourceFilter !== 'all' && (t.trigger_source || 'unknown') !== sourceFilter) return false
@@ -98,8 +136,9 @@ export default function TradeTable({ trades, posts, loading }: Props) {
const totalPnl = priced.reduce((s, t) => s + (t.pnl_usd ?? 0), 0)
const wins = priced.filter(t => (t.pnl_usd ?? 0) > 0).length
const losses = priced.length - wins
const avgHold = filtered.length > 0
? Math.round(filtered.reduce((s, t) => s + t.hold_seconds, 0) / filtered.length)
const withHold = filtered.filter(t => t.hold_seconds !== null)
const avgHold = withHold.length > 0
? Math.round(withHold.reduce((s, t) => s + (t.hold_seconds ?? 0), 0) / withHold.length)
: 0
return (
@@ -111,7 +150,7 @@ export default function TradeTable({ trades, posts, loading }: Props) {
fontSize: 11, fontWeight: 600, letterSpacing: '0.06em',
textTransform: 'uppercase', color: 'var(--ink-3)', marginBottom: 10,
}}>
{isZh ? '按信号来源拆分盈亏' : 'P&L by signal source'}
{isZh ? '按信号来源拆分盈亏' : 'Which signal makes money'}
</div>
<div style={{
display: 'grid',
@@ -142,7 +181,7 @@ export default function TradeTable({ trades, posts, loading }: Props) {
fontSize: 11, fontWeight: 600, color: 'var(--ink-2)',
marginBottom: 4, overflow: 'hidden', textOverflow: 'ellipsis',
}}>
{src}
{sourceLabel(src)}
{s.paper > 0 && (
<span style={{
fontSize: 9, marginLeft: 6, padding: '1px 5px',
@@ -171,7 +210,7 @@ export default function TradeTable({ trades, posts, loading }: Props) {
border: '1px solid var(--line)', borderRadius: 4,
background: 'transparent', cursor: 'pointer', color: 'var(--ink-2)' }}
>
{isZh ? `清除(当前为 “${sourceFilter}”)` : `Clear (showing “${sourceFilter}”)`}
{isZh ? `清除(当前为 “${sourceLabel(sourceFilter)}”)` : `Clear (showing “${sourceLabel(sourceFilter)}”)`}
</button>
)}
</div>
@@ -255,7 +294,7 @@ export default function TradeTable({ trades, posts, loading }: Props) {
<th>{isZh ? '开仓' : 'Entry'}</th>
<th>{isZh ? '平仓' : 'Exit'}</th>
<th>{isZh ? '持仓' : 'Hold'}</th>
<th>{isZh ? '触发内容' : 'Trigger'}</th>
<th>{isZh ? '触发信号' : 'What triggered it'}</th>
<th>P&amp;L</th>
</tr>
</thead>
@@ -263,12 +302,13 @@ export default function TradeTable({ trades, posts, loading }: Props) {
{filtered.length === 0 && (
<tr>
<td colSpan={8} style={{ textAlign: 'center', padding: 40, color: 'var(--ink-3)' }}>
{isZh ? '没有符合条件的交易。' : 'No trades found'}
{locked
? (isZh ? '签名解锁后即可查看交易历史。' : 'Sign to unlock your trade history above.')
: (isZh ? '没有符合条件的交易。' : 'No trades found')}
</td>
</tr>
)}
{pageRows.map(t => {
const tp = posts.find(p => p.id === t.trigger_post_id)
const roi =
t.entry_price && t.exit_price != null
? ((t.exit_price - t.entry_price) / t.entry_price) * 100 * (t.side === 'long' ? 1 : -1)
@@ -283,7 +323,7 @@ export default function TradeTable({ trades, posts, loading }: Props) {
padding: '2px 7px', borderRadius: 4,
background: 'var(--bg-sunk)',
}}>
{src}
{sourceLabel(src)}
</span>
{t.is_paper && (
<span style={{
@@ -310,9 +350,9 @@ export default function TradeTable({ trades, posts, loading }: Props) {
<td className="mono">{t.exit_price != null ? '$' + t.exit_price.toLocaleString() : '—'}</td>
<td className="mono" style={{ color: 'var(--ink-2)' }}>{fmtHold(t.hold_seconds)}</td>
<td style={{ maxWidth: 260 }}>
{tp ? (
{t.trigger_post_text ? (
<span style={{ fontSize: 12, color: 'var(--ink-2)', overflow: 'hidden', textOverflow: 'ellipsis', whiteSpace: 'nowrap', display: 'block' }}>
{tp.text.slice(0, 60)}
{t.trigger_post_text.slice(0, 60)}
</span>
) : (
<span style={{ fontSize: 12, color: 'var(--ink-4)' }}></span>
+48
View File
@@ -0,0 +1,48 @@
'use client'
/**
* AnimatedNumber flashes green/red when its value changes, the way a live
* trading terminal ticks. Pure presentational: it renders `display` (already
* formatted) but watches `value` (the raw number) to decide flash direction.
*
* The flash is a CSS class toggled for ~600ms via a keyframe (`tick-flash-up` /
* `tick-flash-down` in globals.css). Respects prefers-reduced-motion (the CSS
* keyframes are disabled there, so this degrades to a plain number).
*/
import { useEffect, useRef, useState } from 'react'
interface Props {
/** Raw numeric value — drives the flash direction when it changes. */
value: number | null | undefined
/** Pre-formatted string to actually show (e.g. "$72,140"). */
display: string
/** Extra className(s) for the wrapper. */
className?: string
style?: React.CSSProperties
}
export default function AnimatedNumber({ value, display, className = '', style }: Props) {
const prev = useRef<number | null | undefined>(value)
const [dir, setDir] = useState<'up' | 'down' | null>(null)
useEffect(() => {
const p = prev.current
if (value != null && p != null && value !== p) {
setDir(value > p ? 'up' : 'down')
const id = setTimeout(() => setDir(null), 600)
prev.current = value
return () => clearTimeout(id)
}
prev.current = value
}, [value])
return (
<span
className={`tick-num ${dir ? `tick-flash-${dir}` : ''} ${className}`}
style={style}
>
{display}
</span>
)
}
+2 -2
View File
@@ -93,7 +93,7 @@ function PageBtn({ num, active, onClick }: { num: number; active: boolean; onCli
const [hover, setHover] = React.useState(false)
const bg = active
? 'var(--brand, #f5a524)'
? 'var(--amber)'
: hover
? 'var(--bg-sunk)'
: 'transparent'
@@ -105,7 +105,7 @@ function PageBtn({ num, active, onClick }: { num: number; active: boolean; onCli
: 'var(--ink-2)'
const border = active
? '1.5px solid var(--brand, #f5a524)'
? '1.5px solid var(--amber)'
: '1.5px solid var(--line)'
return (
+156
View File
@@ -0,0 +1,156 @@
'use client'
import { useState, useEffect, useCallback } from 'react'
import { useAccount } from 'wagmi'
import { useWsSubscribe } from '@/lib/wsContext'
interface TradeAlert {
id: number
event: 'execution_failed' | 'insufficient_balance' | 'budget_reached'
| 'reconcile_drift' | 'circuit_breaker_tripped'
asset?: string
reason?: string
balance_usd?: number
required_usd?: number
spent_usd?: number
cap_usd?: number
// reconcile_drift fields (from reconciler.py broadcast)
// orphan_hl is a list of {asset, trade_id} dicts, NOT a number
orphan_hl?: unknown[]
marked_closed?: number
ghost_positions?: unknown[]
// circuit_breaker_tripped fields (from circuit_breaker.py broadcast)
system?: string
cb_reason?: string
unlock_at?: string
}
// How long each alert stays visible before auto-dismissing.
const AUTO_DISMISS_MS = 10_000
function alertMessage(alert: TradeAlert): string {
switch (alert.event) {
case 'execution_failed':
return `Auto-trade failed${alert.asset ? ` on ${alert.asset}` : ''}${alert.reason ? `: ${alert.reason}` : ''}. Check your HL API key and account status.`
case 'insufficient_balance':
return `Insufficient balance to open${alert.asset ? ` ${alert.asset}` : ''}: account has $${alert.balance_usd?.toFixed(2) ?? '?'}, trade requires $${alert.required_usd?.toFixed(2) ?? '?'}. Top up your Hyperliquid account.`
case 'budget_reached':
return `Daily budget reached${alert.asset ? ` (${alert.asset})` : ''}: $${alert.spent_usd?.toFixed(0) ?? '?'} spent of $${alert.cap_usd?.toFixed(0) ?? '?'} cap. No more trades today.`
// B47: reconciler detects DB ↔ HL mismatch (ghost/orphan position)
case 'reconcile_drift': {
const parts = []
const orphanCount = (alert.orphan_hl as unknown[])?.length ?? 0
if (orphanCount > 0) parts.push(`${orphanCount} orphan(s) on HL`)
if (alert.marked_closed) parts.push(`${alert.marked_closed} auto-closed`)
if ((alert.ghost_positions as unknown[])?.length) parts.push(`${(alert.ghost_positions as unknown[]).length} ghost(s)`)
return `Position drift detected: ${parts.join(', ') || 'mismatch between DB and HL'}. Check your Hyperliquid account.`
}
// B53: circuit breaker fired — Auto-Trade suspended
case 'circuit_breaker_tripped':
return `Circuit breaker tripped${alert.system ? ` (${alert.system})` : ''}${alert.cb_reason ? `: ${alert.cb_reason}` : ''}. Auto-Trade suspended — turn it back ON on the Trump page to acknowledge and resume.`
default:
return 'Auto-trade event — check your account.'
}
}
let _seq = 0
export default function TradeAlertBanner() {
const { address } = useAccount()
const [alerts, setAlerts] = useState<TradeAlert[]>([])
const dismiss = useCallback((id: number) => {
setAlerts(prev => prev.filter(a => a.id !== id))
}, [])
// Auto-dismiss each alert after AUTO_DISMISS_MS.
// Effect re-runs whenever the alert list changes. For each alert we schedule
// a timeout; cleanup cancels all pending timers when the list updates or
// the component unmounts — prevents a dismissed-then-re-added alert from
// triggering a ghost dismiss.
useEffect(() => {
if (alerts.length === 0) return
const timers = alerts.map(a =>
window.setTimeout(() => dismiss(a.id), AUTO_DISMISS_MS)
)
return () => timers.forEach(clearTimeout)
}, [alerts, dismiss])
useWsSubscribe('trade_alert', useCallback((raw) => {
const msg = raw as { wallet?: string; event?: string } & Record<string, unknown>
if (!address || msg.wallet?.toLowerCase() !== address.toLowerCase()) return
const alert = { id: ++_seq, ...msg } as TradeAlert
setAlerts(prev => [alert, ...prev].slice(0, 3))
}, [address]))
// B47: reconcile_drift — DB↔HL position mismatch flagged by the reconciler.
useWsSubscribe('reconcile_drift', useCallback((raw) => {
const msg = raw as { wallet?: string } & Record<string, unknown>
if (!address || msg.wallet?.toLowerCase() !== address.toLowerCase()) return
const alert = { id: ++_seq, event: 'reconcile_drift' as const, ...msg } as TradeAlert
setAlerts(prev => [alert, ...prev].slice(0, 3))
}, [address]))
// B53: circuit_breaker_tripped — Auto-Trade suspended by the CB.
useWsSubscribe('circuit_breaker_tripped', useCallback((raw) => {
const msg = raw as { wallet?: string; reason?: string } & Record<string, unknown>
if (!address || msg.wallet?.toLowerCase() !== address.toLowerCase()) return
// Rename 'reason' → 'cb_reason' to avoid collision with the trade_alert 'reason' field.
const { reason: cb_reason, ...rest } = msg
const alert = { id: ++_seq, event: 'circuit_breaker_tripped' as const, cb_reason, ...rest } as TradeAlert
setAlerts(prev => [alert, ...prev].slice(0, 3))
}, [address]))
if (alerts.length === 0) return null
return (
<>
<style>{`
@keyframes tradeAlertIn {
from { opacity: 0; transform: translateX(-50%) translateY(-8px); }
to { opacity: 1; transform: translateX(-50%) translateY(0); }
}
@keyframes tradeAlertOut {
from { opacity: 1; }
to { opacity: 0; }
}
`}</style>
<div style={{
position: 'fixed', top: 60, left: '50%', transform: 'translateX(-50%)',
zIndex: 9999, display: 'flex', flexDirection: 'column', gap: 8,
width: 'min(480px, calc(100vw - 32px))',
pointerEvents: 'none',
animation: 'tradeAlertIn 0.2s ease',
}}>
{alerts.map(alert => (
<div key={alert.id} style={{
display: 'flex', alignItems: 'flex-start', gap: 10,
padding: '12px 14px', borderRadius: 10,
background: 'var(--bg)',
border: '1px solid var(--down)',
boxShadow: '0 4px 20px rgba(0,0,0,.3)',
pointerEvents: 'auto',
}}>
<span style={{ fontSize: 16, flexShrink: 0, marginTop: 1 }}></span>
<div style={{ flex: 1, fontSize: 12, lineHeight: 1.5, color: 'var(--ink)' }}>
<strong style={{ color: 'var(--down)', display: 'block', marginBottom: 2 }}>
Auto-trade blocked
</strong>
{alertMessage(alert)}
</div>
<button
onClick={() => dismiss(alert.id)}
style={{
flexShrink: 0, padding: 0, border: 'none', background: 'transparent',
cursor: 'pointer', color: 'var(--ink-4)', fontSize: 16, lineHeight: 1,
}}
aria-label="Dismiss"
>
×
</button>
</div>
))}
</div>
</>
)
}
+189
View File
@@ -0,0 +1,189 @@
'use client'
/**
* MobileWalletSheet bottom-drawer shown on mobile when no injected wallet
* is detected. Offers deep links to common mobile wallets so the user can
* open MetaMask (or Trust / Coinbase / OKX) and land directly on this dApp.
*
* Rendered as a fixed overlay + slide-up panel. Backdrop tap dismisses it.
* The CSS animation class `mobile-sheet-enter` is defined in globals.css.
*
* Usage:
* <MobileWalletSheet open={open} onClose={() => setOpen(false)} />
*/
import { useEffect, useState } from 'react'
import { getWalletLinks } from '@/lib/mobileWallet'
import type { WalletLink } from '@/lib/mobileWallet'
interface Props {
open: boolean
onClose: () => void
}
export default function MobileWalletSheet({ open, onClose }: Props) {
const [links, setLinks] = useState<WalletLink[]>([])
// Build deep links client-side only (needs window.location.href).
useEffect(() => {
if (open) {
setLinks(getWalletLinks(window.location.href))
}
}, [open])
// Lock body scroll while sheet is open.
useEffect(() => {
if (open) {
document.body.style.overflow = 'hidden'
return () => { document.body.style.overflow = '' }
}
}, [open])
// Escape key closes.
useEffect(() => {
if (!open) return
function onKey(e: KeyboardEvent) { if (e.key === 'Escape') onClose() }
window.addEventListener('keydown', onKey)
return () => window.removeEventListener('keydown', onKey)
}, [open, onClose])
if (!open) return null
return (
/* Backdrop */
<div
style={{
position: 'fixed', inset: 0, zIndex: 9000,
background: 'rgba(0,0,0,0.55)',
display: 'flex', alignItems: 'flex-end',
backdropFilter: 'blur(4px)',
WebkitBackdropFilter: 'blur(4px)',
}}
onClick={onClose}
aria-modal="true"
role="dialog"
aria-label="Connect a wallet"
>
{/* Sheet */}
<div
className="mobile-sheet-enter"
style={{
width: '100%',
background: 'var(--bg-elev)',
borderRadius: '20px 20px 0 0',
padding: '20px 20px 32px',
boxShadow: '0 -8px 40px rgba(0,0,0,0.18)',
maxHeight: '80vh',
overflowY: 'auto',
}}
onClick={e => e.stopPropagation()}
>
{/* Handle bar */}
<div style={{
width: 40, height: 4,
background: 'var(--line-2)',
borderRadius: 99,
margin: '0 auto 20px',
}} />
{/* Header */}
<div style={{ marginBottom: 20 }}>
<div style={{ fontSize: 18, fontWeight: 700, letterSpacing: '-0.01em', marginBottom: 4 }}>
Connect a wallet
</div>
<div style={{ fontSize: 13, color: 'var(--ink-3)', lineHeight: 1.5 }}>
Open the dApp inside your wallet's built-in browser to connect.
</div>
</div>
{/* Wallet list */}
<div style={{ display: 'flex', flexDirection: 'column', gap: 10 }}>
{links.map(link => (
<a
key={link.name}
href={link.href}
target="_blank"
rel="noopener noreferrer"
style={{
display: 'flex',
alignItems: 'center',
gap: 14,
padding: '14px 16px',
borderRadius: 'var(--r-md)',
border: '1px solid var(--line)',
background: 'var(--surface)',
textDecoration: 'none',
color: 'inherit',
transition: 'background 120ms, border-color 120ms',
}}
onTouchStart={e => {
(e.currentTarget as HTMLAnchorElement).style.background = 'var(--bg-sunk)'
}}
onTouchEnd={e => {
(e.currentTarget as HTMLAnchorElement).style.background = 'var(--surface)'
}}
>
{/* Icon */}
<div style={{
width: 44, height: 44,
borderRadius: 12,
background: link.color,
display: 'flex', alignItems: 'center', justifyContent: 'center',
fontSize: link.abbr.length > 2 ? 12 : 20,
fontWeight: 700,
color: '#fff',
flexShrink: 0,
letterSpacing: '-0.01em',
}}>
{link.abbr}
</div>
{/* Text */}
<div style={{ flex: 1, minWidth: 0 }}>
<div style={{ fontSize: 15, fontWeight: 600, marginBottom: 2 }}>{link.name}</div>
<div style={{ fontSize: 12, color: 'var(--ink-3)' }}>{link.hint}</div>
</div>
{/* Arrow */}
<svg width="16" height="16" viewBox="0 0 24 24" fill="none" style={{ color: 'var(--ink-3)', flexShrink: 0 }}>
<path d="M9 18l6-6-6-6" stroke="currentColor" strokeWidth="2" strokeLinecap="round" strokeLinejoin="round"/>
</svg>
</a>
))}
</div>
{/* WalletConnect note */}
<div style={{
marginTop: 18,
padding: '12px 14px',
borderRadius: 'var(--r-sm)',
background: 'var(--bg-sunk)',
fontSize: 12,
color: 'var(--ink-3)',
lineHeight: 1.55,
}}>
<strong style={{ color: 'var(--ink-2)' }}>Already in your wallet's browser?</strong>
{' '}Tap Cancel to dismiss, then use the built-in browser navigation to reload the page MetaMask should auto-detect the dApp.
</div>
{/* Close */}
<button
onClick={onClose}
style={{
marginTop: 14,
width: '100%',
padding: '14px',
borderRadius: 'var(--r-md)',
background: 'var(--bg-sunk)',
border: '1px solid var(--line)',
fontSize: 14,
fontWeight: 500,
color: 'var(--ink-2)',
}}
>
Cancel
</button>
</div>
</div>
)
}
+73 -5
View File
@@ -5,11 +5,18 @@ import type {
} from '@/types'
import type { SignedEnvelope } from './signedRequest'
const BASE_URL = process.env.NEXT_PUBLIC_API_URL || 'http://localhost:8000'
function getServerApiBase() {
return (
process.env.API_BASE_URL ||
process.env.INTERNAL_API_URL ||
process.env.NEXT_PUBLIC_API_URL ||
'http://localhost:8000'
)
}
function getApiOrigin() {
return typeof window === 'undefined'
? `${BASE_URL}/api`
? `${getServerApiBase()}/api`
: '/api/proxy/api'
}
@@ -29,6 +36,53 @@ async function fetchJson<T>(path: string, init?: RequestInit): Promise<T> {
return res.json() as Promise<T>
}
export interface PostListResponse {
items: TrumpPost[]
total: number
page: number
limit: number
counts: {
all: number
actionable: number
buy: number
short: number
off_topic: number
}
source_counts: {
source: string
count: number
latest: string | null
}[]
}
export async function getPostsPage(
limit = 20,
page = 1,
source?: string,
filters?: {
sourceIn?: string[]
sourceNotIn?: string[]
archiveOnly?: boolean
sentiment?: 'bullish' | 'bearish' | 'neutral'
signal?: 'buy' | 'short' | 'actionable'
aiScoredOnly?: boolean
},
): Promise<PostListResponse> {
const params = new URLSearchParams({
limit: String(limit),
page: String(page),
})
if (source) params.set('source', source)
if (filters?.sourceIn?.length) params.set('source_in', filters.sourceIn.join(','))
if (filters?.sourceNotIn?.length) params.set('source_not_in', filters.sourceNotIn.join(','))
if (filters?.archiveOnly) params.set('archive_only', 'true')
if (filters?.sentiment) params.set('sentiment', filters.sentiment)
if (filters?.signal) params.set('signal', filters.signal)
if (filters?.aiScoredOnly) params.set('ai_scored_only', 'true')
const q = `/posts-paged?${params.toString()}`
return fetchJson<PostListResponse>(q)
}
export async function getPosts(limit = 20, page = 1, source?: string): Promise<TrumpPost[]> {
const q = `/posts?limit=${limit}&page=${page}` + (source ? `&source=${encodeURIComponent(source)}` : '')
return fetchJson<TrumpPost[]>(q)
@@ -139,6 +193,11 @@ export interface UserPublic {
circuit_breaker_reason?: string | null
/** Master Auto-Trade gate. false (default) = signals shown, not traded. */
auto_trade?: boolean
/** Per-system enable flags. bot_engine gates System-1 (Trump) on
* trump_enabled and System-2 (Macro) on macro_enabled. Auto-Trade ON
* with trump_enabled=false still does NOT open on a Trump signal. */
trump_enabled?: boolean
macro_enabled?: boolean
}
export interface SignalSource {
@@ -403,11 +462,14 @@ export async function setManualWindow(
// ── KOL module ────────────────────────────────────────────────────
export async function getKolPosts(opts: {
handle?: string; source?: string; limit?: number; page?: number
} = {}): Promise<{ items: KolPostSummary[]; page: number; limit: number }> {
handle?: string; source?: string; signalsOnly?: boolean; ticker?: string; days?: number; limit?: number; page?: number
} = {}): Promise<{ items: KolPostSummary[]; page: number; limit: number; total: number }> {
const p = new URLSearchParams()
if (opts.handle) p.set('handle', opts.handle)
if (opts.source) p.set('source', opts.source)
if (opts.signalsOnly) p.set('signals_only', 'true')
if (opts.ticker) p.set('ticker', opts.ticker)
if (opts.days) p.set('days', String(opts.days))
p.set('limit', String(opts.limit ?? 50))
p.set('page', String(opts.page ?? 1))
return fetchJson(`/kol/posts?${p.toString()}`)
@@ -520,7 +582,13 @@ export interface TelegramStatus {
export interface TelegramInitResp {
code: string; deep_link: string; expires_in_seconds: number
}
export async function getTelegramStatus(wallet: string): Promise<TelegramStatus> {
export async function getTelegramStatus(wallet: string, env?: SignedEnvelope): Promise<TelegramStatus> {
// Pass signature when available so the backend returns full binding details.
// Without it the endpoint returns only `bound: boolean` to prevent third-party de-anonymisation.
if (env) {
const qs = new URLSearchParams({ timestamp: String(env.timestamp), signature: env.signature })
return fetchJson<TelegramStatus>(`/telegram/${wallet}/status?${qs}`)
}
return fetchJson<TelegramStatus>(`/telegram/${wallet}/status`)
}
// SignedEnvelope is already imported at the top of this file. Below we
+105
View File
@@ -0,0 +1,105 @@
/**
* Mobile wallet detection and deep-link helpers.
*
* On mobile browsers (Safari / Chrome) there is no injected `window.ethereum`,
* so the `injected()` wagmi connector returns nothing and the user sees
* "No wallet provider found". The fix is to detect this state early and offer
* deep links that open MetaMask / Trust / Coinbase / OKX and land the user
* inside the wallet's in-app browser at the current dApp URL.
*
* Deep-link patterns used:
* MetaMask https://metamask.app.link/dapp/<host><path> (universal link → iOS/Android)
* Trust https://link.trustwallet.com/open_url?coin_id=60&url=<encoded>
* Coinbase https://go.cb-wallet.com/dapp?url=<encoded>
* OKX https://www.okx.com/download?deeplink=okx%3A%2F%2Fmain%2Fdapp%2Fbrowser%3Furl%3D<encoded>
*
* All links open in a new tab (_blank) so if the user doesn't have the app
* installed they land on the wallet's download page without breaking nav.
*/
/** True when the JS runtime has access to browser APIs. */
const isBrowser = typeof window !== 'undefined'
/**
* Rough mobile UA check covers iOS (iPhone/iPad) and Android.
* Intentionally excludes desktop Chrome/Firefox even if the viewport is narrow.
*/
export function isMobileDevice(): boolean {
if (!isBrowser) return false
return /Android|webOS|iPhone|iPad|iPod|BlackBerry|IEMobile|Opera Mini/i.test(navigator.userAgent)
}
/**
* Returns true when an injected EIP-1193 provider is present in the window
* (i.e. the user is already inside MetaMask's browser, has a browser extension,
* or Coinbase Wallet's in-app browser).
*/
export function hasInjectedWallet(): boolean {
if (!isBrowser) return false
// window.ethereum is the canonical EIP-1193 injection point.
// Some wallets also inject under their own namespace but all reputable ones
// also set window.ethereum (or window.web3 as a fallback).
return !!(window as unknown as { ethereum?: unknown }).ethereum
}
/**
* True when the user is on mobile AND has no injected wallet the state
* where we should show the mobile wallet picker instead of a bare error.
*/
export function needsMobileWallet(): boolean {
return isMobileDevice() && !hasInjectedWallet()
}
export interface WalletLink {
name: string
/** Short subtitle shown under the name */
hint: string
/** URL that opens the wallet app and navigates to `dappUrl` */
href: string
/** CSS color for the icon background */
color: string
/** Short letter(s) displayed when no SVG icon is available */
abbr: string
}
/**
* Build the deep-link set for the given dApp URL.
* Pass `window.location.href` (or a canonical URL) as `dappUrl`.
*/
export function getWalletLinks(dappUrl: string): WalletLink[] {
const enc = encodeURIComponent(dappUrl)
// MetaMask universal link: strip the protocol and pass host+path
// e.g. "https://trumpsignal.com/en" → "trumpsignal.com/en"
const hostPath = dappUrl.replace(/^https?:\/\//, '')
return [
{
name: 'MetaMask',
hint: 'Most popular — iOS & Android',
href: `https://metamask.app.link/dapp/${hostPath}`,
color: '#E8831D',
abbr: '🦊',
},
{
name: 'Trust Wallet',
hint: 'Binance-backed, iOS & Android',
href: `https://link.trustwallet.com/open_url?coin_id=60&url=${enc}`,
color: '#3375BB',
abbr: '🛡',
},
{
name: 'Coinbase Wallet',
hint: 'No Coinbase account needed',
href: `https://go.cb-wallet.com/dapp?url=${enc}`,
color: '#1652F0',
abbr: '🔵',
},
{
name: 'OKX Wallet',
hint: 'iOS & Android',
href: `https://www.okx.com/download?deeplink=${encodeURIComponent(`okx://main/dapp/browser?url=${enc}`)}`,
color: '#000000',
abbr: 'OKX',
},
]
}
+118
View File
@@ -0,0 +1,118 @@
import type { TrumpPost } from '@/types'
import { getPosts, getPostsPage, type PostListResponse } from './api'
const LIVE_ARCHIVE_SOURCES = new Set([
'truth',
'btc_bottom_reversal',
'funding_reversal',
'kol_divergence',
])
function isAiScored(post: Pick<TrumpPost, 'ai_confidence' | 'ai_reasoning'>): boolean {
return (post.ai_confidence ?? 0) > 0 || !!post.ai_reasoning
}
function buildSourceCounts(items: TrumpPost[]): PostListResponse['source_counts'] {
const counts = new Map<string, { count: number; latest: string | null }>()
for (const post of items) {
const hit = counts.get(post.source)
if (!hit) {
counts.set(post.source, { count: 1, latest: post.published_at })
continue
}
hit.count += 1
if (!hit.latest || post.published_at > hit.latest) hit.latest = post.published_at
}
return Array.from(counts.entries())
.map(([source, meta]) => ({ source, count: meta.count, latest: meta.latest }))
.sort((a, b) => b.count - a.count || a.source.localeCompare(b.source))
}
export function buildPostListFallbackResponse(
items: TrumpPost[],
source: string,
limit: number,
): PostListResponse {
return {
items,
total: items.length,
page: 1,
limit,
counts: {
all: items.length,
actionable: items.filter(p => p.signal === 'buy' || p.signal === 'short').length,
buy: items.filter(p => p.signal === 'buy').length,
short: items.filter(p => p.signal === 'short').length,
off_topic: items.filter(p => !isAiScored(p)).length,
},
source_counts: [{ source, count: items.length, latest: items[0]?.published_at ?? null }],
}
}
export function buildArchiveFallbackResponse(
allPosts: TrumpPost[],
page: number,
limit: number,
source = 'all',
): PostListResponse {
const archivePosts = allPosts.filter(post => !LIVE_ARCHIVE_SOURCES.has(post.source))
const sourceCounts = buildSourceCounts(archivePosts)
const filtered = source === 'all'
? archivePosts
: archivePosts.filter(post => post.source === source)
const offset = (page - 1) * limit
const items = filtered.slice(offset, offset + limit)
return {
items,
total: filtered.length,
page,
limit,
counts: {
all: filtered.length,
actionable: filtered.filter(p => p.signal === 'buy' || p.signal === 'short').length,
buy: filtered.filter(p => p.signal === 'buy').length,
short: filtered.filter(p => p.signal === 'short').length,
off_topic: filtered.filter(p => !isAiScored(p)).length,
},
source_counts: sourceCounts,
}
}
export async function getInitialPostPage(
limit: number,
page: number,
options: {
source?: string
filters?: {
sourceIn?: string[]
sourceNotIn?: string[]
archiveOnly?: boolean
sentiment?: 'bullish' | 'bearish' | 'neutral'
signal?: 'buy' | 'short' | 'actionable'
aiScoredOnly?: boolean
}
legacyFallbackSource?: string
legacyFallback?: () => Promise<PostListResponse | null>
},
): Promise<PostListResponse | null> {
return getPostsPage(limit, page, options.source, options.filters).catch(async (e) => {
// Only fall back to legacy /posts on 404 (new endpoint not yet deployed).
// Non-404 errors (500, network) should NOT silently mask as empty data —
// a server-side fallback on 500 produces initial HTML that the client
// cannot reproduce on re-fetch (it shows an error instead), causing a
// hydration mismatch. Return null so the page renders empty and the
// client fetches cleanly on mount.
const detail = e instanceof Error ? e.message : ''
if (!detail.includes('404')) return null
if (options.legacyFallback) {
return options.legacyFallback()
}
if (!options.legacyFallbackSource || options.filters?.archiveOnly || options.filters?.sourceIn || options.filters?.sourceNotIn) {
return null
}
const fallbackItems = await getPosts(limit, page, options.legacyFallbackSource).catch(() => null)
return fallbackItems ? buildPostListFallbackResponse(fallbackItems, options.legacyFallbackSource, limit) : null
})
}
+25 -4
View File
@@ -1,9 +1,16 @@
import { createConfig, createStorage, http } from 'wagmi'
import { mainnet } from 'wagmi/chains'
import { injected } from 'wagmi/connectors'
import { injected, walletConnect } from 'wagmi/connectors'
export const chains = [mainnet] as const
// WalletConnect v2 requires a free project ID from https://cloud.walletconnect.com
// Set NEXT_PUBLIC_WALLETCONNECT_PROJECT_ID in .env.local to enable:
// - QR code scanning (desktop → mobile wallet)
// - All WalletConnect-compatible mobile wallets
// Without it, only injected (browser extension) wallets are available.
const wcProjectId = process.env.NEXT_PUBLIC_WALLETCONNECT_PROJECT_ID
export const config = createConfig({
chains,
connectors: [
@@ -12,10 +19,24 @@ export const config = createConfig({
// Brave, Frame, Trust, OKX…) fail to connect, and broke in browsers where
// window.ethereum isn't MetaMask. wagmi v2 auto-discovers all injected
// wallets via EIP-6963 (multiInjectedProviderDiscovery, on by default), so
// a generic injected() connector covers them. This still uses the native
// injected provider path (NOT the MetaMask SDK), so it avoids the SDK
// account-sync bug that motivated the original pin.
// a generic injected() connector covers them.
injected({ shimDisconnect: false }),
// WalletConnect v2 — enabled when NEXT_PUBLIC_WALLETCONNECT_PROJECT_ID is set.
// Provides QR-code pairing (desktop ↔ mobile) and all WalletConnect wallets.
// Get a free project ID at https://cloud.walletconnect.com
...(wcProjectId
? [walletConnect({
projectId: wcProjectId,
metadata: {
name: 'Trump Alpha',
description: 'Live crypto signals — Trump posts, BTC macro, KOL divergence',
url: process.env.NEXT_PUBLIC_SITE_URL || 'https://trumpsignal.com',
icons: ['https://trumpsignal.com/icon'],
},
showQrModal: true,
})]
: []),
],
transports: {
[mainnet.id]: http(),
+9 -1
View File
@@ -27,7 +27,15 @@ interface WsContextValue {
const WsContext = createContext<WsContextValue | null>(null)
const WS_URL = process.env.NEXT_PUBLIC_WS_URL || 'ws://localhost:8000'
// In production, NEXT_PUBLIC_WS_URL must be set (e.g. wss://api.trumpsignal.com).
// Fallback auto-upgrades ws→wss when the page is served over HTTPS to avoid
// mixed-content blocks, and falls back to ws:// for local dev.
const _wsEnv = process.env.NEXT_PUBLIC_WS_URL
const WS_URL = _wsEnv || (
typeof window !== 'undefined' && window.location.protocol === 'https:'
? 'wss://localhost:8000'
: 'ws://localhost:8000'
)
// Exponential backoff: 2s → 4s → 8s → … capped at 60s, plus ±30% jitter
// so a server restart doesn't get hit by all clients at the same instant.
+2 -3
View File
@@ -1,14 +1,13 @@
{
"name": "trumpsignal",
"name": "frontend",
"version": "0.1.0",
"lockfileVersion": 3,
"requires": true,
"packages": {
"": {
"name": "trumpsignal",
"name": "frontend",
"version": "0.1.0",
"dependencies": {
"@parcel/watcher-linux-arm64-glibc": "*",
"@rainbow-me/rainbowkit": "^2.1.3",
"@tanstack/react-query": "^5.40.0",
"lightweight-charts": "^4.1.3",
+1 -1
View File
@@ -1,5 +1,5 @@
{
"name": "trumpsignal",
"name": "frontend",
"version": "0.1.0",
"private": true,
"engines": {
+1 -1
View File
@@ -41,7 +41,7 @@ Manage-only: alerts surface; the user opens on Hyperliquid and the bot then
manages the exit (5-rung stop ladder, de-risk, pyramid, peak-trail). No auto-open.
### 3. KOL talks-vs-trades divergence (highest conviction)
19 crypto KOL feeds ingested daily via RSS. An NLP step extracts ticker(s),
25 crypto KOL feeds ingested daily via RSS. An NLP step extracts ticker(s),
directional stance, and conviction. A separate on-chain step diffs each KOL's
Ethereum wallet. A DIVERGENCE fires when public stance and wallet action
disagree within a ±7-day window (e.g. publicly bullish ETH while selling ETH).
+2 -2
View File
@@ -14,7 +14,7 @@ Trump Alpha is Endorphin's public signal desk: four independent signal engines a
- **BTC Macro Bottom** (long-only): fires when ≥ 2 of 3 agree — AHR999 < 0.45, price ≤ 200-week MA × 1.05, Pi Cycle Bottom. Fires 24 times per multi-year cycle.
- **BTC Funding Reversal**: fires when 30-day cumulative perp funding crosses ±3% AND the most recent cycles start cooling (mean-reversion bet against crowded positioning).
3. **KOL Signal** — 19 crypto KOL feeds ingested daily via RSS: Arthur Hayes (BitMEX co-founder), Delphi Digital, Dragonfly Capital, Bankless, Empire (Jason Yanowitz + Santiago Santos), Unchained (Laura Shin), 0xResearch (Blockworks), Lightspeed (Blockworks), Pomp (Anthony Pompliano), The Defiant, Reflexivity Research (Will Clemente), Bell Curve (Multicoin Capital), The Scoop (The Block / Frank Chaparro), TFTC (Marty Bent), checkmate (Glassnode), coinmetrics, willywoo (Willy Woo), glassnode, and Lyn Alden (Lyn Alden Investment Strategy). AI extracts: ticker(s) mentioned, directional stance (buy/sell/bullish/bearish/reduce/mention), and conviction score.
3. **KOL Signal** — 25 crypto KOL feeds ingested daily via RSS: Arthur Hayes (BitMEX co-founder), Delphi Digital, Bankless, Empire (Jason Yanowitz + Santiago Santos), Unchained (Laura Shin), 0xResearch (Blockworks), Lightspeed (Blockworks), Pomp (Anthony Pompliano), The Defiant, Reflexivity Research (Will Clemente), Bell Curve (Multicoin Capital), The Scoop (The Block / Frank Chaparro), TFTC (Marty Bent), checkmate (Glassnode), coinmetrics, willywoo (Willy Woo), glassnode, Lyn Alden (Lyn Alden Investment Strategy), The DeFi Edge, Bitcoin Magazine, Deribit Insights, Bitfinex Alpha, Forward Guidance, and more. AI extracts: ticker(s) mentioned, directional stance (buy/sell/bullish/bearish/reduce/mention), and conviction score.
4. **Talks-vs-Trades Divergence** — The platform's highest-conviction signal. Cross-references each KOL's public posts against their on-chain Ethereum wallet changes within a ±7-day window. A DIVERGENCE fires when a KOL is publicly bullish but their wallet is selling (or vice versa). An ALIGNMENT fires when public stance and on-chain action agree. On-chain action is treated as ground truth — talk is cheap, wallet movements are not.
@@ -32,7 +32,7 @@ Trump Alpha is Endorphin's public signal desk: four independent signal engines a
**Talks-vs-Trades divergence**: Comparing a KOL's public verbal position on an asset against what their on-chain wallet actually does within the same ±7-day window. The divergence signal (say one thing, do another) is treated as the higher-conviction indicator — on-chain behavior is harder to fake than a tweet or newsletter.
**KOL (Key Opinion Leader)**: In crypto, influential analysts, fund managers, podcast hosts, and content creators whose public views measurably move retail sentiment. Trump Alpha tracks 19 of them across Substack, podcast RSS, and blog feeds.
**KOL (Key Opinion Leader)**: In crypto, influential analysts, fund managers, podcast hosts, and content creators whose public views measurably move retail sentiment. Trump Alpha tracks 25 of them across Substack, podcast RSS, and blog feeds.
**Hyperliquid**: A decentralized perpetual futures exchange. Trump Alpha's auto-trader executes all positions there. API keys are trade-only (no withdrawal permissions) and are stored server-side encrypted.
+27 -11
View File
@@ -1,24 +1,38 @@
import { create } from 'zustand'
// Wallet-specific fields that must be reset whenever the connected address
// changes. Extracted so setWallet can wipe them atomically (B34/B42).
const WALLET_RESET = {
isSubscribed: false,
botReadiness: 'unknown' as const,
hlApiKeySet: false,
hlApiKeyMasked: null as string | null,
paperMode: false,
}
interface DashboardState {
selectedPostId: number | null
asset: 'BTC' | 'ETH'
asset: string
timeframe: '5m' | '15m' | '1H' | '4H' | '1D' | '1W'
walletAddress: string | null
isSubscribed: boolean
botReadiness: 'unknown' | 'saved' | 'verified' | 'ready'
hlApiKeySet: boolean // true if user already has a key saved in backend
hlApiKeyMasked: string | null // e.g. "...a1b2c3" shown after successful save
paperMode: boolean // true = paper trade mode (no HL key needed)
// BUG-08 fix: backend now streams SOL/TRUMP/BNB/etc. — use an open Record
// so any asset tick can be stored, not just BTC/ETH.
livePrices: Record<string, number | null>
setSelectedPost: (id: number | null) => void
setAsset: (asset: 'BTC' | 'ETH') => void
setAsset: (asset: string) => void
setTimeframe: (tf: '5m' | '15m' | '1H' | '4H' | '1D' | '1W') => void
// B34/B42: setWallet resets ALL wallet-specific fields atomically so
// switching wallets never leaks the previous wallet's private state.
setWallet: (address: string | null) => void
setSubscribed: (subscribed: boolean) => void
setBotReadiness: (state: DashboardState['botReadiness']) => void
setHlApiKeySet: (set: boolean, masked?: string) => void
setPaperMode: (paper: boolean) => void
setLivePrice: (asset: string, price: number) => void
}
@@ -27,24 +41,26 @@ export const useDashboardStore = create<DashboardState>((set) => ({
asset: 'BTC',
timeframe: '4H',
walletAddress: null,
isSubscribed: false,
botReadiness: 'unknown',
hlApiKeySet: false,
hlApiKeyMasked: null,
...WALLET_RESET,
livePrices: { BTC: null, ETH: null, SOL: null, TRUMP: null },
setSelectedPost: (id) => set({ selectedPostId: id }),
setAsset: (asset) => set({ asset }),
setTimeframe: (timeframe) => set({ timeframe }),
setWallet: (walletAddress) => set({ walletAddress }),
// Reset all wallet-specific fields on every address change (including null).
setWallet: (walletAddress) => set({ walletAddress, ...WALLET_RESET }),
setSubscribed: (isSubscribed) => set({ isSubscribed }),
setBotReadiness: (botReadiness) => set({ botReadiness }),
setHlApiKeySet: (keySet, masked) =>
set((s) => ({
set(() => ({
hlApiKeySet: keySet,
// Preserve existing mask when called without one (e.g. the /public poll
// only returns a boolean). Only explicitly clear when keySet=false.
hlApiKeyMasked: !keySet ? null : (masked !== undefined ? masked : s.hlApiKeyMasked),
// Never preserve the old mask — if the caller doesn't supply one we
// don't know the new wallet's mask and must show nothing until the full
// /user fetch (BotConfigPanel.applyUserPayload) provides it explicitly.
// Old behaviour of "preserve when masked=undefined" was the root cause
// of cross-wallet HL key mask leakage (B34 follow-up).
hlApiKeyMasked: (keySet && masked !== undefined) ? masked : null,
})),
setPaperMode: (paperMode) => set({ paperMode }),
setLivePrice: (asset, price) =>
set((s) => ({ livePrices: { ...s.livePrices, [asset]: price } })),
}))
+15 -5
View File
@@ -46,12 +46,13 @@ export interface BotTrade {
asset: string
side: 'long' | 'short'
entry_price: number
exit_price: number
pnl_usd: number
hold_seconds: number
trigger_post_id: number
exit_price: number | null // null = externally closed or position still open
pnl_usd: number | null // null = unsettled / externally closed
hold_seconds: number | null // null = not yet computed
trigger_post_id: number | null // null = adopted/manual (no trigger post)
opened_at: string
closed_at: string
closed_at: string | null // null for still-open positions
trigger_post_text?: string | null
/** Source of the triggering signal — 'truth' | 'breakout' | user's module name. */
trigger_source?: string | null
/** True iff this was a paper-mode trade (no Hyperliquid call). */
@@ -75,8 +76,13 @@ export interface KolTicker {
action: KolAction
conviction: number
quote: string
timeframe?: string
stance_change?: boolean
}
export type KolTier = 'trade_signal' | 'directional' | 'noise'
export type KolPostType = 'original' | 'reply' | 'retweet' | 'quote' | 'thread_cont'
export interface KolPostSummary {
id: number
kol_handle: string
@@ -88,6 +94,10 @@ export interface KolPostSummary {
tickers: KolTicker[]
analyzed_at: string | null
analysis_model: string | null
tier?: KolTier | null
post_type?: KolPostType | null
talks_vs_trades_flag?: boolean
sentiment?: 'bullish' | 'bearish' | 'neutral' | null
}
export interface KolPostDetail extends KolPostSummary {