From e984bcbeaebbcb596bd8aa45df095fc4a6b7ba4b Mon Sep 17 00:00:00 2001 From: jimmay5469 Date: Fri, 13 Jul 2018 10:02:29 -0400 Subject: [PATCH] Extract trimmed_hash function for future reuse Co-authored-by: Stamates --- .../templates/address/_responsive_hash.html.eex | 2 +- .../lib/explorer_web/views/address_view.ex | 10 +++++++++- 2 files changed, 10 insertions(+), 2 deletions(-) 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