From c66a6e3698c274ec15b0358ec016d18511a53c19 Mon Sep 17 00:00:00 2001 From: Viktor Baranov Date: Fri, 27 May 2022 15:49:09 +0300 Subject: [PATCH] USD values from CoinGecko for TokenBridge --- .../lib/explorer/chain/supply/token_bridge.ex | 4 +--- .../lib/explorer/exchange_rates/source.ex | 16 ++++++++-------- .../exchange_rates/source/token_bridge.ex | 2 +- 3 files changed, 10 insertions(+), 12 deletions(-) diff --git a/apps/explorer/lib/explorer/chain/supply/token_bridge.ex b/apps/explorer/lib/explorer/chain/supply/token_bridge.ex index bf29e55d30..c83d757657 100644 --- a/apps/explorer/lib/explorer/chain/supply/token_bridge.ex +++ b/apps/explorer/lib/explorer/chain/supply/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 diff --git a/apps/explorer/lib/explorer/exchange_rates/source.ex b/apps/explorer/lib/explorer/exchange_rates/source.ex index bedd85c692..85d8697c0f 100644 --- a/apps/explorer/lib/explorer/exchange_rates/source.ex +++ b/apps/explorer/lib/explorer/exchange_rates/source.ex @@ -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 diff --git a/apps/explorer/lib/explorer/exchange_rates/source/token_bridge.ex b/apps/explorer/lib/explorer/exchange_rates/source/token_bridge.ex index 603cea3bea..3857046f58 100644 --- a/apps/explorer/lib/explorer/exchange_rates/source/token_bridge.ex +++ b/apps/explorer/lib/explorer/exchange_rates/source/token_bridge.ex @@ -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