@@ -4,6 +4,7 @@ import ChainSettingsModal from './ChainSettingsModal';
4
4
import ForceStopModal from './ForceStopModal' ;
5
5
import SettingsIcon from './SettingsIcon' ;
6
6
import Tooltip from './Tooltip' ;
7
+ import './StatusLight.css' ;
7
8
8
9
const Card = ( {
9
10
chain,
@@ -23,8 +24,62 @@ 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
+ console . log ( "chain name: " , chain )
35
+ try {
36
+ const count = await window . electronAPI . getChainBlockCount ( chain . id ) ;
37
+ console . log ( "new count: " , count )
38
+ setBlockCount ( count ) ;
39
+ } catch ( error ) {
40
+ setBlockCount ( - 1 )
41
+ console . error ( 'Failed to fetch block count:' , error ) ;
42
+ }
43
+ } ;
44
+
45
+ const interval = setInterval ( ( ) => {
46
+ // Check on the health and status of chains
47
+ if ( chain . id === "bitwindow" ) {
48
+ // BitWindow does not return a block count, so just check if it is running
49
+ if ( chain . status === 'stopping' || chain . status === 'stopped' ) {
50
+ setProcessHealth ( 'offline' ) ;
51
+ }
52
+ else
53
+ if ( chain . status === 'running' ) {
54
+ setProcessHealth ( 'healthy' ) ;
55
+ }
56
+ else {
57
+ setProcessHealth ( 'warning' ) ;
58
+ }
59
+ } else {
60
+ // Other chains can tell us their current block height
61
+ fetchBlockCount ( ) ;
62
+ if ( chain . status === 'stopping' || chain . status === 'stopped' ) {
63
+ setProcessHealth ( 'offline' ) ;
64
+ }
65
+ else
66
+ if ( blockCount === - 1 ) {
67
+ setProcessHealth ( 'offline' ) ;
68
+ }
69
+ else
70
+ if ( blockCount === 0 ) {
71
+ setProcessHealth ( 'warning' ) ;
72
+ }
73
+ else
74
+ if ( blockCount > 0 ) {
75
+ setProcessHealth ( 'healthy' ) ;
76
+ }
77
+ }
78
+ } , 1000 ) ;
79
+
80
+ return ( ) => clearInterval ( interval ) ;
81
+ } , [ chain . id , chain . status , blockCount ] ) ;
82
+
28
83
const checkDependencies = ( ) => {
29
84
if ( ! chain . dependencies || chain . dependencies . length === 0 ) return true ;
30
85
return chain . dependencies . every ( dep => runningNodes . includes ( dep ) ) ;
@@ -132,6 +187,8 @@ const Card = ({
132
187
return ;
133
188
}
134
189
190
+ setProcessHealth ( 'offline' ) ;
191
+
135
192
console . log ( `Stopping chain ${ chain . id } ` ) ;
136
193
// Update UI immediately to show stopping state
137
194
onUpdateChain ( chain . id , { status : 'stopping' } ) ;
@@ -237,8 +294,17 @@ const Card = ({
237
294
< >
238
295
< div style = { { display : 'flex' , flexDirection : 'column' , flex : 1 , minWidth : '300px' } } >
239
296
< div className = { `card ${ isDarkMode ? 'dark' : 'light' } ` } >
240
- < div className = "card-header" >
241
- < h2 > { chain . display_name } </ h2 >
297
+ < div className = "card-header" style = { { position : 'relative' } } >
298
+ < div style = { { display : 'flex' , alignItems : 'center' , justifyContent : 'space-between' } } >
299
+ < h2 style = { { margin : 0 , lineHeight : 1.2 , textAlign : 'left' } } > { chain . display_name } </ h2 >
300
+ < div className = { `status-light ${ processHealth } ` } title = { `Process Status: ${ processHealth } ` } />
301
+ </ div >
302
+ < div style = { { fontSize : '0.9em' , color : isDarkMode ? 'rgba(255, 255, 255, 0.7)' : 'rgba(51, 51, 51, 0.7)' , marginTop : '4px' , fontWeight : 400 } } >
303
+ { chain . id === 'bitwindow' ?
304
+ ( processHealth === 'healthy' ? 'Running' : 'Not started' ) :
305
+ ( processHealth === 'healthy' && blockCount >= 0 ? `#Blocks: ${ blockCount } ` : 'Not started' ) }
306
+ </ div >
307
+
242
308
</ div >
243
309
< div className = "card-content" >
244
310
< p > { chain . description } </ p >
@@ -294,4 +360,4 @@ const Card = ({
294
360
) ;
295
361
} ;
296
362
297
- export default Card ;
363
+ export default Card ;
0 commit comments