diff --git a/apps/block_scout_web/lib/block_scout_web/channels/stakes_channel.ex b/apps/block_scout_web/lib/block_scout_web/channels/stakes_channel.ex index e8e0f0639d..b883b1648e 100644 --- a/apps/block_scout_web/lib/block_scout_web/channels/stakes_channel.ex +++ b/apps/block_scout_web/lib/block_scout_web/channels/stakes_channel.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} diff --git a/apps/block_scout_web/lib/block_scout_web/templates/stakes/_stakes_modal_delegators_list.html.eex b/apps/block_scout_web/lib/block_scout_web/templates/stakes/_stakes_modal_delegators_list.html.eex index 0de8dccddc..44c8129aed 100644 --- a/apps/block_scout_web/lib/block_scout_web/templates/stakes/_stakes_modal_delegators_list.html.eex +++ b/apps/block_scout_web/lib/block_scout_web/templates/stakes/_stakes_modal_delegators_list.html.eex @@ -15,7 +15,7 @@
<%= amount_col_title = - if @validator_set_apply_block > 0 do + if @is_show_snapshotted_data do gettext("Current Stake Amount") <> "
(" <> gettext("Accounted Stake Amount") <> ")" else gettext("Current Stake Amount") @@ -27,7 +27,7 @@
<%= reward_col_title = - if @pool.is_validator && @validator_set_apply_block > 0 do + if @is_show_snapshotted_data do gettext("Potential Reward Percent") <> "
(" <> gettext("Current Reward Percent") <> ")" else gettext("Potential Reward Percent") @@ -69,11 +69,11 @@
<%= 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 @@
<%= 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 diff --git a/apps/explorer/lib/explorer/staking/contract_state.ex b/apps/explorer/lib/explorer/staking/contract_state.ex index 3a281bac9d..6c70149bec 100644 --- a/apps/explorer/lib/explorer/staking/contract_state.ex +++ b/apps/explorer/lib/explorer/staking/contract_state.ex @@ -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) diff --git a/apps/explorer/lib/explorer/staking/stake_snapshotting.ex b/apps/explorer/lib/explorer/staking/stake_snapshotting.ex index a4a09aeaf9..cbcf76e8c6 100644 --- a/apps/explorer/lib/explorer/staking/stake_snapshotting.ex +++ b/apps/explorer/lib/explorer/staking/stake_snapshotting.ex @@ -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