From 7bbd24ffb30a57b71c25a8c1246389575ee16bec Mon Sep 17 00:00:00 2001 From: jimmay5469 Date: Mon, 9 Jul 2018 11:30:50 -0400 Subject: [PATCH] Change how we identify contract creation transactions and update address link helper Co-authored-by: Stamates --- .../templates/address/_link.html.eex | 14 ++------------ .../address_internal_transaction/index.html.eex | 4 ++-- .../address_transaction/_transaction.html.eex | 4 ++-- .../templates/block_transaction/index.html.eex | 4 ++-- .../templates/chain/_transactions.html.eex | 2 +- .../templates/pending_transaction/index.html.eex | 4 ++-- .../templates/transaction/index.html.eex | 4 ++-- .../index.html.eex | 4 ++-- .../lib/explorer_web/views/transaction_view.ex | 16 ++++++---------- 9 files changed, 21 insertions(+), 35 deletions(-) diff --git a/apps/explorer_web/lib/explorer_web/templates/address/_link.html.eex b/apps/explorer_web/lib/explorer_web/templates/address/_link.html.eex index 5297edad0f..9e4f8487c5 100644 --- a/apps/explorer_web/lib/explorer_web/templates/address/_link.html.eex +++ b/apps/explorer_web/lib/explorer_web/templates/address/_link.html.eex @@ -1,16 +1,6 @@ -<%= if @address do %> - <%= link to: address_path(ExplorerWeb.Endpoint, :show, @locale, @address), "data-address-hash": @address do %> - <%= if contract?(@address) do %> - <%= @address %> - <%= @address |> hash() |> String.slice(0..5) %>–<%= @address |> hash() |> String.slice(-6..-1) %> - <% else %> - <%= @address %> - <%= @address |> hash() |> String.slice(0..5) %>–<%= @address |> hash() |> String.slice(-6..-1) %> - <% end %> - <% end %> -<% else %> +<%= if @address_hash do %> <%= link to: address_path(ExplorerWeb.Endpoint, :show, @locale, @address_hash), "data-address-hash": @address_hash do %> <%= @address_hash %> - <%= to_string(@address_hash) |> String.slice(0..5) %>–<%= to_string(@address_hash) |> String.slice(-6..-1) %> + <%= to_string(@address_hash) |> String.slice(0..5) %>–<%= to_string(@address_hash) |> String.slice(-6..-1) %> <% end %> <% end %> diff --git a/apps/explorer_web/lib/explorer_web/templates/address_internal_transaction/index.html.eex b/apps/explorer_web/lib/explorer_web/templates/address_internal_transaction/index.html.eex index 79f7c717b5..76a89bd546 100644 --- a/apps/explorer_web/lib/explorer_web/templates/address_internal_transaction/index.html.eex +++ b/apps/explorer_web/lib/explorer_web/templates/address_internal_transaction/index.html.eex @@ -98,7 +98,7 @@ - <%= render ExplorerWeb.AddressView, "_link.html", locale: @locale, address: internal_transaction.from_address %> + <%= render ExplorerWeb.AddressView, "_link.html", locale: @locale, address_hash: internal_transaction.from_address_hash %> <%= if ExplorerWeb.InternalTransactionView.create?(internal_transaction) do %> @@ -111,7 +111,7 @@ title: internal_transaction.created_contract_address_hash ) %> <% else %> - <%= render ExplorerWeb.AddressView, "_link.html", locale: @locale, address: internal_transaction.to_address %> + <%= render ExplorerWeb.AddressView, "_link.html", locale: @locale, address_hash: internal_transaction.to_address_hash %> <% end %> <%= ExplorerWeb.TransactionView.value(internal_transaction, include_label: false) %> 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 53c4125a2e..22267674ff 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 @@ -11,13 +11,13 @@ - <%= render ExplorerWeb.AddressView, "_link.html", locale: @locale, address: @transaction.from_address %> + <%= render ExplorerWeb.AddressView, "_link.html", locale: @locale, address_hash: @transaction.from_address_hash %> <%= cond do %> <% @transaction.to_address_hash != nil -> %> - <%= render ExplorerWeb.AddressView, "_link.html", locale: @locale, address: @transaction.to_address %> + <%= render ExplorerWeb.AddressView, "_link.html", locale: @locale, address_hash: @transaction.to_address_hash %> <% @transaction.created_contract_address_hash != nil -> %> <%= link( diff --git a/apps/explorer_web/lib/explorer_web/templates/block_transaction/index.html.eex b/apps/explorer_web/lib/explorer_web/templates/block_transaction/index.html.eex index 82bb7b7154..e863d56bbc 100644 --- a/apps/explorer_web/lib/explorer_web/templates/block_transaction/index.html.eex +++ b/apps/explorer_web/lib/explorer_web/templates/block_transaction/index.html.eex @@ -162,13 +162,13 @@ - <%= render ExplorerWeb.AddressView, "_link.html", locale: @locale, address: transaction.from_address %> + <%= render ExplorerWeb.AddressView, "_link.html", locale: @locale, address_hash: transaction.from_address_hash %> <%= cond do %> <% transaction.to_address_hash != nil -> %> - <%= render ExplorerWeb.AddressView, "_link.html", locale: @locale, address: transaction.to_address %> + <%= render ExplorerWeb.AddressView, "_link.html", locale: @locale, address_hash: transaction.to_address_hash %> <% transaction.created_contract_address_hash != nil -> %> <%= link( diff --git a/apps/explorer_web/lib/explorer_web/templates/chain/_transactions.html.eex b/apps/explorer_web/lib/explorer_web/templates/chain/_transactions.html.eex index 4c478ab400..78f8a1fc25 100644 --- a/apps/explorer_web/lib/explorer_web/templates/chain/_transactions.html.eex +++ b/apps/explorer_web/lib/explorer_web/templates/chain/_transactions.html.eex @@ -11,7 +11,7 @@
<%= render ExplorerWeb.TransactionView, "_link.html", locale: @locale, transaction: transaction %> - <%= render ExplorerWeb.AddressView, "_link.html", locale: @locale, address: transaction.from_address %> + <%= render ExplorerWeb.AddressView, "_link.html", locale: @locale, address_hash: transaction.from_address_hash %> → <%= render ExplorerWeb.AddressView, "_link.html", Keyword.merge(ExplorerWeb.TransactionView.display_to_address(transaction), locale: @locale) %> diff --git a/apps/explorer_web/lib/explorer_web/templates/pending_transaction/index.html.eex b/apps/explorer_web/lib/explorer_web/templates/pending_transaction/index.html.eex index 7b9c9ce9f7..32f3b97002 100644 --- a/apps/explorer_web/lib/explorer_web/templates/pending_transaction/index.html.eex +++ b/apps/explorer_web/lib/explorer_web/templates/pending_transaction/index.html.eex @@ -50,10 +50,10 @@ - <%= render ExplorerWeb.AddressView, "_link.html", locale: @locale, address: transaction.from_address %> + <%= render ExplorerWeb.AddressView, "_link.html", locale: @locale, address_hash: transaction.from_address_hash %> - <%= render ExplorerWeb.AddressView, "_link.html", locale: @locale, address: transaction.to_address %> + <%= render ExplorerWeb.AddressView, "_link.html", locale: @locale, address_hash: transaction.to_address_hash %> <%= ExplorerWeb.TransactionView.value(transaction, include_label: false) %> diff --git a/apps/explorer_web/lib/explorer_web/templates/transaction/index.html.eex b/apps/explorer_web/lib/explorer_web/templates/transaction/index.html.eex index d0539f4a3b..591083d1d2 100644 --- a/apps/explorer_web/lib/explorer_web/templates/transaction/index.html.eex +++ b/apps/explorer_web/lib/explorer_web/templates/transaction/index.html.eex @@ -58,12 +58,12 @@ - <%= render ExplorerWeb.AddressView, "_link.html", locale: @locale, address: transaction.from_address %> + <%= render ExplorerWeb.AddressView, "_link.html", locale: @locale, address_hash: transaction.from_address_hash %> <%= cond do %> <% transaction.to_address_hash != nil -> %> - <%= render ExplorerWeb.AddressView, "_link.html", locale: @locale, address: transaction.to_address %> + <%= render ExplorerWeb.AddressView, "_link.html", locale: @locale, address_hash: transaction.to_address_hash %> <% transaction.created_contract_address_hash != nil -> %> <%= link( "Contract Creation", diff --git a/apps/explorer_web/lib/explorer_web/templates/transaction_internal_transaction/index.html.eex b/apps/explorer_web/lib/explorer_web/templates/transaction_internal_transaction/index.html.eex index dd81d0b563..0842fefd6b 100644 --- a/apps/explorer_web/lib/explorer_web/templates/transaction_internal_transaction/index.html.eex +++ b/apps/explorer_web/lib/explorer_web/templates/transaction_internal_transaction/index.html.eex @@ -38,7 +38,7 @@ <%= internal_transaction.type %> - <%= render ExplorerWeb.AddressView, "_link.html", locale: @locale, address: internal_transaction.from_address %> + <%= render ExplorerWeb.AddressView, "_link.html", locale: @locale, address_hash: internal_transaction.from_address_hash %> <%= if ExplorerWeb.InternalTransactionView.create?(internal_transaction) do %> @@ -51,7 +51,7 @@ title: internal_transaction.created_contract_address_hash ) %> <% else %> - <%= render ExplorerWeb.AddressView, "_link.html", locale: @locale, address: internal_transaction.to_address %> + <%= render ExplorerWeb.AddressView, "_link.html", locale: @locale, address_hash: internal_transaction.to_address_hash %> <% end %> <%= ExplorerWeb.TransactionView.value(internal_transaction, include_label: false) %> diff --git a/apps/explorer_web/lib/explorer_web/views/transaction_view.ex b/apps/explorer_web/lib/explorer_web/views/transaction_view.ex index d4d984c012..493f6ce62f 100644 --- a/apps/explorer_web/lib/explorer_web/views/transaction_view.ex +++ b/apps/explorer_web/lib/explorer_web/views/transaction_view.ex @@ -3,7 +3,7 @@ defmodule ExplorerWeb.TransactionView do alias Cldr.Number alias Explorer.Chain - alias Explorer.Chain.{InternalTransaction, Transaction, Wei} + alias Explorer.Chain.{Address, InternalTransaction, Transaction, Wei} alias Explorer.ExchangeRates.Token alias ExplorerWeb.{AddressView, BlockView} alias ExplorerWeb.ExchangeRates.USD @@ -23,7 +23,7 @@ defmodule ExplorerWeb.TransactionView do def display_to_address(%Transaction{to_address_hash: nil, created_contract_address_hash: address_hash}), do: [address: nil, address_hash: address_hash] - def display_to_address(%Transaction{to_address: address}), do: [address: address] + def display_to_address(%Transaction{to_address: %Address{hash: address_hash}}), do: [address_hash: address_hash] def formatted_fee(%Transaction{} = transaction, opts) do transaction @@ -46,13 +46,9 @@ defmodule ExplorerWeb.TransactionView do AddressView.contract?(from_address) || AddressView.contract?(to_address) end - def involves_contract_creation?(%Transaction{created_contract_address_hash: nil}), do: false + def contract_creation?(%Transaction{to_address: nil}), do: true - def involves_contract_creation?(_), do: true - - def contract_creation?(%Transaction{created_contract_address_hash: nil}), do: false - - def contract_creation?(_), do: true + def contract_creation?(_), do: false def qr_code(%Transaction{hash: hash}) do hash @@ -105,7 +101,7 @@ defmodule ExplorerWeb.TransactionView do def type_suffix(%Transaction{} = transaction) do cond do - involves_contract_creation?(transaction) -> "contract-creation" + contract_creation?(transaction) -> "contract-creation" involves_contract?(transaction) -> "contract" true -> "transaction" end @@ -113,7 +109,7 @@ defmodule ExplorerWeb.TransactionView do def transaction_display_type(%Transaction{} = transaction) do cond do - involves_contract_creation?(transaction) -> gettext("Contract Creation") + contract_creation?(transaction) -> gettext("Contract Creation") involves_contract?(transaction) -> gettext("Contract") true -> gettext("Transaction") end