Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions web/config/dev.exs
Original file line number Diff line number Diff line change
Expand Up @@ -110,3 +110,5 @@ config :zk_arcade, :nft_contract_address, "0xdbC43Ba45381e02825b14322cDdd15eC4B3

config :zk_arcade, :ip_info_api_key, "<IP_INFO_API_KEY>"
config :zk_arcade, :ipgeolocation_api_key, "<IPGEOLOCATION_API_KEY>"

config :zk_arcade, :eth_usd_price_fallback, System.get_env("ETH_PRICE_USD")
2 changes: 2 additions & 0 deletions web/config/runtime.exs
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,8 @@ if config_env() == :prod do
config :zk_arcade, :ip_info_api_key, System.get_env("IP_INFO_API_KEY")
config :zk_arcade, :ipgeolocation_api_key, System.get_env("IPGEOLOCATION_API_KEY")

config :zk_arcade, :eth_usd_price_fallback, String.to_float(System.get_env("ETH_PRICE_USD"))

newrelic_license_key = System.get_env("NEWRELIC_KEY")
newrelic_app_name = System.get_env("NEWRELIC_APP_NAME")

Expand Down
19 changes: 17 additions & 2 deletions web/lib/zk_arcade/eth_price.ex
Original file line number Diff line number Diff line change
Expand Up @@ -45,8 +45,23 @@ defmodule ZkArcade.EthPrice do
case fetch_from_cryptoprices() do
{:ok, price} ->
{:ok, price}
{:error, reason} ->
{:error, reason}
{:error, _} ->
# As a last option, try to get from environment variable

Logger.error("Failed to get the initial ETH price from coingecko and cryptoprices, using environment set value as fallback")

case Application.get_env(:zk_arcade, :eth_usd_price_fallback) do
nil ->
{:error, "ETH_PRICE_USD environment variable is not set"}
price_str ->
case Float.parse(price_str) do
{price, ""} when is_float(price) and price > 0 ->
Logger.info("Successfully fetched ETH price from environment variable: #{price}")
{:ok, price}
_ ->
{:error, "Invalid ETH_PRICE_USD environment variable format"}
end
end
end
end
end
Expand Down