Skip to content

Commit c4c1b6b

Browse files
authored
Merge pull request #185 from Mosas2000/feature/network-status-indicator
Add network status indicator to header
2 parents de305d7 + 23bfd4d commit c4c1b6b

2 files changed

Lines changed: 26 additions & 0 deletions

File tree

frontend/src/components/Header.jsx

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,28 @@
1+
import { useState, useEffect } from 'react';
12
import CopyButton from './ui/copy-button';
23
import { useTheme } from '../context/ThemeContext';
4+
import { NETWORK_NAME, STACKS_API_BASE } from '../config/contracts';
35

46
export 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"

frontend/src/config/contracts.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ export const CONTRACT_ADDRESS = 'SP31PKQVQZVZCK3FM3NH67CGD6G1FMR17VQVS2W5T';
55
export const CONTRACT_NAME = 'tipstream';
66

77
const NETWORK = import.meta.env.VITE_NETWORK || 'mainnet';
8+
export const NETWORK_NAME = NETWORK;
89
export const STACKS_API_BASE = NETWORK === 'mainnet'
910
? 'https://api.hiro.so'
1011
: NETWORK === 'testnet'

0 commit comments

Comments
 (0)