|
|
|
@ -246,7 +246,20 @@ defmodule BlockScoutWeb.AddressChannel do |
|
|
|
|
end |
|
|
|
|
|
|
|
|
|
defp push_current_token_balances(socket, address_current_token_balances, event_postfix, token_type) do |
|
|
|
|
filtered_ctbs = address_current_token_balances |> Enum.filter(fn ctb -> ctb.token_type == token_type end) |
|
|
|
|
filtered_ctbs = |
|
|
|
|
address_current_token_balances |
|
|
|
|
|> Enum.filter(fn ctb -> ctb.token_type == token_type end) |
|
|
|
|
|> Enum.sort_by( |
|
|
|
|
fn ctb -> |
|
|
|
|
value = |
|
|
|
|
if ctb.token.decimals, |
|
|
|
|
do: Decimal.div(ctb.value, Decimal.new(Integer.pow(10, Decimal.to_integer(ctb.token.decimals)))), |
|
|
|
|
else: ctb.value |
|
|
|
|
|
|
|
|
|
{(ctb.token.fiat_value && Decimal.mult(value, ctb.token.fiat_value)) || Decimal.new(0), value} |
|
|
|
|
end, |
|
|
|
|
&sorter/2 |
|
|
|
|
) |
|
|
|
|
|
|
|
|
|
push(socket, "updated_token_balances_" <> event_postfix, %{ |
|
|
|
|
token_balances: |
|
|
|
@ -257,6 +270,15 @@ defmodule BlockScoutWeb.AddressChannel do |
|
|
|
|
}) |
|
|
|
|
end |
|
|
|
|
|
|
|
|
|
defp sorter({fiat_value_1, value_1}, {fiat_value_2, value_2}) do |
|
|
|
|
case {Decimal.compare(fiat_value_1, fiat_value_2), Decimal.compare(value_1, value_2)} do |
|
|
|
|
{:gt, _} -> true |
|
|
|
|
{:eq, :gt} -> true |
|
|
|
|
{:eq, :eq} -> true |
|
|
|
|
_ -> false |
|
|
|
|
end |
|
|
|
|
end |
|
|
|
|
|
|
|
|
|
def push_current_coin_balance( |
|
|
|
|
%Phoenix.Socket{handler: BlockScoutWeb.UserSocketV2} = socket, |
|
|
|
|
block_number, |
|
|
|
|