@@ -15,7 +15,7 @@ import { MIN_DEPOSIT_AMOUNT, MEDIUM_FEE_RATE, SHANNON_CKB_RATIO, MAX_DECIMAL_DIG
1515import { verifyAmount } from 'utils/validators'
1616
1717import { generateDepositTx , generateWithdrawTx , generateClaimTx } from 'services/remote'
18- import { ckbCore } from 'services/chain'
18+ import { ckbCore , getBlockByNumber } from 'services/chain'
1919import { epochParser } from 'utils/parsers'
2020
2121import DAORecord from 'components/CustomRows/DAORecordRow'
@@ -46,6 +46,7 @@ const NervosDAO = ({
4646 const [ errorMessage , setErrorMessage ] = useState ( '' )
4747 const [ withdrawList , setWithdrawList ] = useState < ( string | null ) [ ] > ( [ ] )
4848 const [ globalAPC , setGlobalAPC ] = useState ( 0 )
49+ const [ genesisBlockTimestamp , setGenesisBlockTimestamp ] = useState < number | undefined > ( undefined )
4950
5051 const clearGeneratedTx = useCallback ( ( ) => {
5152 dispatch ( {
@@ -98,6 +99,9 @@ const NervosDAO = ({
9899 useEffect ( ( ) => {
99100 updateNervosDaoData ( { walletID : wallet . id } ) ( dispatch )
100101 updateDepositValue ( `${ MIN_DEPOSIT_AMOUNT } ` )
102+ getBlockByNumber ( '0x0' )
103+ . then ( b => setGenesisBlockTimestamp ( + b . header . timestamp ) )
104+ . catch ( err => console . error ( err ) )
101105 return ( ) => {
102106 clearNervosDaoData ( ) ( dispatch )
103107 clearGeneratedTx ( )
@@ -106,11 +110,13 @@ const NervosDAO = ({
106110
107111 useEffect ( ( ) => {
108112 if ( tipBlockTimestamp ) {
109- calculateGlobalAPC ( tipBlockTimestamp ) . then ( apc => {
110- setGlobalAPC ( apc )
111- } )
113+ calculateGlobalAPC ( tipBlockTimestamp , genesisBlockTimestamp )
114+ . then ( apc => {
115+ setGlobalAPC ( apc )
116+ } )
117+ . catch ( err => console . error ( err ) )
112118 }
113- } , [ tipBlockTimestamp ] )
119+ } , [ tipBlockTimestamp , genesisBlockTimestamp ] )
114120
115121 const onDepositDialogDismiss = ( ) => {
116122 setShowDepositDialog ( false )
@@ -276,14 +282,15 @@ const NervosDAO = ({
276282 onClick = { onActionClick }
277283 tipBlockNumber = { tipBlockNumber }
278284 epoch = { epoch }
285+ genesisBlockTimestamp = { genesisBlockTimestamp }
279286 connectionStatus = { connectionStatus }
280287 />
281288 )
282289 } ) }
283290 </ Stack >
284291 </ >
285292 )
286- } , [ records , withdrawList , t , onActionClick , tipBlockNumber , epoch , connectionStatus ] )
293+ } , [ records , withdrawList , t , onActionClick , tipBlockNumber , epoch , connectionStatus , genesisBlockTimestamp ] )
287294
288295 const free = BigInt ( wallet . balance )
289296 const locked = withdrawList . reduce ( ( acc , w ) => acc + BigInt ( w || 0 ) , BigInt ( 0 ) )
0 commit comments