Fix tags duplication

account
Oleg Sovetnik 3 years ago committed by Viktor Baranov
parent fbcd2b36ca
commit e6e7427f5f
  1. 8
      apps/block_scout_web/lib/block_scout_web/controllers/transaction_internal_transaction_controller.ex
  2. 8
      apps/block_scout_web/lib/block_scout_web/controllers/transaction_log_controller.ex
  3. 8
      apps/block_scout_web/lib/block_scout_web/controllers/transaction_raw_trace_controller.ex
  4. 8
      apps/block_scout_web/lib/block_scout_web/controllers/transaction_token_transfer_controller.ex
  5. 21
      apps/block_scout_web/lib/block_scout_web/models/get_transaction_tags.ex
  6. 11
      apps/block_scout_web/lib/block_scout_web/templates/transaction/_tile.html.eex
  7. 1
      apps/block_scout_web/lib/block_scout_web/templates/transaction/_total_transfers_from_to.html.eex
  8. 6
      apps/block_scout_web/lib/block_scout_web/templates/transaction/overview.html.eex

@ -4,7 +4,7 @@ defmodule BlockScoutWeb.TransactionInternalTransactionController do
import BlockScoutWeb.Account.AuthController, only: [current_user: 1] 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 BlockScoutWeb.Chain, only: [paging_options: 1, next_page_params: 3, split_list_by_page: 1]
import GetAddressTags, only: [get_address_tags: 2] 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 BlockScoutWeb.{AccessHelpers, Controller, InternalTransactionView, TransactionController}
alias Explorer.{Chain, Market} alias Explorer.{Chain, Market}
@ -110,9 +110,9 @@ defmodule BlockScoutWeb.TransactionInternalTransactionController do
transaction: transaction, transaction: transaction,
from_tags: get_address_tags(transaction.from_address_hash, current_user(conn)), from_tags: get_address_tags(transaction.from_address_hash, current_user(conn)),
to_tags: get_address_tags(transaction.to_address_hash, current_user(conn)), to_tags: get_address_tags(transaction.to_address_hash, current_user(conn)),
personal_tx_tag: tx_tags:
get_transaction_tags( get_transaction_with_addresess_tags(
transaction_hash, transaction,
current_user(conn) current_user(conn)
) )
) )

@ -4,7 +4,7 @@ defmodule BlockScoutWeb.TransactionLogController do
import BlockScoutWeb.Account.AuthController, only: [current_user: 1] 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 BlockScoutWeb.Chain, only: [paging_options: 1, next_page_params: 3, split_list_by_page: 1]
import GetAddressTags, only: [get_address_tags: 2] 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 BlockScoutWeb.{AccessHelpers, Controller, TransactionController, TransactionLogView}
alias Explorer.{Chain, Market} alias Explorer.{Chain, Market}
@ -103,9 +103,9 @@ defmodule BlockScoutWeb.TransactionLogController do
exchange_rate: Market.get_exchange_rate(Explorer.coin()) || Token.null(), exchange_rate: Market.get_exchange_rate(Explorer.coin()) || Token.null(),
from_tags: get_address_tags(transaction.from_address_hash, current_user(conn)), from_tags: get_address_tags(transaction.from_address_hash, current_user(conn)),
to_tags: get_address_tags(transaction.to_address_hash, current_user(conn)), to_tags: get_address_tags(transaction.to_address_hash, current_user(conn)),
personal_tx_tag: tx_tags:
get_transaction_tags( get_transaction_with_addresess_tags(
transaction_hash, transaction,
current_user(conn) current_user(conn)
) )
) )

