From 12e5da97cd37fa40c9d88ffc0db72a258fdcf27f Mon Sep 17 00:00:00 2001 From: Tim Mecklem Date: Tue, 19 Jun 2018 11:21:14 -0400 Subject: [PATCH 1/3] Show correct internal transaction type and contract link --- .../index.html.eex | 13 ++++++++++++- .../index.html.eex | 13 ++++++++++++- .../views/internal_transaction_view.ex | 5 +++++ .../views/internal_transaction_view_test.exs | 19 +++++++++++++++++++ 4 files changed, 48 insertions(+), 2 deletions(-) create mode 100644 apps/explorer_web/test/explorer_web/views/internal_transaction_view_test.exs diff --git a/apps/explorer_web/lib/explorer_web/templates/address_internal_transaction/index.html.eex b/apps/explorer_web/lib/explorer_web/templates/address_internal_transaction/index.html.eex index 602fd4326f..80db35c435 100644 --- a/apps/explorer_web/lib/explorer_web/templates/address_internal_transaction/index.html.eex +++ b/apps/explorer_web/lib/explorer_web/templates/address_internal_transaction/index.html.eex @@ -103,7 +103,18 @@ <%= render ExplorerWeb.AddressView, "_link.html", conn: @conn, address: internal_transaction.from_address %> - <%= render ExplorerWeb.AddressView, "_link.html", conn: @conn, address: internal_transaction.to_address %> + <%= if ExplorerWeb.InternalTransactionView.contract?(internal_transaction) do %> + + <%= link( + gettext("Contract Creation"), + class: "transaction__link", + "data-address-hash": internal_transaction.created_contract_address_hash, + to: address_path(ExplorerWeb.Endpoint, :show, @locale, internal_transaction.created_contract_address_hash), + title: internal_transaction.created_contract_address_hash + ) %> + <% else %> + <%= render ExplorerWeb.AddressView, "_link.html", conn: @conn, address: internal_transaction.to_address %> + <% end %> <%= ExplorerWeb.TransactionView.value(internal_transaction, include_label: false) %> diff --git a/apps/explorer_web/lib/explorer_web/templates/transaction_internal_transaction/index.html.eex b/apps/explorer_web/lib/explorer_web/templates/transaction_internal_transaction/index.html.eex index 34c4a9b2ec..c5b44b4d68 100644 --- a/apps/explorer_web/lib/explorer_web/templates/transaction_internal_transaction/index.html.eex +++ b/apps/explorer_web/lib/explorer_web/templates/transaction_internal_transaction/index.html.eex @@ -41,7 +41,18 @@ <%= render ExplorerWeb.AddressView, "_link.html", conn: @conn, address: internal_transaction.from_address %> - <%= render ExplorerWeb.AddressView, "_link.html", conn: @conn, address: internal_transaction.to_address %> + <%= if ExplorerWeb.InternalTransactionView.contract?(internal_transaction) do %> + + <%= link( + gettext("Contract Creation"), + class: "transaction__link", + "data-address-hash": internal_transaction.created_contract_address_hash, + to: address_path(ExplorerWeb.Endpoint, :show, @locale, internal_transaction.created_contract_address_hash), + title: internal_transaction.created_contract_address_hash + ) %> + <% else %> + <%= render ExplorerWeb.AddressView, "_link.html", conn: @conn, address: internal_transaction.to_address %> + <% end %> <%= ExplorerWeb.TransactionView.value(internal_transaction, include_label: false) %> <%= ExplorerWeb.TransactionView.gas(internal_transaction) %> diff --git a/apps/explorer_web/lib/explorer_web/views/internal_transaction_view.ex b/apps/explorer_web/lib/explorer_web/views/internal_transaction_view.ex index 5b82153dc0..68084933a4 100644 --- a/apps/explorer_web/lib/explorer_web/views/internal_transaction_view.ex +++ b/apps/explorer_web/lib/explorer_web/views/internal_transaction_view.ex @@ -1,4 +1,9 @@ defmodule ExplorerWeb.InternalTransactionView do use ExplorerWeb, :view @dialyzer :no_match + + alias Explorer.Chain.InternalTransaction + + def contract?(%InternalTransaction{type: :create}), do: true + def contract?(_), do: false end diff --git a/apps/explorer_web/test/explorer_web/views/internal_transaction_view_test.exs b/apps/explorer_web/test/explorer_web/views/internal_transaction_view_test.exs new file mode 100644 index 0000000000..ba118f5bd1 --- /dev/null +++ b/apps/explorer_web/test/explorer_web/views/internal_transaction_view_test.exs @@ -0,0 +1,19 @@ +defmodule ExplorerWeb.InternalTransactionViewTest do + use ExplorerWeb.ConnCase, async: true + + alias ExplorerWeb.InternalTransactionView + + describe "contract?/1" do + test "with internal transaction of type create returns true" do + internal_transaction = build(:internal_transaction_create) + + assert InternalTransactionView.contract?(internal_transaction) + end + + test "with non-create type internal transaction returns false" do + internal_transaction = build(:internal_transaction) + + refute InternalTransactionView.contract?(internal_transaction) + end + end +end From a90909b506002486365ae21c1a119aff052d5099 Mon Sep 17 00:00:00 2001 From: Tim Mecklem Date: Tue, 19 Jun 2018 14:14:25 -0400 Subject: [PATCH 2/3] Rename helper function to `create?` --- .../templates/address_internal_transaction/index.html.eex | 2 +- .../transaction_internal_transaction/index.html.eex | 2 +- .../lib/explorer_web/views/internal_transaction_view.ex | 4 ++-- .../explorer_web/views/internal_transaction_view_test.exs | 6 +++--- 4 files changed, 7 insertions(+), 7 deletions(-) diff --git a/apps/explorer_web/lib/explorer_web/templates/address_internal_transaction/index.html.eex b/apps/explorer_web/lib/explorer_web/templates/address_internal_transaction/index.html.eex index 80db35c435..713b18a161 100644 --- a/apps/explorer_web/lib/explorer_web/templates/address_internal_transaction/index.html.eex +++ b/apps/explorer_web/lib/explorer_web/templates/address_internal_transaction/index.html.eex @@ -103,7 +103,7 @@ <%= render ExplorerWeb.AddressView, "_link.html", conn: @conn, address: internal_transaction.from_address %> - <%= if ExplorerWeb.InternalTransactionView.contract?(internal_transaction) do %> + <%= if ExplorerWeb.InternalTransactionView.create?(internal_transaction) do %> <%= link( gettext("Contract Creation"), diff --git a/apps/explorer_web/lib/explorer_web/templates/transaction_internal_transaction/index.html.eex b/apps/explorer_web/lib/explorer_web/templates/transaction_internal_transaction/index.html.eex index c5b44b4d68..5d017d1d00 100644 --- a/apps/explorer_web/lib/explorer_web/templates/transaction_internal_transaction/index.html.eex +++ b/apps/explorer_web/lib/explorer_web/templates/transaction_internal_transaction/index.html.eex @@ -41,7 +41,7 @@ <%= render ExplorerWeb.AddressView, "_link.html", conn: @conn, address: internal_transaction.from_address %> - <%= if ExplorerWeb.InternalTransactionView.contract?(internal_transaction) do %> + <%= if ExplorerWeb.InternalTransactionView.create?(internal_transaction) do %> <%= link( gettext("Contract Creation"), diff --git a/apps/explorer_web/lib/explorer_web/views/internal_transaction_view.ex b/apps/explorer_web/lib/explorer_web/views/internal_transaction_view.ex index 68084933a4..c7972efa47 100644 --- a/apps/explorer_web/lib/explorer_web/views/internal_transaction_view.ex +++ b/apps/explorer_web/lib/explorer_web/views/internal_transaction_view.ex @@ -4,6 +4,6 @@ defmodule ExplorerWeb.InternalTransactionView do alias Explorer.Chain.InternalTransaction - def contract?(%InternalTransaction{type: :create}), do: true - def contract?(_), do: false + def create?(%InternalTransaction{type: :create}), do: true + def create?(_), do: false end diff --git a/apps/explorer_web/test/explorer_web/views/internal_transaction_view_test.exs b/apps/explorer_web/test/explorer_web/views/internal_transaction_view_test.exs index ba118f5bd1..4effc5564d 100644 --- a/apps/explorer_web/test/explorer_web/views/internal_transaction_view_test.exs +++ b/apps/explorer_web/test/explorer_web/views/internal_transaction_view_test.exs @@ -3,17 +3,17 @@ defmodule ExplorerWeb.InternalTransactionViewTest do alias ExplorerWeb.InternalTransactionView - describe "contract?/1" do + describe "create?/1" do test "with internal transaction of type create returns true" do internal_transaction = build(:internal_transaction_create) - assert InternalTransactionView.contract?(internal_transaction) + assert InternalTransactionView.create?(internal_transaction) end test "with non-create type internal transaction returns false" do internal_transaction = build(:internal_transaction) - refute InternalTransactionView.contract?(internal_transaction) + refute InternalTransactionView.create?(internal_transaction) end end end From 1c25ad75d80b6a49dacb05edc3414f7567a93ef7 Mon Sep 17 00:00:00 2001 From: Tim Mecklem Date: Tue, 19 Jun 2018 17:16:59 -0400 Subject: [PATCH 3/3] =?UTF-8?q?`mix=20gettext.extract=20=E2=80=94merge`?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- apps/explorer_web/priv/gettext/default.pot | 14 ++++++++++---- .../priv/gettext/en/LC_MESSAGES/default.po | 14 ++++++++++---- 2 files changed, 20 insertions(+), 8 deletions(-) diff --git a/apps/explorer_web/priv/gettext/default.pot b/apps/explorer_web/priv/gettext/default.pot index 941e7de75d..acd1a97fcc 100644 --- a/apps/explorer_web/priv/gettext/default.pot +++ b/apps/explorer_web/priv/gettext/default.pot @@ -355,8 +355,8 @@ msgstr "" msgid "Search by address, transaction hash, or block number" msgstr "" -#: lib/explorer_web/templates/address_internal_transaction/index.html.eex:114 -#: lib/explorer_web/templates/transaction_internal_transaction/index.html.eex:53 +#: lib/explorer_web/templates/address_internal_transaction/index.html.eex:125 +#: lib/explorer_web/templates/transaction_internal_transaction/index.html.eex:64 msgid "There are no Internal Transactions" msgstr "" @@ -504,13 +504,13 @@ msgstr "" msgid "There are no Transactions" msgstr "" -#: lib/explorer_web/templates/address_internal_transaction/index.html.eex:120 +#: lib/explorer_web/templates/address_internal_transaction/index.html.eex:131 #: lib/explorer_web/templates/address_transaction/index.html.eex:139 #: lib/explorer_web/templates/block/index.html.eex:60 #: lib/explorer_web/templates/block_transaction/index.html.eex:200 #: lib/explorer_web/templates/pending_transaction/index.html.eex:69 #: lib/explorer_web/templates/transaction/index.html.eex:90 -#: lib/explorer_web/templates/transaction_internal_transaction/index.html.eex:60 +#: lib/explorer_web/templates/transaction_internal_transaction/index.html.eex:71 msgid "Older" msgstr "" @@ -544,3 +544,9 @@ msgstr "" #: lib/explorer_web/templates/transaction_log/index.html.eex:73 msgid "Newer" msgstr "" + +#, elixir-format +#: lib/explorer_web/templates/address_internal_transaction/index.html.eex:109 +#: lib/explorer_web/templates/transaction_internal_transaction/index.html.eex:47 +msgid "Contract Creation" +msgstr "" diff --git a/apps/explorer_web/priv/gettext/en/LC_MESSAGES/default.po b/apps/explorer_web/priv/gettext/en/LC_MESSAGES/default.po index 508d684272..25bc9849a5 100644 --- a/apps/explorer_web/priv/gettext/en/LC_MESSAGES/default.po +++ b/apps/explorer_web/priv/gettext/en/LC_MESSAGES/default.po @@ -367,8 +367,8 @@ msgstr "" msgid "Search by address, transaction hash, or block number" msgstr "" -#: lib/explorer_web/templates/address_internal_transaction/index.html.eex:114 -#: lib/explorer_web/templates/transaction_internal_transaction/index.html.eex:53 +#: lib/explorer_web/templates/address_internal_transaction/index.html.eex:125 +#: lib/explorer_web/templates/transaction_internal_transaction/index.html.eex:64 msgid "There are no Internal Transactions" msgstr "" @@ -516,13 +516,13 @@ msgstr "" msgid "There are no Transactions" msgstr "" -#: lib/explorer_web/templates/address_internal_transaction/index.html.eex:120 +#: lib/explorer_web/templates/address_internal_transaction/index.html.eex:131 #: lib/explorer_web/templates/address_transaction/index.html.eex:139 #: lib/explorer_web/templates/block/index.html.eex:60 #: lib/explorer_web/templates/block_transaction/index.html.eex:200 #: lib/explorer_web/templates/pending_transaction/index.html.eex:69 #: lib/explorer_web/templates/transaction/index.html.eex:90 -#: lib/explorer_web/templates/transaction_internal_transaction/index.html.eex:60 +#: lib/explorer_web/templates/transaction_internal_transaction/index.html.eex:71 msgid "Older" msgstr "" @@ -556,3 +556,9 @@ msgstr "" #: lib/explorer_web/templates/transaction_log/index.html.eex:73 msgid "Newer" msgstr "" + +#, elixir-format +#: lib/explorer_web/templates/address_internal_transaction/index.html.eex:109 +#: lib/explorer_web/templates/transaction_internal_transaction/index.html.eex:47 +msgid "Contract Creation" +msgstr ""