From ed9e566e8e98fc253720a730ee092888c5c25d1e Mon Sep 17 00:00:00 2001 From: Ayrat Badykov Date: Tue, 13 Aug 2019 10:57:09 +0300 Subject: [PATCH 1/5] fix rsk total supply for empty exchang rate --- apps/explorer/lib/explorer/chain/supply/rsk.ex | 8 ++++++-- .../explorer/test/explorer/chain/supply/rsk_test.exs | 12 +++++++++++- 2 files changed, 17 insertions(+), 3 deletions(-) diff --git a/apps/explorer/lib/explorer/chain/supply/rsk.ex b/apps/explorer/lib/explorer/chain/supply/rsk.ex index cdb043418b..27a13bfdd2 100644 --- a/apps/explorer/lib/explorer/chain/supply/rsk.ex +++ b/apps/explorer/lib/explorer/chain/supply/rsk.ex @@ -17,12 +17,16 @@ defmodule Explorer.Chain.Supply.RSK do @cache_name :rsk_balance @balance_key :balance - def market_cap(exchange_rate) do + def market_cap(%{usd_value: nil}), do: Decimal.new(0) + + def market_cap(%{usd_value: 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 From a9c5982e0e5ce07a97e190513d148556cf81e818 Mon Sep 17 00:00:00 2001 From: Ayrat Badykov Date: Tue, 13 Aug 2019 11:18:44 +0300 Subject: [PATCH 2/5] add CHANGELOG entry --- CHANGELOG.md | 1 + 1 file changed, 1 insertion(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index ade434a9d7..5ae09463b2 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -19,6 +19,7 @@ - [#2403](https://github.com/poanetwork/blockscout/pull/2403) - Return gasPrice field at the result of gettxinfo method ### Fixes +- [#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 From 37794384fb2e681fe8c7c8b8e51a4479d955c2ac Mon Sep 17 00:00:00 2001 From: Ayrat Badykov Date: Tue, 13 Aug 2019 11:21:12 +0300 Subject: [PATCH 3/5] move change entry to new release section --- CHANGELOG.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 5ae09463b2..3b3a02e7e6 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -3,6 +3,7 @@ ### Features ### Fixes +- [#2559](https://github.com/poanetwork/blockscout/pull/2559) - fix rsk total supply for empty exchange rate ### Chore @@ -19,7 +20,6 @@ - [#2403](https://github.com/poanetwork/blockscout/pull/2403) - Return gasPrice field at the result of gettxinfo method ### Fixes -- [#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 From 45a8a48495c13b638dc05ebb8b111ec44becb356 Mon Sep 17 00:00:00 2001 From: Ayrat Badykov Date: Tue, 13 Aug 2019 11:52:40 +0300 Subject: [PATCH 4/5] move CHANGELOG entry to old release --- CHANGELOG.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 3b3a02e7e6..5ae09463b2 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -3,7 +3,6 @@ ### Features ### Fixes -- [#2559](https://github.com/poanetwork/blockscout/pull/2559) - fix rsk total supply for empty exchange rate ### Chore @@ -20,6 +19,7 @@ - [#2403](https://github.com/poanetwork/blockscout/pull/2403) - Return gasPrice field at the result of gettxinfo method ### Fixes +- [#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 From 95da8e1a0cb1168de6819be905a74a4f85551e9f Mon Sep 17 00:00:00 2001 From: Ayrat Badykov Date: Tue, 13 Aug 2019 15:04:41 +0300 Subject: [PATCH 5/5] fix CR issues --- apps/explorer/lib/explorer/chain/supply/rsk.ex | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/apps/explorer/lib/explorer/chain/supply/rsk.ex b/apps/explorer/lib/explorer/chain/supply/rsk.ex index 27a13bfdd2..eb7c4571cd 100644 --- a/apps/explorer/lib/explorer/chain/supply/rsk.ex +++ b/apps/explorer/lib/explorer/chain/supply/rsk.ex @@ -17,9 +17,7 @@ defmodule Explorer.Chain.Supply.RSK do @cache_name :rsk_balance @balance_key :balance - def market_cap(%{usd_value: nil}), do: Decimal.new(0) - - def market_cap(%{usd_value: usd_value}) do + def market_cap(%{usd_value: usd_value}) when not is_nil(usd_value) do btc = circulating() Decimal.mult(btc, usd_value)