|
|
|
@ -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 |
|
|
|
|