|
|
|
@ -1,6 +1,8 @@ |
|
|
|
|
defmodule BlockScoutWeb.Account.Api.V1.UserView do |
|
|
|
|
alias BlockScoutWeb.Account.Api.V1.AccountView |
|
|
|
|
alias Ecto.Changeset |
|
|
|
|
alias Explorer.Chain |
|
|
|
|
alias BlockScoutWeb.API.V2.Helper |
|
|
|
|
|
|
|
|
|
def render("message.json", assigns) do |
|
|
|
|
AccountView.render("message.json", assigns) |
|
|
|
@ -70,11 +72,14 @@ defmodule BlockScoutWeb.Account.Api.V1.UserView do |
|
|
|
|
end |
|
|
|
|
|
|
|
|
|
def prepare_watchlist_address(watchlist, exchange_rate) do |
|
|
|
|
address = get_address(watchlist.address_hash) |
|
|
|
|
|
|
|
|
|
%{ |
|
|
|
|
"id" => watchlist.id, |
|
|
|
|
"address" => Helper.address_with_info(nil, address, watchlist.address_hash), |
|
|
|
|
"address_hash" => watchlist.address_hash, |
|
|
|
|
"name" => watchlist.name, |
|
|
|
|
"address_balance" => if(watchlist.fetched_coin_balance, do: watchlist.fetched_coin_balance.value), |
|
|
|
|
"address_balance" => if(address && address.fetched_coin_balance, do: address.fetched_coin_balance.value), |
|
|
|
|
"exchange_rate" => exchange_rate.usd_value, |
|
|
|
|
"notification_settings" => %{ |
|
|
|
|
"native" => %{ |
|
|
|
@ -102,9 +107,12 @@ defmodule BlockScoutWeb.Account.Api.V1.UserView do |
|
|
|
|
end |
|
|
|
|
|
|
|
|
|
def prepare_custom_abi(custom_abi) do |
|
|
|
|
address = get_address(custom_abi.address_hash) |
|
|
|
|
|
|
|
|
|
%{ |
|
|
|
|
"id" => custom_abi.id, |
|
|
|
|
"contract_address_hash" => custom_abi.address_hash, |
|
|
|
|
"contract_address" => Helper.address_with_info(nil, address, custom_abi.address_hash), |
|
|
|
|
"name" => custom_abi.name, |
|
|
|
|
"abi" => custom_abi.abi |
|
|
|
|
} |
|
|
|
@ -115,7 +123,14 @@ defmodule BlockScoutWeb.Account.Api.V1.UserView do |
|
|
|
|
end |
|
|
|
|
|
|
|
|
|
def prepare_address_tag(address_tag) do |
|
|
|
|
%{"id" => address_tag.id, "address_hash" => address_tag.address_hash, "name" => address_tag.name} |
|
|
|
|
address = get_address(address_tag.address_hash) |
|
|
|
|
|
|
|
|
|
%{ |
|
|
|
|
"id" => address_tag.id, |
|
|
|
|
"address_hash" => address_tag.address_hash, |
|
|
|
|
"address" => Helper.address_with_info(nil, address, address_tag.address_hash), |
|
|
|
|
"name" => address_tag.name |
|
|
|
|
} |
|
|
|
|
end |
|
|
|
|
|
|
|
|
|
def prepare_transaction_tag(nil), do: nil |
|
|
|
@ -125,6 +140,11 @@ defmodule BlockScoutWeb.Account.Api.V1.UserView do |
|
|
|
|
end |
|
|
|
|
|
|
|
|
|
def prepare_public_tags_request(public_tags_request) do |
|
|
|
|
addresses = |
|
|
|
|
Enum.map(public_tags_request.addresses, fn address_hash -> |
|
|
|
|
Helper.address_with_info(nil, get_address(address_hash), address_hash) |
|
|
|
|
end) |
|
|
|
|
|
|
|
|
|
%{ |
|
|
|
|
"id" => public_tags_request.id, |
|
|
|
|
"full_name" => public_tags_request.full_name, |
|
|
|
@ -133,9 +153,17 @@ defmodule BlockScoutWeb.Account.Api.V1.UserView do |
|
|
|
|
"website" => public_tags_request.website, |
|
|
|
|
"tags" => public_tags_request.tags, |
|
|
|
|
"addresses" => public_tags_request.addresses, |
|
|
|
|
"addresses_with_info" => addresses, |
|
|
|
|
"additional_comment" => public_tags_request.additional_comment, |
|
|
|
|
"is_owner" => public_tags_request.is_owner, |
|
|
|
|
"submission_date" => public_tags_request.inserted_at |
|
|
|
|
} |
|
|
|
|
end |
|
|
|
|
|
|
|
|
|
defp get_address(address_hash) do |
|
|
|
|
case Chain.hash_to_address(address_hash, [necessity_by_association: %{:smart_contract => :optional}], false) do |
|
|
|
|
{:ok, address} -> address |
|
|
|
|
_ -> nil |
|
|
|
|
end |
|
|
|
|
end |
|
|
|
|
end |
|
|
|
|