From d72d226a5b4946ee15c3ba2358e40ea376ac6667 Mon Sep 17 00:00:00 2001 From: saneery Date: Tue, 23 Apr 2019 14:13:57 +0300 Subject: [PATCH] add block count updater --- apps/block_scout_web/assets/js/pages/chain.js | 18 +++++++++++++++--- 1 file changed, 15 insertions(+), 3 deletions(-) diff --git a/apps/block_scout_web/assets/js/pages/chain.js b/apps/block_scout_web/assets/js/pages/chain.js index 910d228cf6..d18160d097 100644 --- a/apps/block_scout_web/assets/js/pages/chain.js +++ b/apps/block_scout_web/assets/js/pages/chain.js @@ -24,7 +24,8 @@ export const initialState = { transactionsError: false, transactionsLoading: true, transactionCount: null, - usdMarketCap: null + usdMarketCap: null, + blockCount: null } export const reducer = withMissingBlocks(baseReducer) @@ -46,11 +47,13 @@ function baseReducer (state = initialState, action) { blocks: [ action.msg, ...state.blocks.slice(0, -1) - ] + ], + blockCount: action.msg.blockNumber + 1 }) } else { return Object.assign({}, state, { - blocks: state.blocks.map((block) => block.blockNumber === action.msg.blockNumber ? action.msg : block) + blocks: state.blocks.map((block) => block.blockNumber === action.msg.blockNumber ? action.msg : block), + blockCount: action.msg.blockNumber + 1 }) } } @@ -152,6 +155,15 @@ const elements = { $el.empty().append(numeral(state.transactionCount).format()) } }, + '[data-selector="block-count"]': { + load ($el) { + return { blockCount: numeral($el.text()).value() } + }, + render ($el, state, oldState) { + if (oldState.blockCount === state.blockCount) return + $el.empty().append(numeral(state.blockCount).format()) + } + }, '[data-selector="address-count"]': { render ($el, state, oldState) { if (oldState.addressCount === state.addressCount) return