Add is_snapshotted check before showing snapshotted data

staking
Eduard Sachava 5 years ago committed by Victor Baranov
parent 43d7c53c7a
commit 90710500a9
  1. 6
      apps/block_scout_web/lib/block_scout_web/channels/stakes_channel.ex
  2. 10
      apps/block_scout_web/lib/block_scout_web/templates/stakes/_stakes_modal_delegators_list.html.eex
  3. 20
      apps/explorer/lib/explorer/staking/contract_state.ex
  4. 11
      apps/explorer/lib/explorer/staking/stake_snapshotting.ex

@ -54,7 +54,9 @@ defmodule BlockScoutWeb.StakesChannel do
def handle_in("render_delegators_list", %{"address" => staking_address}, socket) do
pool = Chain.staking_pool(staking_address)
token = ContractState.get(:token)
validator_set_apply_block = ContractState.get(:validator_set_apply_block)
is_show_snapshotted_data =
pool.is_validator && ContractState.get(:validator_set_apply_block) > 0 && ContractState.get(:is_snapshotted)
delegators =
staking_address
@ -75,7 +77,7 @@ defmodule BlockScoutWeb.StakesChannel do
pool: pool,
delegators: delegators,
token: token,
validator_set_apply_block: validator_set_apply_block
is_show_snapshotted_data: is_show_snapshotted_data
)
{:reply, {:ok, %{html: html}}, socket}

@ -15,7 +15,7 @@
<div class="col-4">
<%=
amount_col_title =
if @validator_set_apply_block > 0 do
if @is_show_snapshotted_data do
gettext("Current Stake Amount") <> "<br />(" <> gettext("Accounted Stake Amount") <> ")"
else
gettext("Current Stake Amount")
@ -27,7 +27,7 @@
<div class="col-3">
<%=
reward_col_title =
if @pool.is_validator && @validator_set_apply_block > 0 do
if @is_show_snapshotted_data do
gettext("Potential Reward Percent") <> "<br />(" <> gettext("Current Reward Percent") <> ")"
else
gettext("Potential Reward Percent")
@ -69,11 +69,11 @@
</div>
<div class="col-4 stakes-td stakes-cell">
<%= format_token_amount(delegator.stake_amount, @token, symbol: false) %>
<%= if @pool.is_validator && @validator_set_apply_block > 0 do %>
<%= if @is_show_snapshotted_data do %>
(
<%=
if delegator.snapshotted_stake_amount do
format_token_amount(delegator.snapshotted_stake_amount, @token, symbol: false)
format_token_amount(delegator.snapshotted_stake_amount, @token, symbol: false)
else
0
end
@ -84,7 +84,7 @@
<div class="col-3 stakes-td stakes-cell">
<%= if delegator.reward_ratio do %>
<%= delegator.reward_ratio %>%
<%= if @pool.is_validator && @validator_set_apply_block > 0 do %>
<%= if @is_show_snapshotted_data do %>
(
<%=
if delegator.snapshotted_reward_ratio do

@ -25,7 +25,8 @@ defmodule Explorer.Staking.ContractState do
:staking_contract,
:validator_set_contract,
:block_reward_contract,
:validator_set_apply_block
:validator_set_apply_block,
:is_snapshotted
]
defstruct [
@ -92,7 +93,8 @@ defmodule Explorer.Staking.ContractState do
validator_set_contract: %{abi: validator_set_abi, address: validator_set_contract_address},
block_reward_contract: %{abi: block_reward_abi, address: block_reward_contract_address},
token_contract_address: token_contract_address,
token: get_token(token_contract_address)
token: get_token(token_contract_address),
is_snapshotted: false
)
{:ok, state, {:continue, []}}
@ -261,10 +263,16 @@ defmodule Explorer.Staking.ContractState do
})
if previous_epoch && previous_epoch != 0 && previous_epoch != global_responses.epoch_number do
StakeSnapshotting.start_snapshoting(
%{contracts: contracts, abi: abi, global_responses: global_responses},
block_number
)
with(
true <- :ets.insert(@table_name, is_snapshotted: false),
{:ok, _} <-
StakeSnapshotting.start_snapshoting(
%{contracts: contracts, abi: abi, global_responses: global_responses},
block_number
)
) do
:ets.insert(@table_name, is_snapshotted: true)
end
end
Publisher.broadcast(:staking_update)

@ -127,12 +127,11 @@ defmodule Explorer.Staking.StakeSnapshotting do
})
end)
{:ok, _} =
Chain.import(%{
staking_pools: %{params: pool_entries, on_conflict: staking_pool_on_conflict()},
staking_pools_delegators: %{params: delegator_entries, on_conflict: staking_pools_delegator_on_conflict()},
timeout: :infinity
})
Chain.import(%{
staking_pools: %{params: pool_entries, on_conflict: staking_pool_on_conflict()},
staking_pools_delegators: %{params: delegator_entries, on_conflict: staking_pools_delegator_on_conflict()},
timeout: :infinity
})
end
def transform_requests(minig_address) do

Loading…
Cancel
Save