Skip to content

Commit

Permalink
fix: fix for issue #13
Browse files Browse the repository at this point in the history
  • Loading branch information
day01 committed Jul 4, 2024
1 parent abaeb18 commit 5684546
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 3 deletions.
19 changes: 18 additions & 1 deletion src/leptos.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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)]
Expand Down Expand Up @@ -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 }
Expand Down
21 changes: 19 additions & 2 deletions src/yew.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
use crate::{Ethereum, EthereumBuilder, EthereumError, Event, WalletType};
use ethers::{
providers::Provider,
types::{Address, Signature},
Expand All @@ -11,6 +10,8 @@ use yew::{
Properties,
};

use crate::{Ethereum, EthereumBuilder, EthereumError, Event, WalletType};

#[derive(Clone, PartialEq)]
pub struct EthereumProviderState {
pub ethereum: UseEthereum,
Expand All @@ -32,6 +33,7 @@ pub fn ethereum_context_provider(props: &Props) -> Html {
</ContextProvider<UseEthereum>>
}
}

#[derive(Clone, Debug)]
pub struct UseEthereum {
pub ethereum: UseStateHandle<Ethereum>,
Expand Down Expand Up @@ -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();
Expand Down

0 comments on commit 5684546

Please sign in to comment.