@@ -7,6 +7,129 @@ import { ethBalanceGreaterThanMinStake, shortenAddress, toEtherString } from "..
77import ImportToSignerDialog from "./ImportToSignerDialog" ;
88import "./minipool.css" ;
99
10+ enum MinipoolStatus {
11+ STAKING = "Staking" ,
12+ DISSOLVED = "Dissolved" ,
13+ PRELAUNCH = "Prelaunch" ,
14+ FINALISED = "Finalised"
15+ }
16+
17+ enum ValidatorStatus {
18+ EXITED = "Exited" ,
19+ ENQUEUED = "Enqueued" ,
20+ ACTIVE = "Active" ,
21+ READY_TO_CLOSE = "Ready to Close" ,
22+ INACTIVE = "Inactive"
23+ }
24+
25+ // Color theme constants
26+ const COLOR_THEME = {
27+ SUCCESS : "#81C784" , // Green
28+ WARNING : "#FFC107" , // Amber
29+ ERROR : "#E57373" , // Red
30+ INFO : "#FFB74D" // Orange
31+ } as const ;
32+
33+ // Status information interface
34+ interface StatusInfo {
35+ status : string ;
36+ color : string ;
37+ }
38+
39+ // Validator Status Service
40+ class ValidatorStatusService {
41+ /**
42+ * Determines the minipool status and returns status info
43+ */
44+ getMinipoolStatusInfo ( minipoolData : Minipool ) : StatusInfo {
45+ const status = this . determineMinipoolStatus ( minipoolData ) ;
46+ const color = this . getMinipoolStatusColor ( status ) ;
47+ return { status, color } ;
48+ }
49+
50+ /**
51+ * Determines the validator status and returns status info
52+ */
53+ getValidatorStatusInfo ( minipoolData : Minipool ) : StatusInfo {
54+ const status = this . determineValidatorStatus ( minipoolData ) ;
55+ const color = this . getValidatorStatusColor ( status , minipoolData ) ;
56+ return { status, color } ;
57+ }
58+
59+ /**
60+ * Determines the minipool status based on finalised state
61+ */
62+ private determineMinipoolStatus ( minipoolData : Minipool ) : string {
63+ return minipoolData . finalised ? MinipoolStatus . FINALISED : minipoolData . status . status ;
64+ }
65+
66+ /**
67+ * Determines the validator status with priority-based logic
68+ */
69+ private determineValidatorStatus ( minipoolData : Minipool ) : string {
70+ // Priority 1: Check if finalised
71+ if ( minipoolData . finalised ) {
72+ return ValidatorStatus . EXITED ;
73+ }
74+
75+ // Priority 2: Check if enqueued (staking but no validator index)
76+ if ( minipoolData . status . status === MinipoolStatus . STAKING && ! minipoolData . validator . index ) {
77+ return ValidatorStatus . ENQUEUED ;
78+ }
79+
80+ // Priority 3: Check if validator is active
81+ if ( minipoolData . validator . active ) {
82+ return ValidatorStatus . ACTIVE ;
83+ }
84+
85+ // Priority 4: Check if ready to close (staking with sufficient balance)
86+ if ( minipoolData . status . status === MinipoolStatus . STAKING &&
87+ ethBalanceGreaterThanMinStake ( minipoolData . balances . eth ) ) {
88+ return ValidatorStatus . READY_TO_CLOSE ;
89+ }
90+
91+ // Default: Inactive
92+ return ValidatorStatus . INACTIVE ;
93+ }
94+
95+ /**
96+ * Gets the color for minipool status
97+ */
98+ private getMinipoolStatusColor ( status : string ) : string {
99+ switch ( status ) {
100+ case MinipoolStatus . STAKING :
101+ return COLOR_THEME . SUCCESS ;
102+ case MinipoolStatus . DISSOLVED :
103+ return COLOR_THEME . ERROR ;
104+ case MinipoolStatus . FINALISED :
105+ return COLOR_THEME . WARNING ;
106+ default :
107+ return COLOR_THEME . INFO ;
108+ }
109+ }
110+
111+ /**
112+ * Gets the color for validator status
113+ */
114+ private getValidatorStatusColor ( validatorStatus : string , minipoolData : Minipool ) : string {
115+ // Success color for finalised or active validators
116+ if ( minipoolData . finalised || minipoolData . validator . active ) {
117+ return COLOR_THEME . SUCCESS ;
118+ }
119+
120+ // Warning color for prelaunch, enqueued, or ready to close
121+ if ( minipoolData . status . status === MinipoolStatus . PRELAUNCH ||
122+ [ ValidatorStatus . ENQUEUED , ValidatorStatus . READY_TO_CLOSE ] . includes ( validatorStatus as ValidatorStatus ) ) {
123+ return COLOR_THEME . WARNING ;
124+ }
125+
126+ // Error color for inactive
127+ return COLOR_THEME . ERROR ;
128+ }
129+ } ;
130+
131+ // Initialize status service
132+ const statusService = new ValidatorStatusService ( ) ;
10133
11134function MinipoolCard ( {
12135 data,
@@ -20,31 +143,10 @@ function MinipoolCard({
20143 const [ importToSignerDialogOpen , setImportToSignerDialogOpen ] =
21144 React . useState < boolean > ( false ) ;
22145 const [ showAddress , setShowAddress ] = React . useState < boolean > ( false ) ;
23-
24- const backgroundColor =
25- data . status . status === "Staking"
26- ? "#81C784"
27- : data . status . status === "Dissolved"
28- ? "#E57373"
29- : "#FFB74D" ;
30-
31- const validatorStatus = data . finalised
32- ? "Exited"
33- : ( ! data . validator . index && data . status . status === "Staking" )
34- ? "Enqueued"
35- : ( data . validator . active
36- ? "Active"
37- : ( data . status . status === "Staking" && ethBalanceGreaterThanMinStake ( data . balances . eth )
38- ? "Ready to Close"
39- : "Inactive"
40- )
41- ) ;
42- const validatorStatusColor =
43- data . finalised || data . validator . active
44- ? "#81C784"
45- : ( data . status . status === "Prelaunch" || [ "Enqueued" , "Ready to Close" ] . includes ( validatorStatus ) )
46- ? "#FFC107"
47- : "#E57373" ;
146+
147+ // Get status information using the service
148+ const minipoolStatusInfo = statusService . getMinipoolStatusInfo ( data ) ;
149+ const validatorStatusInfo = statusService . getValidatorStatusInfo ( data ) ;
48150
49151 return (
50152 < Card
@@ -71,14 +173,14 @@ function MinipoolCard({
71173 />
72174 </ div >
73175 < Chip
74- label = { data . finalised ? "Finalised" : data . status . status }
75- sx = { { backgroundColor : data . finalised ? "#FFC107" : backgroundColor } }
176+ label = { minipoolStatusInfo . status }
177+ sx = { { backgroundColor : minipoolStatusInfo . color } }
76178 />
77179 </ div >
78180 < div className = "validator-status" >
79181 < Chip
80- label = { validatorStatus }
81- sx = { { backgroundColor : validatorStatusColor } }
182+ label = { validatorStatusInfo . status }
183+ sx = { { backgroundColor : validatorStatusInfo . color } }
82184 />
83185 </ div >
84186
0 commit comments