1
1
import React , { useState , useCallback , useEffect , useRef } from 'react' ;
2
2
import { useTheme } from '../contexts/ThemeContext' ;
3
3
import ChainSettingsModal from './ChainSettingsModal' ;
4
+ import './StatusLight.css' ;
4
5
import ForceStopModal from './ForceStopModal' ;
5
6
import SettingsIcon from './SettingsIcon' ;
6
7
import Tooltip from './Tooltip' ;
@@ -23,8 +24,49 @@ const Card = ({
23
24
const [ lastActionTime , setLastActionTime ] = useState ( 0 ) ;
24
25
const [ tooltipVisible , setTooltipVisible ] = useState ( false ) ;
25
26
const [ tooltipPosition , setTooltipPosition ] = useState ( { x : 0 , y : 0 } ) ;
27
+ const [ processHealth , setProcessHealth ] = useState ( 'offline' ) ; // 'healthy', 'warning', 'error', 'offline'
28
+ const [ blockCount , setBlockCount ] = useState ( - 1 ) ;
26
29
const buttonRef = useRef ( null ) ;
27
30
31
+ // Periodic chain status / health check
32
+ useEffect ( ( ) => {
33
+ const fetchBlockCount = async ( ) => {
34
+ try {
35
+ const count = await window . electronAPI . getChainBlockCount ( chain . id ) ;
36
+ console . log ( "new count: " , count )
37
+ setBlockCount ( count ) ;
38
+ } catch ( error ) {
39
+ setBlockCount ( - 1 )
40
+ console . error ( 'Failed to fetch block count:' , error ) ;
41
+ }
42
+ } ;
43
+
44
+ // Initial fetch
45
+ fetchBlockCount ( ) ;
46
+
47
+ const interval = setInterval ( ( ) => {
48
+ fetchBlockCount ( ) ;
49
+
50
+ if ( chain . status === 'stopping' || chain . status === 'stopped' ) {
51
+ setProcessHealth ( 'offline' ) ;
52
+ }
53
+ else
54
+ if ( blockCount === - 1 ) {
55
+ setProcessHealth ( 'offline' ) ;
56
+ }
57
+ else
58
+ if ( blockCount === 0 ) {
59
+ setProcessHealth ( 'warning' ) ;
60
+ }
61
+ else
62
+ if ( blockCount > 0 ) {
63
+ setProcessHealth ( 'healthy' ) ;
64
+ }
65
+ } , 1000 ) ;
66
+
67
+ return ( ) => clearInterval ( interval ) ;
68
+ } , [ chain . id , chain . status , blockCount ] ) ;
69
+
28
70
const checkDependencies = ( ) => {
29
71
if ( ! chain . dependencies || chain . dependencies . length === 0 ) return true ;
30
72
return chain . dependencies . every ( dep => runningNodes . includes ( dep ) ) ;
@@ -135,6 +177,7 @@ const Card = ({
135
177
console . log ( `Stopping chain ${ chain . id } ` ) ;
136
178
// Update UI immediately to show stopping state
137
179
onUpdateChain ( chain . id , { status : 'stopping' } ) ;
180
+ setProcessHealth ( 'offline' ) ;
138
181
await onStop ( chain . id ) ;
139
182
} catch ( error ) {
140
183
console . error ( 'Stop failed:' , error ) ;
0 commit comments