Token bridge supply small refactoring

pull/3811/head
Viktor Baranov 4 years ago
parent eeb2aa142c
commit bc9089c337
  1. 1
      apps/block_scout_web/assets/js/lib/currency.js
  2. 26
      apps/explorer/lib/explorer/chain/supply/token_bridge.ex
  3. 2
      apps/explorer/lib/explorer/counters/bridge.ex

@ -12,6 +12,7 @@ function formatTokenUsdValue (value) {
function formatCurrencyValue (value, symbol) { function formatCurrencyValue (value, symbol) {
symbol = symbol || '$' symbol = symbol || '$'
if (isNaN(value) || value === '0') return 'N/A'
if (value === 0) return `${symbol}0.000000` if (value === 0) return `${symbol}0.000000`
if (value < 0.000001) return `${window.localized['Less than']} ${symbol}0.000001` if (value < 0.000001) return `${window.localized['Less than']} ${symbol}0.000001`
if (value < 1) return `${symbol}${numeral(value).format('0.000000')}` if (value < 1) return `${symbol}${numeral(value).format('0.000000')}`

@ -60,7 +60,7 @@ defmodule Explorer.Chain.Supply.TokenBridge do
total_market_cap_from_token_bridge = token_bridge_market_cap(%{usd_value: usd_value}) total_market_cap_from_token_bridge = token_bridge_market_cap(%{usd_value: usd_value})
total_market_cap_from_omni = total_market_cap_from_omni_bridge() total_market_cap_from_omni = total_market_cap_from_omni_bridge()
if total_market_cap_from_omni do if Decimal.cmp(total_market_cap_from_omni, 0) == :gt do
Decimal.add(total_market_cap_from_token_bridge, total_market_cap_from_omni) Decimal.add(total_market_cap_from_token_bridge, total_market_cap_from_omni)
else else
total_market_cap_from_token_bridge total_market_cap_from_token_bridge
@ -68,20 +68,14 @@ defmodule Explorer.Chain.Supply.TokenBridge do
end end
def market_cap(_) do def market_cap(_) do
total_market_cap_from_omni = total_market_cap_from_omni_bridge() Decimal.new(0)
if total_market_cap_from_omni do
total_market_cap_from_omni
else
Decimal.new(0)
end
end end
def token_bridge_market_cap(%{usd_value: usd_value}) when not is_nil(usd_value) do def token_bridge_market_cap(%{usd_value: usd_value}) when not is_nil(usd_value) do
total_coins_from_token_b = total_coins_from_token_bridge() total_coins_from_token_bridge = get_total_coins_from_token_bridge()
if total_coins_from_token_b do if total_coins_from_token_bridge do
Decimal.mult(total_coins_from_token_b, usd_value) Decimal.mult(total_coins_from_token_bridge, usd_value)
else else
Decimal.new(0) Decimal.new(0)
end end
@ -93,7 +87,7 @@ defmodule Explorer.Chain.Supply.TokenBridge do
def total, do: total_chain_supply() def total, do: total_chain_supply()
def total_coins_from_token_bridge, do: Bridge.fetch_token_bridge_total_supply() def get_total_coins_from_token_bridge, do: Bridge.fetch_token_bridge_total_supply()
def total_market_cap_from_omni_bridge, do: Bridge.fetch_omni_bridge_market_cap() def total_market_cap_from_omni_bridge, do: Bridge.fetch_omni_bridge_market_cap()
@ -107,14 +101,14 @@ defmodule Explorer.Chain.Supply.TokenBridge do
Decimal.new(1) Decimal.new(1)
end end
total_coins_from_token_b = total_coins_from_token_bridge() total_coins_from_token_bridge = get_total_coins_from_token_bridge()
total_market_cap_from_omni = total_market_cap_from_omni_bridge() total_market_cap_from_omni = total_market_cap_from_omni_bridge()
if total_coins_from_token_b && total_market_cap_from_omni do if Decimal.cmp(total_coins_from_token_bridge, 0) == :gt && Decimal.cmp(total_market_cap_from_omni, 0) == :gt do
total_coins_from_omni_bridge = Decimal.div(total_market_cap_from_omni, usd_value) total_coins_from_omni_bridge = Decimal.div(total_market_cap_from_omni, usd_value)
Decimal.add(total_coins_from_token_b, total_coins_from_omni_bridge) Decimal.add(total_coins_from_token_bridge, total_coins_from_omni_bridge)
else else
total_coins_from_token_b total_coins_from_token_bridge
end end
end end

@ -119,7 +119,7 @@ defmodule Explorer.Counters.Bridge do
if bridges_table_exists?() do if bridges_table_exists?() do
do_fetch_omni_bridge_market_cap(:ets.lookup(@bridges_table, @current_market_cap_from_omni_bridge_cache_key)) do_fetch_omni_bridge_market_cap(:ets.lookup(@bridges_table, @current_market_cap_from_omni_bridge_cache_key))
else else
0 Decimal.new(0)
end end
end end

Loading…
Cancel
Save