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.
staking
Paul Tsupikoff 5 years ago committed by Victor Baranov
parent d679bc7fbb
commit 7ef37f0071
  1. 4
      apps/block_scout_web/assets/js/pages/stakes/become_candidate.js
  2. 8
      apps/block_scout_web/lib/block_scout_web/channels/stakes_channel.ex
  3. 9
      apps/block_scout_web/lib/block_scout_web/templates/stakes/_stakes_modal_become_candidate.html.eex
  4. 7
      apps/block_scout_web/lib/block_scout_web/templates/stakes/_stakes_top.html.eex

@ -52,7 +52,11 @@ async function becomeCandidate ($modal, store, msg) {
return false
}
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)
}

@ -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}

@ -14,7 +14,14 @@
</div>
</div>
<div class="form-group">
<input mining-address type="text" class="form-control" placeholder="<%= gettext("Your Mining Address") %>">
<input
mining-address
type="text"
class="form-control"
placeholder="<%= gettext("Your Mining Address") %>"
value="<%= @pool && @pool.mining_address_hash %>"
<%= if @pool do "disabled" end %>
/>
</div>
<p class="form-p m-b-0">Minimum Stake:
<span class="text-dark">

@ -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 %>
</div>
</div>

Loading…
Cancel
Save