@ -3,7 +3,7 @@ defmodule BlockScoutWeb.TransactionRawTraceController do
import BlockScoutWeb.Account.AuthController, only: [current_user: 1] import BlockScoutWeb.Account.AuthController, only: [current_user: 1]
import GetAddressTags, only: [get_address_tags: 2] 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 BlockScoutWeb.{AccessHelpers, TransactionController}
alias EthereumJSONRPC alias EthereumJSONRPC
@ -101,9 +101,9 @@ defmodule BlockScoutWeb.TransactionRawTraceController do
transaction: transaction, transaction: transaction,
from_tags: get_address_tags(transaction.from_address_hash, current_user(conn)), from_tags: get_address_tags(transaction.from_address_hash, current_user(conn)),
to_tags: get_address_tags(transaction.to_address_hash, current_user(conn)), to_tags: get_address_tags(transaction.to_address_hash, current_user(conn)),
personal_tx_tag: tx_tags:
get_transaction_tags( get_transaction_with_addresess_tags(
transaction.hash, transaction,
current_user(conn) current_user(conn)
) )
) )

@ -4,7 +4,7 @@ defmodule BlockScoutWeb.TransactionTokenTransferController do
import BlockScoutWeb.Account.AuthController, only: [current_user: 1] 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 BlockScoutWeb.Chain, only: [paging_options: 1, next_page_params: 3, split_list_by_page: 1]
import GetAddressTags, only: [get_address_tags: 2] 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 BlockScoutWeb.{AccessHelpers, Controller, TransactionController, TransactionTokenTransferView}
alias Explorer.{Chain, Market} alias Explorer.{Chain, Market}
@ -114,9 +114,9 @@ defmodule BlockScoutWeb.TransactionTokenTransferController do
transaction: transaction, transaction: transaction,
from_tags: get_address_tags(transaction.from_address_hash, current_user(conn)), from_tags: get_address_tags(transaction.from_address_hash, current_user(conn)),
to_tags: get_address_tags(transaction.to_address_hash, current_user(conn)), to_tags: get_address_tags(transaction.to_address_hash, current_user(conn)),
personal_tx_tag: tx_tags:
get_transaction_tags( get_transaction_with_addresess_tags(
transaction_hash, transaction,
current_user(conn) current_user(conn)
) )
) )

@ -5,12 +5,33 @@ defmodule GetTransactionTags do
# import Ecto.Query, only: [from: 2] # import Ecto.Query, only: [from: 2]
import GetAddressTags, only: [get_address_tags: 2]
alias Explorer.Accounts.TagTransaction alias Explorer.Accounts.TagTransaction
alias Explorer.Chain.Transaction
alias Explorer.Repo 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 def get_transaction_tags(transaction_hash, %{id: identity_id}) do
Repo.get_by(TagTransaction, tx_hash: transaction_hash, identity_id: identity_id) Repo.get_by(TagTransaction, tx_hash: transaction_hash, identity_id: identity_id)
end end
def get_transaction_tags(_, _), do: nil 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 end

