diff --git a/apps/explorer_web/lib/explorer_web/templates/address/_responsive_hash.html.eex b/apps/explorer_web/lib/explorer_web/templates/address/_responsive_hash.html.eex index 7ff3c9d4df..8801b8a730 100644 --- a/apps/explorer_web/lib/explorer_web/templates/address/_responsive_hash.html.eex +++ b/apps/explorer_web/lib/explorer_web/templates/address/_responsive_hash.html.eex @@ -1,4 +1,4 @@ <%= @address_hash %> - <%= @address_hash |> to_string() |> String.slice(0..5) %>–<%= @address_hash |> to_string() |> String.slice(-6..-1) %> + <%= ExplorerWeb.AddressView.trimmed_hash(@address_hash) %> diff --git a/apps/explorer_web/lib/explorer_web/views/address_view.ex b/apps/explorer_web/lib/explorer_web/views/address_view.ex index 800c99cce0..cde119d3b7 100644 --- a/apps/explorer_web/lib/explorer_web/views/address_view.ex +++ b/apps/explorer_web/lib/explorer_web/views/address_view.ex @@ -1,7 +1,7 @@ defmodule ExplorerWeb.AddressView do use ExplorerWeb, :view - alias Explorer.Chain.{Address, Wei, SmartContract} + alias Explorer.Chain.{Address, Hash, SmartContract, Wei} alias Explorer.ExchangeRates.Token alias ExplorerWeb.ExchangeRates.USD @@ -63,5 +63,13 @@ defmodule ExplorerWeb.AddressView do end def smart_contract_verified?(%Address{smart_contract: %SmartContract{}}), do: true + def smart_contract_verified?(%Address{smart_contract: nil}), do: false + + def trimmed_hash(%Hash{} = hash) do + string_hash = to_string(hash) + "#{String.slice(string_hash, 0..5)}–#{String.slice(string_hash, -6..-1)}" + end + + def trimmed_hash(_), do: "" end