@@ -11,7 +11,7 @@ import { myStakePctAtom, myStakeAmountAtom } from "../../atoms";
1111import type { PropsWithChildren } from "react" ;
1212import { useEffect } from "react" ;
1313import { DateTime } from "luxon" ;
14- import { getFmtStake , getDurationText , slowDateTimeNow } from "../../utils" ;
14+ import { slowDateTimeNow , getSolString , getDurationValues } from "../../utils" ;
1515import { formatNumber } from "../../numUtils" ;
1616import { useInterval , useMedia , useUpdate } from "react-use" ;
1717import clsx from "clsx" ;
@@ -48,11 +48,10 @@ export default function IdentityKey() {
4848 { isXXNarrowScreen && (
4949 < Label
5050 label = "Validator Name"
51- value = {
52- truncateKey ? `${ identityKey ?. substring ( 0 , 8 ) } ...` : identityKey
53- }
5451 tooltip = "The validators identity public key"
55- />
52+ >
53+ { truncateKey ? `${ identityKey ?. substring ( 0 , 8 ) } ...` : identityKey }
54+ </ Label >
5655 ) }
5756 { isXNarrowScreen && (
5857 < >
@@ -104,9 +103,10 @@ function DropdownMenu() {
104103 < PeerIcon url = { peer ?. info ?. icon_url } size = { 24 } isYou />
105104 < Label
106105 label = "Validator Name"
107- value = { identityKey }
108106 tooltip = "The validators identity public key"
109- />
107+ >
108+ { identityKey }
109+ </ Label >
110110 </ Flex >
111111 < StakeValue />
112112 < StakePct />
@@ -125,68 +125,75 @@ function VotePubkey() {
125125 return (
126126 < Label
127127 label = "Vote Pubkey"
128- value = { peer ?. vote [ 0 ] ?. vote_account }
129128 tooltip = "The public key of vote account, encoded in base58"
130- />
129+ >
130+ { peer ?. vote [ 0 ] ?. vote_account }
131+ </ Label >
131132 ) ;
132133}
133134
134135function VoteBalance ( ) {
135136 const voteBalance = useAtomValue ( voteBalanceAtom ) ;
137+ const solString = getSolString ( voteBalance ) ;
136138
137139 return (
138140 < >
139141 < Label
140142 label = "Vote Balance"
141- value = { getFmtStake ( voteBalance ) ?? "-" }
142143 tooltip = "Account balance of this validators vote account. The balance is on the highest slot of the currently active fork of the validator."
143- />
144+ >
145+ < ValueWithSuffix value = { solString } suffix = "SOL" />
146+ </ Label >
144147 </ >
145148 ) ;
146149}
147150
148151function IdentityBalance ( ) {
149152 const identityBalance = useAtomValue ( identityBalanceAtom ) ;
153+ const solString = getSolString ( identityBalance ) ;
150154
151155 return (
152156 < Label
153157 label = "Identity Balance"
154- value = { getFmtStake ( identityBalance ) ?? "-" }
155158 tooltip = "Account balance of this validators identity account. The balance is on the highest slot of the currently active fork of the validator."
156- />
159+ >
160+ < ValueWithSuffix value = { solString } suffix = "SOL" />
161+ </ Label >
157162 ) ;
158163}
159164
160165function StakePct ( ) {
161166 const stakePct = useAtomValue ( myStakePctAtom ) ;
162- let value = "-" ;
163167
164- if ( stakePct !== undefined ) {
165- value = formatNumber ( stakePct , {
166- significantDigits : 4 ,
167- trailingZeroes : false ,
168- } ) ;
169- value += "%" ;
170- }
168+ const value =
169+ stakePct === undefined
170+ ? undefined
171+ : formatNumber ( stakePct , {
172+ significantDigits : 4 ,
173+ trailingZeroes : false ,
174+ } ) ;
171175
172176 return (
173177 < Label
174178 label = "Stake %"
175- value = { value }
176179 tooltip = "What percentage of total stake is delegated to this validator"
177- />
180+ >
181+ < ValueWithSuffix value = { value } suffix = "%" />
182+ </ Label >
178183 ) ;
179184}
180185
181186function StakeValue ( ) {
182187 const stake = useAtomValue ( myStakeAmountAtom ) ;
188+ const solString = getSolString ( stake ) ;
183189
184190 return (
185191 < Label
186192 label = "Stake Amount"
187- value = { getFmtStake ( stake ) ?? "-" }
188193 tooltip = "Amount of total stake that is delegated to this validator"
189- />
194+ >
195+ < ValueWithSuffix value = { solString } suffix = "SOL" />
196+ </ Label >
190197 ) ;
191198}
192199
@@ -207,58 +214,82 @@ function Commission() {
207214 ) ;
208215
209216 return (
210- < Label
211- label = "Commission"
212- value = {
213- maxCommission ?. commission !== undefined
214- ? maxCommission . commission . toLocaleString ( ) + "%"
215- : "-"
216- }
217- />
217+ < Label label = "Commission" >
218+ < ValueWithSuffix
219+ value = { maxCommission ?. commission ?. toLocaleString ( ) }
220+ suffix = "%"
221+ />
222+ </ Label >
218223 ) ;
219224}
220225
221226function StartupTime ( ) {
222227 const startupTime = useAtomValue ( startupTimeAtom ) ;
223228
224- const getValue = ( ) => {
225- if ( ! startupTime ) return "-" ;
229+ const getValues = ( ) => {
230+ if ( ! startupTime ) return ;
226231 const uptimeDuration = slowDateTimeNow . diff (
227232 DateTime . fromMillis (
228233 Math . floor ( Number ( startupTime . startupTimeNanos ) / 1_000_000 ) ,
229234 ) ,
230235 ) ;
231236
232- const text = getDurationText ( uptimeDuration . rescale ( ) , {
237+ return getDurationValues ( uptimeDuration . rescale ( ) , {
233238 omitSeconds : true ,
234239 } ) ;
235- return text ;
236240 } ;
237241
242+ const values = getValues ( ) ;
243+
238244 const update = useUpdate ( ) ;
239245 useInterval ( update , 60_000 ) ;
240246
241- return < Label label = "Uptime" value = { getValue ( ) } /> ;
247+ return (
248+ < Label label = "Uptime" >
249+ { values ?. map ( ( [ value , suffix ] , i ) => (
250+ < >
251+ { i !== 0 && "\xa0" }
252+ < ValueWithSuffix key = { i } value = { value } suffix = { suffix } excludeSpace />
253+ </ >
254+ ) ) }
255+ </ Label >
256+ ) ;
242257}
243258
244259interface LabelProps {
245260 label : string ;
246- value ?: string | null ;
247- color ?: string ;
248261 tooltip ?: string ;
249262}
250- function Label ( { label, value, color, tooltip } : LabelProps ) {
251- if ( ! value ) return null ;
252- const textValue = (
253- < Text className = { styles . value } style = { { color : color } } >
254- { value }
255- </ Text >
256- ) ;
263+ function Label ( { label, tooltip, children } : PropsWithChildren < LabelProps > ) {
264+ if ( ! children ) return null ;
265+ const content = < div className = { styles . value } > { children } </ div > ;
257266
258267 return (
259268 < Flex direction = "column" >
260269 < Text className = { styles . label } > { label } </ Text >
261- { tooltip ? < Tooltip content = { tooltip } > { textValue } </ Tooltip > : textValue }
270+ { tooltip ? < Tooltip content = { tooltip } > { content } </ Tooltip > : content }
262271 </ Flex >
263272 ) ;
264273}
274+
275+ function ValueWithSuffix ( {
276+ value,
277+ suffix,
278+ valueColor,
279+ excludeSpace,
280+ } : {
281+ value ?: string | number ;
282+ suffix : string ;
283+ valueColor ?: string ;
284+ excludeSpace ?: boolean ;
285+ } ) {
286+ return (
287+ < >
288+ < span style = { { color : valueColor } } >
289+ { value }
290+ { ! excludeSpace && "\xa0" }
291+ </ span >
292+ < span className = { styles . valueSuffix } > { suffix } </ span >
293+ </ >
294+ ) ;
295+ }
0 commit comments