diff --git a/apps/block_scout_web/lib/block_scout_web/templates/internal_transaction/_tile.html.eex b/apps/block_scout_web/lib/block_scout_web/templates/internal_transaction/_tile.html.eex index 0834820c48..40d0e981c0 100644 --- a/apps/block_scout_web/lib/block_scout_web/templates/internal_transaction/_tile.html.eex +++ b/apps/block_scout_web/lib/block_scout_web/templates/internal_transaction/_tile.html.eex @@ -2,6 +2,7 @@
<%= gettext("Internal Transaction") %> + (<%= type(@internal_transaction) %>)
<%= render BlockScoutWeb.TransactionView, "_link.html", transaction_hash: @internal_transaction.transaction_hash %> diff --git a/apps/block_scout_web/lib/block_scout_web/views/internal_transaction_view.ex b/apps/block_scout_web/lib/block_scout_web/views/internal_transaction_view.ex index ea987e78e1..e1dbbfd7f3 100644 --- a/apps/block_scout_web/lib/block_scout_web/views/internal_transaction_view.ex +++ b/apps/block_scout_web/lib/block_scout_web/views/internal_transaction_view.ex @@ -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 diff --git a/apps/block_scout_web/test/block_scout_web/views/internal_transaction_view_test.exs b/apps/block_scout_web/test/block_scout_web/views/internal_transaction_view_test.exs new file mode 100644 index 0000000000..2d7554b7d8 --- /dev/null +++ b/apps/block_scout_web/test/block_scout_web/views/internal_transaction_view_test.exs @@ -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