Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update Leptos deps #108

Draft
wants to merge 5 commits into
base: main
Choose a base branch
from
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
1,012 changes: 502 additions & 510 deletions Cargo.lock

Large diffs are not rendered by default.

12 changes: 6 additions & 6 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -26,11 +26,11 @@ fvm_ipld_encoding = "0.5"
fvm_shared = { version = "~4.5" }
hex = "0.4"
http = { version = "1", optional = true }
leptos = "0.6"
leptos-use = "0.13"
leptos_axum = { version = "0.6", default-features = false, optional = true }
leptos_meta = "0.6"
leptos_router = "0.6"
leptos = "0.7.3"
leptos-use = "0.15.3"
leptos_axum = { version = "0.7.3", default-features = false, optional = true }
leptos_meta = "0.7.3"
leptos_router = "0.7.3"
libsecp256k1 = "0.7"
log = "0.4"
multihash-codetable = { version = "0.1" }
Expand All @@ -47,7 +47,7 @@ worker = { version = "0.4", features = ['http', 'axum'], optional = true }
worker-macros = { version = "0.4", features = ['http'], optional = true }

[features]
hydrate = ["leptos/hydrate", "leptos_meta/hydrate", "leptos_router/hydrate"]
hydrate = ["leptos/hydrate"]
ssr = [
"dep:tower",
"dep:http",
Expand Down
29 changes: 15 additions & 14 deletions src/app.rs
Original file line number Diff line number Diff line change
@@ -1,23 +1,24 @@
use leptos::{component, create_local_resource, event_target_value, view, IntoView, SignalGet};
use leptos_meta::*;
use leptos_router::*;

use crate::rpc_context::RpcContext;
use leptos::prelude::*;
use leptos::{component, leptos_dom::helpers::event_target_value, view, IntoView};
use leptos_meta::*;
use leptos_router::components::*;
use leptos_router::path;

#[component]
pub fn Loader(loading: impl Fn() -> bool + 'static) -> impl IntoView {
pub fn Loader(loading: impl Fn() -> bool + 'static + Send) -> impl IntoView {
view! { <span class:loader=loading /> }
}

#[component]
pub fn BlockchainExplorer() -> impl IntoView {
let rpc_context = RpcContext::use_context();
let network_name = create_local_resource(
let network_name = Resource::new(

Check failure on line 16 in src/app.rs

View workflow job for this annotation

GitHub Actions / deploy

`*mut u8` cannot be sent between threads safely

Check failure on line 16 in src/app.rs

View workflow job for this annotation

GitHub Actions / deploy

`Rc<RefCell<wasm_bindgen_futures::Inner>>` cannot be sent between threads safely

Check failure on line 16 in src/app.rs

View workflow job for this annotation

GitHub Actions / e2e

`*mut u8` cannot be sent between threads safely

Check failure on line 16 in src/app.rs

View workflow job for this annotation

GitHub Actions / e2e

`Rc<RefCell<wasm_bindgen_futures::Inner>>` cannot be sent between threads safely
move || rpc_context.get(),
move |provider| async move { provider.network_name().await.ok() },
);

let network_version = create_local_resource(
let network_version = Resource::new(
move || rpc_context.get(),
move |provider| async move { provider.network_version().await.ok() },
);
Expand All @@ -33,12 +34,12 @@
<p>StateNetworkName</p>
<p class="px-8">
<span>{move || network_name.get()}</span>
<Loader loading=move || network_name.loading().get() />
<Loader loading=move || network_name.get().is_none() />
</p>
<p>StateNetworkVersion</p>
<p class="px-8">
<span>{move || network_version.get()}</span>
<Loader loading=move || network_name.loading().get() />
<Loader loading=move || network_version.get().is_none() />
</p>
}
}
Expand All @@ -52,11 +53,11 @@
<Stylesheet href="/style.css" />
<Link rel="icon" type_="image/x-icon" href="/favicon.ico" />
<Router>
<Routes>
<Route path="/" view=BlockchainExplorer />
<Route path="/faucet" view=crate::faucet::views::Faucets />
<Route path="/faucet/calibnet" view=crate::faucet::views::Faucet_Calibnet />
<Route path="/faucet/mainnet" view=crate::faucet::views::Faucet_Mainnet />
<Routes fallback=|| "Not found.">
<Route path=path!("/") view=BlockchainExplorer />
<Route path=path!("/faucet") view=crate::faucet::views::Faucets />
<Route path=path!("/faucet/calibnet") view=crate::faucet::views::Faucet_Calibnet />
<Route path=path!("/faucet/mainnet") view=crate::faucet::views::Faucet_Mainnet />
</Routes>
</Router>
}
Expand Down
26 changes: 11 additions & 15 deletions src/faucet/controller.rs
Original file line number Diff line number Diff line change
@@ -1,10 +1,8 @@
use super::{model::FaucetModel, utils::sign_with_secret_key};
use cid::Cid;
use fvm_shared::{address::Network, econ::TokenAmount};
use leptos::{
create_local_resource, create_local_resource_with_initial_value, create_rw_signal, spawn_local,
SignalGet as _, SignalSet as _, SignalUpdate as _,
};
use leptos::prelude::*;
use leptos::task::spawn_local;

use crate::{
address::parse_address, lotus_json::LotusJson, message::message_transfer,
Expand All @@ -21,8 +19,8 @@
impl FaucetController {
pub fn new(network: Network) -> Self {
let is_mainnet = network == Network::Mainnet;
let target_address = create_rw_signal(String::new());
let target_balance = create_local_resource_with_initial_value(
let target_address = RwSignal::new(String::new());
let target_balance = Resource::new(

Check failure on line 23 in src/faucet/controller.rs

View workflow job for this annotation

GitHub Actions / deploy

`*mut u8` cannot be sent between threads safely

Check failure on line 23 in src/faucet/controller.rs

View workflow job for this annotation

GitHub Actions / deploy

`Rc<RefCell<wasm_bindgen_futures::Inner>>` cannot be sent between threads safely

Check failure on line 23 in src/faucet/controller.rs

View workflow job for this annotation

GitHub Actions / e2e

`*mut u8` cannot be sent between threads safely

Check failure on line 23 in src/faucet/controller.rs

View workflow job for this annotation

GitHub Actions / e2e

`Rc<RefCell<wasm_bindgen_futures::Inner>>` cannot be sent between threads safely
move || target_address.get(),
move |address| async move {
if let Ok(address) = parse_address(&address, network) {
Expand All @@ -35,9 +33,8 @@
TokenAmount::from_atto(0)
}
},
Some(TokenAmount::from_atto(0)),
);
let sender_address = create_local_resource(
let sender_address = Resource::new(
move || (),
move |()| async move {
faucet_address(is_mainnet)
Expand All @@ -46,7 +43,7 @@
.ok()
},
);
let faucet_balance = create_local_resource_with_initial_value(
let faucet_balance = Resource::new(
move || sender_address.get().flatten(),
move |addr| async move {
if let Some(addr) = addr {
Expand All @@ -59,14 +56,13 @@
TokenAmount::from_atto(0)
}
},
Some(TokenAmount::from_atto(0)),
);
let faucet = FaucetModel {
network,
send_disabled: create_rw_signal(false),
send_limited: create_rw_signal(0),
sent_messages: create_rw_signal(Vec::new()),
error_messages: create_rw_signal(Vec::new()),
send_disabled: RwSignal::new(false),
send_limited: RwSignal::new(0),
sent_messages: RwSignal::new(Vec::new()),
error_messages: RwSignal::new(Vec::new()),
target_balance,
faucet_balance,
target_address,
Expand All @@ -76,7 +72,7 @@

#[allow(dead_code)]
pub fn refetch_balances(&self) {
use leptos::SignalGetUntracked;
use leptos::prelude::GetUntracked;

log::info!("Checking for new transactions");
self.faucet.target_balance.refetch();
Expand Down
11 changes: 4 additions & 7 deletions src/faucet/model.rs
Original file line number Diff line number Diff line change
@@ -1,9 +1,6 @@
use cid::Cid;
use fvm_shared::{
address::{Address, Network},
econ::TokenAmount,
};
use leptos::{Resource, RwSignal};
use fvm_shared::{address::Network, econ::TokenAmount};
use leptos::prelude::{Resource, RwSignal};

#[derive(Clone)]
pub(super) struct FaucetModel {
Expand All @@ -12,7 +9,7 @@ pub(super) struct FaucetModel {
pub send_limited: RwSignal<i32>,
pub sent_messages: RwSignal<Vec<(Cid, bool)>>,
pub error_messages: RwSignal<Vec<String>>,
pub faucet_balance: Resource<Option<Address>, TokenAmount>,
pub target_balance: Resource<String, TokenAmount>,
pub faucet_balance: Resource<TokenAmount>,
pub target_balance: Resource<TokenAmount>,
pub target_address: RwSignal<String>,
}
2 changes: 1 addition & 1 deletion src/faucet/utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ use crate::{lotus_json::LotusJson, message::SignedMessage};
#[cfg(feature = "ssr")]
use fvm_shared::address::Network;
use fvm_shared::{address::Address, message::Message};
use leptos::{server, ServerFnError};
use leptos::{prelude::ServerFnError, server};

#[server]
pub async fn faucet_address(is_mainnet: bool) -> Result<LotusJson<Address>, ServerFnError> {
Expand Down
53 changes: 23 additions & 30 deletions src/faucet/views.rs
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
use fvm_shared::address::Network;
use leptos::{component, event_target_value, view, IntoView, SignalGet};
use leptos::{component, leptos_dom::helpers::event_target_value, view, IntoView};

use leptos::*;
use leptos::prelude::*;
#[cfg(feature = "hydrate")]
use leptos_use::*;

use crate::faucet::controller::FaucetController;

#[component]
pub fn Faucet(target_network: Network) -> impl IntoView {
let faucet = create_rw_signal(FaucetController::new(target_network));
let faucet = RwSignal::new(FaucetController::new(target_network));

#[cfg(feature = "hydrate")]
let _ = use_interval_fn(
Expand All @@ -33,7 +33,6 @@ pub fn Faucet(target_network: Network) -> impl IntoView {
view! {
{move || {
let errors = faucet.get().get_error_messages();
if !errors.is_empty() {
view! {
<div class="fixed top-4 left-1/2 transform -translate-x-1/2 z-50">
{errors
Expand Down Expand Up @@ -67,9 +66,6 @@ pub fn Faucet(target_network: Network) -> impl IntoView {
</div>
}
.into_view()
} else {
view! {}.into_view()
}
}}
<div class="max-w-2xl mx-auto">
<div class="my-4 flex">
Expand All @@ -86,30 +82,31 @@ pub fn Faucet(target_network: Network) -> impl IntoView {
class="flex-grow border border-gray-300 p-2 rounded-l"
/>
{move || {
if faucet.get().is_send_disabled() {
view! {
<button class="bg-gray-400 text-white font-bold py-2 px-4 rounded-r" disabled=true>
"Sending..."
</button>
}
let is_disabled = faucet.get().is_send_disabled() || faucet.get().get_send_rate_limit_remaining() > 0;
let button_text = if faucet.get().is_send_disabled() {
"Sending...".to_string()
} else if faucet.get().get_send_rate_limit_remaining() > 0 {
let duration = faucet.get().get_send_rate_limit_remaining();
view! {
<button class="bg-gray-400 text-white font-bold py-2 px-4 rounded-r" disabled=true>
{format!("Rate-limited! {duration}s")}
</button>
}
format!("Rate-limited! {duration}s")
} else {
view! {
<button
class="bg-green-500 hover:bg-green-600 text-white font-bold py-2 px-4 rounded-r"
on:click=move |_| {
"Send".to_string()
};
view! {
<button
class={if is_disabled {
"bg-gray-400 text-white font-bold py-2 px-4 rounded-r"
} else {
"bg-green-500 hover:bg-green-600 text-white font-bold py-2 px-4 rounded-r"
}}
disabled={is_disabled}
on:click=move |_| {
if !is_disabled {
faucet.get().drip();
}
>
Send
</button>
}
}
>
{button_text}
</button>
}
}}

Expand All @@ -127,7 +124,6 @@ pub fn Faucet(target_network: Network) -> impl IntoView {
<hr class="my-4 border-t border-gray-300" />
{move || {
let messages = faucet.get().get_sent_messages();
if !messages.is_empty() {
view! {
<div class="mt-4">
<h3 class="text-lg font-semibold">Transactions:</h3>
Expand All @@ -147,9 +143,6 @@ pub fn Faucet(target_network: Network) -> impl IntoView {
</div>
}
.into_view()
} else {
view! {}.into_view()
}
}}
</div>
}
Expand Down
4 changes: 2 additions & 2 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ mod utils;
pub fn hydrate() {
_ = console_log::init_with_level(log::Level::Debug);
console_error_panic_hook::set_once();
leptos::mount_to_body(App);
leptos::mount::mount_to_body(App);
}

#[cfg(feature = "ssr")]
Expand All @@ -25,7 +25,7 @@ mod ssr_imports {

use crate::{app::App, faucet};
use axum::{routing::post, Extension, Router};
use leptos::*;
use leptos::prelude::*;
use leptos_axum::{generate_route_list, LeptosRoutes};
use worker::{event, Context, Env, HttpRequest, Result};

Expand Down
Loading
Loading