Generalize available_supply across application versions

pull/8088/head
Viktor Baranov 1 year ago
parent 643c4eb071
commit f91f53e8ba
  1. 2
      CHANGELOG.md
  2. 21
      apps/block_scout_web/lib/block_scout_web/controllers/api/v2/stats_controller.ex
  3. 18
      apps/block_scout_web/lib/block_scout_web/controllers/chain/market_history_chart_controller.ex

@ -10,7 +10,7 @@
- [#8040](https://github.com/blockscout/blockscout/pull/8040) - Resolve issue with Docker image for Mac M1/M2 - [#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 - [#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 ### Chore

@ -94,7 +94,7 @@ defmodule BlockScoutWeb.API.V2.StatsController do
exchange_rate = Market.get_coin_exchange_rate() exchange_rate = Market.get_coin_exchange_rate()
recent_market_history = Market.fetch_recent_history() 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 = price_history_data =
recent_market_history recent_market_history
@ -122,23 +122,4 @@ defmodule BlockScoutWeb.API.V2.StatsController do
available_supply: current_total_supply available_supply: current_total_supply
}) })
end 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 end

@ -29,16 +29,22 @@ defmodule BlockScoutWeb.Chain.MarketHistoryChartController do
end end
end end
defp available_supply(:ok, exchange_rate) do def available_supply(:ok, exchange_rate), do: exchange_rate.available_supply || 0
to_string(exchange_rate.available_supply || 0)
end
defp available_supply({:ok, supply_for_days}, _exchange_rate) do def available_supply({:ok, supply_for_days}, _exchange_rate) do
supply_for_days supply_for_days
|> Jason.encode() |> Jason.encode()
|> case do |> 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
end end

Loading…
Cancel
Save