add block count updater

pull/1813/head
saneery 6 years ago
parent 0c61d26c6a
commit d72d226a5b
  1. 18
      apps/block_scout_web/assets/js/pages/chain.js

@ -24,7 +24,8 @@ export const initialState = {
transactionsError: false, transactionsError: false,
transactionsLoading: true, transactionsLoading: true,
transactionCount: null, transactionCount: null,
usdMarketCap: null usdMarketCap: null,
blockCount: null
} }
export const reducer = withMissingBlocks(baseReducer) export const reducer = withMissingBlocks(baseReducer)
@ -46,11 +47,13 @@ function baseReducer (state = initialState, action) {
blocks: [ blocks: [
action.msg, action.msg,
...state.blocks.slice(0, -1) ...state.blocks.slice(0, -1)
] ],
blockCount: action.msg.blockNumber + 1
}) })
} else { } else {
return Object.assign({}, state, { 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()) $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"]': { '[data-selector="address-count"]': {
render ($el, state, oldState) { render ($el, state, oldState) {
if (oldState.addressCount === state.addressCount) return if (oldState.addressCount === state.addressCount) return

Loading…
Cancel
Save