diff --git a/CHANGELOG.md b/CHANGELOG.md index d6a8480e0d..33496ee991 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -10,7 +10,7 @@ - [#8040](https://github.com/blockscout/blockscout/pull/8040) - Resolve issue with Docker image for Mac M1/M2 - [#8060](https://github.com/blockscout/blockscout/pull/8060) - Fix eth_getLogs API endpoint -- [#8082](https://github.com/blockscout/blockscout/pull/8082) - Fix Rootstock charts API +- [#8082](https://github.com/blockscout/blockscout/pull/8082), [#8088](https://github.com/blockscout/blockscout/pull/8088) - Fix Rootstock charts API ### Chore diff --git a/apps/block_scout_web/lib/block_scout_web/controllers/api/v2/stats_controller.ex b/apps/block_scout_web/lib/block_scout_web/controllers/api/v2/stats_controller.ex index 921ed5c4bf..f85e5f54be 100644 --- a/apps/block_scout_web/lib/block_scout_web/controllers/api/v2/stats_controller.ex +++ b/apps/block_scout_web/lib/block_scout_web/controllers/api/v2/stats_controller.ex @@ -94,7 +94,7 @@ defmodule BlockScoutWeb.API.V2.StatsController do exchange_rate = Market.get_coin_exchange_rate() recent_market_history = Market.fetch_recent_history() - current_total_supply = available_supply(Chain.supply_for_days(), exchange_rate) + current_total_supply = MarketHistoryChartController.available_supply(Chain.supply_for_days(), exchange_rate) price_history_data = recent_market_history @@ -122,23 +122,4 @@ defmodule BlockScoutWeb.API.V2.StatsController do available_supply: current_total_supply }) end - - defp available_supply(:ok, exchange_rate), do: exchange_rate.available_supply || 0 - - defp available_supply({:ok, supply_for_days}, _exchange_rate) do - supply_for_days - |> Jason.encode() - |> case do - {:ok, _data} -> - current_date = - supply_for_days - |> Map.keys() - |> Enum.max(Date) - - Map.get(supply_for_days, current_date) - - _ -> - nil - end - end end diff --git a/apps/block_scout_web/lib/block_scout_web/controllers/chain/market_history_chart_controller.ex b/apps/block_scout_web/lib/block_scout_web/controllers/chain/market_history_chart_controller.ex index 5ab997f4a9..a9816adcbd 100644 --- a/apps/block_scout_web/lib/block_scout_web/controllers/chain/market_history_chart_controller.ex +++ b/apps/block_scout_web/lib/block_scout_web/controllers/chain/market_history_chart_controller.ex @@ -29,16 +29,22 @@ defmodule BlockScoutWeb.Chain.MarketHistoryChartController do end end - defp available_supply(:ok, exchange_rate) do - to_string(exchange_rate.available_supply || 0) - end + def available_supply(:ok, exchange_rate), do: exchange_rate.available_supply || 0 - defp available_supply({:ok, supply_for_days}, _exchange_rate) do + def available_supply({:ok, supply_for_days}, _exchange_rate) do supply_for_days |> Jason.encode() |> case do - {:ok, data} -> data - _ -> [] + {:ok, _data} -> + current_date = + supply_for_days + |> Map.keys() + |> Enum.max(Date) + + Map.get(supply_for_days, current_date) + + _ -> + nil end end