chore: Unknown token in email template (#9883)

pull/9900/head
Victor Baranov 7 months ago committed by GitHub
parent 592cb2e6d4
commit 7077ec57d9
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
  1. 55
      apps/explorer/lib/explorer/account/notifier/summary.ex

@ -10,6 +10,8 @@ defmodule Explorer.Account.Notifier.Summary do
alias Explorer.{Chain, Repo}
alias Explorer.Chain.{Transaction, Wei}
@unknown "Unknown"
defstruct [
:transaction_hash,
:from_address_hash,
@ -69,9 +71,9 @@ defmodule Explorer.Account.Notifier.Summary do
)
end
def fetch_summary(%Chain.Transaction{block_number: nil}), do: :nothing
defp fetch_summary(%Chain.Transaction{block_number: nil}), do: :nothing
def fetch_summary(%Chain.Transaction{created_contract_address_hash: nil} = transaction) do
defp fetch_summary(%Chain.Transaction{created_contract_address_hash: nil} = transaction) do
%Summary{
transaction_hash: transaction.hash,
method: method(transaction),
@ -86,7 +88,7 @@ defmodule Explorer.Account.Notifier.Summary do
}
end
def fetch_summary(%Chain.Transaction{to_address_hash: nil} = transaction) do
defp fetch_summary(%Chain.Transaction{to_address_hash: nil} = transaction) do
%Summary{
transaction_hash: transaction.hash,
method: "contract_creation",
@ -101,14 +103,14 @@ defmodule Explorer.Account.Notifier.Summary do
}
end
def fetch_summary(_), do: :nothing
defp fetch_summary(_), do: :nothing
def fetch_summary(%Chain.Transaction{block_number: nil}, _), do: :nothing
defp fetch_summary(%Chain.Transaction{block_number: nil}, _), do: :nothing
def fetch_summary(
%Chain.Transaction{} = transaction,
%Chain.TokenTransfer{} = transfer
) do
defp fetch_summary(
%Chain.Transaction{} = transaction,
%Chain.TokenTransfer{} = transfer
) do
case transfer.token.type do
"ERC-20" ->
%Summary{
@ -120,7 +122,7 @@ defmodule Explorer.Account.Notifier.Summary do
amount: amount(transfer),
subject: transfer.token.type,
tx_fee: fee(transaction),
name: transfer.token.name,
name: token_name(transfer),
type: transfer.token.type
}
@ -134,7 +136,7 @@ defmodule Explorer.Account.Notifier.Summary do
block_number: transfer.block_number,
subject: to_string(transfer.token_ids && List.first(transfer.token_ids)),
tx_fee: fee(transaction),
name: transfer.token.name,
name: token_name(transfer),
type: transfer.token.type
}
@ -148,7 +150,7 @@ defmodule Explorer.Account.Notifier.Summary do
block_number: transfer.block_number,
subject: token_ids(transfer),
tx_fee: fee(transaction),
name: transfer.token.name,
name: token_name(transfer),
type: transfer.token.type
}
@ -164,15 +166,15 @@ defmodule Explorer.Account.Notifier.Summary do
block_number: transfer.block_number,
subject: if(token_ids_string == "", do: transfer.token.type, else: token_ids_string),
tx_fee: fee(transaction),
name: transfer.token.name,
name: token_name(transfer),
type: transfer.token.type
}
end
end
def fetch_summary(_, _), do: :nothing
defp fetch_summary(_, _), do: :nothing
def method(%{from_address_hash: from, to_address_hash: to}) do
defp method(%{from_address_hash: from, to_address_hash: to}) do
{:ok, burn_address} = format_address(burn_address_hash_string())
cond do
@ -182,17 +184,17 @@ defmodule Explorer.Account.Notifier.Summary do
end
end
def format_address(address_hash_string) do
defp format_address(address_hash_string) do
Chain.string_to_address_hash(address_hash_string)
end
def amount(%Chain.Transaction{} = transaction) do
defp amount(%Chain.Transaction{} = transaction) do
Wei.to(transaction.value, :ether)
end
def amount(%Chain.TokenTransfer{amount: amount}) when is_nil(amount), do: nil
defp amount(%Chain.TokenTransfer{amount: amount}) when is_nil(amount), do: nil
def amount(%Chain.TokenTransfer{amount: amount} = transfer) do
defp amount(%Chain.TokenTransfer{amount: amount} = transfer) do
decimals =
Decimal.new(
Integer.pow(
@ -207,20 +209,21 @@ defmodule Explorer.Account.Notifier.Summary do
)
end
def token_ids(%Chain.TokenTransfer{token_ids: nil}), do: ""
defp token_ids(%Chain.TokenTransfer{token_ids: nil}), do: ""
def token_ids(%Chain.TokenTransfer{token_ids: token_ids}) do
defp token_ids(%Chain.TokenTransfer{token_ids: token_ids}) do
Enum.map_join(token_ids, ", ", fn id -> to_string(id) end)
end
def token_decimals(%Chain.TokenTransfer{} = transfer) do
transfer.token.decimals || Decimal.new(1)
defp token_name(%Chain.TokenTransfer{} = transfer) do
transfer.token.name || @unknown
end
def type(%Chain.Transaction{}), do: :coin
def type(%Chain.InternalTransaction{}), do: :coin
defp token_decimals(%Chain.TokenTransfer{} = transfer) do
transfer.token.decimals || Decimal.new(0)
end
def fee(%Chain.Transaction{} = transaction) do
defp fee(%Chain.Transaction{} = transaction) do
{_, fee} = Transaction.fee(transaction, :gwei)
fee
end

Loading…
Cancel
Save