From e8d2fe2717583c071fc878b6d3f1fdb42c120bed Mon Sep 17 00:00:00 2001 From: Michael Mallan Date: Fri, 20 Dec 2024 14:40:13 +0000 Subject: [PATCH] send max from all owned coins only Coin selection considers only those unconfirmed coins from self, and the same should apply when the user chooses the MAX option without explicitly selecting coins. Unconfirmed coins that are not from self should only be included if the user has selected them explicitly. --- liana-gui/src/app/state/spend/step.rs | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/liana-gui/src/app/state/spend/step.rs b/liana-gui/src/app/state/spend/step.rs index 506214b3..504966e4 100644 --- a/liana-gui/src/app/state/spend/step.rs +++ b/liana-gui/src/app/state/spend/step.rs @@ -283,8 +283,11 @@ impl DefineSpend { } outpoints } else if self.send_max_to_recipient.is_some() { - // If user has not selected coins, send the max available from all coins. - self.coins.iter().map(|(c, _)| c.outpoint).collect() + // If user has not selected coins, send the max available from all owned coins. + self.coins + .iter() + .filter_map(|(c, _)| coin_is_owned(c).then_some(c.outpoint)) + .collect() } else { Vec::new() // pass empty list for auto-selection }; @@ -358,10 +361,9 @@ impl DefineSpend { self.amount_left_to_select = Some(Amount::from_sat(missing)); if !self.is_user_coin_selection { // The missing amount is based on all candidates for coin selection - // being used, which are all coins if there's a recipient with max - // or otherwise all owned coins. + // being used, which are all owned coins. for (coin, selected) in &mut self.coins { - *selected = self.send_max_to_recipient.is_some() || coin_is_owned(coin); + *selected = coin_is_owned(coin); } } if let Some((i, recipient)) = recipient_with_max {