From 7b0cd50e04847c4dad6263efa0640be442cbd39f Mon Sep 17 00:00:00 2001 From: nikitosing Date: Fri, 22 Apr 2022 21:22:17 +0300 Subject: [PATCH] Fix displaying own names on internal tx tiles --- .../templates/address/_link.html.eex | 4 +-- .../address/_responsive_hash.html.eex | 2 +- .../lib/block_scout_web/views/address_view.ex | 14 +++++++--- apps/block_scout_web/priv/gettext/default.pot | 26 +++++++++---------- .../priv/gettext/en/LC_MESSAGES/default.po | 26 +++++++++---------- 5 files changed, 39 insertions(+), 33 deletions(-) diff --git a/apps/block_scout_web/lib/block_scout_web/templates/address/_link.html.eex b/apps/block_scout_web/lib/block_scout_web/templates/address/_link.html.eex index e1272aee76..275a8f058d 100644 --- a/apps/block_scout_web/lib/block_scout_web/templates/address/_link.html.eex +++ b/apps/block_scout_web/lib/block_scout_web/templates/address/_link.html.eex @@ -1,6 +1,6 @@ <%= if @address do %> <%= if assigns[:show_full_hash] do %> - <%= if name = if assigns[:ignore_implementation_name], do: implementation_name(@address) || primary_name(@address), else: primary_name(@address) do %> + <%= if name = if assigns[:ignore_implementation_name], do: primary_name(@address), else: implementation_name(@address) || primary_name(@address) do %> <%= name %> | <% end %> <%= link to: address_path(BlockScoutWeb.Endpoint, :show, @address), "data-test": "address_hash_link", class: assigns[:class] do %> @@ -9,7 +9,7 @@ <% else %> <%= link to: address_path(BlockScoutWeb.Endpoint, :show, @address), "data-test": "address_hash_link", class: assigns[:class] do %> - <%= render BlockScoutWeb.AddressView, "_responsive_hash.html", address: @address, contract: @contract, truncate: assigns[:truncate], use_custom_tooltip: @use_custom_tooltip, no_tooltip: assigns[:no_tooltip], custom_classes_tooltip: assigns[:custom_classes_tooltip] %> + <%= render BlockScoutWeb.AddressView, "_responsive_hash.html", address: @address, contract: @contract, truncate: assigns[:truncate], use_custom_tooltip: @use_custom_tooltip, no_tooltip: assigns[:no_tooltip], custom_classes_tooltip: assigns[:custom_classes_tooltip], ignore_implementation_name: assigns[:ignore_implementation_name] %> <% end %> <% end %> <% end %> diff --git a/apps/block_scout_web/lib/block_scout_web/templates/address/_responsive_hash.html.eex b/apps/block_scout_web/lib/block_scout_web/templates/address/_responsive_hash.html.eex index 168e68da36..06b0954cb0 100644 --- a/apps/block_scout_web/lib/block_scout_web/templates/address/_responsive_hash.html.eex +++ b/apps/block_scout_web/lib/block_scout_web/templates/address/_responsive_hash.html.eex @@ -1,5 +1,5 @@ - <%= if name = if assigns[:ignore_implementation_name], do: implementation_name(@address) || primary_name(@address), else: primary_name(@address) do %> + <%= if name = if assigns[:ignore_implementation_name], do: primary_name(@address), else: implementation_name(@address) || primary_name(@address) do %> <%= if assigns[:no_tooltip] do %> <%= if @use_custom_tooltip == true do %> <%= name %> (<%= short_hash(@address) %>...) diff --git a/apps/block_scout_web/lib/block_scout_web/views/address_view.ex b/apps/block_scout_web/lib/block_scout_web/views/address_view.ex index d915238c48..6c49191dae 100644 --- a/apps/block_scout_web/lib/block_scout_web/views/address_view.ex +++ b/apps/block_scout_web/lib/block_scout_web/views/address_view.ex @@ -4,7 +4,7 @@ defmodule BlockScoutWeb.AddressView do require Logger alias BlockScoutWeb.{AccessHelpers, LayoutView} - alias Explorer.{Chain, CustomContractsHelpers} + alias Explorer.{Chain, CustomContractsHelpers, Repo} alias Explorer.Chain.{Address, Hash, InternalTransaction, SmartContract, Token, TokenTransfer, Transaction, Wei} alias Explorer.Chain.Block.Reward alias Explorer.ExchangeRates.Token, as: TokenExchangeRate @@ -176,9 +176,11 @@ defmodule BlockScoutWeb.AddressView do end @doc """ - Returns the primary name of an address if available. + Returns the primary name of an address if available. If there is no names on address function performs preload of names association. """ - def primary_name(%Address{names: [_ | _] = address_names}) do + def primary_name(_, second_time? \\ false) + + def primary_name(%Address{names: [_ | _] = address_names}, _second_time?) do case Enum.find(address_names, &(&1.primary == true)) do nil -> %Address.Name{name: name} = Enum.at(address_names, 0) @@ -189,7 +191,11 @@ defmodule BlockScoutWeb.AddressView do end end - def primary_name(%Address{names: _}), do: nil + def primary_name(%Address{names: _} = address, false) do + primary_name(Repo.preload(address, [:names]), true) + end + + def primary_name(%Address{names: _}, true), do: nil def implementation_name(%Address{smart_contract: %{implementation_name: implementation_name}}), do: implementation_name diff --git a/apps/block_scout_web/priv/gettext/default.pot b/apps/block_scout_web/priv/gettext/default.pot index 321a607d85..fe7b187da3 100644 --- a/apps/block_scout_web/priv/gettext/default.pot +++ b/apps/block_scout_web/priv/gettext/default.pot @@ -430,7 +430,7 @@ msgstr "" #, elixir-format #: lib/block_scout_web/templates/address/_tabs.html.eex:48 #: lib/block_scout_web/templates/address/overview.html.eex:290 lib/block_scout_web/templates/address_validation/index.html.eex:11 -#: lib/block_scout_web/views/address_view.ex:365 +#: lib/block_scout_web/views/address_view.ex:371 msgid "Blocks Validated" msgstr "" @@ -569,13 +569,13 @@ msgstr "" #: lib/block_scout_web/templates/address/_tabs.html.eex:58 #: lib/block_scout_web/templates/api_docs/_action_tile.html.eex:165 lib/block_scout_web/templates/api_docs/_action_tile.html.eex:187 #: lib/block_scout_web/templates/api_docs/_eth_rpc_item.html.eex:126 lib/block_scout_web/templates/api_docs/_eth_rpc_item.html.eex:149 -#: lib/block_scout_web/views/address_view.ex:358 +#: lib/block_scout_web/views/address_view.ex:364 msgid "Code" msgstr "" #, elixir-format #: lib/block_scout_web/templates/address/_tabs.html.eex:34 -#: lib/block_scout_web/views/address_view.ex:364 +#: lib/block_scout_web/views/address_view.ex:370 msgid "Coin Balance History" msgstr "" @@ -910,7 +910,7 @@ msgid "Decoded" msgstr "" #, elixir-format -#: lib/block_scout_web/views/address_view.ex:359 +#: lib/block_scout_web/views/address_view.ex:365 msgid "Decompiled Code" msgstr "" @@ -1377,7 +1377,7 @@ msgstr "" #, elixir-format #: lib/block_scout_web/templates/address/_tabs.html.eex:28 #: lib/block_scout_web/templates/address_internal_transaction/index.html.eex:17 lib/block_scout_web/templates/transaction/_tabs.html.eex:11 -#: lib/block_scout_web/templates/transaction_internal_transaction/index.html.eex:6 lib/block_scout_web/views/address_view.ex:355 +#: lib/block_scout_web/templates/transaction_internal_transaction/index.html.eex:6 lib/block_scout_web/views/address_view.ex:361 #: lib/block_scout_web/views/transaction_view.ex:512 msgid "Internal Transactions" msgstr "" @@ -1492,7 +1492,7 @@ msgstr "" #, elixir-format #: lib/block_scout_web/templates/address/_tabs.html.eex:41 #: lib/block_scout_web/templates/address_logs/index.html.eex:10 lib/block_scout_web/templates/transaction/_tabs.html.eex:17 -#: lib/block_scout_web/templates/transaction_log/index.html.eex:8 lib/block_scout_web/views/address_view.ex:366 +#: lib/block_scout_web/templates/transaction_log/index.html.eex:8 lib/block_scout_web/views/address_view.ex:372 #: lib/block_scout_web/views/transaction_view.ex:513 msgid "Logs" msgstr "" @@ -1933,14 +1933,14 @@ msgstr "" #, elixir-format #: lib/block_scout_web/templates/address/_tabs.html.eex:81 -#: lib/block_scout_web/templates/tokens/overview/_tabs.html.eex:27 lib/block_scout_web/views/address_view.ex:360 +#: lib/block_scout_web/templates/tokens/overview/_tabs.html.eex:27 lib/block_scout_web/views/address_view.ex:366 #: lib/block_scout_web/views/tokens/overview_view.ex:43 msgid "Read Contract" msgstr "" #, elixir-format #: lib/block_scout_web/templates/address/_tabs.html.eex:88 -#: lib/block_scout_web/templates/tokens/overview/_tabs.html.eex:41 lib/block_scout_web/views/address_view.ex:361 +#: lib/block_scout_web/templates/tokens/overview/_tabs.html.eex:41 lib/block_scout_web/views/address_view.ex:367 msgid "Read Proxy" msgstr "" @@ -2628,7 +2628,7 @@ msgstr "" #: lib/block_scout_web/templates/address_token_transfer/index.html.eex:19 lib/block_scout_web/templates/tokens/instance/overview/_tabs.html.eex:3 #: lib/block_scout_web/templates/tokens/instance/transfer/index.html.eex:16 lib/block_scout_web/templates/tokens/overview/_tabs.html.eex:5 #: lib/block_scout_web/templates/tokens/transfer/index.html.eex:14 lib/block_scout_web/templates/transaction/_tabs.html.eex:4 -#: lib/block_scout_web/templates/transaction_token_transfer/index.html.eex:7 lib/block_scout_web/views/address_view.ex:357 +#: lib/block_scout_web/templates/transaction_token_transfer/index.html.eex:7 lib/block_scout_web/views/address_view.ex:363 #: lib/block_scout_web/views/tokens/instance/overview_view.ex:195 lib/block_scout_web/views/tokens/overview_view.ex:41 #: lib/block_scout_web/views/transaction_view.ex:511 msgid "Token Transfers" @@ -2649,7 +2649,7 @@ msgstr "" #: lib/block_scout_web/templates/address/overview.html.eex:191 lib/block_scout_web/templates/address_token/overview.html.eex:58 #: lib/block_scout_web/templates/address_token_transfer/index.html.eex:13 lib/block_scout_web/templates/layout/_topnav.html.eex:69 #: lib/block_scout_web/templates/layout/_topnav.html.eex:101 lib/block_scout_web/templates/tokens/index.html.eex:10 -#: lib/block_scout_web/views/address_view.ex:354 +#: lib/block_scout_web/views/address_view.ex:360 msgid "Tokens" msgstr "" @@ -2797,7 +2797,7 @@ msgstr "" #: lib/block_scout_web/templates/address/overview.html.eex:216 lib/block_scout_web/templates/address_transaction/index.html.eex:13 #: lib/block_scout_web/templates/block/overview.html.eex:80 lib/block_scout_web/templates/block_transaction/index.html.eex:10 #: lib/block_scout_web/templates/chain/show.html.eex:236 lib/block_scout_web/templates/layout/_topnav.html.eex:43 -#: lib/block_scout_web/views/address_view.ex:356 +#: lib/block_scout_web/views/address_view.ex:362 msgid "Transactions" msgstr "" @@ -3139,13 +3139,13 @@ msgstr "" #, elixir-format #: lib/block_scout_web/templates/address/_tabs.html.eex:95 -#: lib/block_scout_web/templates/tokens/overview/_tabs.html.eex:34 lib/block_scout_web/views/address_view.ex:362 +#: lib/block_scout_web/templates/tokens/overview/_tabs.html.eex:34 lib/block_scout_web/views/address_view.ex:368 msgid "Write Contract" msgstr "" #, elixir-format #: lib/block_scout_web/templates/address/_tabs.html.eex:102 -#: lib/block_scout_web/templates/tokens/overview/_tabs.html.eex:48 lib/block_scout_web/views/address_view.ex:363 +#: lib/block_scout_web/templates/tokens/overview/_tabs.html.eex:48 lib/block_scout_web/views/address_view.ex:369 msgid "Write Proxy" 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 321a607d85..fe7b187da3 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 @@ -430,7 +430,7 @@ msgstr "" #, elixir-format #: lib/block_scout_web/templates/address/_tabs.html.eex:48 #: lib/block_scout_web/templates/address/overview.html.eex:290 lib/block_scout_web/templates/address_validation/index.html.eex:11 -#: lib/block_scout_web/views/address_view.ex:365 +#: lib/block_scout_web/views/address_view.ex:371 msgid "Blocks Validated" msgstr "" @@ -569,13 +569,13 @@ msgstr "" #: lib/block_scout_web/templates/address/_tabs.html.eex:58 #: lib/block_scout_web/templates/api_docs/_action_tile.html.eex:165 lib/block_scout_web/templates/api_docs/_action_tile.html.eex:187 #: lib/block_scout_web/templates/api_docs/_eth_rpc_item.html.eex:126 lib/block_scout_web/templates/api_docs/_eth_rpc_item.html.eex:149 -#: lib/block_scout_web/views/address_view.ex:358 +#: lib/block_scout_web/views/address_view.ex:364 msgid "Code" msgstr "" #, elixir-format #: lib/block_scout_web/templates/address/_tabs.html.eex:34 -#: lib/block_scout_web/views/address_view.ex:364 +#: lib/block_scout_web/views/address_view.ex:370 msgid "Coin Balance History" msgstr "" @@ -910,7 +910,7 @@ msgid "Decoded" msgstr "" #, elixir-format -#: lib/block_scout_web/views/address_view.ex:359 +#: lib/block_scout_web/views/address_view.ex:365 msgid "Decompiled Code" msgstr "" @@ -1377,7 +1377,7 @@ msgstr "" #, elixir-format #: lib/block_scout_web/templates/address/_tabs.html.eex:28 #: lib/block_scout_web/templates/address_internal_transaction/index.html.eex:17 lib/block_scout_web/templates/transaction/_tabs.html.eex:11 -#: lib/block_scout_web/templates/transaction_internal_transaction/index.html.eex:6 lib/block_scout_web/views/address_view.ex:355 +#: lib/block_scout_web/templates/transaction_internal_transaction/index.html.eex:6 lib/block_scout_web/views/address_view.ex:361 #: lib/block_scout_web/views/transaction_view.ex:512 msgid "Internal Transactions" msgstr "" @@ -1492,7 +1492,7 @@ msgstr "" #, elixir-format #: lib/block_scout_web/templates/address/_tabs.html.eex:41 #: lib/block_scout_web/templates/address_logs/index.html.eex:10 lib/block_scout_web/templates/transaction/_tabs.html.eex:17 -#: lib/block_scout_web/templates/transaction_log/index.html.eex:8 lib/block_scout_web/views/address_view.ex:366 +#: lib/block_scout_web/templates/transaction_log/index.html.eex:8 lib/block_scout_web/views/address_view.ex:372 #: lib/block_scout_web/views/transaction_view.ex:513 msgid "Logs" msgstr "" @@ -1933,14 +1933,14 @@ msgstr "" #, elixir-format #: lib/block_scout_web/templates/address/_tabs.html.eex:81 -#: lib/block_scout_web/templates/tokens/overview/_tabs.html.eex:27 lib/block_scout_web/views/address_view.ex:360 +#: lib/block_scout_web/templates/tokens/overview/_tabs.html.eex:27 lib/block_scout_web/views/address_view.ex:366 #: lib/block_scout_web/views/tokens/overview_view.ex:43 msgid "Read Contract" msgstr "" #, elixir-format #: lib/block_scout_web/templates/address/_tabs.html.eex:88 -#: lib/block_scout_web/templates/tokens/overview/_tabs.html.eex:41 lib/block_scout_web/views/address_view.ex:361 +#: lib/block_scout_web/templates/tokens/overview/_tabs.html.eex:41 lib/block_scout_web/views/address_view.ex:367 msgid "Read Proxy" msgstr "" @@ -2628,7 +2628,7 @@ msgstr "" #: lib/block_scout_web/templates/address_token_transfer/index.html.eex:19 lib/block_scout_web/templates/tokens/instance/overview/_tabs.html.eex:3 #: lib/block_scout_web/templates/tokens/instance/transfer/index.html.eex:16 lib/block_scout_web/templates/tokens/overview/_tabs.html.eex:5 #: lib/block_scout_web/templates/tokens/transfer/index.html.eex:14 lib/block_scout_web/templates/transaction/_tabs.html.eex:4 -#: lib/block_scout_web/templates/transaction_token_transfer/index.html.eex:7 lib/block_scout_web/views/address_view.ex:357 +#: lib/block_scout_web/templates/transaction_token_transfer/index.html.eex:7 lib/block_scout_web/views/address_view.ex:363 #: lib/block_scout_web/views/tokens/instance/overview_view.ex:195 lib/block_scout_web/views/tokens/overview_view.ex:41 #: lib/block_scout_web/views/transaction_view.ex:511 msgid "Token Transfers" @@ -2649,7 +2649,7 @@ msgstr "" #: lib/block_scout_web/templates/address/overview.html.eex:191 lib/block_scout_web/templates/address_token/overview.html.eex:58 #: lib/block_scout_web/templates/address_token_transfer/index.html.eex:13 lib/block_scout_web/templates/layout/_topnav.html.eex:69 #: lib/block_scout_web/templates/layout/_topnav.html.eex:101 lib/block_scout_web/templates/tokens/index.html.eex:10 -#: lib/block_scout_web/views/address_view.ex:354 +#: lib/block_scout_web/views/address_view.ex:360 msgid "Tokens" msgstr "" @@ -2797,7 +2797,7 @@ msgstr "" #: lib/block_scout_web/templates/address/overview.html.eex:216 lib/block_scout_web/templates/address_transaction/index.html.eex:13 #: lib/block_scout_web/templates/block/overview.html.eex:80 lib/block_scout_web/templates/block_transaction/index.html.eex:10 #: lib/block_scout_web/templates/chain/show.html.eex:236 lib/block_scout_web/templates/layout/_topnav.html.eex:43 -#: lib/block_scout_web/views/address_view.ex:356 +#: lib/block_scout_web/views/address_view.ex:362 msgid "Transactions" msgstr "" @@ -3139,13 +3139,13 @@ msgstr "" #, elixir-format #: lib/block_scout_web/templates/address/_tabs.html.eex:95 -#: lib/block_scout_web/templates/tokens/overview/_tabs.html.eex:34 lib/block_scout_web/views/address_view.ex:362 +#: lib/block_scout_web/templates/tokens/overview/_tabs.html.eex:34 lib/block_scout_web/views/address_view.ex:368 msgid "Write Contract" msgstr "" #, elixir-format #: lib/block_scout_web/templates/address/_tabs.html.eex:102 -#: lib/block_scout_web/templates/tokens/overview/_tabs.html.eex:48 lib/block_scout_web/views/address_view.ex:363 +#: lib/block_scout_web/templates/tokens/overview/_tabs.html.eex:48 lib/block_scout_web/views/address_view.ex:369 msgid "Write Proxy" msgstr ""