diff --git a/CHANGELOG.md b/CHANGELOG.md index c4381426e9..4e8f0b8a4b 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -20,6 +20,7 @@ ### Fixes - [#2562](https://github.com/poanetwork/blockscout/pull/2562) - Fix dark theme flickering +- [#2559](https://github.com/poanetwork/blockscout/pull/2559) - fix rsk total supply for empty exchange rate - [#2553](https://github.com/poanetwork/blockscout/pull/2553) - Dark theme import to the end of sass - [#2550](https://github.com/poanetwork/blockscout/pull/2550) - correctly encode decimal values for frontend - [#2549](https://github.com/poanetwork/blockscout/pull/2549) - Fix wrong colour of tooltip diff --git a/apps/explorer/lib/explorer/chain/supply/rsk.ex b/apps/explorer/lib/explorer/chain/supply/rsk.ex index cdb043418b..eb7c4571cd 100644 --- a/apps/explorer/lib/explorer/chain/supply/rsk.ex +++ b/apps/explorer/lib/explorer/chain/supply/rsk.ex @@ -17,12 +17,14 @@ defmodule Explorer.Chain.Supply.RSK do @cache_name :rsk_balance @balance_key :balance - def market_cap(exchange_rate) do + def market_cap(%{usd_value: usd_value}) when not is_nil(usd_value) do btc = circulating() - Decimal.mult(btc, exchange_rate.usd_value) + Decimal.mult(btc, usd_value) end + def market_cap(_), do: Decimal.new(0) + @doc "Equivalent to getting the circulating value " def supply_for_days(days) do now = Timex.now() diff --git a/apps/explorer/test/explorer/chain/supply/rsk_test.exs b/apps/explorer/test/explorer/chain/supply/rsk_test.exs index 71d3a530bb..6efc2bb844 100644 --- a/apps/explorer/test/explorer/chain/supply/rsk_test.exs +++ b/apps/explorer/test/explorer/chain/supply/rsk_test.exs @@ -24,7 +24,17 @@ defmodule Explorer.Chain.Supply.RSKTest do exchange_rate = %{Token.null() | usd_value: Decimal.new(1_000_000)} - assert Decimal.equal?(RSK.market_cap(exchange_rate), Decimal.new(100.0000)) + assert Decimal.equal?(RSK.market_cap(exchange_rate), Decimal.from_float(100.0000)) + end + + test "returns zero when exchange_rate is empty" do + assert RSK.market_cap(nil) == Decimal.new(0) + end + + test "returns zero when usd_value is nil" do + exchange_rate = %{Token.null() | usd_value: nil} + + assert RSK.market_cap(exchange_rate) == Decimal.new(0) end end