From 68f8dbc43ba00de04b1ee33e0e8f2bd77242b127 Mon Sep 17 00:00:00 2001 From: jp1ac4 <121959000+jp1ac4@users.noreply.github.com> Date: Mon, 25 Mar 2024 08:46:44 +0000 Subject: [PATCH] gui: fix condition to create draft spend The `balance_available` value was not being refreshed when new coins were received and so it was sometimes not possible to click Next. It's enough, however, to check the amount left to select is 0, and so both the `balance_available` and `total_amount` fields can be removed. --- gui/src/app/state/spend/step.rs | 19 ------------------- gui/src/app/view/spend/mod.rs | 6 +----- 2 files changed, 1 insertion(+), 24 deletions(-) diff --git a/gui/src/app/state/spend/step.rs b/gui/src/app/state/spend/step.rs index 6efe4647..0cd1f2bd 100644 --- a/gui/src/app/state/spend/step.rs +++ b/gui/src/app/state/spend/step.rs @@ -68,7 +68,6 @@ pub trait Step { } pub struct DefineSpend { - balance_available: Amount, recipients: Vec, /// If set, this is the index of a recipient that should /// receive the max amount. @@ -99,16 +98,6 @@ impl DefineSpend { coins: &[Coin], timelock: u16, ) -> Self { - let balance_available = coins - .iter() - .filter_map(|coin| { - if coin.spend_info.is_none() { - Some(coin.amount) - } else { - None - } - }) - .sum(); let coins: Vec<(Coin, bool)> = coins .iter() .filter_map(|c| { @@ -121,7 +110,6 @@ impl DefineSpend { .collect(); Self { - balance_available, network, descriptor, curve: secp256k1::Secp256k1::verification_only(), @@ -630,7 +618,6 @@ impl Step for DefineSpend { fn view<'a>(&'a self, cache: &'a Cache) -> Element<'a, view::Message> { view::spend::create_spend_tx( cache, - &self.balance_available, self.recipients .iter() .enumerate() @@ -640,12 +627,6 @@ impl Step for DefineSpend { .map(view::Message::CreateSpend) }) .collect(), - Amount::from_sat( - self.recipients - .iter() - .map(|r| r.amount().unwrap_or(0_u64)) - .sum(), - ), self.is_valid, self.is_duplicate, self.timelock, diff --git a/gui/src/app/view/spend/mod.rs b/gui/src/app/view/spend/mod.rs index a5c9099f..4f5ad1e1 100644 --- a/gui/src/app/view/spend/mod.rs +++ b/gui/src/app/view/spend/mod.rs @@ -112,9 +112,7 @@ pub fn spend_view<'a>( #[allow(clippy::too_many_arguments)] pub fn create_spend_tx<'a>( cache: &'a Cache, - balance_available: &'a Amount, recipients: Vec>, - total_amount: Amount, is_valid: bool, duplicate: bool, timelock: u16, @@ -300,9 +298,7 @@ pub fn create_spend_tx<'a>( .push( if is_valid && !duplicate - && (is_self_send - || (total_amount < *balance_available - && Some(&Amount::from_sat(0)) == amount_left)) + && (is_self_send || Some(&Amount::from_sat(0)) == amount_left) { button::primary(None, "Next") .on_press(Message::CreateSpend(CreateSpendMessage::Generate))