From ecd35d2bd171c5975de62188d142494268e394a2 Mon Sep 17 00:00:00 2001 From: edouard Date: Mon, 9 Jan 2023 11:01:23 +0100 Subject: [PATCH] Add available balance to choose recipient step --- gui/src/app/state/spend/mod.rs | 2 +- gui/src/app/state/spend/step.rs | 19 ++++++++++++++----- gui/src/app/view/spend/step.rs | 17 ++++++++++++----- 3 files changed, 27 insertions(+), 11 deletions(-) diff --git a/gui/src/app/state/spend/mod.rs b/gui/src/app/state/spend/mod.rs index 9d10d729..c07a5e9b 100644 --- a/gui/src/app/state/spend/mod.rs +++ b/gui/src/app/state/spend/mod.rs @@ -109,7 +109,7 @@ impl CreateSpendPanel { draft: step::TransactionDraft::default(), current: 0, steps: vec![ - Box::new(step::ChooseRecipients::default()), + Box::new(step::ChooseRecipients::new(coins)), Box::new(step::ChooseCoins::new( coins.to_vec(), timelock, diff --git a/gui/src/app/state/spend/step.rs b/gui/src/app/state/spend/step.rs index 890ec0ad..49f3e7d8 100644 --- a/gui/src/app/state/spend/step.rs +++ b/gui/src/app/state/spend/step.rs @@ -42,22 +42,30 @@ pub trait Step { } pub struct ChooseRecipients { + balance_available: Amount, recipients: Vec, is_valid: bool, is_duplicate: bool, } -impl std::default::Default for ChooseRecipients { - fn default() -> Self { +impl ChooseRecipients { + pub fn new(coins: &[Coin]) -> Self { Self { + balance_available: coins + .iter() + .filter_map(|coin| { + if coin.spend_info.is_none() { + Some(coin.amount) + } else { + None + } + }) + .sum(), recipients: vec![Recipient::default()], is_valid: false, is_duplicate: false, } } -} - -impl ChooseRecipients { fn check_valid(&mut self) { self.is_valid = !self.recipients.is_empty(); self.is_duplicate = false; @@ -117,6 +125,7 @@ impl Step for ChooseRecipients { fn view<'a>(&'a self, _cache: &'a Cache) -> Element<'a, view::Message> { view::spend::step::choose_recipients_view( + &self.balance_available, self.recipients .iter() .enumerate() diff --git a/gui/src/app/view/spend/step.rs b/gui/src/app/view/spend/step.rs index 93051760..18e0179b 100644 --- a/gui/src/app/view/spend/step.rs +++ b/gui/src/app/view/spend/step.rs @@ -23,12 +23,13 @@ use crate::{ }, }; -pub fn choose_recipients_view( - recipients: Vec>, +pub fn choose_recipients_view<'a>( + balance_available: &'a Amount, + recipients: Vec>, total_amount: Amount, is_valid: bool, duplicate: bool, -) -> Element { +) -> Element<'a, Message> { modal( false, None, @@ -53,8 +54,14 @@ pub fn choose_recipients_view( .spacing(20) .align_items(Alignment::Center) .push( - Container::new(text(format!("{}", total_amount)).bold()) - .width(Length::Fill), + Container::new( + Row::new() + .align_items(Alignment::Center) + .spacing(5) + .push(text(format!("{}", total_amount)).bold()) + .push(text(format!("/ {}", balance_available))), + ) + .width(Length::Fill), ) .push_maybe(if duplicate { Some(text("Two recipient addresses are the same").style(color::WARNING))