diff --git a/apps/block_scout_web/lib/block_scout_web/templates/address/_metatags.html.eex b/apps/block_scout_web/lib/block_scout_web/templates/address/_metatags.html.eex new file mode 100644 index 0000000000..4e1824765e --- /dev/null +++ b/apps/block_scout_web/lib/block_scout_web/templates/address/_metatags.html.eex @@ -0,0 +1,15 @@ +<%= if assigns[:address] do %> + + <%= gettext( + "%{address} - %{subnetwork} Explorer", + address: BlockScoutWeb.AddressView.address_page_title(@address), + subnetwork: LayoutView.subnetwork_title() + ) %> + + "> + Explorer.coin() <> ", "<> LayoutView.network_title() %>"> +<% else %> + + <%= gettext "Top Accounts - %{subnetwork} Explorer", subnetwork: LayoutView.subnetwork_title() %> + +<% end %> diff --git a/apps/block_scout_web/lib/block_scout_web/templates/address/overview.html.eex b/apps/block_scout_web/lib/block_scout_web/templates/address/overview.html.eex index ad5f4c4ec9..01bfa54b55 100644 --- a/apps/block_scout_web/lib/block_scout_web/templates/address/overview.html.eex +++ b/apps/block_scout_web/lib/block_scout_web/templates/address/overview.html.eex @@ -23,7 +23,7 @@ <% end %> - <%= Cldr.Number.to_string!(@transaction_count, format: "#,###") %> + <%= Cldr.Number.to_string!(@transaction_count, format: "#,###") %> <%= gettext("Transactions") %> <%= if validator?(@validation_count) do %> diff --git a/apps/block_scout_web/lib/block_scout_web/templates/address_contract/_metatags.html.eex b/apps/block_scout_web/lib/block_scout_web/templates/address_contract/_metatags.html.eex new file mode 100644 index 0000000000..3ef2a67ca2 --- /dev/null +++ b/apps/block_scout_web/lib/block_scout_web/templates/address_contract/_metatags.html.eex @@ -0,0 +1 @@ +<%= render BlockScoutWeb.AddressView, "_metatags.html", conn: @conn, address: @address %> diff --git a/apps/block_scout_web/lib/block_scout_web/templates/address_internal_transaction/_metatags.html.eex b/apps/block_scout_web/lib/block_scout_web/templates/address_internal_transaction/_metatags.html.eex new file mode 100644 index 0000000000..3ef2a67ca2 --- /dev/null +++ b/apps/block_scout_web/lib/block_scout_web/templates/address_internal_transaction/_metatags.html.eex @@ -0,0 +1 @@ +<%= render BlockScoutWeb.AddressView, "_metatags.html", conn: @conn, address: @address %> diff --git a/apps/block_scout_web/lib/block_scout_web/templates/address_read_contract/_metatags.html.eex b/apps/block_scout_web/lib/block_scout_web/templates/address_read_contract/_metatags.html.eex new file mode 100644 index 0000000000..3ef2a67ca2 --- /dev/null +++ b/apps/block_scout_web/lib/block_scout_web/templates/address_read_contract/_metatags.html.eex @@ -0,0 +1 @@ +<%= render BlockScoutWeb.AddressView, "_metatags.html", conn: @conn, address: @address %> diff --git a/apps/block_scout_web/lib/block_scout_web/templates/address_token/_metatags.html.eex b/apps/block_scout_web/lib/block_scout_web/templates/address_token/_metatags.html.eex new file mode 100644 index 0000000000..3ef2a67ca2 --- /dev/null +++ b/apps/block_scout_web/lib/block_scout_web/templates/address_token/_metatags.html.eex @@ -0,0 +1 @@ +<%= render BlockScoutWeb.AddressView, "_metatags.html", conn: @conn, address: @address %> diff --git a/apps/block_scout_web/lib/block_scout_web/templates/address_token_transfer/_metatags.html.eex b/apps/block_scout_web/lib/block_scout_web/templates/address_token_transfer/_metatags.html.eex new file mode 100644 index 0000000000..3ef2a67ca2 --- /dev/null +++ b/apps/block_scout_web/lib/block_scout_web/templates/address_token_transfer/_metatags.html.eex @@ -0,0 +1 @@ +<%= render BlockScoutWeb.AddressView, "_metatags.html", conn: @conn, address: @address %> diff --git a/apps/block_scout_web/lib/block_scout_web/templates/address_transaction/_metatags.html.eex b/apps/block_scout_web/lib/block_scout_web/templates/address_transaction/_metatags.html.eex new file mode 100644 index 0000000000..3ef2a67ca2 --- /dev/null +++ b/apps/block_scout_web/lib/block_scout_web/templates/address_transaction/_metatags.html.eex @@ -0,0 +1 @@ +<%= render BlockScoutWeb.AddressView, "_metatags.html", conn: @conn, address: @address %> diff --git a/apps/block_scout_web/lib/block_scout_web/templates/address_validation/_metatags.html.eex b/apps/block_scout_web/lib/block_scout_web/templates/address_validation/_metatags.html.eex new file mode 100644 index 0000000000..3ef2a67ca2 --- /dev/null +++ b/apps/block_scout_web/lib/block_scout_web/templates/address_validation/_metatags.html.eex @@ -0,0 +1 @@ +<%= render BlockScoutWeb.AddressView, "_metatags.html", conn: @conn, address: @address %> diff --git a/apps/block_scout_web/lib/block_scout_web/views/address_view.ex b/apps/block_scout_web/lib/block_scout_web/views/address_view.ex index c536d52398..0e9cd57b7a 100644 --- a/apps/block_scout_web/lib/block_scout_web/views/address_view.ex +++ b/apps/block_scout_web/lib/block_scout_web/views/address_view.ex @@ -3,6 +3,7 @@ defmodule BlockScoutWeb.AddressView do alias Explorer.Chain alias Explorer.Chain.{Address, Hash, InternalTransaction, SmartContract, Token, TokenTransfer, Transaction, Wei} + alias BlockScoutWeb.LayoutView @dialyzer :no_match @@ -231,4 +232,12 @@ defmodule BlockScoutWeb.AddressView do "0x" <> short_address end + + def address_page_title(address) do + cond do + smart_contract_verified?(address) -> "#{address.smart_contract.name} (#{to_string(address)})" + contract?(address) -> "Contract #{to_string(address)}" + true -> "#{to_string(address)}" + end + end end diff --git a/apps/block_scout_web/test/block_scout_web/views/address_view_test.exs b/apps/block_scout_web/test/block_scout_web/views/address_view_test.exs index 41ac8a75a2..76bad2032f 100644 --- a/apps/block_scout_web/test/block_scout_web/views/address_view_test.exs +++ b/apps/block_scout_web/test/block_scout_web/views/address_view_test.exs @@ -316,4 +316,25 @@ defmodule BlockScoutWeb.AddressViewTest do assert String.length(short_hash) == 6 end end + + describe "address_page_title/1" do + test "uses the Smart Contract name when the contract is verified" do + smart_contract = build(:smart_contract, name: "POA") + address = build(:address, smart_contract: smart_contract) + + assert AddressView.address_page_title(address) == "POA (#{address.hash})" + end + + test "uses the string 'Contract' when it's a contract" do + address = build(:contract_address, smart_contract: nil) + + assert AddressView.address_page_title(address) == "Contract #{address.hash}" + end + + test "uses the address hash when it is not a contract" do + address = build(:address, smart_contract: nil) + + assert AddressView.address_page_title(address) == "#{address.hash}" + end + end end