Fix 'Stake' and 'Become a Candidate' popups

staking
Vadim 5 years ago committed by Victor Baranov
parent 3424f47c0e
commit 7f3f983ceb
  1. 12
      apps/block_scout_web/assets/js/pages/stakes/become_candidate.js
  2. 13
      apps/block_scout_web/lib/block_scout_web/channels/stakes_channel.ex
  3. 12
      apps/block_scout_web/lib/block_scout_web/templates/stakes/_stakes_modal_become_candidate.html.eex
  4. 6
      apps/block_scout_web/lib/block_scout_web/templates/stakes/_stakes_modal_stake.html.eex
  5. 5
      apps/block_scout_web/lib/block_scout_web/templates/stakes/_stakes_modal_withdraw.html.eex

@ -16,9 +16,10 @@ export function openBecomeCandidateModal (store) {
.push('render_become_candidate') .push('render_become_candidate')
.receive('ok', msg => { .receive('ok', msg => {
const $modal = $(msg.html) const $modal = $(msg.html)
const $form = $modal.find('form')
setupValidation( setupValidation(
$modal.find('form'), $form,
{ {
'candidate-stake': value => isCandidateStakeValid(value, store, msg), 'candidate-stake': value => isCandidateStakeValid(value, store, msg),
'mining-address': value => isMiningAddressValid(value, store) 'mining-address': value => isMiningAddressValid(value, store)
@ -26,7 +27,14 @@ export function openBecomeCandidateModal (store) {
$modal.find('form button') $modal.find('form button')
) )
$modal.find('form').submit(() => { $modal.find('[data-available-amount]').click(e => {
const amount = $(e.currentTarget).data('available-amount')
$('[candidate-stake]', $form).val(amount).trigger('input')
$('.tooltip').tooltip('hide')
return false
})
$form.submit(() => {
becomeCandidate($modal, store, msg) becomeCandidate($modal, store, msg)
return false return false
}) })

@ -107,7 +107,7 @@ defmodule BlockScoutWeb.StakesChannel do
end end
def handle_in("render_become_candidate", _, socket) do def handle_in("render_become_candidate", _, socket) do
min_candidate_stake = ContractState.get(:min_candidate_stake) min_candidate_stake = Decimal.new(ContractState.get(:min_candidate_stake))
token = ContractState.get(:token) token = ContractState.get(:token)
balance = Chain.fetch_last_token_balance(socket.assigns.account, token.contract_address_hash) balance = Chain.fetch_last_token_balance(socket.assigns.account, token.contract_address_hash)
@ -140,19 +140,22 @@ defmodule BlockScoutWeb.StakesChannel do
ContractState.get(:min_delegator_stake) ContractState.get(:min_delegator_stake)
end end
min_stake = Decimal.new(min_stake)
delegator_staked = Decimal.new((delegator && delegator.stake_amount) || 0)
html = html =
View.render_to_string(StakesView, "_stakes_modal_stake.html", View.render_to_string(StakesView, "_stakes_modal_stake.html",
min_stake: min_stake,
balance: balance, balance: balance,
token: token, delegator_staked: delegator_staked,
min_stake: min_stake,
pool: pool, pool: pool,
delegator: delegator token: token
) )
result = %{ result = %{
html: html, html: html,
balance: balance, balance: balance,
delegator_staked: (delegator && delegator.stake_amount) || 0, delegator_staked: delegator_staked,
min_stake: min_stake, min_stake: min_stake,
self_staked_amount: pool.self_staked_amount, self_staked_amount: pool.self_staked_amount,
total_staked_amount: pool.total_staked_amount total_staked_amount: pool.total_staked_amount

@ -16,9 +16,15 @@
</span> </span>
</p> </p>
<p class="form-p"><%= gettext("Your Balance:") %> <p class="form-p"><%= gettext("Your Balance:") %>
<span class="text-dark"> <%= if @balance >= @min_candidate_stake do %>
<%= format_token_amount(@balance, @token) %> <span class="text-dark link-dotted" data-available-amount="<%= from_wei(@balance, @token) %>">
</span> <%= format_token_amount(@balance, @token) %>
</span>
<% else %>
<span class="text-dark">
<%= format_token_amount(@balance, @token) %>
</span>
<% end %>
</p> </p>
<div class="form-buttons"><%= render BlockScoutWeb.CommonComponentsView, "_btn_add_full.html", text: gettext("Become a Candidate"), extra_class: "full-width" %></div> <div class="form-buttons"><%= render BlockScoutWeb.CommonComponentsView, "_btn_add_full.html", text: gettext("Become a Candidate"), extra_class: "full-width" %></div>
</form> </form>

@ -10,12 +10,12 @@
<form> <form>
<%= render BlockScoutWeb.CommonComponentsView, "_input_group.html", id: "delegator-stake", classes: "form-group", input_classes: "form-control n-b-r", attributes: "delegator-stake", type: "text", placeholder: gettext("Amount"), prepend: @token.symbol %> <%= render BlockScoutWeb.CommonComponentsView, "_input_group.html", id: "delegator-stake", classes: "form-group", input_classes: "form-control n-b-r", attributes: "delegator-stake", type: "text", placeholder: gettext("Amount"), prepend: @token.symbol %>
<% has_stake = @delegator && Decimal.positive?(@delegator.stake_amount) %> <% has_stake = Decimal.positive?(@delegator_staked) %>
<%= if has_stake do %> <%= if has_stake do %>
<p class="form-p m-b-0"><%= gettext("Your Current Stake:") %> <p class="form-p m-b-0"><%= gettext("Your Current Stake:") %>
<span class="text-dark"> <span class="text-dark">
<%= format_token_amount(@delegator.stake_amount, @token) %> <%= format_token_amount(@delegator_staked, @token) %>
</span> </span>
</p> </p>
<% else %> <% else %>
@ -26,7 +26,7 @@
</p> </p>
<% end %> <% end %>
<p class="form-p"><%= gettext("Your Balance:") %> <p class="form-p"><%= gettext("Your Balance:") %>
<%= if Decimal.positive?(@balance) do %> <%= if Decimal.add(@delegator_staked, @balance) >= @min_stake do %>
<span class="text-dark link-dotted" data-available-amount="<%= from_wei(@balance, @token) %>"> <span class="text-dark link-dotted" data-available-amount="<%= from_wei(@balance, @token) %>">
<%= format_token_amount(@balance, @token) %> <%= format_token_amount(@balance, @token) %>
</span> </span>

@ -36,11 +36,12 @@
%> %>
<% end %> <% end %>
<%= if Decimal.positive?(@delegator.max_withdraw_allowed) do %> <%= if Decimal.positive?(@delegator.max_withdraw_allowed) do %>
<p class="form-p m-b-0-7"><%= gettext("Available Now:") %> <div class="form-p m-b-0-7"><%= gettext("Available Now:") %>
<span class="text-dark link-dotted" data-available-amount="<%= from_wei(@delegator.max_withdraw_allowed, @token) %>"> <span class="text-dark link-dotted" data-available-amount="<%= from_wei(@delegator.max_withdraw_allowed, @token) %>">
<%= format_token_amount(@delegator.max_withdraw_allowed, @token) %> <%= format_token_amount(@delegator.max_withdraw_allowed, @token) %>
</span> </span>
</p> <%= render BlockScoutWeb.CommonComponentsView, "_i_tooltip.html", text: gettext("You can withdraw this amount right now.") %>
</div>
<%= <%=
render BlockScoutWeb.StakesView, render BlockScoutWeb.StakesView,
"_stakes_btn_withdraw.html", "_stakes_btn_withdraw.html",

Loading…
Cancel
Save