From 8662f7cdf9e92d971c7273fc92774ce83bea36ab Mon Sep 17 00:00:00 2001 From: Vadim Date: Thu, 21 May 2020 16:40:46 +0300 Subject: [PATCH] Fix displaying fractional balances in header --- .../_stakes_stats_item_account.html.eex | 30 +++++++++++++++---- .../block_scout_web/views/stakes_helpers.ex | 22 +++++++++----- 2 files changed, 38 insertions(+), 14 deletions(-) diff --git a/apps/block_scout_web/lib/block_scout_web/templates/stakes/_stakes_stats_item_account.html.eex b/apps/block_scout_web/lib/block_scout_web/templates/stakes/_stakes_stats_item_account.html.eex index 4c2a2c5d7f..fe19d078a8 100644 --- a/apps/block_scout_web/lib/block_scout_web/templates/stakes/_stakes_stats_item_account.html.eex +++ b/apps/block_scout_web/lib/block_scout_web/templates/stakes/_stakes_stats_item_account.html.eex @@ -17,18 +17,36 @@ <% - balance = format_token_amount(@account[:balance], @token, digits: 5, ellipsize: false, symbol: true) - stake_amount = format_token_amount(@account[:stake_amount], @token, digits: 5, ellipsize: false, symbol: true) - ordered_withdraw = format_token_amount(@account[:ordered_withdraw], @token, digits: 5, ellipsize: false, symbol: true) + balance = format_token_amount(@account[:balance], @token, digits: 5, no_tooltip: true, symbol: true) + balance_full = if @account[:balance] do + "#{from_wei(@account[:balance], @token)} #{@token.symbol}" + else + "-" + end + + stake_amount = format_token_amount(@account[:stake_amount], @token, digits: 5, no_tooltip: true, symbol: true) + stake_amount_full = if @account[:stake_amount] do + "#{from_wei(@account[:stake_amount], @token)} #{@token.symbol}" + else + "-" + end + + ordered_withdraw = format_token_amount(@account[:ordered_withdraw], @token, digits: 5, no_tooltip: true, symbol: true) + ordered_withdraw_full = if @account[:ordered_withdraw] do + "#{from_wei(@account[:ordered_withdraw], @token)} #{@token.symbol}" + else + "-" + end %> - : <%= balance %>"> + + : <%= balance_full %>"> <%= gettext "Balance" %>: <%= balance %> - : <%= stake_amount %>"> + : <%= stake_amount_full %>"> <%= gettext "Staked" %>: <%= stake_amount %> <%= if @account[:ordered_withdraw] && @account[:ordered_withdraw] > 0 do %> - : <%= ordered_withdraw %>"> + : <%= ordered_withdraw_full %>"> <%= gettext "Ordered" %>: <%= ordered_withdraw %> <% end %> diff --git a/apps/block_scout_web/lib/block_scout_web/views/stakes_helpers.ex b/apps/block_scout_web/lib/block_scout_web/views/stakes_helpers.ex index 10e1f75a60..ff4f38150b 100644 --- a/apps/block_scout_web/lib/block_scout_web/views/stakes_helpers.ex +++ b/apps/block_scout_web/lib/block_scout_web/views/stakes_helpers.ex @@ -63,20 +63,26 @@ defmodule BlockScoutWeb.StakesHelpers do symbol = if Keyword.get(options, :symbol, true), do: " #{token.symbol}" digits = Keyword.get(options, :digits, 5) ellipsize = Keyword.get(options, :ellipsize, true) + no_tooltip = Keyword.get(options, :no_tooltip, false) reduced = from_wei(amount, token) if digits >= -reduced.exp or not ellipsize do "#{Number.to_string!(reduced, fractional_digits: min(digits, -reduced.exp))}#{symbol}" else - HTML.raw(~s""" - - #{Number.to_string!(reduced, fractional_digits: digits)}...#{symbol} - - """) + clipped = "#{Number.to_string!(reduced, fractional_digits: digits)}...#{symbol}" + if no_tooltip do + clipped + else + HTML.raw(~s""" + + #{clipped} + + """) + end end end end