Improve autorefreshing of Validators tab

staking
Vadim 5 years ago committed by Victor Baranov
parent 5c0c835120
commit 8e72c36031
  1. 26
      apps/block_scout_web/assets/js/pages/stakes.js
  2. 6
      apps/block_scout_web/lib/block_scout_web/channels/stakes_channel.ex
  3. 13
      apps/block_scout_web/lib/block_scout_web/notifier.ex

@ -17,18 +17,19 @@ import { openClaimWithdrawalModal } from './stakes/claim_withdrawal'
import { openWarningModal } from '../lib/modals'
export const initialState = {
channel: null,
web3: null,
account: null,
blockRewardContract: null,
channel: null,
lastBlockNumber: 0,
lastEpochNumber: 0,
network: null,
refreshInterval: null,
stakingAllowed: false,
stakingContract: null,
blockRewardContract: null,
tokenDecimals: 0,
tokenSymbol: '',
refreshInterval: null,
lastEpochNumber: 0,
lastBlockNumber: 0,
stakingAllowed: false
validatorSetApplyBlock: 0,
web3: null
}
// 100 - id of xDai network, 101 - id of xDai test network
@ -72,9 +73,10 @@ export function reducer (state = initialState, action) {
}
case 'RECEIVED_UPDATE': {
return Object.assign({}, state, {
lastEpochNumber: action.lastEpochNumber,
lastBlockNumber: action.lastBlockNumber,
stakingAllowed: action.stakingAllowed
lastEpochNumber: action.lastEpochNumber,
stakingAllowed: action.stakingAllowed,
validatorSetApplyBlock: action.validatorSetApplyBlock
})
}
case 'RECEIVED_CONTRACTS': {
@ -130,13 +132,15 @@ if ($stakesPage.length) {
if (
msg.staking_allowed !== state.stakingAllowed ||
msg.epoch_number > state.lastEpochNumber ||
msg.validator_set_apply_block != state.validatorSetApplyBlock ||
(state.refreshInterval && msg.block_number >= state.lastBlockNumber + state.refreshInterval)
) {
store.dispatch({
type: 'RECEIVED_UPDATE',
lastEpochNumber: msg.epoch_number,
lastBlockNumber: msg.block_number,
stakingAllowed: msg.staking_allowed
lastEpochNumber: msg.epoch_number,
stakingAllowed: msg.staking_allowed,
validatorSetApplyBlock: msg.validator_set_apply_block
})
refreshPage(store)
}

@ -27,8 +27,9 @@ defmodule BlockScoutWeb.StakesChannel do
"staking_update",
%{
block_number: BlockNumber.get_max(),
epoch_number: ContractState.get(:epoch_number, 0),
staking_allowed: ContractState.get(:staking_allowed, false),
epoch_number: ContractState.get(:epoch_number, 0)
validator_set_apply_block: ContractState.get(:validator_set_apply_block, 0)
},
socket
)
@ -251,9 +252,10 @@ defmodule BlockScoutWeb.StakesChannel do
def handle_out("staking_update", data, socket) do
push(socket, "staking_update", %{
epoch_number: data.epoch_number,
block_number: data.block_number,
epoch_number: data.epoch_number,
staking_allowed: data.staking_allowed,
validator_set_apply_block: data.validator_set_apply_block,
top_html: StakesController.render_top(socket)
})

@ -108,16 +108,11 @@ defmodule BlockScoutWeb.Notifier do
end
def handle_event({:chain_event, :staking_update}) do
epoch_number = ContractState.get(:epoch_number, 0)
epoch_end_block = ContractState.get(:epoch_end_block, 0)
staking_allowed = ContractState.get(:staking_allowed, false)
block_number = BlockNumber.get_max()
Endpoint.broadcast("stakes:staking_update", "staking_update", %{
epoch_number: epoch_number,
epoch_end_block: epoch_end_block,
staking_allowed: staking_allowed,
block_number: block_number
block_number: BlockNumber.get_max(),
epoch_number: ContractState.get(:epoch_number, 0),
staking_allowed: ContractState.get(:staking_allowed, false),
validator_set_apply_block: ContractState.get(:validator_set_apply_block, 0)
})
end

Loading…
Cancel
Save