|
|
@ -1,7 +1,8 @@ |
|
|
|
defmodule BlockScoutWeb.AddressTokenBalanceController do |
|
|
|
defmodule BlockScoutWeb.AddressTokenBalanceController do |
|
|
|
use BlockScoutWeb, :controller |
|
|
|
use BlockScoutWeb, :controller |
|
|
|
|
|
|
|
|
|
|
|
alias BlockScoutWeb.AccessHelpers |
|
|
|
import BlockScoutWeb.AddressView, only: [from_address_hash: 1] |
|
|
|
|
|
|
|
alias BlockScoutWeb.{AccessHelpers, CustomContractsHelpers} |
|
|
|
alias Explorer.{Chain, Market} |
|
|
|
alias Explorer.{Chain, Market} |
|
|
|
|
|
|
|
|
|
|
|
def index(conn, %{"address_id" => address_hash_string} = params) do |
|
|
|
def index(conn, %{"address_id" => address_hash_string} = params) do |
|
|
@ -12,18 +13,50 @@ defmodule BlockScoutWeb.AddressTokenBalanceController do |
|
|
|
|> Chain.fetch_last_token_balances() |
|
|
|
|> Chain.fetch_last_token_balances() |
|
|
|
|> Market.add_price() |
|
|
|
|> Market.add_price() |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
circles_addresses_list = CustomContractsHelpers.get_custom_addresses_list(:circles_addresses) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
circles_total_balance = |
|
|
|
|
|
|
|
if Enum.count(circles_addresses_list) > 0 do |
|
|
|
|
|
|
|
token_balances |
|
|
|
|
|
|
|
|> Enum.reduce(Decimal.new(0), fn token_balance, acc_balance -> |
|
|
|
|
|
|
|
{:ok, token_address} = Chain.hash_to_address(token_balance.address_hash) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
created_from_address_hash = |
|
|
|
|
|
|
|
if from_address_hash(token_address), |
|
|
|
|
|
|
|
do: "0x" <> Base.encode16(from_address_hash(token_address).bytes, case: :lower), |
|
|
|
|
|
|
|
else: nil |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if Enum.member?(circles_addresses_list, created_from_address_hash) && token_balance.token.name == "Circles" && |
|
|
|
|
|
|
|
token_balance.token.symbol == "CRC" do |
|
|
|
|
|
|
|
Decimal.add(acc_balance, token_balance.value) |
|
|
|
|
|
|
|
else |
|
|
|
|
|
|
|
acc_balance |
|
|
|
|
|
|
|
end |
|
|
|
|
|
|
|
end) |
|
|
|
|
|
|
|
else |
|
|
|
|
|
|
|
Decimal.new(0) |
|
|
|
|
|
|
|
end |
|
|
|
|
|
|
|
|
|
|
|
case AccessHelpers.restricted_access?(address_hash_string, params) do |
|
|
|
case AccessHelpers.restricted_access?(address_hash_string, params) do |
|
|
|
{:ok, false} -> |
|
|
|
{:ok, false} -> |
|
|
|
conn |
|
|
|
conn |
|
|
|
|> put_status(200) |
|
|
|
|> put_status(200) |
|
|
|
|> put_layout(false) |
|
|
|
|> put_layout(false) |
|
|
|
|> render("_token_balances.html", address_hash: address_hash, token_balances: token_balances) |
|
|
|
|> render("_token_balances.html", |
|
|
|
|
|
|
|
address_hash: address_hash, |
|
|
|
|
|
|
|
token_balances: token_balances, |
|
|
|
|
|
|
|
circles_total_balance: circles_total_balance |
|
|
|
|
|
|
|
) |
|
|
|
|
|
|
|
|
|
|
|
_ -> |
|
|
|
_ -> |
|
|
|
conn |
|
|
|
conn |
|
|
|
|> put_status(200) |
|
|
|
|> put_status(200) |
|
|
|
|> put_layout(false) |
|
|
|
|> put_layout(false) |
|
|
|
|> render("_token_balances.html", address_hash: address_hash, token_balances: []) |
|
|
|
|> render("_token_balances.html", |
|
|
|
|
|
|
|
address_hash: address_hash, |
|
|
|
|
|
|
|
token_balances: [], |
|
|
|
|
|
|
|
circles_total_balance: Decimal.new(0) |
|
|
|
|
|
|
|
) |
|
|
|
end |
|
|
|
end |
|
|
|
else |
|
|
|
else |
|
|
|
_ -> |
|
|
|
_ -> |
|
|
|