'use client' import { useState, useEffect } from 'react' import Link from 'next/link' import { usePathname } from 'next/navigation' import { useAccount, useConnect, useDisconnect } from 'wagmi' import { useTranslations } from 'next-intl' import { getFirstReadyConnector, walletConnectErrorLabel } from '@/lib/walletConnect' // i18n shelved — LanguageSwitch hidden but kept on disk for future revival. // import LanguageSwitch from './LanguageSwitch' function BrandMark() { return α } function ThemeToggle() { const [theme, setTheme] = useState<'light' | 'dark'>('light') useEffect(() => { const stored = localStorage.getItem('theme') as 'light' | 'dark' | null const t = stored || 'light' setTheme(t) document.documentElement.dataset.theme = t }, []) function toggle() { const next = theme === 'dark' ? 'light' : 'dark' setTheme(next) localStorage.setItem('theme', next) document.documentElement.dataset.theme = next } return ( {theme === 'dark' ? ( ) : ( )} ) } export default function Navbar() { const t = useTranslations('nav') const pathname = usePathname() const { address, isConnected } = useAccount() const { connectAsync, connectors } = useConnect() const { disconnect } = useDisconnect() const [mounted, setMounted] = useState(false) const [walletMenuOpen, setWalletMenuOpen] = useState(false) const [copied, setCopied] = useState(false) const [connectError, setConnectError] = useState('') async function copyAddress(addr: string) { let ok = false try { if (navigator.clipboard?.writeText) { await navigator.clipboard.writeText(addr) ok = true } else { // Fallback for non-secure contexts where the Clipboard API is absent. const ta = document.createElement('textarea') ta.value = addr ta.style.position = 'fixed' ta.style.opacity = '0' document.body.appendChild(ta) ta.select() ok = document.execCommand('copy') document.body.removeChild(ta) } } catch { ok = false } setCopied(ok) setTimeout(() => setCopied(false), 1500) } useEffect(() => { setMounted(true) }, []) useEffect(() => { setWalletMenuOpen(false) }, [pathname, address]) useEffect(() => { if (isConnected) setConnectError('') }, [isConnected]) const locale = pathname.split('/')[1] || 'en' const path = '/' + pathname.split('/').slice(2).join('/') 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)) } } // Two independent trading systems get their own top-level tabs — no // intermediate "Signals" hub. Trump = event scalp; BTC = reversal. const tabs = [ { key: '/', label: t('tabs.overview') }, { key: '/trump', label: t('tabs.trump') }, { key: '/macro', label: t('tabs.vibes') }, { key: '/kol', label: t('tabs.kol') }, { key: '/trades', label: t('tabs.trades') }, { key: '/analytics', label: t('tabs.analytics') }, { key: '/settings', label: t('tabs.settings') }, ] function isActive(key: string) { if (key === '/') return path === '/' || path === '//' // /posts (legacy hub) still resolves but isn't a tab; treat it + /archive // as part of the Trump section so a tab stays highlighted there. if (key === '/trump') return path.startsWith('/trump') || path.startsWith('/posts') || path.startsWith('/archive') return path.startsWith(key) } const shortAddr = address ? `${address.slice(0, 6)}…${address.slice(-4)}` : null return ( {t('brand')} {tabs.map(tab => ( {tab.label} ))} {/* — shelved until i18n coverage is complete */} {!mounted ? ( {t('actions.connectWallet')} ) : isConnected && shortAddr ? ( setWalletMenuOpen(open => !open)} onBlur={(e) => { if (!e.currentTarget.parentElement?.contains(e.relatedTarget as Node | null)) { setWalletMenuOpen(false) } }} aria-expanded={walletMenuOpen} aria-haspopup="menu" > {shortAddr} { e.preventDefault() if (address) copyAddress(address) }} > {copied ? t('actions.copied') : t('actions.copyAddress')} { e.preventDefault() disconnect() setWalletMenuOpen(false) }} > {t('actions.disconnect')} ) : ( { void handleConnectWallet() }} > {t('actions.connectWallet')} )} {!isConnected && connectError ? ( {connectError} ) : null} ) }
{connectError}