Fix transaction tags in tile; summary

account
Oleg Sovetnik 3 years ago committed by Viktor Baranov
parent e6e7427f5f
commit 311a47373f
  1. 18
      apps/block_scout_web/lib/block_scout_web/models/get_transaction_tags.ex
  2. 4
      apps/explorer/lib/explorer/accounts/notifier/notify.ex
  3. 42
      apps/explorer/lib/explorer/accounts/notifier/summary.ex

@ -11,13 +11,16 @@ defmodule GetTransactionTags do
alias Explorer.Chain.Transaction
alias Explorer.Repo
def get_transaction_with_addresess_tags(%Transaction{} = transaction, %{id: identity_id}) do
def get_transaction_with_addresess_tags(
%Transaction{} = transaction,
%{id: identity_id, watchlist_id: watchlist_id}
) do
tx_tag = get_transaction_tags(transaction.hash, %{id: identity_id})
addresses_tags = get_addresses_tags_for_transaction(transaction, %{id: identity_id})
addresses_tags = get_addresses_tags_for_transaction(transaction, %{id: identity_id, watchlist_id: watchlist_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_with_addresess_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)
@ -25,9 +28,12 @@ defmodule GetTransactionTags do
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})
def get_addresses_tags_for_transaction(
%Transaction{} = transaction,
%{id: identity_id, watchlist_id: watchlist_id}
) do
from_tags = get_address_tags(transaction.from_address_hash, %{id: identity_id, watchlist_id: watchlist_id})
to_tags = get_address_tags(transaction.to_address_hash, %{id: identity_id, watchlist_id: watchlist_id})
%{
personal_tags: Enum.dedup(from_tags.personal_tags ++ to_tags.personal_tags),

@ -51,7 +51,9 @@ defmodule Explorer.Accounts.Notifier.Notify do
Enum.each(outgoing_addresses, fn address -> notify_watchlist(address, summary, :outgoing) end)
end
defp notify_watchlist(%Explorer.Accounts.WatchlistAddress{} = address, summary, direction) do
defp notify_watchlists(nil), do: nil
defp notify_watchlist(%WatchlistAddress{} = address, summary, direction) do
case ForbiddenAddress.check(address.address_hash) do
{:ok, _address_hash} ->
with %WatchlistNotification{} = notification <-

@ -22,27 +22,18 @@ defmodule Explorer.Accounts.Notifier.Summary do
:type
]
def process(%Chain.TokenTransfer{} = transfer) do
preloaded_transfer = preload(transfer)
summary = fetch_summary(preloaded_transfer.transaction, preloaded_transfer)
if summary do
Logger.debug("--- transfer summary", fetcher: :account)
Logger.debug(summary, fetcher: :account)
end
[summary]
end
def process(%Chain.Transaction{} = transaction) do
preloaded_transaction = preload(transaction)
transfers_summaries = handle_collection(transaction, preloaded_transaction.token_transfers)
transfers_summaries =
handle_collection(
transaction,
preloaded_transaction.token_transfers
)
transaction_summary = fetch_summary(transaction)
if transaction_summary do
if transaction_summary != :nothing do
Logger.debug("--- transaction summary", fetcher: :account)
Logger.debug(transaction_summary, fetcher: :account)
end
@ -53,11 +44,26 @@ defmodule Explorer.Accounts.Notifier.Summary do
[transaction_summary | transfers_summaries]
|> Enum.filter(fn summary ->
not (is_nil(summary) or
summary == :nothing or
is_nil(summary.amount) or
summary.amount == Decimal.new(0))
end)
end
def process(%Chain.TokenTransfer{} = transfer) do
preloaded_transfer = preload(transfer)
summary = fetch_summary(preloaded_transfer.transaction, preloaded_transfer)
if summary != :nothing do
Logger.debug("--- transfer summary", fetcher: :account)
Logger.debug(summary, fetcher: :account)
[summary]
else
[]
end
end
def process(_), do: nil
def handle_collection(_transaction, []), do: []
@ -73,7 +79,7 @@ defmodule Explorer.Accounts.Notifier.Summary do
)
end
def fetch_summary(%Chain.Transaction{block_number: nil}), do: nil
def fetch_summary(%Chain.Transaction{block_number: nil}), do: :nothing
def fetch_summary(%Chain.Transaction{} = transaction) do
%Summary{
@ -92,7 +98,7 @@ defmodule Explorer.Accounts.Notifier.Summary do
def fetch_summary(_), do: :nothing
def fetch_summary(%Chain.Transaction{block_number: nil}, _), do: nil
def fetch_summary(%Chain.Transaction{block_number: nil}, _), do: :nothing
def fetch_summary(
%Chain.Transaction{} = transaction,
@ -143,6 +149,8 @@ defmodule Explorer.Accounts.Notifier.Summary do
end
end
def fetch_summary(_, _), do: :nothing
@burn_address "0x0000000000000000000000000000000000000000"
def method(%{from_address_hash: from, to_address_hash: to}) do

Loading…
Cancel
Save