Use view function for displaying addresses on transaction detail overview

pull/688/head
Stamates 6 years ago
parent 6b8fca4aaf
commit 849306a95b
  1. 10
      apps/block_scout_web/lib/block_scout_web/templates/transaction/overview.html.eex
  2. 58
      apps/block_scout_web/lib/block_scout_web/views/address_view.ex

@ -14,14 +14,10 @@
</div> </div>
<h1 class="card-title"><%= gettext "Transaction Details" %> </h1> <h1 class="card-title"><%= gettext "Transaction Details" %> </h1>
<h3 data-test="transaction_detail_hash"><%= @transaction %> </h3> <h3 data-test="transaction_detail_hash"><%= @transaction %> </h3>
<span class="d-block mb-2"> <span class="d-block mb-2 text-muted">
<%= render BlockScoutWeb.AddressView, "_link.html", address_hash: @transaction.from_address_hash, contract: BlockScoutWeb.AddressView.contract?(@transaction.from_address) %> <%= BlockScoutWeb.AddressView.display_address_hash(assigns[:current_address], @transaction.from_address) %>
<span class="text-muted"> &rarr; </span> <span class="text-muted"> &rarr; </span>
<%= if @transaction.to_address_hash do %> <%= BlockScoutWeb.AddressView.display_address_hash(assigns[:current_address], @transaction.to_address) %>
<%= render BlockScoutWeb.AddressView, "_link.html", address_hash: @transaction.to_address_hash, contract: BlockScoutWeb.AddressView.contract?(@transaction.to_address) %>
<% else %>
<%= gettext("Contract Address Pending") %>
<% end %>
</span> </span>
<div class="d-flex flex-row justify-content-start text-muted"> <div class="d-flex flex-row justify-content-start text-muted">
<span class="mr-4 text-<%= BlockScoutWeb.TransactionView.type_suffix(@transaction) %>"><%= BlockScoutWeb.TransactionView.transaction_display_type(@transaction) %></span> <span class="mr-4 text-<%= BlockScoutWeb.TransactionView.type_suffix(@transaction) %>"><%= BlockScoutWeb.TransactionView.transaction_display_type(@transaction) %></span>

@ -34,36 +34,10 @@ defmodule BlockScoutWeb.AddressView do
def contract?(nil), do: true def contract?(nil), do: true
def hash(%Address{hash: hash}) do
to_string(hash)
end
def qr_code(%Address{hash: hash}) do
hash
|> to_string()
|> QRCode.to_png()
|> Base.encode64()
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: ""
def smart_contract_with_read_only_functions?(%Address{smart_contract: %SmartContract{}} = address) do
Enum.any?(address.smart_contract.abi, & &1["constant"])
end
def smart_contract_with_read_only_functions?(%Address{smart_contract: nil}), do: false
def display_address_hash(current_address, target_address, truncate \\ false) def display_address_hash(current_address, target_address, truncate \\ false)
def display_address_hash(nil, nil, _truncate), do: gettext("Contract Address Pending")
def display_address_hash(nil, target_address, truncate) do def display_address_hash(nil, target_address, truncate) do
render( render(
"_link.html", "_link.html",
@ -90,4 +64,32 @@ defmodule BlockScoutWeb.AddressView do
) )
end end
end end
def hash(%Address{hash: hash}) do
to_string(hash)
end
def qr_code(%Address{hash: hash}) do
hash
|> to_string()
|> QRCode.to_png()
|> Base.encode64()
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: ""
def smart_contract_with_read_only_functions?(%Address{smart_contract: %SmartContract{}} = address) do
Enum.any?(address.smart_contract.abi, & &1["constant"])
end
def smart_contract_with_read_only_functions?(%Address{smart_contract: nil}), do: false
end end

Loading…
Cancel
Save