From 888e56c13d9bbd3ef3f1c50422ca7d11aa0bbbea Mon Sep 17 00:00:00 2001 From: Ed Man Date: Wed, 11 Sep 2019 18:20:52 +0300 Subject: [PATCH] Improve UI and delegators logic for banned pools (#2670) Add ban reason, delegators' ban period, and make corresponding UI changes. --- .../assets/css/components/_stakes_table.scss | 6 ++ .../stakes/_modal_validator_info.scss | 10 ++++ .../assets/css/components/stakes/_stakes.scss | 1 + .../channels/stakes_channel.ex | 2 + .../controllers/stakes_controller.ex | 1 + .../templates/stakes/_rows.html.eex | 15 ++++- .../_stakes_modal_validator_info.html.eex | 19 +++++-- .../chain/import/runner/staking_pools.ex | 3 + .../lib/explorer/chain/staking_pool.ex | 10 +++- .../lib/explorer/staking/contract_reader.ex | 3 + .../lib/explorer/staking/contract_state.ex | 12 +++- .../posdao/ValidatorSetAuRa.json | 57 +++++++++++++++++++ ...additional_ban_fields_to_staking_pools.exs | 11 ++++ .../explorer/staking/contract_state_test.exs | 14 ++++- 14 files changed, 152 insertions(+), 12 deletions(-) create mode 100644 apps/explorer/priv/repo/migrations/20190904170014_add_additional_ban_fields_to_staking_pools.exs diff --git a/apps/block_scout_web/assets/css/components/_stakes_table.scss b/apps/block_scout_web/assets/css/components/_stakes_table.scss index 84322f9463..da5cdf1a86 100644 --- a/apps/block_scout_web/assets/css/components/_stakes_table.scss +++ b/apps/block_scout_web/assets/css/components/_stakes_table.scss @@ -114,6 +114,12 @@ $stakes-table-cell-separation: 25px !default; background-color: $stakes-banned-background; color: $stakes-banned-color; } + + .stakes-td-banned-info { + display: block; + float: left; + padding-right: 30px; + } } .stakes-td-order { diff --git a/apps/block_scout_web/assets/css/components/stakes/_modal_validator_info.scss b/apps/block_scout_web/assets/css/components/stakes/_modal_validator_info.scss index 3df5db9001..b0514b55bc 100644 --- a/apps/block_scout_web/assets/css/components/stakes/_modal_validator_info.scss +++ b/apps/block_scout_web/assets/css/components/stakes/_modal_validator_info.scss @@ -47,3 +47,13 @@ padding: 0; } } + +.modal-validator-alert { + padding: 10px 30px; + background-color: #fff3f7; + color: #ff7986; + border-top: 1px solid #fee6ef; + border-bottom: 1px solid #fee6ef; + line-height: 1.5; + font-size: 14px; +} diff --git a/apps/block_scout_web/assets/css/components/stakes/_stakes.scss b/apps/block_scout_web/assets/css/components/stakes/_stakes.scss index 7ed7a7b3a7..86ccaa7b86 100644 --- a/apps/block_scout_web/assets/css/components/stakes/_stakes.scss +++ b/apps/block_scout_web/assets/css/components/stakes/_stakes.scss @@ -95,6 +95,7 @@ $stakes-stats-item-border-color: #fff !default; display: flex; justify-content: flex-end; padding-right: 30px; + float: left; } .stakes-control { 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 54902c1764..bcbd3309a4 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 @@ -36,12 +36,14 @@ defmodule BlockScoutWeb.StakesChannel do def handle_in("render_validator_info", %{"address" => staking_address}, socket) do pool = Chain.staking_pool(staking_address) + delegator = socket.assigns[:account] && Chain.staking_pool_delegator(staking_address, socket.assigns.account) average_block_time = AverageBlockTime.average_block_time() token = ContractState.get(:token) html = View.render_to_string(StakesView, "_stakes_modal_validator_info.html", validator: pool, + delegator: delegator, average_block_time: average_block_time, token: token ) diff --git a/apps/block_scout_web/lib/block_scout_web/controllers/stakes_controller.ex b/apps/block_scout_web/lib/block_scout_web/controllers/stakes_controller.ex index 749d2edc87..f28519102f 100644 --- a/apps/block_scout_web/lib/block_scout_web/controllers/stakes_controller.ex +++ b/apps/block_scout_web/lib/block_scout_web/controllers/stakes_controller.ex @@ -92,6 +92,7 @@ defmodule BlockScoutWeb.StakesController do "_rows.html", token: token, pool: pool, + delegator: delegator, index: index, average_block_time: average_block_time, pools_type: filter, diff --git a/apps/block_scout_web/lib/block_scout_web/templates/stakes/_rows.html.eex b/apps/block_scout_web/lib/block_scout_web/templates/stakes/_rows.html.eex index 866164cdcb..6eeaeb990f 100644 --- a/apps/block_scout_web/lib/block_scout_web/templates/stakes/_rows.html.eex +++ b/apps/block_scout_web/lib/block_scout_web/templates/stakes/_rows.html.eex @@ -34,9 +34,20 @@ <%= if @pool.is_banned do %> - Banned until block #<%= @pool.banned_until %> (<%= estimated_unban_day(@pool.banned_until, @average_block_time) %>) + Banned until block #<%= @pool.banned_until %> (<%= estimated_unban_day(@pool.banned_until, @average_block_time) %>). + <%= if @delegator && + @delegator.delegator_address_hash != @pool.staking_address_hash && + @pool.are_delegators_banned && + @pool.banned_until != @pool.banned_delegators_until do %> + You will be able to withdraw after block #<%= @pool.banned_delegators_until %> (<%= estimated_unban_day(@pool.banned_delegators_until, @average_block_time) %>) + <% end %> - <% else %> + <% end %> + <%= if !@pool.is_banned || + (!@pool.are_delegators_banned && + @delegator && + @delegator.delegator_address_hash != @pool.staking_address_hash + ) do %>
<%= if @buttons.move do %> <%= render BlockScoutWeb.StakesView, "_stakes_control_move.html", address: @pool.staking_address_hash %> diff --git a/apps/block_scout_web/lib/block_scout_web/templates/stakes/_stakes_modal_validator_info.html.eex b/apps/block_scout_web/lib/block_scout_web/templates/stakes/_stakes_modal_validator_info.html.eex index ee7d64c309..69691b472b 100644 --- a/apps/block_scout_web/lib/block_scout_web/templates/stakes/_stakes_modal_validator_info.html.eex +++ b/apps/block_scout_web/lib/block_scout_web/templates/stakes/_stakes_modal_validator_info.html.eex @@ -10,6 +10,19 @@
+ <%= if @validator.is_banned do %> + + <% end %> <%= render BlockScoutWeb.CommonComponentsView, "_modal_close_button.html" %>