From 789f952433d7ccc0f09924359bd87b83b0bdcf55 Mon Sep 17 00:00:00 2001 From: edouardparis Date: Mon, 30 Oct 2023 16:01:53 +0100 Subject: [PATCH] fix gui: update labels if user signed an unsaved tx --- gui/src/app/state/psbt.rs | 30 ++++++++++++++++++++++++++---- 1 file changed, 26 insertions(+), 4 deletions(-) diff --git a/gui/src/app/state/psbt.rs b/gui/src/app/state/psbt.rs index ead5d3aa..7931d22e 100644 --- a/gui/src/app/state/psbt.rs +++ b/gui/src/app/state/psbt.rs @@ -111,6 +111,7 @@ impl PsbtState { self.wallet.clone(), cache.datadir_path.clone(), cache.network, + self.saved, ); let cmd = action.load(daemon); self.action = Some(Box::new(action)); @@ -318,6 +319,7 @@ pub struct SignAction { hws: HardwareWallets, error: Option, signed: HashSet, + is_saved: bool, } impl SignAction { @@ -326,6 +328,7 @@ impl SignAction { wallet: Arc, datadir_path: PathBuf, network: Network, + is_saved: bool, ) -> Self { Self { chosen_hw: None, @@ -334,6 +337,7 @@ impl SignAction { wallet, error: None, signed, + is_saved, } } } @@ -384,10 +388,28 @@ impl Action for SignAction { self.signed.insert(fingerprint); let daemon = daemon.clone(); tx.psbt = psbt.clone(); - return Command::perform( - async move { daemon.update_spend_tx(&psbt).map_err(|e| e.into()) }, - Message::Updated, - ); + if self.is_saved { + return Command::perform( + async move { daemon.update_spend_tx(&psbt).map_err(|e| e.into()) }, + Message::Updated, + ); + // If the spend transaction was never saved before, then both the psbt and + // labels attached to it must be updated. + } else { + let mut labels = HashMap::>::new(); + for (item, label) in tx.labels() { + if !label.is_empty() { + labels.insert(label_item_from_str(item), Some(label.clone())); + } + } + return Command::perform( + async move { + daemon.update_spend_tx(&psbt)?; + daemon.update_labels(&labels).map_err(|e| e.into()) + }, + Message::Updated, + ); + } } }, Message::Updated(res) => match res {