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
parent
e4e79adea1
commit
955db36c42
@ -1,3 +1,34 @@ |
|||||||
defmodule BlockScoutWeb.InternalTransactionView do |
defmodule BlockScoutWeb.InternalTransactionView do |
||||||
use BlockScoutWeb, :view |
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 |
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…
Reference in new issue