Use custom format for usd display to remove decimal comma on homepage

Co-authored-by: tmecklem <timothy@mecklem.com>
pull/202/head
jimmay5469 7 years ago
parent 0246dc45db
commit a4c966009e
  1. 6
      apps/explorer_web/lib/explorer_web/exchange_rates/usd.ex
  2. 6
      apps/explorer_web/lib/explorer_web/templates/chain/show.html.eex
  3. 16
      apps/explorer_web/lib/explorer_web/views/chain_view.ex

@ -17,6 +17,12 @@ defmodule ExplorerWeb.ExchangeRates.USD do
alias Explorer.Chain.Wei
alias Explorer.ExchangeRates.Token
def from(nil), do: null()
def from(%Decimal{} = usd_decimal) do
%__MODULE__{value: usd_decimal}
end
def from(nil, _), do: null()
def from(_, nil), do: null()

@ -28,16 +28,16 @@
<div class="u-push-md-left">
<div class="graph__squares graph__squares--price"></div>
<%= gettext "Price" %> </br>
$<%= format_exchange_rate(@exchange_rate) %> <%= gettext "USD" %>
<%= format_exchange_rate(@exchange_rate) %>
</div>
<div>
<div class="graph__squares graph__squares--mcap"></div>
<%= gettext "Market Cap" %> </br>
$<%= format_market_cap(@exchange_rate) %> <%= gettext "USD" %>
<%= format_market_cap(@exchange_rate) %>
</div>
<div class="u-push-md-right">
<%= gettext "24h Volume" %> </br>
$<%= format_volume_24h(@exchange_rate) %> <%= gettext "USD" %>
<%= format_volume_24h(@exchange_rate) %>
</div>
</div>
</div>

@ -2,6 +2,7 @@ defmodule ExplorerWeb.ChainView do
use ExplorerWeb, :view
alias Explorer.ExchangeRates.Token
alias ExplorerWeb.ExchangeRates.USD
def encode_market_history_data(market_history_data) do
market_history_data
@ -16,17 +17,20 @@ defmodule ExplorerWeb.ChainView do
def format_exchange_rate(%Token{usd_value: nil}), do: nil
def format_exchange_rate(%Token{usd_value: usd_value}) do
Cldr.Number.to_string!(usd_value, fractional_digits: 6)
usd_value
|> USD.from()
|> format_usd_value()
end
def format_volume_24h(%Token{volume_24h_usd: volume_24h}) do
format_number(volume_24h)
volume_24h
|> USD.from()
|> format_usd_value()
end
def format_market_cap(%Token{market_cap_usd: market_cap}) do
format_number(market_cap)
market_cap
|> USD.from()
|> format_usd_value()
end
defp format_number(nil), do: nil
defp format_number(number), do: Cldr.Number.to_string!(number)
end

Loading…
Cancel
Save