@@ -16,6 +16,7 @@ import { getLocaleForNumberFormat } from "../../utils/translations"
16
16
// Constants
17
17
const NA_ERROR = "n/a"
18
18
const ZERO = "0"
19
+ const MAX_EFFECTIVE_BALANCE = 32
19
20
20
21
// Styled components
21
22
const Container = styled . div `
@@ -73,11 +74,13 @@ const StyledIcon = styled(Icon)`
73
74
}
74
75
`
75
76
76
- const BeaconchainTooltip = ( ) => (
77
+ // BeaconchainTooltip component
78
+ const BeaconchainTooltip = ( { isEthStore } : { isEthStore ?: boolean } ) => (
77
79
< Tooltip
78
80
content = {
79
81
< div >
80
82
< Translation id = "data-provided-by" /> { " " }
83
+ { isEthStore && < span > ETH.STORE </ span > }
81
84
< Link to = "https://beaconcha.in" > Beaconcha.in</ Link >
82
85
</ div >
83
86
}
@@ -106,6 +109,7 @@ const StakingStatsBox: React.FC<IProps> = () => {
106
109
intl . locale as Lang
107
110
)
108
111
112
+ // Helper functions
109
113
const formatInteger = ( amount : number ) : string =>
110
114
new Intl . NumberFormat ( localeForStatsBoxNumbers ) . format ( amount )
111
115
@@ -116,35 +120,27 @@ const StakingStatsBox: React.FC<IProps> = () => {
116
120
maximumSignificantDigits : 2 ,
117
121
} ) . format ( amount )
118
122
123
+ // API call, data formatting, and state setting
119
124
; ( async ( ) => {
120
125
try {
121
126
const {
122
- data : { totalvalidatorbalance , validatorscount } ,
127
+ data : { apr , effective_balances_sum_wei } ,
123
128
} = await getData < {
124
- data : { totalvalidatorbalance : number ; validatorscount : number }
125
- } > ( "https://mainnet.beaconcha.in/api/v1/epoch/latest" )
126
- const valueTotalEth = formatInteger (
127
- Number ( ( totalvalidatorbalance * 1e-9 ) . toFixed ( 0 ) )
129
+ data : { apr : number ; effective_balances_sum_wei : number }
130
+ } > ( "https://beaconcha.in/api/v1/ethstore/latest" )
131
+ const totalEffectiveBalance : number = effective_balances_sum_wei * 1e-18
132
+ const valueTotalEth = formatInteger ( Math . floor ( totalEffectiveBalance ) )
133
+ const valueTotalValidators = formatInteger (
134
+ totalEffectiveBalance / MAX_EFFECTIVE_BALANCE
128
135
)
129
- const valueTotalValidators = formatInteger ( validatorscount )
136
+ const valueCurrentApr = formatPercentage ( apr )
130
137
setTotalEth ( valueTotalEth )
131
138
setTotalValidators ( valueTotalValidators )
132
- } catch ( error ) {
133
- setTotalEth ( null )
134
- setTotalValidators ( null )
135
- }
136
- } ) ( )
137
- ; ( async ( ) => {
138
- try {
139
- const {
140
- data : { apr } ,
141
- } = await getData < {
142
- data : { apr : number }
143
- } > ( "https://beaconcha.in/api/v1/ethstore/latest" )
144
- const valueCurrentApr = formatPercentage ( apr )
145
139
setCurrentApr ( valueCurrentApr )
146
140
} catch ( error ) {
141
+ setTotalEth ( null )
147
142
setCurrentApr ( null )
143
+ setTotalValidators ( null )
148
144
}
149
145
} ) ( )
150
146
} , [ intl . locale ] )
@@ -185,7 +181,7 @@ const StakingStatsBox: React.FC<IProps> = () => {
185
181
) }
186
182
< Label >
187
183
< Translation id = "page-staking-stats-box-metric-3" />
188
- < BeaconchainTooltip />
184
+ < BeaconchainTooltip isEthStore />
189
185
</ Label >
190
186
</ Cell >
191
187
</ Container >
0 commit comments