diff --git a/apps/block_scout_web/lib/block_scout_web/templates/tokens/overview/_tabs.html.eex b/apps/block_scout_web/lib/block_scout_web/templates/tokens/overview/_tabs.html.eex
index b2ca5f3d18..ac7d9fce2a 100644
--- a/apps/block_scout_web/lib/block_scout_web/templates/tokens/overview/_tabs.html.eex
+++ b/apps/block_scout_web/lib/block_scout_web/templates/tokens/overview/_tabs.html.eex
@@ -8,15 +8,6 @@
) %>
- <%= if TransferView.smart_contract_with_read_only_functions?(@token) do %>
-
- <%= link(
- gettext("Read Contract"),
- to: token_read_contract_path(@conn, :index, @token.contract_address_hash),
- class: "nav-link #{tab_status("read_contract", @conn.request_path)}")%>
-
- <% end %>
-
<%= link(
gettext("Token Holders"),
@@ -35,6 +26,15 @@
) %>
<% end %>
+
+ <%= 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: "nav-link #{tab_status("read_contract", @conn.request_path)}")%>
+
+ <% end %>
@@ -55,12 +55,7 @@
class: "dropdown-item #{tab_status("token_transfers", @conn.request_path)}",
to: token_path(@conn, :show, @token.contract_address_hash)
) %>
- <%= if TransferView.smart_contract_with_read_only_functions?(@token) do %>
- <%= link(
- gettext("Read Contract"),
- to: "#",
- class: "dropdown-item #{tab_status("read_contract", @conn.request_path)}")%>
- <% end %>
+
<%= link(
gettext("Token Holders"),
class: "dropdown-item #{tab_status("token_holders", @conn.request_path)}",
@@ -74,6 +69,13 @@
to: token_inventory_path(@conn, :index, @token.contract_address_hash)
) %>
<% end %>
+
+ <%= if smart_contract_with_read_only_functions?(@token) do %>
+ <%= link(
+ gettext("Read Contract"),
+ to: "#",
+ class: "dropdown-item #{tab_status("read_contract", @conn.request_path)}")%>
+ <% end %>
diff --git a/apps/block_scout_web/lib/block_scout_web/views/tokens/overview_view.ex b/apps/block_scout_web/lib/block_scout_web/views/tokens/overview_view.ex
index f36bca8b80..f8fdfb867b 100644
--- a/apps/block_scout_web/lib/block_scout_web/views/tokens/overview_view.ex
+++ b/apps/block_scout_web/lib/block_scout_web/views/tokens/overview_view.ex
@@ -1,8 +1,7 @@
defmodule BlockScoutWeb.Tokens.OverviewView do
use BlockScoutWeb, :view
- alias Explorer.Chain.Token
- alias BlockScoutWeb.Tokens.TransferView
+ alias Explorer.Chain.{Address, SmartContract, Token}
@tabs ["token_transfers", "token_holders", "read_contract", "inventory"]
@@ -38,4 +37,12 @@ defmodule BlockScoutWeb.Tokens.OverviewView do
def display_inventory?(%Token{type: "ERC-721"}), do: true
def display_inventory?(_), do: false
+
+ 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
diff --git a/apps/block_scout_web/lib/block_scout_web/views/tokens/transfer_view.ex b/apps/block_scout_web/lib/block_scout_web/views/tokens/transfer_view.ex
index 09944bcd03..cf002200e4 100644
--- a/apps/block_scout_web/lib/block_scout_web/views/tokens/transfer_view.ex
+++ b/apps/block_scout_web/lib/block_scout_web/views/tokens/transfer_view.ex
@@ -1,14 +1,5 @@
defmodule BlockScoutWeb.Tokens.TransferView do
use BlockScoutWeb, :view
- alias Explorer.Chain.{Address, SmartContract, Token}
alias BlockScoutWeb.Tokens.OverviewView
-
- 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
diff --git a/apps/block_scout_web/test/block_scout_web/views/tokens/overview_view_test.exs b/apps/block_scout_web/test/block_scout_web/views/tokens/overview_view_test.exs
index 22f1e81299..4ac295a710 100644
--- a/apps/block_scout_web/test/block_scout_web/views/tokens/overview_view_test.exs
+++ b/apps/block_scout_web/test/block_scout_web/views/tokens/overview_view_test.exs
@@ -78,4 +78,62 @@ defmodule BlockScoutWeb.Tokens.OverviewViewTest do
assert OverviewView.display_inventory?(token) == false
end
end
+
+ describe "smart_contract_with_read_only_functions?/1" do
+ test "returns true when abi has read only functions" do
+ smart_contract =
+ insert(
+ :smart_contract,
+ abi: [
+ %{
+ "constant" => true,
+ "inputs" => [],
+ "name" => "get",
+ "outputs" => [%{"name" => "", "type" => "uint256"}],
+ "payable" => false,
+ "stateMutability" => "view",
+ "type" => "function"
+ }
+ ]
+ )
+
+ address = insert(:address, smart_contract: smart_contract)
+
+ token = insert(:token, contract_address: address)
+
+ assert OverviewView.smart_contract_with_read_only_functions?(token)
+ end
+
+ test "returns false when there is no read only functions" do
+ smart_contract =
+ insert(
+ :smart_contract,
+ abi: [
+ %{
+ "constant" => false,
+ "inputs" => [%{"name" => "x", "type" => "uint256"}],
+ "name" => "set",
+ "outputs" => [],
+ "payable" => false,
+ "stateMutability" => "nonpayable",
+ "type" => "function"
+ }
+ ]
+ )
+
+ address = insert(:address, smart_contract: smart_contract)
+
+ token = insert(:token, contract_address: address)
+
+ refute OverviewView.smart_contract_with_read_only_functions?(token)
+ end
+
+ test "returns false when smart contract is not verified" do
+ address = insert(:address, smart_contract: nil)
+
+ token = insert(:token, contract_address: address)
+
+ refute OverviewView.smart_contract_with_read_only_functions?(token)
+ end
+ end
end
diff --git a/apps/block_scout_web/test/block_scout_web/views/tokens/transfer_view_test.exs b/apps/block_scout_web/test/block_scout_web/views/tokens/transfer_view_test.exs
index a8a1c726ce..147c34c861 100644
--- a/apps/block_scout_web/test/block_scout_web/views/tokens/transfer_view_test.exs
+++ b/apps/block_scout_web/test/block_scout_web/views/tokens/transfer_view_test.exs
@@ -2,62 +2,4 @@ defmodule BlockScoutWeb.Tokens.TransferViewTest do
use BlockScoutWeb.ConnCase, async: true
alias BlockScoutWeb.Tokens.TransferView
-
- describe "smart_contract_with_read_only_functions?/1" do
- test "returns true when abi has read only functions" do
- smart_contract =
- insert(
- :smart_contract,
- abi: [
- %{
- "constant" => true,
- "inputs" => [],
- "name" => "get",
- "outputs" => [%{"name" => "", "type" => "uint256"}],
- "payable" => false,
- "stateMutability" => "view",
- "type" => "function"
- }
- ]
- )
-
- address = insert(:address, smart_contract: smart_contract)
-
- token = insert(:token, contract_address: address)
-
- assert TransferView.smart_contract_with_read_only_functions?(token)
- end
-
- test "returns false when there is no read only functions" do
- smart_contract =
- insert(
- :smart_contract,
- abi: [
- %{
- "constant" => false,
- "inputs" => [%{"name" => "x", "type" => "uint256"}],
- "name" => "set",
- "outputs" => [],
- "payable" => false,
- "stateMutability" => "nonpayable",
- "type" => "function"
- }
- ]
- )
-
- address = insert(:address, smart_contract: smart_contract)
-
- token = insert(:token, contract_address: address)
-
- refute TransferView.smart_contract_with_read_only_functions?(token)
- end
-
- test "returns false when smart contract is not verified" do
- address = insert(:address, smart_contract: nil)
-
- token = insert(:token, contract_address: address)
-
- refute TransferView.smart_contract_with_read_only_functions?(token)
- end
- end
end