|
|
|
@ -10,34 +10,7 @@ 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 |
|
|
|
|
|
|
|
|
|
def transaction_display_type(%Transaction{} = transaction) do |
|
|
|
|
cond do |
|
|
|
|
contract_creation?(transaction) -> gettext("Contract Creation") |
|
|
|
|
contract?(transaction) -> gettext("Contract") |
|
|
|
|
true -> gettext("Transaction") |
|
|
|
|
end |
|
|
|
|
end |
|
|
|
|
|
|
|
|
|
# This is the address to be shown in the to field |
|
|
|
|
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] |
|
|
|
|
defguardp is_transaction_type(mod) when mod in [InternalTransaction, Transaction] |
|
|
|
|
|
|
|
|
|
def confirmations(%Transaction{block: block}, named_arguments) when is_list(named_arguments) do |
|
|
|
|
case block do |
|
|
|
@ -46,11 +19,11 @@ defmodule ExplorerWeb.TransactionView do |
|
|
|
|
end |
|
|
|
|
end |
|
|
|
|
|
|
|
|
|
def gas_used(%Transaction{gas_used: nil}), do: gettext("Pending") |
|
|
|
|
# This is the address to be shown in the to field |
|
|
|
|
def display_to_address(%Transaction{to_address_hash: nil, created_contract_address_hash: address_hash}), |
|
|
|
|
do: [address: nil, address_hash: address_hash] |
|
|
|
|
|
|
|
|
|
def gas_used(%Transaction{gas_used: gas_used}) do |
|
|
|
|
Number.to_string!(gas_used) |
|
|
|
|
end |
|
|
|
|
def display_to_address(%Transaction{to_address: address}), do: [address: address] |
|
|
|
|
|
|
|
|
|
def formatted_fee(%Transaction{} = transaction, opts) do |
|
|
|
|
transaction |
|
|
|
@ -63,6 +36,24 @@ defmodule ExplorerWeb.TransactionView do |
|
|
|
|
end |
|
|
|
|
end |
|
|
|
|
|
|
|
|
|
def gas_used(%Transaction{gas_used: nil}), do: gettext("Pending") |
|
|
|
|
|
|
|
|
|
def gas_used(%Transaction{gas_used: gas_used}) do |
|
|
|
|
Number.to_string!(gas_used) |
|
|
|
|
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,22 +61,19 @@ 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)} |
|
|
|
|
def format_gas_limit(gas) do |
|
|
|
|
Number.to_string!(gas) |
|
|
|
|
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} |
|
|
|
|
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 |
|
|
|
|
|
|
|
|
|
def format_gas_limit(gas) do |
|
|
|
|
Number.to_string!(gas) |
|
|
|
|
end |
|
|
|
|
|
|
|
|
|
def formatted_usd_value(%Transaction{value: nil}, _token), do: nil |
|
|
|
@ -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 |
|
|
|
|