Skip to content

Commit

Permalink
USD values from CoinGecko for TokenBridge
Browse files Browse the repository at this point in the history
  • Loading branch information
vbaranov committed May 27, 2022
1 parent 93f202d commit b27d546
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 11 deletions.
4 changes: 2 additions & 2 deletions .dialyzer-ignore
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,8 @@ lib/block_scout_web/views/layout_view.ex:145: The call 'Elixir.Poison.Parser':'p
lib/block_scout_web/views/layout_view.ex:237: The call 'Elixir.Poison.Parser':'parse!'
lib/explorer/smart_contract/reader.ex:435
lib/indexer/fetcher/token_total_supply_on_demand.ex:16
lib/explorer/exchange_rates/source.ex:116
lib/explorer/exchange_rates/source.ex:119
lib/explorer/exchange_rates/source.ex:117
lib/explorer/exchange_rates/source.ex:120
lib/explorer/smart_contract/solidity/verifier.ex:223
lib/block_scout_web/templates/address_contract/index.html.eex:158
lib/block_scout_web/templates/address_contract/index.html.eex:195
Expand Down
4 changes: 1 addition & 3 deletions apps/explorer/lib/explorer/chain/supply/token_bridge.ex
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
13 changes: 7 additions & 6 deletions apps/explorer/lib/explorer/exchange_rates/source.ex
Original file line number Diff line number Diff line change
Expand Up @@ -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 """
Expand All @@ -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),
Expand Down

0 comments on commit b27d546

Please sign in to comment.