From 30824949acf5d1bfcce9d131d3b8d854e4974088 Mon Sep 17 00:00:00 2001 From: Felipe Renan Date: Thu, 26 Jul 2018 11:12:19 -0300 Subject: [PATCH] Don't show `IN` or `OUT` when the address ins't in the transaction --- .../address_transaction/_transaction.html.eex | 14 ++++++++++---- .../explorer_web/views/address_transaction_view.ex | 10 ++++++++++ .../explorer_web/features/pages/address_page.ex | 4 ++++ 3 files changed, 24 insertions(+), 4 deletions(-) diff --git a/apps/explorer_web/lib/explorer_web/templates/address_transaction/_transaction.html.eex b/apps/explorer_web/lib/explorer_web/templates/address_transaction/_transaction.html.eex index 99966c1aa1..20d3961f17 100644 --- a/apps/explorer_web/lib/explorer_web/templates/address_transaction/_transaction.html.eex +++ b/apps/explorer_web/lib/explorer_web/templates/address_transaction/_transaction.html.eex @@ -28,10 +28,16 @@ <% end %> - <%= if @address.hash == @transaction.from_address_hash do %> - <%= gettext "OUT" %> - <% else %> - <%= gettext "IN" %> + <%= if transaction_from_or_to_current_address?(@transaction, @address.hash) do %> + <%= if @transaction.from_address_hash == @address.hash do %> + + <%= gettext "OUT" %> + + <% else %> + + <%= gettext "IN" %> + + <% end %> <% end %> diff --git a/apps/explorer_web/lib/explorer_web/views/address_transaction_view.ex b/apps/explorer_web/lib/explorer_web/views/address_transaction_view.ex index 89531c532d..edb599d239 100644 --- a/apps/explorer_web/lib/explorer_web/views/address_transaction_view.ex +++ b/apps/explorer_web/lib/explorer_web/views/address_transaction_view.ex @@ -11,4 +11,14 @@ defmodule ExplorerWeb.AddressTransactionView do _ -> gettext("All") 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 diff --git a/apps/explorer_web/test/explorer_web/features/pages/address_page.ex b/apps/explorer_web/test/explorer_web/features/pages/address_page.ex index 49934e5dd8..a8ad4d8e17 100644 --- a/apps/explorer_web/test/explorer_web/features/pages/address_page.ex +++ b/apps/explorer_web/test/explorer_web/features/pages/address_page.ex @@ -84,4 +84,8 @@ defmodule ExplorerWeb.AddressPage do def token_transfer(address_hash, count: count) do css("[data-test='token_transfer_address_hash']", count: count, text: to_string(address_hash)) end + + def transaction_type do + css("[data-test='transaction_type']") + end end