|
|
|
@ -47,6 +47,7 @@ defmodule Explorer.Chain do |
|
|
|
|
Address.CurrentTokenBalance, |
|
|
|
|
Address.TokenBalance, |
|
|
|
|
Block, |
|
|
|
|
CurrencyHelper, |
|
|
|
|
Data, |
|
|
|
|
DecompiledSmartContract, |
|
|
|
|
Hash, |
|
|
|
@ -2689,10 +2690,19 @@ defmodule Explorer.Chain do |
|
|
|
|
@doc """ |
|
|
|
|
Return the balance in usd corresponding to this token. Return nil if the fiat_value of the token is not present. |
|
|
|
|
""" |
|
|
|
|
def balance_in_fiat(token_balance) do |
|
|
|
|
def balance_in_fiat(%{fiat_value: fiat_value} = token_balance) when not is_nil(fiat_value) do |
|
|
|
|
token_balance.fiat_value |
|
|
|
|
end |
|
|
|
|
|
|
|
|
|
def balance_in_fiat(%{token: %{fiat_value: fiat_value, decimals: decimals}}) when nil in [fiat_value, decimals] do |
|
|
|
|
nil |
|
|
|
|
end |
|
|
|
|
|
|
|
|
|
def balance_in_fiat(%{token: %{fiat_value: fiat_value, decimals: decimals}} = token_balance) do |
|
|
|
|
tokens = CurrencyHelper.divide_decimals(token_balance.value, decimals) |
|
|
|
|
Decimal.mult(tokens, fiat_value) |
|
|
|
|
end |
|
|
|
|
|
|
|
|
|
defp contract?(%{contract_code: nil}), do: false |
|
|
|
|
|
|
|
|
|
defp contract?(%{contract_code: _}), do: true |
|
|
|
|