diff --git a/CHANGELOG.md b/CHANGELOG.md index dd7fd94b67..f1848e5c6a 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -29,6 +29,7 @@ ### Chore - [#2127](https://github.com/poanetwork/blockscout/pull/2127) - use previouse chromedriver version +- [#2118](https://github.com/poanetwork/blockscout/pull/2118) - show only the last decompiled contract ### Chore diff --git a/apps/block_scout_web/lib/block_scout_web/templates/address_decompiled_contract/index.html.eex b/apps/block_scout_web/lib/block_scout_web/templates/address_decompiled_contract/index.html.eex index 173744603c..6cb4ccf6ab 100644 --- a/apps/block_scout_web/lib/block_scout_web/templates/address_decompiled_contract/index.html.eex +++ b/apps/block_scout_web/lib/block_scout_web/templates/address_decompiled_contract/index.html.eex @@ -2,7 +2,8 @@ <%= render BlockScoutWeb.AddressView, "overview.html", assigns %>
<%= render BlockScoutWeb.AddressView, "_tabs.html", assigns %> - <%= for contract <- sort_contracts_by_version(@address.decompiled_smart_contracts) do %> + <% contract = last_decompiled_contract_version(@address.decompiled_smart_contracts) %> + <%= if contract do %>

<%= gettext "Decompiler version" %>

@@ -21,6 +22,10 @@
+ <% else %> +
+ <%= gettext "There is no decompilded contracts for this address." %> +
<% end %>
diff --git a/apps/block_scout_web/lib/block_scout_web/views/address_decompiled_contract_view.ex b/apps/block_scout_web/lib/block_scout_web/views/address_decompiled_contract_view.ex index b92d356479..438f344199 100644 --- a/apps/block_scout_web/lib/block_scout_web/views/address_decompiled_contract_view.ex +++ b/apps/block_scout_web/lib/block_scout_web/views/address_decompiled_contract_view.ex @@ -230,10 +230,8 @@ defmodule BlockScoutWeb.AddressDecompiledContractView do end) end - def sort_contracts_by_version(decompiled_contracts) do - decompiled_contracts - |> Enum.sort_by(& &1.decompiler_version) - |> Enum.reverse() + def last_decompiled_contract_version(decompiled_contracts) do + Enum.max_by(decompiled_contracts, & &1.decompiler_version) end defp add_line_numbers(code) do diff --git a/apps/block_scout_web/priv/gettext/default.pot b/apps/block_scout_web/priv/gettext/default.pot index e9763e2287..6a5a9d2e36 100644 --- a/apps/block_scout_web/priv/gettext/default.pot +++ b/apps/block_scout_web/priv/gettext/default.pot @@ -1490,7 +1490,7 @@ msgid "EVM Version" msgstr "" #, elixir-format -#: lib/block_scout_web/templates/address_decompiled_contract/index.html.eex:16 +#: lib/block_scout_web/templates/address_decompiled_contract/index.html.eex:17 msgid "Copy Decompiled Contract Code" msgstr "" @@ -1505,12 +1505,12 @@ msgid "Decompiled code" msgstr "" #, elixir-format -#: lib/block_scout_web/templates/address_decompiled_contract/index.html.eex:14 +#: lib/block_scout_web/templates/address_decompiled_contract/index.html.eex:15 msgid "Decompiled contract code" msgstr "" #, elixir-format -#: lib/block_scout_web/templates/address_decompiled_contract/index.html.eex:7 +#: lib/block_scout_web/templates/address_decompiled_contract/index.html.eex:8 msgid "Decompiler version" msgstr "" @@ -1697,3 +1697,8 @@ msgstr "" #: lib/block_scout_web/templates/transaction/overview.html.eex:178 msgid " Token Transfer" msgstr "" + +#, elixir-format +#: lib/block_scout_web/templates/address_decompiled_contract/index.html.eex:27 +msgid "There is no decompilded contracts for this address." +msgstr "" diff --git a/apps/block_scout_web/priv/gettext/en/LC_MESSAGES/default.po b/apps/block_scout_web/priv/gettext/en/LC_MESSAGES/default.po index 654a848278..49ccd3f61a 100644 --- a/apps/block_scout_web/priv/gettext/en/LC_MESSAGES/default.po +++ b/apps/block_scout_web/priv/gettext/en/LC_MESSAGES/default.po @@ -1490,7 +1490,7 @@ msgid "EVM Version" msgstr "" #, elixir-format -#: lib/block_scout_web/templates/address_decompiled_contract/index.html.eex:16 +#: lib/block_scout_web/templates/address_decompiled_contract/index.html.eex:17 msgid "Copy Decompiled Contract Code" msgstr "" @@ -1505,12 +1505,12 @@ msgid "Decompiled code" msgstr "" #, elixir-format -#: lib/block_scout_web/templates/address_decompiled_contract/index.html.eex:14 +#: lib/block_scout_web/templates/address_decompiled_contract/index.html.eex:15 msgid "Decompiled contract code" msgstr "" #, elixir-format -#: lib/block_scout_web/templates/address_decompiled_contract/index.html.eex:7 +#: lib/block_scout_web/templates/address_decompiled_contract/index.html.eex:8 msgid "Decompiler version" msgstr "" @@ -1693,7 +1693,12 @@ msgstr "" msgid "New Smart Contract Verification" msgstr "" -#, elixir-format, fuzzy +#, elixir-format #: lib/block_scout_web/templates/transaction/overview.html.eex:178 msgid " Token Transfer" msgstr "" + +#, elixir-format, fuzzy +#: lib/block_scout_web/templates/address_decompiled_contract/index.html.eex:27 +msgid "There is no decompilded contracts for this address." +msgstr "" diff --git a/apps/block_scout_web/test/block_scout_web/views/address_decompiled_contract_view_test.exs b/apps/block_scout_web/test/block_scout_web/views/address_decompiled_contract_view_test.exs index 334ea36baa..abac26beae 100644 --- a/apps/block_scout_web/test/block_scout_web/views/address_decompiled_contract_view_test.exs +++ b/apps/block_scout_web/test/block_scout_web/views/address_decompiled_contract_view_test.exs @@ -96,15 +96,15 @@ defmodule BlockScoutWeb.AddressDecompiledContractViewTest do end end - describe "sort_contracts_by_version/1" do - test "sorts contracts in lexicographical order" do + describe "last_decompiled_contract_version/1" do + test "returns last version" do contract2 = insert(:decompiled_smart_contract, decompiler_version: "v2") contract1 = insert(:decompiled_smart_contract, decompiler_version: "v1") contract3 = insert(:decompiled_smart_contract, decompiler_version: "v3") - result = AddressDecompiledContractView.sort_contracts_by_version([contract2, contract1, contract3]) + result = AddressDecompiledContractView.last_decompiled_contract_version([contract2, contract1, contract3]) - assert result == [contract3, contract2, contract1] + assert result == contract3 end end end