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 b10fac526e..5afc1f23fb 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 @@ -16,9 +16,10 @@ export function openBecomeCandidateModal (store) { .push('render_become_candidate') .receive('ok', msg => { const $modal = $(msg.html) + const $form = $modal.find('form') setupValidation( - $modal.find('form'), + $form, { 'candidate-stake': value => isCandidateStakeValid(value, store, msg), 'mining-address': value => isMiningAddressValid(value, store) @@ -26,7 +27,14 @@ export function openBecomeCandidateModal (store) { $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) return false }) 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 62ef1a1daa..8be45d5d55 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 @@ -107,7 +107,7 @@ defmodule BlockScoutWeb.StakesChannel do end 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) 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) end + min_stake = Decimal.new(min_stake) + delegator_staked = Decimal.new((delegator && delegator.stake_amount) || 0) + html = View.render_to_string(StakesView, "_stakes_modal_stake.html", - min_stake: min_stake, balance: balance, - token: token, + delegator_staked: delegator_staked, + min_stake: min_stake, pool: pool, - delegator: delegator + token: token ) result = %{ html: html, balance: balance, - delegator_staked: (delegator && delegator.stake_amount) || 0, + delegator_staked: delegator_staked, min_stake: min_stake, self_staked_amount: pool.self_staked_amount, total_staked_amount: pool.total_staked_amount 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 d919e20a44..b843eb13e1 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 @@ -16,9 +16,15 @@
<%= gettext("Your Balance:") %> - - <%= format_token_amount(@balance, @token) %> - + <%= if @balance >= @min_candidate_stake do %> + + <%= format_token_amount(@balance, @token) %> + + <% else %> + + <%= format_token_amount(@balance, @token) %> + + <% end %>
diff --git a/apps/block_scout_web/lib/block_scout_web/templates/stakes/_stakes_modal_stake.html.eex b/apps/block_scout_web/lib/block_scout_web/templates/stakes/_stakes_modal_stake.html.eex index ed188727ac..dd5baec303 100644 --- a/apps/block_scout_web/lib/block_scout_web/templates/stakes/_stakes_modal_stake.html.eex +++ b/apps/block_scout_web/lib/block_scout_web/templates/stakes/_stakes_modal_stake.html.eex @@ -10,12 +10,12 @@