Fix displaying fractional balances in header

staking
Vadim 5 years ago committed by Victor Baranov
parent 4d0007ee87
commit 8662f7cdf9
  1. 30
      apps/block_scout_web/lib/block_scout_web/templates/stakes/_stakes_stats_item_account.html.eex
  2. 22
      apps/block_scout_web/lib/block_scout_web/views/stakes_helpers.ex

@ -17,18 +17,36 @@
</span>
<span class="stakes-top-stats-label">
<%
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
%>
<span class="stakes-top-stats-label-item" data-placement="bottom" data-toggle="tooltip" title="<%= gettext "Balance" %>: <%= balance %>">
<span class="stakes-top-stats-label-item" data-placement="bottom" data-toggle="tooltip" title="<%= gettext "Balance" %>: <%= balance_full %>">
<%= gettext "Balance" %>: <%= balance %>
</span>
<span class="stakes-top-stats-label-item" data-placement="bottom" data-toggle="tooltip" title="<%= gettext "Staked" %>: <%= stake_amount %>">
<span class="stakes-top-stats-label-item" data-placement="bottom" data-toggle="tooltip" title="<%= gettext "Staked" %>: <%= stake_amount_full %>">
<%= gettext "Staked" %>: <%= stake_amount %>
</span>
<%= if @account[:ordered_withdraw] && @account[:ordered_withdraw] > 0 do %>
<span class="stakes-top-stats-label-item" data-placement="bottom" data-toggle="tooltip" title="<%= gettext "Ordered" %>: <%= ordered_withdraw %>">
<span class="stakes-top-stats-label-item" data-placement="bottom" data-toggle="tooltip" title="<%= gettext "Ordered" %>: <%= ordered_withdraw_full %>">
<%= gettext "Ordered" %>: <%= ordered_withdraw %>
</span>
<% end %>

@ -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"""
<span
data-placement="top"
data-toggle="tooltip"
title="#{Number.to_string!(reduced, fractional_digits: -reduced.exp)}#{symbol}">
#{Number.to_string!(reduced, fractional_digits: digits)}...#{symbol}
</span>
""")
clipped = "#{Number.to_string!(reduced, fractional_digits: digits)}...#{symbol}"
if no_tooltip do
clipped
else
HTML.raw(~s"""
<span
data-placement="top"
data-toggle="tooltip"
title="#{Number.to_string!(reduced, fractional_digits: -reduced.exp)}#{symbol}">
#{clipped}
</span>
""")
end
end
end
end

Loading…
Cancel
Save