fix long contracts names

pull/2883/head
Max Alekseenko 5 years ago
parent 047bf5bdef
commit 8b5226dbf6
  1. 6
      apps/block_scout_web/lib/block_scout_web/templates/address/_responsive_hash.html.eex
  2. 4
      apps/block_scout_web/lib/block_scout_web/templates/address/overview.html.eex
  3. 7
      apps/block_scout_web/lib/block_scout_web/views/address_view.ex

@ -3,7 +3,11 @@
<%= if @use_custom_tooltip == true do %> <%= if @use_custom_tooltip == true do %>
<span><%= name %> (<%= short_hash(@address) %>...)</span> <span><%= name %> (<%= short_hash(@address) %>...)</span>
<% else %> <% else %>
<span data-toggle="tooltip" data-placement="top" title="<%= @address %>"><%= name %> (<%= short_hash(@address) %>...)</span> <span data-toggle="tooltip" data-placement="top" title="<%= @address %>">
<span class="d-none d-md-none d-lg-inline-block d-xl-inline"><%= short_contract_name(name, 30) %></span>
<span class="d-inline-block d-md-inline-block d-lg-none d-xl-none"><%= short_contract_name(name, 10) %></span>
<span> (<%= BlockScoutWeb.AddressView.trimmed_hash(@address.hash) %>)</span>
</span>
<% end %> <% end %>
<% else %> <% else %>
<%= if assigns[:truncate] do %> <%= if assigns[:truncate] do %>

@ -62,7 +62,9 @@
<h3 class="address-detail-hash-title <%= if BlockScoutWeb.AddressView.contract?(@address) do %>contract-address<% end %>" data-test="address_detail_hash"><%= @address %></h3> <h3 class="address-detail-hash-title <%= if BlockScoutWeb.AddressView.contract?(@address) do %>contract-address<% end %>" data-test="address_detail_hash"><%= @address %></h3>
<div class="d-flex flex-column flex-lg-row justify-content-start text-muted"> <div class="d-flex flex-column flex-lg-row justify-content-start text-muted">
<%= if address_name = primary_name(@address) do %> <%= if address_name = primary_name(@address) do %>
<strong class="mr-4 mb-2 text-dark"><%= address_name %></strong> <strong class="mr-4 mb-2 text-dark" title="<%= address_name %>">
<%= short_contract_name(address_name, 30) %>
</strong>
<% end %> <% end %>
<%= if @address.token do %> <%= if @address.token do %>
<span class="mr-4 mb-2"> <span class="mr-4 mb-2">

@ -323,6 +323,13 @@ defmodule BlockScoutWeb.AddressView do
"0x" <> short_address "0x" <> short_address
end end
def short_contract_name(name, max_length) do
part_length = Kernel.trunc(max_length / 4)
if (String.length(name) <= max_length),
do: name,
else: "#{String.slice(name, 0, max_length - part_length)}..#{String.slice(name, -part_length, part_length)}"
end
def address_page_title(address) do def address_page_title(address) do
cond do cond do
smart_contract_verified?(address) -> "#{address.smart_contract.name} (#{to_string(address)})" smart_contract_verified?(address) -> "#{address.smart_contract.name} (#{to_string(address)})"

Loading…
Cancel
Save