<%= ExplorerWeb.TransactionView.transaction_display_type(transaction) %>
diff --git a/apps/explorer_web/lib/explorer_web/views/address_view.ex b/apps/explorer_web/lib/explorer_web/views/address_view.ex
index dadaa7e9e7..0e657c0902 100644
--- a/apps/explorer_web/lib/explorer_web/views/address_view.ex
+++ b/apps/explorer_web/lib/explorer_web/views/address_view.ex
@@ -8,9 +8,6 @@ defmodule ExplorerWeb.AddressView do
@dialyzer :no_match
- def contract?(%Address{contract_code: nil}), do: false
- def contract?(%Address{contract_code: _}), do: true
-
def address_title(%Address{} = address) do
if contract?(address) do
gettext("Contract Address")
@@ -22,7 +19,6 @@ defmodule ExplorerWeb.AddressView do
@doc """
Returns a formatted address balance and includes the unit.
"""
-
def balance(%Address{fetched_balance: nil}), do: ""
def balance(%Address{fetched_balance: balance}) do
@@ -35,6 +31,10 @@ defmodule ExplorerWeb.AddressView do
to_string(fetched_balance_block_number)
end
+ def contract?(%Address{contract_code: nil}), do: false
+
+ def contract?(%Address{contract_code: _}), do: true
+
def formatted_usd(%Address{fetched_balance: nil}, _), do: nil
def formatted_usd(%Address{fetched_balance: balance}, %Token{} = exchange_rate) do
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 59ceeb0b94..d23ab0e115 100644
--- a/apps/explorer_web/lib/explorer_web/views/transaction_view.ex
+++ b/apps/explorer_web/lib/explorer_web/views/transaction_view.ex
@@ -10,26 +10,12 @@ defmodule ExplorerWeb.TransactionView do
import ExplorerWeb.Gettext
- def contract_creation?(%Transaction{created_contract_address_hash: nil}), do: false
- def contract_creation?(_), do: true
-
- def contract?(%Transaction{from_address: from_address, to_address: to_address}) do
- AddressView.contract?(from_address) || AddressView.contract?(to_address)
- end
-
- def tile_class(%Transaction{} = transaction) do
- cond do
- contract_creation?(transaction) -> "tile-type-contract-creation"
- contract?(transaction) -> "tile-type-contract"
- true -> "tile-type-transaction"
- end
- end
+ defguardp is_transaction_type(mod) when mod in [InternalTransaction, Transaction]
- def transaction_display_type(%Transaction{} = transaction) do
- cond do
- contract_creation?(transaction) -> gettext("Contract Creation")
- contract?(transaction) -> gettext("Contract")
- true -> gettext("Transaction")
+ def confirmations(%Transaction{block: block}, named_arguments) when is_list(named_arguments) do
+ case block do
+ nil -> 0
+ _ -> Chain.confirmations(block, named_arguments)
end
end
@@ -39,11 +25,15 @@ defmodule ExplorerWeb.TransactionView do
def display_to_address(%Transaction{to_address: address}), do: [address: address]
- def confirmations(%Transaction{block: block}, named_arguments) when is_list(named_arguments) do
- case block do
- nil -> 0
- _ -> Chain.confirmations(block, named_arguments)
- end
+ def formatted_fee(%Transaction{} = transaction, opts) do
+ transaction
+ |> Chain.fee(:wei)
+ |> fee_to_currency(opts)
+ |> case do
+ {_, nil} -> nil
+ {:actual, value} -> value
+ {:maximum, value} -> "<= " <> value
+ end
end
def gas_used(%Transaction{gas_used: nil}), do: gettext("Pending")
@@ -52,17 +42,18 @@ defmodule ExplorerWeb.TransactionView do
Number.to_string!(gas_used)
end
- def formatted_fee(%Transaction{} = transaction, opts) do
- transaction
- |> Chain.fee(:wei)
- |> fee_to_currency(opts)
- |> case do
- {_, nil} -> nil
- {:actual, value} -> value
- {:maximum, value} -> "<= " <> value
- end
+ def involves_contract?(%Transaction{from_address: from_address, to_address: to_address}) do
+ AddressView.contract?(from_address) || AddressView.contract?(to_address)
end
+ def involves_contract_creation?(%Transaction{created_contract_address_hash: nil}), do: false
+
+ def involves_contract_creation?(_), do: true
+
+ def contract_creation?(%Transaction{created_contract_address_hash: nil}), do: false
+
+ def contract_creation?(_), do: true
+
def qr_code(%Transaction{hash: hash}) do
hash
|> to_string()
@@ -70,24 +61,21 @@ defmodule ExplorerWeb.TransactionView do
|> Base.encode64()
end
- defp fee_to_currency({fee_type, fee}, denomination: denomination) do
- {fee_type, format_wei_value(Wei.from(fee, :wei), denomination)}
- end
-
- defp fee_to_currency({fee_type, fee}, exchange_rate: %Token{} = exchange_rate) do
- formatted =
- fee
- |> Wei.from(:wei)
- |> USD.from(exchange_rate)
- |> format_usd_value()
-
- {fee_type, formatted}
- end
-
def format_gas_limit(gas) do
Number.to_string!(gas)
end
+ def formatted_status(transaction) do
+ transaction
+ |> Chain.transaction_to_status()
+ |> case do
+ :failed -> gettext("Failed")
+ :out_of_gas -> gettext("Out of Gas")
+ :pending -> gettext("Pending")
+ :success -> gettext("Success")
+ end
+ end
+
def formatted_usd_value(%Transaction{value: nil}, _token), do: nil
def formatted_usd_value(%Transaction{value: value}, token) do
@@ -96,8 +84,6 @@ defmodule ExplorerWeb.TransactionView do
defdelegate formatted_timestamp(block), to: BlockView
- defguardp is_transaction_type(mod) when mod in [InternalTransaction, Transaction]
-
def gas(%type{gas: gas}) when is_transaction_type(type) do
Cldr.Number.to_string!(gas)
end
@@ -117,14 +103,19 @@ defmodule ExplorerWeb.TransactionView do
Chain.transaction_to_status(transaction)
end
- def formatted_status(transaction) do
- transaction
- |> Chain.transaction_to_status()
- |> case do
- :failed -> gettext("Failed")
- :out_of_gas -> gettext("Out of Gas")
- :pending -> gettext("Pending")
- :success -> gettext("Success")
+ def type_suffix(%Transaction{} = transaction) do
+ cond do
+ involves_contract_creation?(transaction) -> "contract-creation"
+ involves_contract?(transaction) -> "contract"
+ true -> "transaction"
+ end
+ end
+
+ def transaction_display_type(%Transaction{} = transaction) do
+ cond do
+ involves_contract_creation?(transaction) -> gettext("Contract Creation")
+ involves_contract?(transaction) -> gettext("Contract")
+ true -> gettext("Transaction")
end
end
@@ -139,4 +130,18 @@ defmodule ExplorerWeb.TransactionView do
include_label? = Keyword.get(opts, :include_label, true)
format_wei_value(value, :ether, include_unit_label: include_label?)
end
+
+ defp fee_to_currency({fee_type, fee}, denomination: denomination) do
+ {fee_type, format_wei_value(Wei.from(fee, :wei), denomination)}
+ end
+
+ defp fee_to_currency({fee_type, fee}, exchange_rate: %Token{} = exchange_rate) do
+ formatted =
+ fee
+ |> Wei.from(:wei)
+ |> USD.from(exchange_rate)
+ |> format_usd_value()
+
+ {fee_type, formatted}
+ end
end
diff --git a/apps/explorer_web/test/explorer_web/features/pages/home_page.ex b/apps/explorer_web/test/explorer_web/features/pages/home_page.ex
index affe0b970a..804bba10e3 100644
--- a/apps/explorer_web/test/explorer_web/features/pages/home_page.ex
+++ b/apps/explorer_web/test/explorer_web/features/pages/home_page.ex
@@ -12,7 +12,7 @@ defmodule ExplorerWeb.HomePage do
end
def contract_creation(%InternalTransaction{created_contract_address_hash: hash}) do
- css("[data-address-hash='#{hash}']", text: "Contract Creation")
+ css("[data-test='contract-creation'] [data-address-hash='#{hash}']")
end
def search(session, text) do
diff --git a/apps/explorer_web/test/explorer_web/features/viewing_blocks_test.exs b/apps/explorer_web/test/explorer_web/features/viewing_blocks_test.exs
index bc0c465544..01d43f6f77 100644
--- a/apps/explorer_web/test/explorer_web/features/viewing_blocks_test.exs
+++ b/apps/explorer_web/test/explorer_web/features/viewing_blocks_test.exs
@@ -23,7 +23,7 @@ defmodule ExplorerWeb.ViewingBlocksTest do
test "viewing blocks on the home page", %{session: session} do
session
|> HomePage.visit_page()
- |> assert_has(HomePage.blocks(count: 5))
+ |> assert_has(HomePage.blocks(count: 4))
end
test "search for blocks from home page", %{session: session} do