From 7ef37f0071d8d46f8e6b2dbd710722c1fe4c6159 Mon Sep 17 00:00:00 2001 From: Paul Tsupikoff Date: Wed, 28 Aug 2019 16:48:25 +0300 Subject: [PATCH] Improve UI for becoming a candidate for existing pools (#2620) 1. If an address has been a pool some time ago, but was deactivated since, we can't use addPool() method anymore due to limitations in the contract. Instead, we fetch previously existing pool, provide unchangeable mining address, and use stake() method for reactivating the pool. 2. Banned pools can't become a candidate again, so the button is disabled. --- .../assets/js/pages/stakes/become_candidate.js | 6 +++++- .../lib/block_scout_web/channels/stakes_channel.ex | 8 ++++++-- .../stakes/_stakes_modal_become_candidate.html.eex | 9 ++++++++- .../templates/stakes/_stakes_top.html.eex | 7 ++++++- 4 files changed, 25 insertions(+), 5 deletions(-) diff --git a/apps/block_scout_web/assets/js/pages/stakes/become_candidate.js b/apps/block_scout_web/assets/js/pages/stakes/become_candidate.js index 8b28dc80fe..0a95a3a174 100644 --- a/apps/block_scout_web/assets/js/pages/stakes/become_candidate.js +++ b/apps/block_scout_web/assets/js/pages/stakes/become_candidate.js @@ -52,7 +52,11 @@ async function becomeCandidate ($modal, store, msg) { return false } - makeContractCall(stakingContract.methods.addPool(stake.toString(), miningAddress), store) + if (msg.pool_exists) { + makeContractCall(stakingContract.methods.stake(store.getState().account, stake.toString()), store) + } else { + makeContractCall(stakingContract.methods.addPool(stake.toString(), miningAddress), store) + } } catch (err) { openErrorModal('Error', err.message) } 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 c4916b9017..3e199e4aff 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 @@ -77,6 +77,7 @@ defmodule BlockScoutWeb.StakesChannel do end def handle_in("render_become_candidate", _, socket) do + pool = Chain.staking_pool(socket.assigns.account) min_candidate_stake = ContractState.get(:min_candidate_stake) token = ContractState.get(:token) balance = Chain.fetch_last_token_balance(socket.assigns.account, token.contract_address_hash) @@ -85,12 +86,15 @@ defmodule BlockScoutWeb.StakesChannel do View.render_to_string(StakesView, "_stakes_modal_become_candidate.html", min_candidate_stake: min_candidate_stake, balance: balance, - token: token + token: token, + pool: pool ) result = %{ html: html, - min_candidate_stake: min_candidate_stake + balance: balance, + min_candidate_stake: min_candidate_stake, + pool_exists: not is_nil(pool) } {:reply, {:ok, result}, socket} diff --git a/apps/block_scout_web/lib/block_scout_web/templates/stakes/_stakes_modal_become_candidate.html.eex b/apps/block_scout_web/lib/block_scout_web/templates/stakes/_stakes_modal_become_candidate.html.eex index 6dab8a04e7..33ef69fa04 100644 --- a/apps/block_scout_web/lib/block_scout_web/templates/stakes/_stakes_modal_become_candidate.html.eex +++ b/apps/block_scout_web/lib/block_scout_web/templates/stakes/_stakes_modal_become_candidate.html.eex @@ -14,7 +14,14 @@
- "> + " + value="<%= @pool && @pool.mining_address_hash %>" + <%= if @pool do "disabled" end %> + />

Minimum Stake: diff --git a/apps/block_scout_web/lib/block_scout_web/templates/stakes/_stakes_top.html.eex b/apps/block_scout_web/lib/block_scout_web/templates/stakes/_stakes_top.html.eex index 75fab761b6..ff876226a3 100644 --- a/apps/block_scout_web/lib/block_scout_web/templates/stakes/_stakes_top.html.eex +++ b/apps/block_scout_web/lib/block_scout_web/templates/stakes/_stakes_top.html.eex @@ -12,7 +12,12 @@ <%= render BlockScoutWeb.StakesView, "_stakes_btn_remove_pool.html", text: gettext("Remove My Pool"), extra_class: "js-remove-pool" %> <% end %> <% else %> - <%= render BlockScoutWeb.CommonComponentsView, "_btn_add_full.html", text: gettext("Become a Candidate"), extra_class: "js-become-candidate" %> + <%= + render BlockScoutWeb.CommonComponentsView, "_btn_add_full.html", + text: gettext("Become a Candidate"), + extra_class: "js-become-candidate", + disabled: @account[:pool] && @account.pool.is_banned + %> <% end %>