diff --git a/apps/block_scout_web/assets/js/lib/market_history_chart.js b/apps/block_scout_web/assets/js/lib/market_history_chart.js index 7cc6527fcf..c863b6aa51 100644 --- a/apps/block_scout_web/assets/js/lib/market_history_chart.js +++ b/apps/block_scout_web/assets/js/lib/market_history_chart.js @@ -75,7 +75,11 @@ function getPriceData (marketHistoryData) { } function getMarketCapData (marketHistoryData, availableSupply) { - return marketHistoryData.map(({ date, closingPrice }) => ({x: date, y: closingPrice * availableSupply})) + if (availableSupply !== null && typeof availableSupply === 'object') { + return marketHistoryData.map(({ date, closingPrice }) => ({x: date, y: closingPrice * availableSupply[date]})) + } else { + return marketHistoryData.map(({ date, closingPrice }) => ({x: date, y: closingPrice * availableSupply})) + } } class MarketHistoryChart { @@ -100,18 +104,25 @@ class MarketHistoryChart { borderColor: sassVariables.secondary, lineTension: 0 } + this.availableSupply = availableSupply config.data.datasets = [this.price, this.marketCap] this.chart = new Chart(el, config) } update (availableSupply, marketHistoryData) { this.price.data = getPriceData(marketHistoryData) - this.marketCap.data = getMarketCapData(marketHistoryData, availableSupply) + if (this.availableSupply !== null && typeof this.availableSupply === 'object') { + const today = new Date().toJSON().slice(0, 10) + this.availableSupply[today] = availableSupply + this.marketCap.data = getMarketCapData(marketHistoryData, this.availableSupply) + } else { + this.marketCap.data = getMarketCapData(marketHistoryData, availableSupply) + } this.chart.update() } } export function createMarketHistoryChart (ctx) { - const availableSupply = ctx.dataset.available_supply + const availableSupply = JSON.parse(ctx.dataset.available_supply) const marketHistoryData = humps.camelizeKeys(JSON.parse(ctx.dataset.market_history_data)) return new MarketHistoryChart(ctx, availableSupply, marketHistoryData) diff --git a/apps/block_scout_web/lib/block_scout_web/controllers/chain_controller.ex b/apps/block_scout_web/lib/block_scout_web/controllers/chain_controller.ex index 6aa4cb7470..73bd85915e 100644 --- a/apps/block_scout_web/lib/block_scout_web/controllers/chain_controller.ex +++ b/apps/block_scout_web/lib/block_scout_web/controllers/chain_controller.ex @@ -40,6 +40,7 @@ defmodule BlockScoutWeb.ChainController do average_block_time: Chain.average_block_time(), blocks: blocks, exchange_rate: exchange_rate, + available_supply: available_supply(Chain.supply_for_days(30), exchange_rate), market_history_data: market_history_data, transaction_estimated_count: transaction_estimated_count, transactions: transactions @@ -78,4 +79,17 @@ defmodule BlockScoutWeb.ChainController do ) ) end + + defp available_supply(:ok, exchange_rate) do + to_string(exchange_rate.available_supply || 0) + end + + defp available_supply({:ok, supply_for_days}, _exchange_rate) do + supply_for_days + |> Jason.encode() + |> case do + {:ok, data} -> data + _ -> [] + end + end end diff --git a/apps/block_scout_web/lib/block_scout_web/templates/chain/show.html.eex b/apps/block_scout_web/lib/block_scout_web/templates/chain/show.html.eex index ff0c15f50e..c0f4051811 100644 --- a/apps/block_scout_web/lib/block_scout_web/templates/chain/show.html.eex +++ b/apps/block_scout_web/lib/block_scout_web/templates/chain/show.html.eex @@ -3,7 +3,7 @@
- +
diff --git a/apps/block_scout_web/lib/block_scout_web/templates/internal_transaction/_tile.html.eex b/apps/block_scout_web/lib/block_scout_web/templates/internal_transaction/_tile.html.eex index 0834820c48..40d0e981c0 100644 --- a/apps/block_scout_web/lib/block_scout_web/templates/internal_transaction/_tile.html.eex +++ b/apps/block_scout_web/lib/block_scout_web/templates/internal_transaction/_tile.html.eex @@ -2,6 +2,7 @@
<%= gettext("Internal Transaction") %> + (<%= type(@internal_transaction) %>)
<%= render BlockScoutWeb.TransactionView, "_link.html", transaction_hash: @internal_transaction.transaction_hash %> diff --git a/apps/block_scout_web/lib/block_scout_web/templates/layout/_topnav.html.eex b/apps/block_scout_web/lib/block_scout_web/templates/layout/_topnav.html.eex index 89e7b8ac61..2257a48876 100644 --- a/apps/block_scout_web/lib/block_scout_web/templates/layout/_topnav.html.eex +++ b/apps/block_scout_web/lib/block_scout_web/templates/layout/_topnav.html.eex @@ -15,7 +15,7 @@ <%= gettext("Blocks") %> -