@@ -7,6 +7,7 @@ import appState from 'states/initStates/app'
77import { AppActions , StateWithDispatch } from 'states/stateProvider/reducer'
88import { updateNervosDaoData , clearNervosDaoData } from 'states/stateProvider/actionCreators'
99
10+ import calculateGlobalAPY from 'utils/calculateGlobalAPY'
1011import calculateFee from 'utils/calculateFee'
1112import { shannonToCKBFormatter , CKBToShannonFormatter } from 'utils/formatters'
1213import { MIN_DEPOSIT_AMOUNT , MEDIUM_FEE_RATE , CapacityUnit } from 'utils/const'
@@ -28,6 +29,7 @@ const NervosDAO = ({
2829 loadings : { sending = false } ,
2930 tipBlockNumber,
3031 tipBlockHash,
32+ tipBlockTimestamp,
3133 epoch,
3234 } ,
3335 wallet,
@@ -41,6 +43,7 @@ const NervosDAO = ({
4143 const [ activeRecord , setActiveRecord ] = useState < State . NervosDAORecord | null > ( null )
4244 const [ errorMessage , setErrorMessage ] = useState ( '' )
4345 const [ withdrawList , setWithdrawList ] = useState < ( string | null ) [ ] > ( [ ] )
46+ const [ globalAPY , setGlobalAPY ] = useState ( 0 )
4447
4548 const clearGeneratedTx = useCallback ( ( ) => {
4649 dispatch ( {
@@ -92,6 +95,14 @@ const NervosDAO = ({
9295 }
9396 } , [ clearGeneratedTx , dispatch , updateDepositValue , wallet . id ] )
9497
98+ useEffect ( ( ) => {
99+ if ( tipBlockTimestamp ) {
100+ calculateGlobalAPY ( tipBlockTimestamp ) . then ( apy => {
101+ setGlobalAPY ( apy )
102+ } )
103+ }
104+ } , [ tipBlockTimestamp ] )
105+
95106 const onDepositDialogDismiss = ( ) => {
96107 setShowDepositDialog ( false )
97108 setDepositValue ( `${ MIN_DEPOSIT_AMOUNT } ` )
@@ -278,9 +289,10 @@ const NervosDAO = ({
278289 < Text as = "span" variant = "small" block > { `Epoch number: ${ epochInfo . number } ` } </ Text >
279290 < Text as = "span" variant = "small" block > { `Epoch index: ${ epochInfo . index } ` } </ Text >
280291 < Text as = "span" variant = "small" block > { `Epoch length: ${ epochInfo . length } ` } </ Text >
292+ < Text as = "span" variant = "small" block > { `APY: ~${ globalAPY } %` } </ Text >
281293 </ Stack >
282294 )
283- } , [ epoch ] )
295+ } , [ epoch , globalAPY ] )
284296
285297 return (
286298 < >
0 commit comments