diff --git a/src/leptos.rs b/src/leptos.rs index af861f9..3941520 100644 --- a/src/leptos.rs +++ b/src/leptos.rs @@ -8,6 +8,7 @@ use ethers::{ use leptos::*; use log::{debug, error}; use serde::Serialize; +use url::Url; /// Structure informing about current ethereum connection state #[derive(Debug, Clone)] @@ -112,7 +113,23 @@ impl EthereumInnerContext { builder.rpc_node(rpc_url); } - let ethereum = builder.url("http://localhost").build(); + let app_url = if let Some(app_url) = std::option_env!("APP_URL") { + app_url + } else { + "http://localhost" + }; + + let ethereum = builder + .url( + Url::parse(app_url).expect( + format!( + "Correct app url in variable APP_URL is not provided. '{:?}'", + std::option_env!("APP_URL") + ) + .as_str(), + ), + ) + .build(); let (ethers, set_ethers) = create_signal(ethereum); Self { ethers, set_ethers, state, set_state } diff --git a/src/yew.rs b/src/yew.rs index 4460066..02b397b 100644 --- a/src/yew.rs +++ b/src/yew.rs @@ -1,4 +1,3 @@ -use crate::{Ethereum, EthereumBuilder, EthereumError, Event, WalletType}; use ethers::{ providers::Provider, types::{Address, Signature}, @@ -11,6 +10,8 @@ use yew::{ Properties, }; +use crate::{Ethereum, EthereumBuilder, EthereumError, Event, WalletType}; + #[derive(Clone, PartialEq)] pub struct EthereumProviderState { pub ethereum: UseEthereum, @@ -32,6 +33,7 @@ pub fn ethereum_context_provider(props: &Props) -> Html { </ContextProvider<UseEthereum>> } } + #[derive(Clone, Debug)] pub struct UseEthereum { pub ethereum: UseStateHandle<Ethereum>, @@ -138,7 +140,22 @@ pub fn use_ethereum() -> UseEthereum { let chain_id = use_state(move || None as Option<u64>); let pairing_url = use_state(move || None as Option<String>); - let ethereum = use_state(move || builder.url(Url::parse("http://localhost").unwrap()).build()); + let app_url = + if let Some(app_url) = std::option_env!("APP_URL") { app_url } else { "http://localhost" }; + + let ethereum = use_state(move || { + builder + .url( + Url::parse(app_url).expect( + format!( + "Correct app url in variable APP_URL is not provided. '{:?}'", + std::option_env!("APP_URL") + ) + .as_ref(), + ), + ) + .build() + }); let con = connected.clone(); let acc = accounts.clone();