Don't show `IN` or `OUT` when the address ins't in the transaction

pull/417/head
Felipe Renan 6 years ago
parent b6a4e48414
commit 30824949ac
  1. 12
      apps/explorer_web/lib/explorer_web/templates/address_transaction/_transaction.html.eex
  2. 10
      apps/explorer_web/lib/explorer_web/views/address_transaction_view.ex
  3. 4
      apps/explorer_web/test/explorer_web/features/pages/address_page.ex

@ -28,10 +28,16 @@
<% end %> <% end %>
</span> </span>
<span> <span>
<%= if @address.hash == @transaction.from_address_hash do %> <%= if transaction_from_or_to_current_address?(@transaction, @address.hash) do %>
<span class="badge badge-danger tile-badge"><%= gettext "OUT" %></span> <%= if @transaction.from_address_hash == @address.hash do %>
<span data-test="transaction_type" class="badge badge-danger tile-badge">
<%= gettext "OUT" %>
</span>
<% else %> <% else %>
<span class="badge badge-success tile-badge"><%= gettext "IN" %></span> <span data-test="transaction_type" class="badge badge-success tile-badge">
<%= gettext "IN" %>
</span>
<% end %>
<% end %> <% end %>
<span class="ml-1" data-from-now="<%= @transaction.block.timestamp %>"></span> <span class="ml-1" data-from-now="<%= @transaction.block.timestamp %>"></span>
<span class="ml-1"> <span class="ml-1">

@ -11,4 +11,14 @@ defmodule ExplorerWeb.AddressTransactionView do
_ -> gettext("All") _ -> gettext("All")
end end
end end
@doc """
Check if the given address is the to_address_hash or from_address_hash from the transaction.
When the transaction has token transfers, the transaction is going to be shown even when the
transaction is the to or from of the given address.
"""
def transaction_from_or_to_current_address?(transaction, address_hash) do
transaction.from_address_hash == address_hash || transaction.to_address_hash == address_hash
end
end end

@ -84,4 +84,8 @@ defmodule ExplorerWeb.AddressPage do
def token_transfer(address_hash, count: count) do def token_transfer(address_hash, count: count) do
css("[data-test='token_transfer_address_hash']", count: count, text: to_string(address_hash)) css("[data-test='token_transfer_address_hash']", count: count, text: to_string(address_hash))
end end
def transaction_type do
css("[data-test='transaction_type']")
end
end end

Loading…
Cancel
Save