@@ -369,24 +369,25 @@ export const fetchBlockDetails = async (hashOrHeight: string): Promise<BlockInfo
369369 }
370370
371371 const data = response . data ;
372+ console . log ( 'Block data received:' , data ) ; // Debug log
372373
373374 // Process the block data according to blockchain.info API format
374375 const processedData : BlockInfo = {
375- hash : data . hash ,
376+ hash : data . hash || '' ,
376377 height : data . height || 0 ,
377378 time : data . time || Math . floor ( Date . now ( ) / 1000 ) ,
378379 size : data . size || 0 ,
379380 txCount : data . n_tx || 0 ,
380- prevBlockHash : data . prev_block ,
381- nextBlockHash : data . next_block ,
382- merkleRoot : data . mrkl_root ,
383- version : data . ver ,
384- bits : data . bits ,
385- nonce : data . nonce ,
386- weight : data . weight ,
387- difficulty : data . difficulty ,
388- transactions : data . tx || [ ] ,
389- reward : data . reward || 0
381+ prevBlockHash : data . prev_block || '' ,
382+ nextBlockHash : data . next_block || '' ,
383+ merkleRoot : data . mrkl_root || '' ,
384+ version : data . ver || 0 ,
385+ bits : data . bits || 0 ,
386+ nonce : data . nonce || 0 ,
387+ weight : data . weight || 0 ,
388+ difficulty : data . difficulty || 0 ,
389+ transactions : Array . isArray ( data . tx ) ? data . tx : [ ] ,
390+ reward : calculateBlockReward ( data . height || 0 )
390391 } ;
391392
392393 return processedData ;
@@ -400,6 +401,15 @@ export const fetchBlockDetails = async (hashOrHeight: string): Promise<BlockInfo
400401 }
401402} ;
402403
404+ // Helper function to calculate block reward based on height
405+ const calculateBlockReward = ( height : number ) : number => {
406+ const INITIAL_REWARD = 50 ;
407+ const HALVING_INTERVAL = 210000 ;
408+ const halvings = Math . floor ( height / HALVING_INTERVAL ) ;
409+ if ( halvings >= 64 ) return 0 ; // After 64 halvings, reward becomes 0
410+ return INITIAL_REWARD / Math . pow ( 2 , halvings ) ;
411+ } ;
412+
403413export const fetchNetworkStats = blockApi . fetchNetworkStats ;
404414export const fetchMempoolInfo = blockApi . fetchMempoolInfo ;
405415export const generateNetworkChartData = blockApi . generateNetworkChartData ;
0 commit comments