Display shortened addresses in named address links (#839)

* Display shortened addresses in named address links
* Simplify HTML for named address links
pull/844/head
Alex Garibay 6 years ago committed by GitHub
parent f6a24e7b0b
commit b738291a5c
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 3
      apps/block_scout_web/lib/block_scout_web/templates/address/_responsive_hash.html.eex
  2. 10
      apps/block_scout_web/lib/block_scout_web/views/address_view.ex
  3. 8
      apps/block_scout_web/test/block_scout_web/views/address_view_test.exs

@ -1,7 +1,6 @@
<span class="<%= if @contract do %>contract-address<% end %>" data-address-hash="<%= @address.hash %>">
<%= if name = primary_name(@address) do %>
<span class="d-none d-md-none d-lg-inline" data-toggle="tooltip" data-placement="top" title="<%= @address.hash %>"><%= name %></span>
<span class="d-md-inline-block d-lg-none " data-toggle="tooltip" data-placement="top" title="<%= @address.hash %>"><%= name %></span>
<span data-toggle="tooltip" data-placement="top" title="<%= @address.hash %>"><%= name %> (<%= short_hash(@address) %>...)</span>
<% else %>
<%= if assigns[:truncate] do %>
<%= BlockScoutWeb.AddressView.trimmed_hash(@address.hash) %>

@ -219,4 +219,14 @@ defmodule BlockScoutWeb.AddressView do
defp tab_name(["internal_transactions"]), do: gettext("Internal Transactions")
defp tab_name(["contracts"]), do: gettext("Code")
defp tab_name(["read_contract"]), do: gettext("Read Contract")
def short_hash(%Address{hash: hash}) do
<<
"0x",
short_address::binary-size(6),
_rest::binary
>> = to_string(hash)
"0x" <> short_address
end
end

@ -321,4 +321,12 @@ defmodule BlockScoutWeb.AddressViewTest do
assert AddressView.current_tab_name(path) == "Read Contract"
end
end
describe "short_hash/1" do
test "returns a shortened hash of 6 hex characters" do
address = insert(:address)
assert "0x" <> short_hash = AddressView.short_hash(address)
assert String.length(short_hash) == 6
end
end
end

Loading…
Cancel
Save