From ca3bd63667c7c357e899aeceb91d7adb512d65eb Mon Sep 17 00:00:00 2001 From: Michael Mallan Date: Mon, 10 Feb 2025 11:19:49 +0000 Subject: [PATCH 1/2] gui(installer): prevent deletion of all recovery paths --- liana-gui/src/installer/step/descriptor/editor/mod.rs | 1 + liana-gui/src/installer/view/editor/template/custom.rs | 8 ++++++-- 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/liana-gui/src/installer/step/descriptor/editor/mod.rs b/liana-gui/src/installer/step/descriptor/editor/mod.rs index b4dfa94c..c6157d9e 100644 --- a/liana-gui/src/installer/step/descriptor/editor/mod.rs +++ b/liana-gui/src/installer/step/descriptor/editor/mod.rs @@ -508,6 +508,7 @@ impl Step for DefineDescriptor { threshold: p.threshold, keys: self.path_keys(p), }), + self.paths.len().saturating_sub(1), // subtract 1 for primary path self.valid(), ), }; diff --git a/liana-gui/src/installer/view/editor/template/custom.rs b/liana-gui/src/installer/view/editor/template/custom.rs index e6eb0782..5f72811c 100644 --- a/liana-gui/src/installer/view/editor/template/custom.rs +++ b/liana-gui/src/installer/view/editor/template/custom.rs @@ -59,6 +59,7 @@ pub fn custom_template<'a>( use_taproot: bool, primary_path: Path<'a>, recovery_paths: &mut dyn Iterator>, + num_recovery_paths: usize, valid: bool, ) -> Element<'a, Message> { layout( @@ -144,6 +145,9 @@ pub fn custom_template<'a>( .iter() .enumerate() .map(|(j, recovery_key)| { + // We cannot delete a key if doing so would remove all recovery paths, + // i.e. if there is only 1 recovery path and it contains only 1 key. + let fixed = num_recovery_paths < 2 && p.keys.len() < 2; if let Some(key) = recovery_key { defined_key( &key.name, @@ -154,14 +158,14 @@ pub fn custom_template<'a>( } else { None }, - false, + fixed, ) } else { undefined_key( color::ORANGE, "Recovery key", !p.keys[0..j].iter().any(|k| k.is_none()), - false, + fixed, ) } .map(move |msg| message::DefinePath::Key(j, msg)) From 99ba17d0920d9d00a6d0df6d3c5169fe524b1363 Mon Sep 17 00:00:00 2001 From: Michael Mallan Date: Mon, 10 Feb 2025 13:28:59 +0000 Subject: [PATCH 2/2] gui(installer): allow deletion of any prim key if more than one --- liana-gui/src/installer/view/editor/template/custom.rs | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/liana-gui/src/installer/view/editor/template/custom.rs b/liana-gui/src/installer/view/editor/template/custom.rs index 5f72811c..24cc011d 100644 --- a/liana-gui/src/installer/view/editor/template/custom.rs +++ b/liana-gui/src/installer/view/editor/template/custom.rs @@ -62,6 +62,7 @@ pub fn custom_template<'a>( num_recovery_paths: usize, valid: bool, ) -> Element<'a, Message> { + let prim_keys_fixed = primary_path.keys.len() < 2; // can only delete a primary key if there are 2 or more layout( progress, None, @@ -114,14 +115,14 @@ pub fn custom_template<'a>( } else { None }, - i == 0, + prim_keys_fixed, ) } else { undefined_key( color::GREEN, "Primary key", !primary_path.keys[0..i].iter().any(|k| k.is_none()), - i == 0, + prim_keys_fixed, ) } .map(move |msg| message::DefinePath::Key(i, msg))