File size: 3,598 Bytes
7200823
c6b6c96
7200823
 
c6b6c96
 
7200823
 
c6b6c96
 
de40b1a
 
 
 
 
c6b6c96
 
 
 
 
 
 
 
 
 
 
 
 
 
7200823
 
 
 
de40b1a
7200823
 
c6b6c96
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
7200823
de40b1a
c6b6c96
de40b1a
 
 
 
 
 
 
 
7200823
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
'use client'
import { Bell, Search, Globe, Wifi, Zap } from 'lucide-react'
import { useState, useEffect } from 'react'

interface TorqueStatus { configured: boolean; status: string; sessionEvents: number }

export function Topbar() {
  const [time, setTime] = useState('')
  const [torque, setTorque] = useState<TorqueStatus | null>(null)

  useEffect(() => {
    const u = () => setTime(new Date().toLocaleTimeString('en-US', { hour12: false }))
    u(); const i = setInterval(u, 1000); return () => clearInterval(i)
  }, [])

  useEffect(() => {
    const fetchStatus = async () => {
      try {
        const res = await fetch('/api/torque/status')
        if (res.ok) setTorque(await res.json())
      } catch {}
    }
    fetchStatus()
    const i = setInterval(fetchStatus, 8000)
    return () => clearInterval(i)
  }, [])

  const isLive = torque?.configured && torque?.status === 'connected'

  return (
    <header className="h-14 border-b border-hairline-dark bg-surface-card/80 backdrop-blur-sm flex items-center justify-between px-6">
      <div className="relative">
        <Search className="absolute left-3 top-1/2 -translate-y-1/2 w-4 h-4 text-muted" />
        <input type="text" placeholder="Search wallets, campaigns..." className="w-64 h-9 pl-9 pr-4 rounded-lg bg-surface-elevated border border-hairline-dark text-body-sm text-[#eaecef] placeholder:text-muted focus:outline-none focus:ring-1 focus:ring-brand-yellow/50 transition" />
      </div>
      <div className="flex items-center gap-4">
        {torque && (
          <div className={`flex items-center gap-2 px-3 py-1.5 rounded-pill border ${isLive ? 'bg-trading-up/10 border-trading-up/20' : 'bg-trading-down/10 border-trading-down/20'}`}>
            <div className={`w-2 h-2 rounded-full ${isLive ? 'bg-trading-up animate-pulse' : 'bg-trading-down'}`} />
            <span className={`text-caption font-semibold ${isLive ? 'text-trading-up' : 'text-trading-down'}`}>
              TORQUE {isLive ? 'LIVE' : 'OFFLINE'}
            </span>
          </div>
        )}
        {!torque && (
          <div className="flex items-center gap-2 px-3 py-1.5 rounded-pill bg-muted/10 border border-muted/20">
            <div className="w-2 h-2 rounded-full bg-muted animate-pulse" />
            <span className="text-caption text-muted font-semibold">CONNECTING...</span>
          </div>
        )}
        {torque && torque.sessionEvents > 0 && (
          <div className="flex items-center gap-1.5 px-2.5 py-1 rounded-pill bg-brand-yellow/10 border border-brand-yellow/20">
            <Zap className="w-3 h-3 text-brand-yellow" />
            <span className="font-mono text-caption text-brand-yellow font-semibold">{torque.sessionEvents}</span>
          </div>
        )}
        <span className="font-mono text-num-sm text-muted tabular-nums">{time}</span>
        <button className="flex items-center gap-1.5 text-muted hover:text-[#eaecef] transition">
          <Wifi className={`w-4 h-4 ${isLive ? 'text-trading-up' : 'text-muted'}`} /><span className="text-caption">Solana</span>
        </button>
        <button className="relative p-2 rounded-lg hover:bg-surface-elevated transition">
          <Bell className="w-4 h-4 text-muted" />
          <span className="absolute top-1 right-1 w-2 h-2 bg-brand-yellow rounded-full" />
        </button>
        <button className="flex items-center gap-2 px-4 py-2 rounded-md bg-brand-yellow text-ink text-button font-semibold hover:bg-brand-yellow-active transition">
          <Globe className="w-4 h-4" />Connect
        </button>
      </div>
    </header>
  )
}