update metadata in controller

pull/1691/head
Ayrat Badykov 6 years ago
parent 11a288120f
commit 8d083f5415
No known key found for this signature in database
GPG Key ID: B44668E265E9396F
  1. 15
      apps/block_scout_web/lib/block_scout_web/controllers/tokens/holder_controller.ex

@ -3,6 +3,7 @@ defmodule BlockScoutWeb.Tokens.HolderController do
alias BlockScoutWeb.Tokens.HolderView alias BlockScoutWeb.Tokens.HolderView
alias Explorer.{Chain, Market} alias Explorer.{Chain, Market}
alias Indexer.Token.MetadataUpdater
alias Phoenix.View alias Phoenix.View
import BlockScoutWeb.Chain, import BlockScoutWeb.Chain,
@ -18,6 +19,8 @@ defmodule BlockScoutWeb.Tokens.HolderController do
token_balances <- Chain.fetch_token_holders_from_token_hash(address_hash, paging_options(params)) do token_balances <- Chain.fetch_token_holders_from_token_hash(address_hash, paging_options(params)) do
{token_balances_paginated, next_page} = split_list_by_page(token_balances) {token_balances_paginated, next_page} = split_list_by_page(token_balances)
check_if_percentage_is_correct(token_balances, token)
next_page_path = next_page_path =
case next_page_params(next_page, token_balances_paginated, params) do case next_page_params(next_page, token_balances_paginated, params) do
nil -> nil ->
@ -61,4 +64,16 @@ defmodule BlockScoutWeb.Tokens.HolderController do
not_found(conn) not_found(conn)
end end
end end
defp check_if_percentage_is_correct(token_balances, token) do
value_from_balances =
Enum.reduce(token_balances, Decimal.new(0), fn balance, acc ->
Decimal.add(balance.value, acc)
end)
if !(Decimal.cmp(token.total_supply, value_from_balances) == :eq ||
Decimal.cmp(token.total_supply, value_from_balances) == :gt) do
Task.start(MetadataUpdater, :update_metadata, [token])
end
end
end end

Loading…
Cancel
Save