Add type to Internal Transaction tile

Add a helper function to Internal Transaction view to get the type to be
displayed. When it is an Internal Transaction of type `:call`, show the
`:call_type` instead.
pull/955/head
Lucas Narciso 6 years ago
parent e4e79adea1
commit 955db36c42
No known key found for this signature in database
GPG Key ID: 9E89F4CF3FBAB001
  1. 1
      apps/block_scout_web/lib/block_scout_web/templates/internal_transaction/_tile.html.eex
  2. 31
      apps/block_scout_web/lib/block_scout_web/views/internal_transaction_view.ex
  3. 40
      apps/block_scout_web/test/block_scout_web/views/internal_transaction_view_test.exs

@ -2,6 +2,7 @@
<div class="row">
<div class="col-md-2 d-flex flex-row flex-md-column align-items-left justify-content-start justify-content-lg-center mb-1 mb-md-0 pl-md-4">
<%= gettext("Internal Transaction") %>
<span>(<%= type(@internal_transaction) %>)</span>
</div>
<div class="col-md-7 col-lg-8 d-flex flex-column text-nowrap pr-2 pr-sm-2 pr-md-0">
<%= render BlockScoutWeb.TransactionView, "_link.html", transaction_hash: @internal_transaction.transaction_hash %>

@ -1,3 +1,34 @@
defmodule BlockScoutWeb.InternalTransactionView do
use BlockScoutWeb, :view
alias Explorer.Chain.InternalTransaction
import BlockScoutWeb.Gettext
@doc """
Returns the formatted string for the type of the internal transaction.
When the type is `call`, we return the formatted string for the call type.
Examples:
iex> BlockScoutWeb.InternalTransactionView.type(%Explorer.Chain.InternalTransaction{type: :reward})
"Reward"
iex> BlockScoutWeb.InternalTransactionView.type(%Explorer.Chain.InternalTransaction{type: :call, call_type: :delegatecall})
"Delegate Call"
"""
def type(%InternalTransaction{type: :call, call_type: call_type}) do
formatted_type(call_type)
end
def type(%InternalTransaction{type: type}) do
formatted_type(type)
end
defp formatted_type(:call), do: gettext("Call")
defp formatted_type(:delegatecall), do: gettext("Delegate Call")
defp formatted_type(:create), do: gettext("Create")
defp formatted_type(:suicide), do: gettext("Suicide")
defp formatted_type(:reward), do: gettext("Reward")
end

@ -0,0 +1,40 @@
defmodule BlockScoutWeb.InternalTransactionViewTest do
use BlockScoutWeb.ConnCase, async: true
alias BlockScoutWeb.InternalTransactionView
alias Explorer.Chain.InternalTransaction
doctest BlockScoutWeb.InternalTransactionView
describe "type/1" do
test "returns the correct string when the type is :call and call type is :call" do
internal_transaction = %InternalTransaction{type: :call, call_type: :call}
assert InternalTransactionView.type(internal_transaction) == "Call"
end
test "returns the correct string when the type is :call and call type is :delegate_call" do
internal_transaction = %InternalTransaction{type: :call, call_type: :delegatecall}
assert InternalTransactionView.type(internal_transaction) == "Delegate Call"
end
test "returns the correct string when the type is :create" do
internal_transaction = %InternalTransaction{type: :create}
assert InternalTransactionView.type(internal_transaction) == "Create"
end
test "returns the correct string when the type is :suicide" do
internal_transaction = %InternalTransaction{type: :suicide}
assert InternalTransactionView.type(internal_transaction) == "Suicide"
end
test "returns the correct string when the type is :reward" do
internal_transaction = %InternalTransaction{type: :reward}
assert InternalTransactionView.type(internal_transaction) == "Reward"
end
end
end
Loading…
Cancel
Save