1+ import { useState , useEffect } from 'react' ;
12import CopyButton from './ui/copy-button' ;
23import { useTheme } from '../context/ThemeContext' ;
4+ import { NETWORK_NAME , STACKS_API_BASE } from '../config/contracts' ;
35
46export default function Header ( { userData, onAuth, authLoading } ) {
57 const { theme, toggleTheme } = useTheme ( ) ;
8+ const [ apiReachable , setApiReachable ] = useState ( null ) ;
9+
10+ useEffect ( ( ) => {
11+ let cancelled = false ;
12+ const checkApi = async ( ) => {
13+ try {
14+ const res = await fetch ( `${ STACKS_API_BASE } /v2/info` , { signal : AbortSignal . timeout ( 5000 ) } ) ;
15+ if ( ! cancelled ) setApiReachable ( res . ok ) ;
16+ } catch {
17+ if ( ! cancelled ) setApiReachable ( false ) ;
18+ }
19+ } ;
20+ checkApi ( ) ;
21+ const interval = setInterval ( checkApi , 30000 ) ;
22+ return ( ) => { cancelled = true ; clearInterval ( interval ) ; } ;
23+ } , [ ] ) ;
24+
25+ const networkLabel = NETWORK_NAME . charAt ( 0 ) . toUpperCase ( ) + NETWORK_NAME . slice ( 1 ) ;
626
727 return (
828 < nav className = "bg-gradient-to-r from-gray-900 to-black shadow-xl border-b border-white/10" >
@@ -23,6 +43,11 @@ export default function Header({ userData, onAuth, authLoading }) {
2343 </ div >
2444
2545 < div className = "flex items-center space-x-3 sm:space-x-6" >
46+ < div className = "hidden sm:flex items-center gap-1.5 px-3 py-1.5 rounded-lg bg-white/10 border border-white/5" >
47+ < span className = { `h-2 w-2 rounded-full ${ apiReachable === null ? 'bg-yellow-400 animate-pulse' : apiReachable ? 'bg-green-400' : 'bg-red-400' } ` } />
48+ < span className = "text-[10px] font-bold text-gray-300 uppercase tracking-wider" > { networkLabel } </ span >
49+ </ div >
50+
2651 < button
2752 onClick = { toggleTheme }
2853 className = "p-2 rounded-lg text-gray-300 hover:text-white hover:bg-white/10 transition-colors min-h-[44px] min-w-[44px] flex items-center justify-center"
0 commit comments