USD values from CoinGecko for TokenBridge

pull/5613/head
Viktor Baranov 3 years ago
parent 93f202d437
commit c66a6e3698
  1. 4
      apps/explorer/lib/explorer/chain/supply/token_bridge.ex
  2. 16
      apps/explorer/lib/explorer/exchange_rates/source.ex
  3. 2
      apps/explorer/lib/explorer/exchange_rates/source/token_bridge.ex

@ -92,10 +92,8 @@ defmodule Explorer.Chain.Supply.TokenBridge do
def total_market_cap_from_omni_bridge, do: Bridge.fetch_omni_bridge_market_cap()
def total_chain_supply do
source = Application.get_env(:explorer, Source)[:source]
usd_value =
case Source.fetch_exchange_rates(source) do
case Source.fetch_exchange_rates(Source.CoinGecko) do
{:ok, [rates]} ->
rates.usd_value

@ -3,6 +3,7 @@ defmodule Explorer.ExchangeRates.Source do
Behaviour for fetching exchange rates from external sources.
"""
alias Explorer.ExchangeRates.{Source, Token}
alias Explorer.ExchangeRates.Source.CoinGecko
alias HTTPoison.{Error, Response}
@doc """
@ -16,16 +17,16 @@ defmodule Explorer.ExchangeRates.Source do
@spec fetch_exchange_rates_for_token(String.t()) :: {:ok, [Token.t()]} | {:error, any}
def fetch_exchange_rates_for_token(symbol) do
source = Application.get_env(:explorer, Source)[:source]
source_url = source.source_url(symbol)
fetch_exchange_rates_request(source, source_url, source.headers())
source_url = CoinGecko.source_url(symbol)
headers = CoinGecko.headers()
fetch_exchange_rates_request(CoinGecko, source_url, headers)
end
@spec fetch_exchange_rates_for_token_address(String.t()) :: {:ok, [Token.t()]} | {:error, any}
def fetch_exchange_rates_for_token_address(address_hash) do
source = Application.get_env(:explorer, Source)[:source]
source_url = source.source_url(address_hash)
fetch_exchange_rates_request(source, source_url, source.headers())
source_url = CoinGecko.source_url(address_hash)
headers = CoinGecko.headers()
fetch_exchange_rates_request(CoinGecko, source_url, headers)
end
defp fetch_exchange_rates_request(_source, source_url, _headers) when is_nil(source_url),
@ -87,8 +88,7 @@ defmodule Explorer.ExchangeRates.Source do
@spec exchange_rates_source() :: module()
defp exchange_rates_source do
source = Application.get_env(:explorer, Source)[:source]
config(:source) || source
config(:source) || Explorer.ExchangeRates.Source.CoinGecko
end
@spec config(atom()) :: term

@ -61,7 +61,7 @@ defmodule Explorer.ExchangeRates.Source.TokenBridge do
@spec secondary_source() :: module()
defp secondary_source do
config(:secondary_source) || Application.get_env(:explorer, Explorer.ExchangeRates.Source)[:source]
config(:secondary_source) || Explorer.ExchangeRates.Source.CoinGecko
end
@spec config(atom()) :: term

Loading…
Cancel
Save