@@ -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,15 @@ 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 && (
84
+ < Link to = "https://github.com/gobitfly/eth.store/" > ETH.STORE, </ Link >
85
+ ) }
81
86
< Link to = "https://beaconcha.in" > Beaconcha.in</ Link >
82
87
</ div >
83
88
}
@@ -106,6 +111,7 @@ const StakingStatsBox: React.FC<IProps> = () => {
106
111
intl . locale as Lang
107
112
)
108
113
114
+ // Helper functions
109
115
const formatInteger = ( amount : number ) : string =>
110
116
new Intl . NumberFormat ( localeForStatsBoxNumbers ) . format ( amount )
111
117
@@ -116,35 +122,27 @@ const StakingStatsBox: React.FC<IProps> = () => {
116
122
maximumSignificantDigits : 2 ,
117
123
} ) . format ( amount )
118
124
125
+ // API call, data formatting, and state setting
119
126
; ( async ( ) => {
120
127
try {
121
128
const {
122
- data : { totalvalidatorbalance , validatorscount } ,
129
+ data : { apr , effective_balances_sum_wei } ,
123
130
} = 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 ) )
131
+ data : { apr : number ; effective_balances_sum_wei : number }
132
+ } > ( "https://beaconcha.in/api/v1/ethstore/latest" )
133
+ const totalEffectiveBalance : number = effective_balances_sum_wei * 1e-18
134
+ const valueTotalEth = formatInteger ( Math . floor ( totalEffectiveBalance ) )
135
+ const valueTotalValidators = formatInteger (
136
+ totalEffectiveBalance / MAX_EFFECTIVE_BALANCE
128
137
)
129
- const valueTotalValidators = formatInteger ( validatorscount )
138
+ const valueCurrentApr = formatPercentage ( apr )
130
139
setTotalEth ( valueTotalEth )
131
140
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/650" )
144
- const valueCurrentApr = formatPercentage ( apr )
145
141
setCurrentApr ( valueCurrentApr )
146
142
} catch ( error ) {
143
+ setTotalEth ( null )
147
144
setCurrentApr ( null )
145
+ setTotalValidators ( null )
148
146
}
149
147
} ) ( )
150
148
} , [ intl . locale ] )
@@ -185,7 +183,7 @@ const StakingStatsBox: React.FC<IProps> = () => {
185
183
) }
186
184
< Label >
187
185
< Translation id = "page-staking-stats-box-metric-3" />
188
- < BeaconchainTooltip />
186
+ < BeaconchainTooltip isEthStore />
189
187
</ Label >
190
188
</ Cell >
191
189
</ Container >
0 commit comments