From 5c3fd3a8fd9776065ad55cb751cb433e972363ca Mon Sep 17 00:00:00 2001 From: Vadim Date: Wed, 27 May 2020 16:27:22 +0300 Subject: [PATCH] Improve popups and some tooltips --- .../js/pages/stakes/become_candidate.js | 2 +- .../assets/js/pages/stakes/claim_reward.js | 2 +- .../assets/js/pages/stakes/make_stake.js | 2 +- .../assets/js/pages/stakes/move_stake.js | 14 +++++-- .../channels/stakes_channel.ex | 36 ++++++++++------- ...stakes_modal_claim_reward_content.html.eex | 4 +- .../_stakes_modal_delegators_list.html.eex | 39 +++++++++++++------ .../stakes/_stakes_modal_move.html.eex | 20 ++++++---- .../stakes/_stakes_modal_stake.html.eex | 2 +- .../stakes/_stakes_progress.html.eex | 2 +- .../templates/stakes/_table.html.eex | 26 +++++++++++-- apps/explorer/lib/explorer/chain.ex | 5 ++- apps/explorer/test/explorer/chain_test.exs | 19 +++++++++ 13 files changed, 125 insertions(+), 48 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 5afc1f23fb..d1665c07d0 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 @@ -84,7 +84,7 @@ function isMiningAddressValid (value, store) { const web3 = store.getState().web3 const miningAddress = value.trim().toLowerCase() - if (miningAddress === store.getState().account || !web3.utils.isAddress(miningAddress)) { + if (miningAddress === store.getState().account.toLowerCase() || !web3.utils.isAddress(miningAddress)) { return 'Invalid mining address' } diff --git a/apps/block_scout_web/assets/js/pages/stakes/claim_reward.js b/apps/block_scout_web/assets/js/pages/stakes/claim_reward.js index 788286c0cc..ecd821ce56 100644 --- a/apps/block_scout_web/assets/js/pages/stakes/claim_reward.js +++ b/apps/block_scout_web/assets/js/pages/stakes/claim_reward.js @@ -112,7 +112,7 @@ function onPoolsFound ($modal, $modalBody, channel, store) { $poolsDropdown.on('change', () => { if (status === 'recalculation' || status === 'claiming') return false - const data = $('option:selected', this).data() + const data = $('option:selected', $poolsDropdown).data() const tokenRewardSum = data.tokenRewardSum ? data.tokenRewardSum : '0' const nativeRewardSum = data.nativeRewardSum ? data.nativeRewardSum : '0' const gasLimit = data.gasLimit ? data.gasLimit : '0' diff --git a/apps/block_scout_web/assets/js/pages/stakes/make_stake.js b/apps/block_scout_web/assets/js/pages/stakes/make_stake.js index 27291c6ffe..ad8b1b0664 100644 --- a/apps/block_scout_web/assets/js/pages/stakes/make_stake.js +++ b/apps/block_scout_web/assets/js/pages/stakes/make_stake.js @@ -68,7 +68,7 @@ function isDelegatorStakeValid (value, store, msg, address) { if (!stake.isPositive() || stake.isZero()) { return 'Invalid amount' } else if (stake.plus(currentStake).isLessThan(minStake)) { - const staker = (account === address) ? 'candidate' : 'delegate' + const staker = (account.toLowerCase() === address.toLowerCase()) ? 'candidate' : 'delegate' return `Minimum ${staker} stake is ${minStake.shiftedBy(-decimals)} ${store.getState().tokenSymbol}` } else if (stake.isGreaterThan(balance)) { return 'Insufficient funds' diff --git a/apps/block_scout_web/assets/js/pages/stakes/move_stake.js b/apps/block_scout_web/assets/js/pages/stakes/move_stake.js index 9fa7668c71..112bed01c5 100644 --- a/apps/block_scout_web/assets/js/pages/stakes/move_stake.js +++ b/apps/block_scout_web/assets/js/pages/stakes/move_stake.js @@ -19,12 +19,14 @@ export function openMoveStakeModal (event, store) { } function setupModal ($modal, fromAddress, store, msg) { + const $form = $modal.find('form') + setupChart($modal.find('.js-pool-from-progress'), msg.from.self_staked_amount, msg.from.total_staked_amount) if (msg.to) { setupChart($modal.find('.js-pool-to-progress'), msg.to.self_staked_amount, msg.to.total_staked_amount) setupValidation( - $modal.find('form'), + $form, { 'move-amount': value => isMoveAmountValid(value, store, msg) }, @@ -32,7 +34,7 @@ function setupModal ($modal, fromAddress, store, msg) { ) } - $modal.find('form').submit(() => { + $form.submit(() => { moveStake($modal, fromAddress, store, msg) return false }) @@ -44,10 +46,16 @@ function setupModal ($modal, fromAddress, store, msg) { .push('render_move_stake', { from: fromAddress, to: toAddress, amount }) .receive('ok', msg => { $modal.html($(msg.html).html()) - $modal.addClass('show').css('padding-right: 12px; display: block;') + $modal.modal('show') setupModal($modal, fromAddress, store, msg) }) }) + $modal.find('[data-available-amount]').click(e => { + const amount = $(e.currentTarget).data('available-amount') + $('[move-amount]', $form).val(amount).trigger('input') + $('.tooltip').tooltip('hide') + return false + }) } function moveStake ($modal, fromAddress, store, msg) { 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 fc12877589..e181adaf71 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 @@ -173,20 +173,6 @@ defmodule BlockScoutWeb.StakesChannel do delegator_to = to_address && Chain.staking_pool_delegator(to_address, socket.assigns.account) token = ContractState.get(:token) - min_from_stake = - if delegator_from.address_hash == delegator_from.staking_address_hash do - ContractState.get(:min_candidate_stake) - else - ContractState.get(:min_delegator_stake) - end - - min_to_stake = - if to_address == socket.assigns.account do - ContractState.get(:min_candidate_stake) - else - ContractState.get(:min_delegator_stake) - end - html = View.render_to_string(StakesView, "_stakes_modal_move.html", token: token, @@ -198,6 +184,15 @@ defmodule BlockScoutWeb.StakesChannel do amount: amount ) + min_from_stake = + Decimal.new( + if delegator_from.address_hash == delegator_from.staking_address_hash do + ContractState.get(:min_candidate_stake) + else + ContractState.get(:min_delegator_stake) + end + ) + result = %{ html: html, max_withdraw_allowed: delegator_from.max_withdraw_allowed, @@ -209,8 +204,19 @@ defmodule BlockScoutWeb.StakesChannel do }, to: if pool_to do + stake_amount = Decimal.new((delegator_to && delegator_to.stake_amount) || 0) + + min_to_stake = + Decimal.new( + if to_address == socket.assigns.account do + ContractState.get(:min_candidate_stake) + else + ContractState.get(:min_delegator_stake) + end + ) + %{ - stake_amount: (delegator_to && delegator_to.stake_amount) || 0, + stake_amount: stake_amount, min_stake: min_to_stake, self_staked_amount: pool_to.self_staked_amount, total_staked_amount: pool_to.total_staked_amount diff --git a/apps/block_scout_web/lib/block_scout_web/templates/stakes/_stakes_modal_claim_reward_content.html.eex b/apps/block_scout_web/lib/block_scout_web/templates/stakes/_stakes_modal_claim_reward_content.html.eex index ea8e75e93f..1ec1477448 100644 --- a/apps/block_scout_web/lib/block_scout_web/templates/stakes/_stakes_modal_claim_reward_content.html.eex +++ b/apps/block_scout_web/lib/block_scout_web/templates/stakes/_stakes_modal_claim_reward_content.html.eex @@ -26,7 +26,7 @@

diff --git a/apps/block_scout_web/lib/block_scout_web/templates/stakes/_stakes_modal_delegators_list.html.eex b/apps/block_scout_web/lib/block_scout_web/templates/stakes/_stakes_modal_delegators_list.html.eex index eec415645e..67f81ff442 100644 --- a/apps/block_scout_web/lib/block_scout_web/templates/stakes/_stakes_modal_delegators_list.html.eex +++ b/apps/block_scout_web/lib/block_scout_web/templates/stakes/_stakes_modal_delegators_list.html.eex @@ -11,12 +11,11 @@

<%= - pool_type = - if @pool.is_validator do - gettext("validator") - else - gettext("candidate") - end + pool_type = cond do + @pool.is_validator -> gettext("validator") + @pool.is_active -> gettext("candidate") + true -> gettext("pool owner") + end render( BlockScoutWeb.StakesView, @@ -28,29 +27,45 @@
<%= - amount_col_title = + title = if @show_snapshotted_data do - gettext("Current Stake Amount") <> "
(" <> gettext("Accounted Stake Amount") <> ")" + gettext("Current Stake Amount") <> "
(" <> gettext("Working Stake Amount") <> ")" else gettext("Current Stake Amount") end - render BlockScoutWeb.StakesView, "_stakes_th.html", title: amount_col_title, tooltip: gettext("Amount of %{symbol} placed by an address.", symbol: @token.symbol) + tooltip = + gettext("Amount of %{symbol} placed by an address.", symbol: @token.symbol) <> + if @show_snapshotted_data do + gettext(" Working Stake Amount is an amount which is accounted and working at the current staking epoch.") + else + "" + end + + render BlockScoutWeb.StakesView, "_stakes_th.html", title: title, tooltip: tooltip %>
<%= - reward_col_title = + title = if @show_snapshotted_data do gettext("Potential Reward Percent") <> "
(" <> gettext("Current Reward Percent") <> ")" else gettext("Potential Reward Percent") end + tooltip = + gettext("Reward distribution is based on stake amount. Validator receives a minimum of %{min}%.", min: @validator_min_reward_percent) <> + if @show_snapshotted_data do + " " <> gettext("Current Reward Percent is calculated based on the Working Stake Amount.") + else + "" + end + render BlockScoutWeb.StakesView, "_stakes_th.html", - title: reward_col_title, - tooltip: gettext("Reward distribution is based on stake amount. Validator receives a minimum of %{min}%.", min: @validator_min_reward_percent) + title: title, + tooltip: tooltip %>
diff --git a/apps/block_scout_web/lib/block_scout_web/templates/stakes/_stakes_modal_move.html.eex b/apps/block_scout_web/lib/block_scout_web/templates/stakes/_stakes_modal_move.html.eex index 84cc730e97..dae1a54784 100644 --- a/apps/block_scout_web/lib/block_scout_web/templates/stakes/_stakes_modal_move.html.eex +++ b/apps/block_scout_web/lib/block_scout_web/templates/stakes/_stakes_modal_move.html.eex @@ -4,7 +4,7 @@ <%= render BlockScoutWeb.CommonComponentsView, "_modal_close_button.html" %>