From 30f1f3d4e8380a3c25a85a955ddfb2466b89c4b4 Mon Sep 17 00:00:00 2001 From: Victor Baranov Date: Wed, 16 Sep 2020 19:56:05 +0300 Subject: [PATCH] Fix acquire of market cap from omnni-bridge --- .../lib/explorer/chain/supply/token_bridge.ex | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/apps/explorer/lib/explorer/chain/supply/token_bridge.ex b/apps/explorer/lib/explorer/chain/supply/token_bridge.ex index aaba5b34e2..f8937726ee 100644 --- a/apps/explorer/lib/explorer/chain/supply/token_bridge.ex +++ b/apps/explorer/lib/explorer/chain/supply/token_bridge.ex @@ -217,7 +217,7 @@ defmodule Explorer.Chain.Supply.TokenBridge do query = from(t in Token, where: t.contract_address_hash == ^bridged_token_hash, - select: t.total_supply + select: {t.total_supply, t.decimals} ) bridged_token_balance = @@ -226,10 +226,14 @@ defmodule Explorer.Chain.Supply.TokenBridge do bridged_token_balance_formatted = if bridged_token_balance do - bridged_token_balance_wei = %Explorer.Chain.Wei{value: bridged_token_balance} + {bridged_token_balance_with_decimals, decimals} = bridged_token_balance - bridged_token_balance_wei - |> Wei.to(:ether) + decimals_multiplier = + 10 + |> :math.pow(Decimal.to_integer(decimals)) + |> Decimal.from_float() + + Decimal.div(bridged_token_balance_with_decimals, decimals_multiplier) else bridged_token_balance end @@ -247,7 +251,7 @@ defmodule Explorer.Chain.Supply.TokenBridge do if bridged_token_price do Decimal.add(acc, Decimal.mult(bridged_token_price, bridged_token_balance)) else - Decimal.new(0) + acc end end)