Skip to content

Commit

Permalink
Leptos v0.6.5 (#40)
Browse files Browse the repository at this point in the history
* Leptos v0.6.5
* Use updated flake.nix borrowed from #56
  • Loading branch information
sectore authored Feb 13, 2024
1 parent 69175b8 commit fa100dc
Show file tree
Hide file tree
Showing 23 changed files with 326 additions and 458 deletions.
465 changes: 158 additions & 307 deletions Cargo.lock

Large diffs are not rendered by default.

7 changes: 3 additions & 4 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -25,10 +25,9 @@ fedimint-mint-client = "0.2.1-rc1"
fedimint-ln-client = "0.2.1-rc1"
futures = "0.3.28"
hex = "0.4.3"
leptos = { version = "0.4.8", features = ["csr"] }
leptos-qr-scanner = { git = "https://github.com/elsirion/leptos-qr-scanner", rev = "75e976e99d9c1ed64921081a23f7da823d2a0b6d" }
leptos_icons = { version = "0.0.15", features = ["macros", "BsLightningCharge", "FaCoinsSolid"] }
leptos_meta = { version = "0.4.8", features = ["csr"] }
leptos = { version = "0.6.5", features = ["csr"] }
leptos-qr-scanner = { git = "https://github.com/elsirion/leptos-qr-scanner", rev = "5830bd6f75d7836189ef1434f71a10222a737a44" }
leptos_meta = { version = "0.6.5", features = ["csr"] }
lightning-invoice = { version = "0.26.0", features = [ "serde" ] }
qrcode-generator = "4.1.8"

Expand Down
42 changes: 29 additions & 13 deletions src/client.rs
Original file line number Diff line number Diff line change
@@ -1,26 +1,31 @@
use crate::db::PersistentMemDb;
use fedimint_client::secret::{PlainRootSecretStrategy, RootSecretStrategy};
use fedimint_core::core::OperationId;
use fedimint_client::{Client, FederationInfo};
use fedimint_core::api::InviteCode;
use fedimint_core::db::{IRawDatabase};
use fedimint_core::core::OperationId;
use fedimint_core::db::IDatabaseTransactionOpsCore;
use fedimint_core::db::IRawDatabase;
use fedimint_core::task::spawn;
use fedimint_core::util::BoxStream;
use fedimint_core::Amount;
use fedimint_ln_client::{LightningClientInit, LightningClientModule, LightningOperationMeta, LightningOperationMetaPay, LightningOperationMetaVariant};
use fedimint_ln_client::{
LightningClientInit, LightningClientModule, LightningOperationMeta, LightningOperationMetaPay,
LightningOperationMetaVariant,
};
use fedimint_mint_client::{
MintClientInit, MintClientModule, MintOperationMeta, MintOperationMetaVariant, OOBNotes,
};
use fedimint_wallet_client::WalletClientInit;
use futures::StreamExt;
use leptos::warn;
use leptos::logging::warn;
use lightning_invoice::{Bolt11Invoice, Bolt11InvoiceDescription};
use rand::thread_rng;
use serde::{Deserialize, Serialize};
use std::fmt::{Debug, Formatter};
use std::str::FromStr;
use std::time::SystemTime;
use fedimint_mint_client::{MintClientInit, MintClientModule, MintOperationMeta, MintOperationMetaVariant, OOBNotes};
use thiserror::Error as ThisError;
use tokio::sync::{mpsc, oneshot, watch};
use fedimint_core::db::IDatabaseTransactionOpsCore;
use rand::thread_rng;
use tracing::{debug, info};

#[derive(Debug, Clone)]
Expand Down Expand Up @@ -179,8 +184,11 @@ async fn run_client(mut rpc: mpsc::Receiver<RpcCall>) {
client_builder.with_module(MintClientInit);
client_builder.with_module(LightningClientInit);
client_builder.with_primary_module(1);
client_builder.with_federation_info(FederationInfo::from_invite_code(invite_code).await.unwrap());
let client_res = client_builder.build(PlainRootSecretStrategy::to_root_secret(&client_secret)).await;
client_builder
.with_federation_info(FederationInfo::from_invite_code(invite_code).await.unwrap());
let client_res = client_builder
.build(PlainRootSecretStrategy::to_root_secret(&client_secret))
.await;

match client_res {
Ok(client) => {
Expand Down Expand Up @@ -256,7 +264,10 @@ async fn run_client(mut rpc: mpsc::Receiver<RpcCall>) {
info!("Receiving notes: \"{notes}\"");
let notes: OOBNotes = notes.parse()?;
let amount = notes.total_amount();
client.get_first_module::<MintClientModule>().reissue_external_notes(notes, ()).await?;
client
.get_first_module::<MintClientModule>()
.reissue_external_notes(notes, ())
.await?;
Ok(RpcResponse::Receive(amount))
}
let _ = response_sender
Expand Down Expand Up @@ -288,7 +299,8 @@ async fn run_client(mut rpc: mpsc::Receiver<RpcCall>) {
amount,
description,
} => {
let (operation_id, invoice) = match client.get_first_module::<LightningClientModule>()
let (operation_id, invoice) = match client
.get_first_module::<LightningClientModule>()
.create_bolt11_invoice(amount, description, None, ())
.await
{
Expand All @@ -302,7 +314,8 @@ async fn run_client(mut rpc: mpsc::Receiver<RpcCall>) {
};

let (await_paid_sender, await_paid_receiver) = watch::channel(false);
let mut subscription = client.get_first_module::<LightningClientModule>()
let mut subscription = client
.get_first_module::<LightningClientModule>()
.subscribe_ln_receive(operation_id)
.await
.expect("subscribing to a just created operation can't fail")
Expand Down Expand Up @@ -356,7 +369,10 @@ async fn run_client(mut rpc: mpsc::Receiver<RpcCall>) {

(amount, description)
}
LightningOperationMetaVariant::Pay(LightningOperationMetaPay {invoice, ..}) => {
LightningOperationMetaVariant::Pay(LightningOperationMetaPay {
invoice,
..
}) => {
// TODO: add fee
let amount = -(invoice
.amount_milli_satoshis()
Expand Down
35 changes: 17 additions & 18 deletions src/components/app.rs
Original file line number Diff line number Diff line change
@@ -1,30 +1,29 @@
use crate::components::{Footer, Joined, Logo, SubmitForm, WalletSelector};

use crate::client::ClientRpc;
use crate::components::service_worker::ServiceWorker;
use crate::context::provide_client_context;
use crate::utils::empty_view;
use anyhow::anyhow;
use leptos::*;
use leptos_meta::{Title, Meta, Link};
use leptos::SignalGet;
use leptos::*;
use leptos_meta::{Link, Meta, Title};
use tracing::info;
use crate::components::service_worker::ServiceWorker;

//
// App component
//
#[component]
pub fn App(cx: Scope) -> impl IntoView {
pub fn App() -> impl IntoView {
pub const CODE_VERSION: &str = env!("FEDIMINT_BUILD_CODE_VERSION");

info!("Starting Webimint version {CODE_VERSION} ...");

let client = ClientRpc::new();
provide_client_context(cx, client.clone());
provide_client_context(client.clone());

let res_client = client.clone();
let wallets_resource = create_resource(
cx,
|| (),
move |()| {
let client = res_client.clone();
Expand All @@ -33,13 +32,13 @@ pub fn App(cx: Scope) -> impl IntoView {
);

let action_client = client.clone();
let select_wallet_action = create_action(cx, move |wallet_name: &String| {
let select_wallet_action = create_action(move |wallet_name: &String| {
let wallet_name = wallet_name.clone();
let client = action_client.clone();
async move { client.select_wallet(wallet_name).await.ok() }
});

let join_action = create_action(cx, move |invite: &String| {
let join_action = create_action(move |invite: &String| {
let invite = invite.clone();
let client = client.clone();
async move { client.join(invite).await }
Expand All @@ -60,7 +59,7 @@ pub fn App(cx: Scope) -> impl IntoView {
|| select_wallet == Some(Some(true)))
};

view! { cx,
view! {
<ServiceWorker path="./service-worker.js" />

<Title text="Webimint" />
Expand All @@ -80,27 +79,27 @@ pub fn App(cx: Scope) -> impl IntoView {
<main class="w-full pb-24 flex-grow ">
<Show
when=show_select_wallet
fallback=|_| empty_view()
fallback=|| empty_view()
>
{
move || {
if let Some(Some(wallets)) = wallets_resource.read(cx) {
view! { cx,
if let Some(Some(wallets)) = wallets_resource.get() {
view! {
<WalletSelector
available=wallets
on_select=move |wallet_name| select_wallet_action.dispatch(wallet_name)
/>
}.into_view(cx)
}.into_view()
} else {
empty_view().into_view(cx)
empty_view().into_view()
}
}
}

</Show>
<Show
when=show_join
fallback=|_| empty_view()
fallback=|| empty_view()
>
<h1 class="font-heading text-gray-900 text-4xl font-semibold mb-6">"Join a Federation"</h1>
<SubmitForm
Expand All @@ -114,9 +113,9 @@ pub fn App(cx: Scope) -> impl IntoView {

<Show
when=show_join_error
fallback=|_| empty_view()
fallback=|| empty_view()
>
{move || view!{ cx, <div class="text-body text-md mt-4"><span class="text-red-500">{
{move || view!{<div class="text-body text-md mt-4"><span class="text-red-500">{
format!("✗ Failed to join federation: {:?}", join_action.value().with(|r| {
match r {
Some(Err(e)) =>anyhow!("{:?}", e),
Expand All @@ -128,7 +127,7 @@ pub fn App(cx: Scope) -> impl IntoView {

<Show
when=show_wallet
fallback=|_| empty_view()
fallback=|| empty_view()
>
<Joined />
</Show>
Expand Down
16 changes: 8 additions & 8 deletions src/components/balance.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
use fedimint_core::Amount;
use leptos::logging::*;
use leptos::*;

use crate::context::ClientContext;
Expand All @@ -7,10 +8,9 @@ use crate::context::ClientContext;
// Balance component
//
#[component]
pub fn Balance(cx: Scope, #[prop(optional, into)] class: String) -> impl IntoView {
let ClientContext { client, .. } = expect_context::<ClientContext>(cx);
pub fn Balance(#[prop(optional, into)] class: String) -> impl IntoView {
let ClientContext { client, .. } = expect_context::<ClientContext>();
let balance_resource = create_local_resource(
cx,
|| (),
move |()| async move {
let balance_stream = match client.get_value().subscribe_balance().await {
Expand All @@ -21,18 +21,18 @@ pub fn Balance(cx: Scope, #[prop(optional, into)] class: String) -> impl IntoVie
std::future::pending().await
}
};
create_signal_from_stream(cx, balance_stream)
create_signal_from_stream(balance_stream)
},
);
let balance = move || match balance_resource.read(cx) {
None => view! { cx, <p>"Loading..."</p> }.into_view(cx),
let balance = move || match balance_resource.get() {
None => view! { <p>"Loading..."</p> }.into_view(),
Some(balance) => {
let balance_msat = move || balance.get().unwrap_or(Amount::ZERO).msats;
view! { cx, {balance_msat} " msat" }.into_view(cx)
view! { {balance_msat} " msat" }.into_view()
}
};

view! { cx,
view! {
<div class=class>
<h2 class="text-xl leading-tight w-full font-body font-semibold pb-4 mb-4 text-gray-400 border-b-2 border-gray-200">"Balance"</h2>
<h3 class="text-4xl">{balance}</h3>
Expand Down
4 changes: 2 additions & 2 deletions src/components/footer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@ use leptos::*;
use crate::components::LogoFedimint;

#[component]
pub fn Footer(cx: Scope, version: &'static str, #[prop(optional, into)] class: String) -> impl IntoView {
pub fn Footer(version: &'static str, #[prop(optional, into)] class: String) -> impl IntoView {
let version_prefix: &'static str = &version[..7];
view! { cx,
view! {
<div class={format!("flex justify-center items-center text-body text-sm text-gray-500 {class}")}>
"Webimint version "
<a
Expand Down
19 changes: 9 additions & 10 deletions src/components/joined.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,19 +18,18 @@ enum Tab {
// First view whenever an user joined a Federation
//
#[component]
pub fn Joined(cx: Scope) -> impl IntoView {
let ClientContext { client, .. } = expect_context::<ClientContext>(cx);
pub fn Joined() -> impl IntoView {
let ClientContext { client, .. } = expect_context::<ClientContext>();

// get name of the federation
let name_resource = create_resource(
cx,
|| (),
move |_| async move { client.get_value().get_name().await },
);

let federation_label = move || {
name_resource
.read(cx)
.get()
.map(|value| match value {
Err(error) => format!("Failed to get federation name {error:?}"),
Ok(value) => value,
Expand All @@ -39,9 +38,9 @@ pub fn Joined(cx: Scope) -> impl IntoView {
.unwrap_or_else(|| "Loading...".into())
};

let (tab, set_tab) = create_signal(cx, Tab::Receive);
let (tab, set_tab) = create_signal(Tab::Receive);

view! { cx,
view! {
<h1 class="font-heading text-gray-900 text-4xl font-semibold">{federation_label}</h1>
<Balance class="my-12" />
<ul
Expand Down Expand Up @@ -112,25 +111,25 @@ pub fn Joined(cx: Scope) -> impl IntoView {

<Show
when=move || tab.get() == Tab::Send
fallback=|_| empty_view()
fallback=|| empty_view()
>
<Send />
</Show>
<Show
when=move || tab.get() == Tab::Receive
fallback=|_| empty_view()
fallback=|| empty_view()
>
<Receive />
</Show>
<Show
when=move || tab.get() == Tab::ReceiveLn
fallback=|_| empty_view()
fallback=|| empty_view()
>
<ReceiveLn />
</Show>
<Show
when=move || tab.get() == Tab::TxList
fallback=|_| empty_view()
fallback=|| empty_view()
>
<TxList update_signal=move || {tab.get();} />
</Show>
Expand Down
Loading

0 comments on commit fa100dc

Please sign in to comment.