From 03c2bd76b8c6c1b721014afb37da7732ddfeb0cd Mon Sep 17 00:00:00 2001 From: jp1ac4 <121959000+jp1ac4@users.noreply.github.com> Date: Wed, 13 Sep 2023 11:39:45 +0100 Subject: [PATCH 1/3] gui(installer): install and start automatically on final step --- gui/src/installer/step/mod.rs | 35 ++++---- gui/src/installer/view.rs | 148 ++-------------------------------- 2 files changed, 29 insertions(+), 154 deletions(-) diff --git a/gui/src/installer/step/mod.rs b/gui/src/installer/step/mod.rs index 8fbaadaa..cfa579a5 100644 --- a/gui/src/installer/step/mod.rs +++ b/gui/src/installer/step/mod.rs @@ -20,7 +20,10 @@ use liana::miniscript::bitcoin::bip32::Fingerprint; use liana_ui::widget::*; -use crate::installer::{context::Context, message::Message, view}; +use crate::{ + bitcoind::Bitcoind, + installer::{context::Context, message::Message, view}, +}; pub trait Step { fn update(&mut self, _message: Message) -> Command { @@ -60,7 +63,7 @@ impl From for Box { pub struct Final { generating: bool, - context: Option, + internal_bitcoind: Option, warning: Option, config_path: Option, hot_signer_fingerprint: Fingerprint, @@ -70,7 +73,7 @@ pub struct Final { impl Final { pub fn new(hot_signer_fingerprint: Fingerprint) -> Self { Self { - context: None, + internal_bitcoind: None, generating: false, warning: None, config_path: None, @@ -82,7 +85,7 @@ impl Final { impl Step for Final { fn load_context(&mut self, ctx: &Context) { - self.context = Some(ctx.clone()); + self.internal_bitcoind = ctx.internal_bitcoind.clone(); if let Some(signer) = &ctx.recovered_signer { self.hot_signer_fingerprint = signer.fingerprint(); self.hot_signer_is_not_used = false; @@ -98,6 +101,13 @@ impl Step for Final { self.hot_signer_is_not_used = true; } } + fn load(&self) -> Command { + if !self.generating && self.config_path.is_none() { + Command::perform(async {}, |_| Message::Install) + } else { + Command::none() + } + } fn update(&mut self, message: Message) -> Command { match message { Message::Installed(res) => { @@ -107,7 +117,13 @@ impl Step for Final { self.config_path = None; self.warning = Some(e.to_string()); } - Ok(path) => self.config_path = Some(path), + Ok(path) => { + self.config_path = Some(path.clone()); + let internal_bitcoind = self.internal_bitcoind.clone(); + return Command::perform(async {}, move |_| { + Message::Exit(path.clone(), internal_bitcoind) + }); + } } } Message::Install => { @@ -121,20 +137,11 @@ impl Step for Final { } fn view(&self, progress: (usize, usize)) -> Element { - let ctx = self.context.as_ref().unwrap(); - let desc = ctx.descriptor.as_ref().unwrap().to_string(); view::install( progress, - ctx, - desc, self.generating, self.config_path.as_ref(), self.warning.as_ref(), - if self.hot_signer_is_not_used { - None - } else { - Some(self.hot_signer_fingerprint) - }, ) } } diff --git a/gui/src/installer/view.rs b/gui/src/installer/view.rs index eada4c36..3ee62d28 100644 --- a/gui/src/installer/view.rs +++ b/gui/src/installer/view.rs @@ -24,7 +24,6 @@ use crate::{ bitcoind::StartInternalBitcoindError, hw::HardwareWallet, installer::{ - context::Context, message::{self, Message}, prompt, step::{DownloadState, InstallState}, @@ -1090,158 +1089,27 @@ pub fn start_internal_bitcoind<'a>( pub fn install<'a>( progress: (usize, usize), - context: &Context, - descriptor: String, generating: bool, config_path: Option<&std::path::PathBuf>, warning: Option<&'a String>, - signer: Option, ) -> Element<'a, Message> { layout( progress, - "Final step", + "Finalize installation", Column::new() - .push(text( - "Check your information before finalizing the install process:", - )) - .push( - Container::new( - Column::new() - .spacing(10) - .push( - card::simple( - Column::new() - .spacing(5) - .push(text("Descriptor:").small().bold()) - .push(text(descriptor).small()), - ) - .width(Length::Fill), - ) - .push_maybe(if context.hws.is_empty() && signer.is_none() { - None - } else { - Some( - card::simple( - Column::new() - .spacing(5) - .push(text("Registered signing devices:").small().bold()) - .push_maybe(if context.hws.is_empty() { - None - } else { - Some(context.hws.iter().fold( - Column::new(), - |acc, hw| { - acc.push( - Row::new() - .spacing(5) - .push_maybe( - context.keys.iter().find_map(|k| { - if k.master_fingerprint == hw.1 - { - Some( - text(k.name.clone()) - .small() - .bold(), - ) - } else { - None - } - }), - ) - .push( - text(format!("#{}", hw.1)).small(), - ) - .push(text(hw.0.to_string()).small()), - ) - }, - )) - }) - .push_maybe(signer.as_ref().map(|fingerprint| { - Row::new() - .spacing(5) - .push_maybe(context.keys.iter().find_map(|k| { - if k.master_fingerprint == *fingerprint { - Some(text(k.name.clone()).small().bold()) - } else { - None - } - })) - .push(text(format!("#{}", fingerprint)).small()) - .push(text("This computer").small()) - })), - ) - .width(Length::Fill), - ) - }) - .push( - card::simple( - Column::new() - .push(text("Bitcoind:").small().bold()) - .push( - Row::new() - .spacing(5) - .align_items(Alignment::Center) - .push(text("Cookie path:").small()) - .push( - text(format!( - "{}", - context - .bitcoind_config - .as_ref() - .unwrap() - .cookie_path - .to_string_lossy() - )) - .small(), - ), - ) - .push( - Row::new() - .spacing(5) - .align_items(Alignment::Center) - .push(text("Address:").small()) - .push( - text(format!( - "{}", - context.bitcoind_config.as_ref().unwrap().addr - )) - .small(), - ), - ), - ) - .width(Length::Fill), - ), - ) - .max_width(1000), - ) - .push(Space::with_height(Length::Fixed(50.0))) .push_maybe(warning.map(|e| card::invalid(text(e)))) .push(if generating { - Container::new(button::primary(None, "Installing ...").width(Length::Fixed(200.0))) - } else if let Some(path) = config_path { + Container::new(text("Installing...")) + } else if config_path.is_some() { Container::new( - Column::new() - .push(Container::new(text("Installed !"))) - .push(Container::new( - button::primary(None, "Start") - .on_press(Message::Exit( - path.clone(), - context.internal_bitcoind.clone(), - )) - .width(Length::Fixed(200.0)), - )) + Row::new() + .spacing(10) .align_items(Alignment::Center) - .spacing(20), + .push(icon::circle_check_icon().style(color::GREEN)) + .push(text("Installed").style(color::GREEN)), ) - .padding(50) - .width(Length::Fill) - .center_x() } else { - Container::new( - button::primary(None, "Finalize installation") - .on_press(Message::Install) - .width(Length::Fixed(200.0)), - ) + Container::new(Space::with_height(Length::Fixed(25.0))) }) .spacing(10) .width(Length::Fill), From 45f91216d5d0991d7aebde8d4c8bc99edaf5521a Mon Sep 17 00:00:00 2001 From: jp1ac4 <121959000+jp1ac4@users.noreply.github.com> Date: Thu, 14 Sep 2023 14:11:41 +0100 Subject: [PATCH 2/3] gui(installer): remove unused fields from final step --- gui/src/installer/mod.rs | 7 +++---- gui/src/installer/step/mod.rs | 27 +++++++-------------------- 2 files changed, 10 insertions(+), 24 deletions(-) diff --git a/gui/src/installer/mod.rs b/gui/src/installer/mod.rs index 128ac34c..04ff4e22 100644 --- a/gui/src/installer/mod.rs +++ b/gui/src/installer/mod.rs @@ -120,7 +120,6 @@ impl Installer { } pub fn update(&mut self, message: Message) -> Command { - let hot_signer_fingerprint = self.signer.lock().unwrap().fingerprint(); match message { Message::CreateWallet => { self.steps = vec![ @@ -132,7 +131,7 @@ impl Installer { SelectBitcoindTypeStep::new().into(), InternalBitcoindStep::new(&self.context.data_dir).into(), DefineBitcoind::new().into(), - Final::new(hot_signer_fingerprint).into(), + Final::new().into(), ]; self.next() } @@ -147,7 +146,7 @@ impl Installer { SelectBitcoindTypeStep::new().into(), InternalBitcoindStep::new(&self.context.data_dir).into(), DefineBitcoind::new().into(), - Final::new(hot_signer_fingerprint).into(), + Final::new().into(), ]; self.next() } @@ -160,7 +159,7 @@ impl Installer { SelectBitcoindTypeStep::new().into(), InternalBitcoindStep::new(&self.context.data_dir).into(), DefineBitcoind::new().into(), - Final::new(hot_signer_fingerprint).into(), + Final::new().into(), ]; self.next() } diff --git a/gui/src/installer/step/mod.rs b/gui/src/installer/step/mod.rs index cfa579a5..e6664a9d 100644 --- a/gui/src/installer/step/mod.rs +++ b/gui/src/installer/step/mod.rs @@ -16,7 +16,6 @@ pub use mnemonic::{BackupMnemonic, RecoverMnemonic}; use std::path::PathBuf; use iced::{Command, Subscription}; -use liana::miniscript::bitcoin::bip32::Fingerprint; use liana_ui::widget::*; @@ -66,40 +65,28 @@ pub struct Final { internal_bitcoind: Option, warning: Option, config_path: Option, - hot_signer_fingerprint: Fingerprint, - hot_signer_is_not_used: bool, } impl Final { - pub fn new(hot_signer_fingerprint: Fingerprint) -> Self { + pub fn new() -> Self { Self { internal_bitcoind: None, generating: false, warning: None, config_path: None, - hot_signer_fingerprint, - hot_signer_is_not_used: false, } } } +impl Default for Final { + fn default() -> Self { + Self::new() + } +} + impl Step for Final { fn load_context(&mut self, ctx: &Context) { self.internal_bitcoind = ctx.internal_bitcoind.clone(); - if let Some(signer) = &ctx.recovered_signer { - self.hot_signer_fingerprint = signer.fingerprint(); - self.hot_signer_is_not_used = false; - } else if ctx - .descriptor - .as_ref() - .unwrap() - .to_string() - .contains(&self.hot_signer_fingerprint.to_string()) - { - self.hot_signer_is_not_used = false; - } else { - self.hot_signer_is_not_used = true; - } } fn load(&self) -> Command { if !self.generating && self.config_path.is_none() { From f771e674faccf150a5210b3abe829d443619c3e6 Mon Sep 17 00:00:00 2001 From: jp1ac4 <121959000+jp1ac4@users.noreply.github.com> Date: Wed, 4 Oct 2023 18:22:37 +0100 Subject: [PATCH 3/3] gui(installer): restrict clicking previous on final step --- gui/src/installer/view.rs | 38 ++++++++++++++++++++++---------------- 1 file changed, 22 insertions(+), 16 deletions(-) diff --git a/gui/src/installer/view.rs b/gui/src/installer/view.rs index 3ee62d28..502bea0f 100644 --- a/gui/src/installer/view.rs +++ b/gui/src/installer/view.rs @@ -302,7 +302,7 @@ pub fn define_descriptor<'a>( .push(Space::with_height(Length::Fixed(20.0))) .spacing(50), false, - None, + Some(Message::Previous), ) } @@ -422,7 +422,7 @@ pub fn import_descriptor<'a>( .push_maybe(error.map(|e| card::error("Invalid descriptor", e.to_string()))) .spacing(50), true, - None, + Some(Message::Previous), ) } @@ -630,7 +630,7 @@ pub fn participate_xpub<'a>( }) .spacing(50), true, - None, + Some(Message::Previous), ) } @@ -722,7 +722,7 @@ pub fn register_descriptor<'a>( }) .spacing(50), true, - None, + Some(Message::Previous), ) } @@ -790,7 +790,7 @@ pub fn backup_descriptor<'a>( }) .spacing(50), true, - None, + Some(Message::Previous), ) } @@ -877,7 +877,7 @@ pub fn define_bitcoin<'a>( ) .spacing(50), true, - None, + Some(Message::Previous), ) } @@ -971,7 +971,7 @@ pub fn select_bitcoind_type<'a>(progress: (usize, usize)) -> Element<'a, Message ), ), true, - None, + Some(Message::Previous), ) } @@ -1093,6 +1093,11 @@ pub fn install<'a>( config_path: Option<&std::path::PathBuf>, warning: Option<&'a String>, ) -> Element<'a, Message> { + let prev_msg = if !generating && warning.is_some() { + Some(Message::Previous) + } else { + None + }; layout( progress, "Finalize installation", @@ -1114,7 +1119,7 @@ pub fn install<'a>( .spacing(10) .width(Length::Fill), true, - None, + prev_msg, ) } @@ -1624,7 +1629,7 @@ pub fn backup_mnemonic<'a>( }) .spacing(50), true, - None, + Some(Message::Previous), ) } @@ -1727,7 +1732,7 @@ pub fn recover_mnemonic<'a>( }) .spacing(50), true, - None, + Some(Message::Previous), ) } @@ -1738,6 +1743,10 @@ fn layout<'a>( padding_left: bool, previous_message: Option, ) -> Element<'a, Message> { + let mut prev_button = button::transparent(Some(icon::previous_icon()), "Previous"); + if let Some(msg) = previous_message { + prev_button = prev_button.on_press(msg); + } Container::new(scrollable( Column::new() .width(Length::Fill) @@ -1746,12 +1755,9 @@ fn layout<'a>( Row::new() .align_items(Alignment::Center) .push( - Container::new( - button::transparent(Some(icon::previous_icon()), "Previous") - .on_press(previous_message.unwrap_or(Message::Previous)), - ) - .width(Length::FillPortion(2)) - .center_x(), + Container::new(prev_button) + .width(Length::FillPortion(2)) + .center_x(), ) .push(Container::new(h3(title)).width(Length::FillPortion(8))) .push(