Consolidate `Application.get_env(:explorer, :coin)` calls

pull/201/head
Tim Mecklem 7 years ago
parent 5306637825
commit 4404fa8590
  1. 7
      apps/explorer/lib/explorer.ex
  2. 7
      apps/explorer/lib/explorer/market/history/source/crypto_compare.ex
  3. 4
      apps/explorer_web/lib/explorer_web/controllers/address_controller.ex
  4. 4
      apps/explorer_web/lib/explorer_web/controllers/address_internal_transaction_controller.ex
  5. 4
      apps/explorer_web/lib/explorer_web/controllers/address_transaction_controller.ex
  6. 6
      apps/explorer_web/lib/explorer_web/controllers/chain_controller.ex
  7. 4
      apps/explorer_web/lib/explorer_web/controllers/transaction_controller.ex
  8. 6
      apps/explorer_web/lib/explorer_web/controllers/transaction_internal_transaction_controller.ex
  9. 4
      apps/explorer_web/lib/explorer_web/controllers/transaction_log_controller.ex

@ -6,4 +6,11 @@ defmodule Explorer do
Contexts are also responsible for managing your data, regardless
if it comes from the database, an external API or others.
"""
@doc """
Returns the configured coin for `Explorer`
"""
def coin do
Application.get_env(:explorer, :coin)
end
end

@ -37,11 +37,6 @@ defmodule Explorer.Market.History.Source.CryptoCompare do
configured_url || "https://min-api.cryptocompare.com"
end
@spec configured_coin :: String.t()
defp configured_coin do
Application.get_env(:explorer, :coin)
end
@spec date(unix_timestamp()) :: Date.t()
defp date(unix_timestamp) do
unix_timestamp
@ -65,7 +60,7 @@ defmodule Explorer.Market.History.Source.CryptoCompare do
@spec history_url(non_neg_integer()) :: String.t()
defp history_url(previous_days) do
query_params = %{
"fsym" => configured_coin(),
"fsym" => Explorer.coin(),
"limit" => previous_days,
"tsym" => "USD"
}

@ -8,10 +8,6 @@ defmodule ExplorerWeb.AddressController do
redirect(conn, to: address_transaction_path(conn, :index, locale, id))
end
def coin do
Application.get_env(:explorer, :coin)
end
def transaction_count(%Address{} = address) do
Chain.address_to_transaction_count(address)
end

@ -5,7 +5,7 @@ defmodule ExplorerWeb.AddressInternalTransactionController do
use ExplorerWeb, :controller
import ExplorerWeb.AddressController, only: [coin: 0, transaction_count: 1]
import ExplorerWeb.AddressController, only: [transaction_count: 1]
alias Explorer.{Chain, Market}
alias Explorer.ExchangeRates.Token
@ -31,7 +31,7 @@ defmodule ExplorerWeb.AddressInternalTransactionController do
conn,
"index.html",
address: address,
exchange_rate: Market.get_exchange_rate(coin()) || Token.null(),
exchange_rate: Market.get_exchange_rate(Explorer.coin()) || Token.null(),
filter: params["filter"],
page: page,
transaction_count: transaction_count(address)

@ -5,7 +5,7 @@ defmodule ExplorerWeb.AddressTransactionController do
use ExplorerWeb, :controller
import ExplorerWeb.AddressController, only: [coin: 0, transaction_count: 1]
import ExplorerWeb.AddressController, only: [transaction_count: 1]
alias Explorer.{Chain, Market}
alias Explorer.ExchangeRates.Token
@ -33,7 +33,7 @@ defmodule ExplorerWeb.AddressTransactionController do
conn,
"index.html",
address: address,
exchange_rate: Market.get_exchange_rate(coin()) || Token.null(),
exchange_rate: Market.get_exchange_rate(Explorer.coin()) || Token.null(),
filter: params["filter"],
page: page,
transaction_count: transaction_count(address)

@ -12,7 +12,7 @@ defmodule ExplorerWeb.ChainController do
"show.html",
chain: Statistics.fetch(),
market_history_data: Market.fetch_recent_history(30),
exchange_rate: Market.get_exchange_rate(coin()) || Token.null()
exchange_rate: Market.get_exchange_rate(Explorer.coin()) || Token.null()
)
end
@ -29,10 +29,6 @@ defmodule ExplorerWeb.ChainController do
end
end
defp coin do
Application.get_env(:explorer, :coin)
end
defp redirect_search_results(conn, %Address{} = item) do
redirect(conn, to: address_path(conn, :show, Gettext.get_locale(), item))
end

@ -48,8 +48,4 @@ defmodule ExplorerWeb.TransactionController do
defp last_seen_collated_hash(transactions) do
List.last(transactions).hash
end
def coin do
Application.get_env(:explorer, :coin)
end
end

@ -1,8 +1,6 @@
defmodule ExplorerWeb.TransactionInternalTransactionController do
use ExplorerWeb, :controller
import ExplorerWeb.TransactionController, only: [coin: 0]
alias Explorer.{Chain, Market}
alias Explorer.ExchangeRates.Token
@ -29,10 +27,10 @@ defmodule ExplorerWeb.TransactionInternalTransactionController do
render(
conn,
"index.html",
exchange_rate: Market.get_exchange_rate(Explorer.coin()) || Token.null(),
internal_transactions: internal_transactions,
max_block_number: max_block_number,
transaction: transaction,
exchange_rate: Market.get_exchange_rate(coin()) || Token.null()
transaction: transaction
)
else
:error ->

@ -1,8 +1,6 @@
defmodule ExplorerWeb.TransactionLogController do
use ExplorerWeb, :controller
import ExplorerWeb.TransactionController, only: [coin: 0]
alias Explorer.{Chain, Market}
alias Explorer.ExchangeRates.Token
@ -31,7 +29,7 @@ defmodule ExplorerWeb.TransactionLogController do
logs: logs,
max_block_number: max_block_number(),
transaction: transaction,
exchange_rate: Market.get_exchange_rate(coin()) || Token.null()
exchange_rate: Market.get_exchange_rate(Explorer.coin()) || Token.null()
)
else
:error ->

Loading…
Cancel
Save