@ -1,9 +1,7 @@
<% status = transaction_status(@transaction) %> <% status = transaction_status(@transaction) %>
<% error_in_internal_tx = @transaction.has_error_in_internal_txs %> <% error_in_internal_tx = @transaction.has_error_in_internal_txs %>
<% current_user = AuthController.current_user(@conn) %> <% current_user = AuthController.current_user(@conn) %>
<% from_tags = GetAddressTags.get_address_tags(@transaction.from_address_hash, current_user) %> <% tx_tags = GetTransactionTags.get_transaction_with_addresess_tags(@transaction, 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) %>
<div class="tile tile-type-<%= type_suffix(@transaction) %> fade-in <%= status_class(@transaction) %>" data-test="<%= type_suffix(@transaction) %>" data-identifier-hash="<%= @transaction.hash %>"> <div class="tile tile-type-<%= type_suffix(@transaction) %> fade-in <%= status_class(@transaction) %>" data-test="<%= type_suffix(@transaction) %>" data-identifier-hash="<%= @transaction.hash %>">
<div class="row tile-body" data-selector="token-transfers-toggle" data-test="chain_transaction"> <div class="row tile-body" data-selector="token-transfers-toggle" data-test="chain_transaction">
<!-- Color Block --> <!-- Color Block -->
@ -35,11 +33,10 @@
<%= if method_name do %> <%= if method_name do %>
<%= render BlockScoutWeb.FormView, "_tag.html", text: method_name, additional_classes: ["method", "ml-1"] %> <%= render BlockScoutWeb.FormView, "_tag.html", text: method_name, additional_classes: ["method", "ml-1"] %>
<% end %> <% end %>
<%= render BlockScoutWeb.AddressView, "_labels.html", tags: from_tags %> <%= if tx_tags.personal_tx_tag do %>
<%= render BlockScoutWeb.AddressView, "_labels.html", tags: to_tags %> <%= render BlockScoutWeb.FormView, "_tag.html", text: tx_tags.personal_tx_tag.name, additional_classes: [tag_name_to_label(tx_tags.personal_tx_tag.name), "ml-1"] %>
<%= if personal_tx_tag do %>
<%= render BlockScoutWeb.FormView, "_tag.html", text: personal_tx_tag.name, additional_classes: [tag_name_to_label(personal_tx_tag.name), "ml-1"] %>
<% end %> <% end %>
<%= render BlockScoutWeb.AddressView, "_labels.html", tags: tx_tags %>
</div> </div>
</span> </span>
<span> <span>

@ -1,6 +1,5 @@
<%= with {:ok, from_address} <- Chain.hash_to_address(@transfer.from_address_hash), <%= with {:ok, from_address} <- Chain.hash_to_address(@transfer.from_address_hash),
{:ok, to_address} <- Chain.hash_to_address(@transfer.to_address_hash) do %> {:ok, to_address} <- Chain.hash_to_address(@transfer.to_address_hash) do %>
<% IO.inspect @current_user %>
<% from_tags = GetAddressTags.get_address_tags(@transfer.from_address_hash, @current_user) %> <% from_tags = GetAddressTags.get_address_tags(@transfer.from_address_hash, @current_user) %>
<% to_tags = GetAddressTags.get_address_tags(@transfer.to_address_hash, @current_user) %> <% to_tags = GetAddressTags.get_address_tags(@transfer.to_address_hash, @current_user) %>
<tr> <tr>

@ -49,14 +49,12 @@
<h1 class="card-title"> <h1 class="card-title">
<div style="display: inline-block; vertical-align: bottom; line-height: 25px;"> <div style="display: inline-block; vertical-align: bottom; line-height: 25px;">
<%= gettext "Transaction Details" %> <%= gettext "Transaction Details" %>
<%= render BlockScoutWeb.AddressView, "_labels.html", tags: @from_tags %> <% personal_tx_tag = if assigns[:tx_tags], do: @tx_tags.personal_tx_tag, else: nil %>
<%= render BlockScoutWeb.AddressView, "_labels.html", tags: @to_tags %>
<% personal_tx_tag = if assigns[:personal_tx_tag], do: @personal_tx_tag, else: nil %>
<%= if personal_tx_tag do %> <%= if personal_tx_tag do %>
<%= render BlockScoutWeb.FormView, "_tag.html", text: personal_tx_tag.name, additional_classes: [tag_name_to_label(personal_tx_tag.name), "ml-1"] %> <%= render BlockScoutWeb.FormView, "_tag.html", text: personal_tx_tag.name, additional_classes: [tag_name_to_label(personal_tx_tag.name), "ml-1"] %>
<% end %> <% end %>
<%= render BlockScoutWeb.AddressView, "_labels.html", tags: @tx_tags %>
</div> </div>
<%= render BlockScoutWeb.AddressView, "_labels.html", tags: tags %>
</h1> </h1>
<%= if status == :pending do %> <%= if status == :pending do %>
<div class="tile tile-muted d-flex justify-content-center align-items-center mb-4"> <div class="tile tile-muted d-flex justify-content-center align-items-center mb-4">

Loading…
Cancel
Save