diff --git a/apps/block_scout_web/lib/block_scout_web/controllers/transaction_internal_transaction_controller.ex b/apps/block_scout_web/lib/block_scout_web/controllers/transaction_internal_transaction_controller.ex index 6605d17b7d..fbf3b21586 100644 --- a/apps/block_scout_web/lib/block_scout_web/controllers/transaction_internal_transaction_controller.ex +++ b/apps/block_scout_web/lib/block_scout_web/controllers/transaction_internal_transaction_controller.ex @@ -4,7 +4,7 @@ defmodule BlockScoutWeb.TransactionInternalTransactionController do import BlockScoutWeb.Account.AuthController, only: [current_user: 1] import BlockScoutWeb.Chain, only: [paging_options: 1, next_page_params: 3, split_list_by_page: 1] import GetAddressTags, only: [get_address_tags: 2] - import GetTransactionTags, only: [get_transaction_tags: 2] + import GetTransactionTags, only: [get_transaction_with_addresess_tags: 2] alias BlockScoutWeb.{AccessHelpers, Controller, InternalTransactionView, TransactionController} alias Explorer.{Chain, Market} @@ -110,9 +110,9 @@ defmodule BlockScoutWeb.TransactionInternalTransactionController do transaction: transaction, from_tags: get_address_tags(transaction.from_address_hash, current_user(conn)), to_tags: get_address_tags(transaction.to_address_hash, current_user(conn)), - personal_tx_tag: - get_transaction_tags( - transaction_hash, + tx_tags: + get_transaction_with_addresess_tags( + transaction, current_user(conn) ) ) diff --git a/apps/block_scout_web/lib/block_scout_web/controllers/transaction_log_controller.ex b/apps/block_scout_web/lib/block_scout_web/controllers/transaction_log_controller.ex index 48dcdb5c39..5564ce4f7f 100644 --- a/apps/block_scout_web/lib/block_scout_web/controllers/transaction_log_controller.ex +++ b/apps/block_scout_web/lib/block_scout_web/controllers/transaction_log_controller.ex @@ -4,7 +4,7 @@ defmodule BlockScoutWeb.TransactionLogController do import BlockScoutWeb.Account.AuthController, only: [current_user: 1] import BlockScoutWeb.Chain, only: [paging_options: 1, next_page_params: 3, split_list_by_page: 1] import GetAddressTags, only: [get_address_tags: 2] - import GetTransactionTags, only: [get_transaction_tags: 2] + import GetTransactionTags, only: [get_transaction_with_addresess_tags: 2] alias BlockScoutWeb.{AccessHelpers, Controller, TransactionController, TransactionLogView} alias Explorer.{Chain, Market} @@ -103,9 +103,9 @@ defmodule BlockScoutWeb.TransactionLogController do exchange_rate: Market.get_exchange_rate(Explorer.coin()) || Token.null(), from_tags: get_address_tags(transaction.from_address_hash, current_user(conn)), to_tags: get_address_tags(transaction.to_address_hash, current_user(conn)), - personal_tx_tag: - get_transaction_tags( - transaction_hash, + tx_tags: + get_transaction_with_addresess_tags( + transaction, current_user(conn) ) ) diff --git a/apps/block_scout_web/lib/block_scout_web/controllers/transaction_raw_trace_controller.ex b/apps/block_scout_web/lib/block_scout_web/controllers/transaction_raw_trace_controller.ex index 984b7683b0..4ede9417d5 100644 --- a/apps/block_scout_web/lib/block_scout_web/controllers/transaction_raw_trace_controller.ex +++ b/apps/block_scout_web/lib/block_scout_web/controllers/transaction_raw_trace_controller.ex @@ -3,7 +3,7 @@ defmodule BlockScoutWeb.TransactionRawTraceController do import BlockScoutWeb.Account.AuthController, only: [current_user: 1] import GetAddressTags, only: [get_address_tags: 2] - import GetTransactionTags, only: [get_transaction_tags: 2] + import GetTransactionTags, only: [get_transaction_with_addresess_tags: 2] alias BlockScoutWeb.{AccessHelpers, TransactionController} alias EthereumJSONRPC @@ -101,9 +101,9 @@ defmodule BlockScoutWeb.TransactionRawTraceController do transaction: transaction, from_tags: get_address_tags(transaction.from_address_hash, current_user(conn)), to_tags: get_address_tags(transaction.to_address_hash, current_user(conn)), - personal_tx_tag: - get_transaction_tags( - transaction.hash, + tx_tags: + get_transaction_with_addresess_tags( + transaction, current_user(conn) ) ) diff --git a/apps/block_scout_web/lib/block_scout_web/controllers/transaction_token_transfer_controller.ex b/apps/block_scout_web/lib/block_scout_web/controllers/transaction_token_transfer_controller.ex index d9908f0058..2bb8fe9aef 100644 --- a/apps/block_scout_web/lib/block_scout_web/controllers/transaction_token_transfer_controller.ex +++ b/apps/block_scout_web/lib/block_scout_web/controllers/transaction_token_transfer_controller.ex @@ -4,7 +4,7 @@ defmodule BlockScoutWeb.TransactionTokenTransferController do import BlockScoutWeb.Account.AuthController, only: [current_user: 1] import BlockScoutWeb.Chain, only: [paging_options: 1, next_page_params: 3, split_list_by_page: 1] import GetAddressTags, only: [get_address_tags: 2] - import GetTransactionTags, only: [get_transaction_tags: 2] + import GetTransactionTags, only: [get_transaction_with_addresess_tags: 2] alias BlockScoutWeb.{AccessHelpers, Controller, TransactionController, TransactionTokenTransferView} alias Explorer.{Chain, Market} @@ -114,9 +114,9 @@ defmodule BlockScoutWeb.TransactionTokenTransferController do transaction: transaction, from_tags: get_address_tags(transaction.from_address_hash, current_user(conn)), to_tags: get_address_tags(transaction.to_address_hash, current_user(conn)), - personal_tx_tag: - get_transaction_tags( - transaction_hash, + tx_tags: + get_transaction_with_addresess_tags( + transaction, current_user(conn) ) ) diff --git a/apps/block_scout_web/lib/block_scout_web/models/get_transaction_tags.ex b/apps/block_scout_web/lib/block_scout_web/models/get_transaction_tags.ex index 0bec387cab..1f16d3829a 100644 --- a/apps/block_scout_web/lib/block_scout_web/models/get_transaction_tags.ex +++ b/apps/block_scout_web/lib/block_scout_web/models/get_transaction_tags.ex @@ -5,12 +5,33 @@ defmodule GetTransactionTags do # import Ecto.Query, only: [from: 2] + import GetAddressTags, only: [get_address_tags: 2] + alias Explorer.Accounts.TagTransaction + alias Explorer.Chain.Transaction alias Explorer.Repo + def get_transaction_with_addresess_tags(%Transaction{} = transaction, %{id: identity_id}) do + tx_tag = get_transaction_tags(transaction.hash, %{id: identity_id}) + addresses_tags = get_addresses_tags_for_transaction(transaction, %{id: identity_id}) + Map.put(addresses_tags, :personal_tx_tag, tx_tag) + end + + def get_transaction_with_addresses_tags(_, _), do: %{personal_tags: [], watchlist_names: [], personal_tx_tag: nil} + def get_transaction_tags(transaction_hash, %{id: identity_id}) do Repo.get_by(TagTransaction, tx_hash: transaction_hash, identity_id: identity_id) end def get_transaction_tags(_, _), do: nil + + def get_addresses_tags_for_transaction(%Transaction{} = transaction, %{id: identity_id}) do + from_tags = get_address_tags(transaction.from_address_hash, %{id: identity_id}) + to_tags = get_address_tags(transaction.to_address_hash, %{id: identity_id}) + + %{ + personal_tags: Enum.dedup(from_tags.personal_tags ++ to_tags.personal_tags), + watchlist_names: Enum.dedup(from_tags.watchlist_names ++ to_tags.watchlist_names) + } + end end diff --git a/apps/block_scout_web/lib/block_scout_web/templates/transaction/_tile.html.eex b/apps/block_scout_web/lib/block_scout_web/templates/transaction/_tile.html.eex index a04a050e38..39e472375e 100644 --- a/apps/block_scout_web/lib/block_scout_web/templates/transaction/_tile.html.eex +++ b/apps/block_scout_web/lib/block_scout_web/templates/transaction/_tile.html.eex @@ -1,9 +1,7 @@ <% status = transaction_status(@transaction) %> <% error_in_internal_tx = @transaction.has_error_in_internal_txs %> <% current_user = AuthController.current_user(@conn) %> -<% from_tags = GetAddressTags.get_address_tags(@transaction.from_address_hash, current_user) %> -<% to_tags = GetAddressTags.get_address_tags(@transaction.to_address_hash, current_user) %> -<% personal_tx_tag = GetTransactionTags.get_transaction_tags(@transaction.hash, current_user) %> +<% tx_tags = GetTransactionTags.get_transaction_with_addresess_tags(@transaction, current_user) %>