diff --git a/apps/explorer_web/lib/explorer_web/views/chain_view.ex b/apps/explorer_web/lib/explorer_web/views/chain_view.ex index 05623335ae..4e666c639e 100644 --- a/apps/explorer_web/lib/explorer_web/views/chain_view.ex +++ b/apps/explorer_web/lib/explorer_web/views/chain_view.ex @@ -14,8 +14,6 @@ defmodule ExplorerWeb.ChainView do end end - def format_exchange_rate(%Token{usd_value: nil}), do: nil - def format_exchange_rate(%Token{usd_value: usd_value}) do usd_value |> USD.from() diff --git a/apps/explorer_web/test/explorer_web/views/chain_view_test.exs b/apps/explorer_web/test/explorer_web/views/chain_view_test.exs index 71cbf1646f..89c47e061e 100644 --- a/apps/explorer_web/test/explorer_web/views/chain_view_test.exs +++ b/apps/explorer_web/test/explorer_web/views/chain_view_test.exs @@ -1,3 +1,33 @@ defmodule ExplorerWeb.ChainViewTest do use ExplorerWeb.ConnCase, async: true + + alias Explorer.ExchangeRates.Token + alias ExplorerWeb.ChainView + + describe "format_exchange_rate/1" do + test "returns a formatted usd value from a `Token`'s usd_value" do + token = %Token{usd_value: Decimal.new(5.45)} + + assert "$5.45 USD" == ChainView.format_exchange_rate(token) + assert nil == ChainView.format_exchange_rate(%Token{usd_value: nil}) + end + end + + describe "format_volume_24h/1" do + test "returns a formatted usd value from a `Token`'s volume_24h_usd" do + token = %Token{volume_24h_usd: Decimal.new(5.456)} + + assert "$5.456 USD" == ChainView.format_volume_24h(token) + assert nil == ChainView.format_volume_24h(%Token{volume_24h_usd: nil}) + end + end + + describe "format_market_cap/1" do + test "returns a formatted usd value from a `Token`'s market_cap_usd" do + token = %Token{market_cap_usd: Decimal.new(5.4)} + + assert "$5.40 USD" == ChainView.format_market_cap(token) + assert nil == ChainView.format_market_cap(%Token{market_cap_usd: nil}) + end + end end