From 0365794f910833e400f2418e52b6259f3ccb9b22 Mon Sep 17 00:00:00 2001 From: edouard Date: Mon, 28 Nov 2022 18:07:22 +0100 Subject: [PATCH] installer: add final step summary --- gui/src/installer/mod.rs | 8 ++- gui/src/installer/step/descriptor.rs | 19 +++--- gui/src/installer/step/mod.rs | 17 ++++- gui/src/installer/view.rs | 94 +++++++++++++++++++++++++--- 4 files changed, 115 insertions(+), 23 deletions(-) diff --git a/gui/src/installer/mod.rs b/gui/src/installer/mod.rs index 625ba123..5ba5f7de 100644 --- a/gui/src/installer/mod.rs +++ b/gui/src/installer/mod.rs @@ -166,9 +166,13 @@ impl Installer { pub async fn install(ctx: Context) -> Result { let hardware_wallets = ctx - .hw_tokens + .hws .iter() - .map(|(kind, fingerprint, token)| HardwareWalletConfig::new(kind, fingerprint, token)) + .filter_map(|(kind, fingerprint, token)| { + token + .as_ref() + .map(|token| HardwareWalletConfig::new(kind, fingerprint, token)) + }) .collect(); let mut cfg: liana::config::Config = ctx diff --git a/gui/src/installer/step/descriptor.rs b/gui/src/installer/step/descriptor.rs index 898e8a28..ba0b8739 100644 --- a/gui/src/installer/step/descriptor.rs +++ b/gui/src/installer/step/descriptor.rs @@ -399,7 +399,7 @@ pub struct RegisterDescriptor { descriptor: Option, processing: bool, chosen_hw: Option, - hws: Vec<(HardwareWallet, Option<[u8; 32]>)>, + hws: Vec<(HardwareWallet, Option<[u8; 32]>, bool)>, error: Option, } @@ -410,7 +410,7 @@ impl Step for RegisterDescriptor { fn update(&mut self, message: Message) -> Command { match message { Message::Select(i) => { - if let Some((hw, hmac)) = self.hws.get(i) { + if let Some((hw, hmac, _)) = self.hws.get(i) { if hmac.is_none() { let device = hw.device.clone(); let descriptor = self.descriptor.as_ref().unwrap().to_string(); @@ -434,7 +434,8 @@ impl Step for RegisterDescriptor { .iter_mut() .find(|hw_h| hw_h.0.fingerprint == fingerprint) { - hw_h.1 = Some(hmac.unwrap_or([0x00; 32])); + hw_h.1 = hmac; + hw_h.2 = true; } } Err(e) => self.error = Some(e), @@ -445,9 +446,9 @@ impl Step for RegisterDescriptor { if !self .hws .iter() - .any(|(h, _)| h.fingerprint == hw.fingerprint) + .any(|(h, _, _)| h.fingerprint == hw.fingerprint) { - self.hws.push((hw, None)); + self.hws.push((hw, None, false)); } } } @@ -459,11 +460,9 @@ impl Step for RegisterDescriptor { Command::none() } fn apply(&mut self, ctx: &mut Context) -> bool { - for (hw, token) in &self.hws { - if let Some(token) = token { - if *token != [0x00; 32] { - ctx.hw_tokens.push((hw.kind, hw.fingerprint, *token)); - } + for (hw, token, registered) in &self.hws { + if *registered { + ctx.hws.push((hw.kind, hw.fingerprint, *token)); } } true diff --git a/gui/src/installer/step/mod.rs b/gui/src/installer/step/mod.rs index a0b404fb..e0e08ee7 100644 --- a/gui/src/installer/step/mod.rs +++ b/gui/src/installer/step/mod.rs @@ -42,7 +42,11 @@ pub struct Context { pub bitcoin_config: BitcoinConfig, pub bitcoind_config: Option, pub descriptor: Option, - pub hw_tokens: Vec<(DeviceKind, bitcoin::util::bip32::Fingerprint, [u8; 32])>, + pub hws: Vec<( + DeviceKind, + bitcoin::util::bip32::Fingerprint, + Option<[u8; 32]>, + )>, pub data_dir: PathBuf, } @@ -53,7 +57,7 @@ impl Context { network, poll_interval_secs: Duration::from_secs(30), }, - hw_tokens: Vec::new(), + hws: Vec::new(), bitcoind_config: None, descriptor: None, data_dir, @@ -206,6 +210,7 @@ impl From for Box { pub struct Final { generating: bool, + context: Option, warning: Option, config_path: Option, } @@ -213,6 +218,7 @@ pub struct Final { impl Final { pub fn new() -> Self { Self { + context: None, generating: false, warning: None, config_path: None, @@ -221,6 +227,9 @@ impl Final { } impl Step for Final { + fn load_context(&mut self, ctx: &Context) { + self.context = Some(ctx.clone()); + } fn update(&mut self, message: Message) -> Command { match message { Message::Installed(res) => { @@ -244,7 +253,11 @@ impl Step for Final { } fn view(&self) -> Element { + let ctx = self.context.as_ref().unwrap(); + let desc = ctx.descriptor.as_ref().unwrap().to_string(); view::install( + ctx, + desc, self.generating, self.config_path.as_ref(), self.warning.as_ref(), diff --git a/gui/src/installer/view.rs b/gui/src/installer/view.rs index 96c11170..8c923de7 100644 --- a/gui/src/installer/view.rs +++ b/gui/src/installer/view.rs @@ -7,6 +7,7 @@ use crate::{ hw::HardwareWallet, installer::{ message::{self, Message}, + step::Context, Error, }, ui::{ @@ -298,7 +299,7 @@ pub fn import_descriptor<'a>( pub fn register_descriptor<'a>( descriptor: String, - hws: &[(HardwareWallet, Option<[u8; 32]>)], + hws: &[(HardwareWallet, Option<[u8; 32]>, bool)], error: Option<&Error>, processing: bool, chosen_hw: Option, @@ -306,16 +307,19 @@ pub fn register_descriptor<'a>( layout( Column::new() .push(text("Register descriptor").bold().size(50)) - .push( + .push(card::simple( Column::new() + .push(text("The descriptor:").small().bold()) .push(text(descriptor.clone()).small()) .push( - button::transparent_border(Some(icon::clipboard_icon()), "Copy") - .on_press(Message::Clibpboard(descriptor)), + Row::new().push(Column::new().width(Length::Fill)).push( + button::transparent_border(Some(icon::clipboard_icon()), "Copy") + .on_press(Message::Clibpboard(descriptor)), + ), ) .spacing(10) - .align_items(Alignment::Center), - ) + .max_width(1000), + )) .push_maybe(error.map(|e| card::error("Failed to import xpub", e.to_string()))) .push( Column::new() @@ -345,7 +349,7 @@ pub fn register_descriptor<'a>( &hw.0, Some(i) == chosen_hw, processing, - hw.1.is_some(), + hw.2, )) }), ) @@ -488,15 +492,87 @@ pub fn define_bitcoin<'a>( } pub fn install<'a>( + context: &Context, + descriptor: String, generating: bool, config_path: Option<&std::path::PathBuf>, warning: Option<&'a String>, ) -> Element<'a, Message> { let mut col = Column::new() + .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( + card::simple( + Column::new() + .spacing(5) + .push(text("Hardware devices:").small().bold()) + .push(context.hws.iter().fold(Column::new(), |acc, hw| { + acc.push( + Row::new() + .spacing(5) + .push(text(hw.0.to_string()).small()) + .push(text(format!("(fingerprint: {})", hw.1)).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), + ), + ) + .padding(50) + .max_width(1000), + ) + .spacing(50) .width(Length::Fill) .height(Length::Fill) - .padding(100) - .spacing(50) .align_items(Alignment::Center); if let Some(error) = warning {