Extract trimmed_hash function for future reuse

Co-authored-by: Stamates <stamates@hotmail.com>
pull/395/head
jimmay5469 6 years ago
parent 04590a381d
commit e984bcbeae
  1. 2
      apps/explorer_web/lib/explorer_web/templates/address/_responsive_hash.html.eex
  2. 10
      apps/explorer_web/lib/explorer_web/views/address_view.ex

@ -1,4 +1,4 @@
<span class="<%= if @contract do %>contract-address<% end %>">
<span class="d-none d-md-none d-lg-inline"><%= @address_hash %></span>
<span class="d-md-block d-lg-none "><%= @address_hash |> to_string() |> String.slice(0..5) %>&ndash;<%= @address_hash |> to_string() |> String.slice(-6..-1) %></span>
<span class="d-md-block d-lg-none "><%= ExplorerWeb.AddressView.trimmed_hash(@address_hash) %></span>
</span>

@ -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

Loading…
Cancel
Save