From 471b905930fc6a42b19d7832be827bb5c8df260f Mon Sep 17 00:00:00 2001 From: Ayrat Badykov Date: Fri, 30 Aug 2019 12:43:46 +0300 Subject: [PATCH] add tabs --- .../tokens/instance/overview/_tabs.html.eex | 15 +++++++++++++++ .../views/tokens/instance/overview_view.ex | 10 +++++++++- 2 files changed, 24 insertions(+), 1 deletion(-) create mode 100644 apps/block_scout_web/lib/block_scout_web/templates/tokens/instance/overview/_tabs.html.eex diff --git a/apps/block_scout_web/lib/block_scout_web/templates/tokens/instance/overview/_tabs.html.eex b/apps/block_scout_web/lib/block_scout_web/templates/tokens/instance/overview/_tabs.html.eex new file mode 100644 index 0000000000..c026783b08 --- /dev/null +++ b/apps/block_scout_web/lib/block_scout_web/templates/tokens/instance/overview/_tabs.html.eex @@ -0,0 +1,15 @@ +
+ <%= link( + gettext("Token Transfers"), + class: "card-tab #{tab_status("token_transfers", @conn.request_path)}", + to: token_path(@conn, :show, @token.contract_address_hash) + ) + %> + <%= if smart_contract_with_read_only_functions?(@token) do %> + <%= link( + gettext("Read Contract"), + to: token_read_contract_path(@conn, :index, @token.contract_address_hash), + class: "card-tab #{tab_status("read_contract", @conn.request_path)}") + %> + <% end %> +
diff --git a/apps/block_scout_web/lib/block_scout_web/views/tokens/instance/overview_view.ex b/apps/block_scout_web/lib/block_scout_web/views/tokens/instance/overview_view.ex index bb5eca56f9..5574d7d727 100644 --- a/apps/block_scout_web/lib/block_scout_web/views/tokens/instance/overview_view.ex +++ b/apps/block_scout_web/lib/block_scout_web/views/tokens/instance/overview_view.ex @@ -1,8 +1,8 @@ defmodule BlockScoutWeb.Tokens.Instance.OverviewView do use BlockScoutWeb, :view - alias Explorer.Chain.Token alias BlockScoutWeb.CurrencyHelpers + alias Explorer.Chain.{Address, SmartContract, Token} def token_name?(%Token{name: nil}), do: false def token_name?(%Token{name: _}), do: true @@ -18,4 +18,12 @@ defmodule BlockScoutWeb.Tokens.Instance.OverviewView do price = token.usd_value Decimal.mult(tokens, price) end + + def smart_contract_with_read_only_functions?( + %Token{contract_address: %Address{smart_contract: %SmartContract{}}} = token + ) do + Enum.any?(token.contract_address.smart_contract.abi, & &1["constant"]) + end + + def smart_contract_with_read_only_functions?(%Token{contract_address: %Address{smart_contract: nil}}), do: false end