Skip to content

Commit

Permalink
chore: add warning on ecash send excess amount
Browse files Browse the repository at this point in the history
  • Loading branch information
toyota-corolla0 committed Feb 27, 2024
1 parent 39791f2 commit 91c5979
Showing 1 changed file with 22 additions and 5 deletions.
27 changes: 22 additions & 5 deletions src/components/send_ecash.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
use fedimint_core::Amount;
use fedimint_mint_client::OOBNotes;
use leptos::*;

use super::{CopyableText, ErrorBlock, QrCode, SubmitButton, SuccessBlock};
use super::{CopyableText, ErrorBlock, QrCode, SubmitButton, SuccessBlock, WarningBlock};
use crate::client::RpcError;
use crate::context::ClientContext;

//
Expand All @@ -14,10 +16,20 @@ pub fn SendEcash() -> impl IntoView {
let (amount, set_amount) = create_signal("".to_owned());
let (error, set_error) = create_signal(None);

#[derive(Clone)]
struct ActionReturn {
requested_amount: Amount,
result: anyhow::Result<OOBNotes, RpcError>,
}
let client = client.clone();
let submit_action = create_action(move |amount: &Amount| {
let amount = amount.clone();
async move { client.get_value().ecash_send(amount).await }
let amount = amount.to_owned();
async move {
ActionReturn {
requested_amount: amount,
result: client.get_value().ecash_send(amount).await,
}
}
});

let parse_and_submit = move || {
Expand Down Expand Up @@ -67,7 +79,7 @@ pub fn SendEcash() -> impl IntoView {

{move || {
submit_action.value().get().map(|r| {
r.err().map(|err| {
r.result.err().map(|err| {
view! {
<ErrorBlock>
{format!("{:?}", err)}
Expand All @@ -79,13 +91,18 @@ pub fn SendEcash() -> impl IntoView {

{move || {
submit_action.value().get().map(|r| {
r.ok().map(|notes| {
r.result.ok().map(move |notes| {
let total = notes.total_amount();
let notes_string_signal = Signal::derive(move || notes.to_string());
view! {
<SuccessBlock>
{format!("Notes representing {} shown below.", total)}
</SuccessBlock>
<Show when=move || total != r.requested_amount>
<WarningBlock>
{format!("The notes represent {} more than the amount you requested.", total-r.requested_amount)}
</WarningBlock>
</Show>
<CopyableText
text=notes_string_signal
rows=10
Expand Down

0 comments on commit 91c5979

Please sign in to comment.