From c638350eb9c69c6375ae9c59599e3604c4387d9a Mon Sep 17 00:00:00 2001 From: edouardparis Date: Fri, 19 Jul 2024 12:32:02 +0200 Subject: [PATCH] Add list of words for new generated mnemonic in share xpubs panel close #1203 --- gui/src/installer/step/share_xpubs.rs | 15 ++++--- gui/src/installer/view.rs | 62 +++++++++++++++++++++++---- 2 files changed, 63 insertions(+), 14 deletions(-) diff --git a/gui/src/installer/step/share_xpubs.rs b/gui/src/installer/step/share_xpubs.rs index 5a65d3bb..40dd1f5c 100644 --- a/gui/src/installer/step/share_xpubs.rs +++ b/gui/src/installer/step/share_xpubs.rs @@ -32,14 +32,19 @@ pub struct SignerXpubs { signer: Arc>, xpubs: Vec, next_account: ChildNumber, + words: [&'static str; 12], + did_backup: bool, } impl SignerXpubs { fn new(signer: Arc>) -> Self { + let words = { signer.lock().unwrap().mnemonic() }; Self { + words, signer, xpubs: Vec::new(), next_account: ChildNumber::from_hardened_idx(0).unwrap(), + did_backup: false, } } @@ -57,15 +62,12 @@ impl SignerXpubs { } pub fn view(&self) -> Element { - view::signer_xpubs(&self.xpubs) + view::signer_xpubs(&self.xpubs, &self.words, self.did_backup) } } pub struct ShareXpubs { network: Network, - - shared: bool, - hw_xpubs: Vec, xpubs_signer: SignerXpubs, } @@ -75,7 +77,6 @@ impl ShareXpubs { Self { network, hw_xpubs: Vec::new(), - shared: false, xpubs_signer: SignerXpubs::new(signer), } } @@ -86,7 +87,6 @@ impl Step for ShareXpubs { // Verification of the values is happening when the user click on Next button. fn update(&mut self, hws: &mut HardwareWallets, message: Message) -> Command { match message { - Message::UserActionDone(shared) => self.shared = shared, Message::ImportXpub(fg, res) => { if let Some(hw_xpubs) = self.hw_xpubs.iter_mut().find(|x| x.fingerprint == fg) { hw_xpubs.processing = false; @@ -105,6 +105,9 @@ impl Step for ShareXpubs { Message::UseHotSigner => { self.xpubs_signer.select(self.network); } + Message::UserActionDone(done) => { + self.xpubs_signer.did_backup = done; + } Message::Select(i) => { if let Some(HardwareWallet::Supported { device, diff --git a/gui/src/installer/view.rs b/gui/src/installer/view.rs index 59ef5dfc..e94285fb 100644 --- a/gui/src/installer/view.rs +++ b/gui/src/installer/view.rs @@ -422,18 +422,22 @@ pub fn import_descriptor<'a>( ) } -pub fn signer_xpubs(xpubs: &[String]) -> Element { +const BACKUP_WARNING: &str = + "Beware to back up the mnemonic as it will NOT be stored on the computer."; + +pub fn signer_xpubs<'a>( + xpubs: &'a [String], + words: &'a [&'static str; 12], + did_backup: bool, +) -> Element<'a, Message> { Container::new( Column::new() .push( Button::new( Row::new().align_items(Alignment::Center).push( Column::new() - .push(text("This computer").bold()) - .push( - text("Derive a key from a mnemonic stored on this computer") - .small(), - ) + .push(text("Generate a new mnemonic").bold()) + .push(text(BACKUP_WARNING).small().style(color::ORANGE)) .spacing(5) .width(Length::Fill), ), @@ -451,6 +455,39 @@ pub fn signer_xpubs(xpubs: &[String]) -> Element { .push_maybe(if xpubs.is_empty() { None } else { + Some( + Container::new(words.iter().enumerate().fold( + Column::new().spacing(5), + |acc, (i, w)| { + acc.push( + Row::new() + .align_items(Alignment::End) + .push( + Container::new(text(format!("#{}", i + 1)).small()) + .width(Length::Fixed(50.0)), + ) + .push(text(*w).bold()), + ) + }, + )) + .padding(15), + ) + }) + .push_maybe(if !xpubs.is_empty() { + Some( + Container::new( + checkbox( + "I have backed up the mnemonic, show the extended public key", + did_backup, + ) + .on_toggle(Message::UserActionDone), + ) + .padding(10), + ) + } else { + None + }) + .push_maybe(if !xpubs.is_empty() && did_backup { Some(xpubs.iter().fold(Column::new().padding(15), |col, xpub| { col.push( Row::new() @@ -475,6 +512,8 @@ pub fn signer_xpubs(xpubs: &[String]) -> Element { ), ) })) + } else { + None }), ) .style(theme::Container::Card(theme::Card::Simple)) @@ -571,17 +610,24 @@ pub fn share_xpubs<'a>( ) -> Element<'a, Message> { layout( (0, 0), - "Share your public keys", + "Share your public keys (Xpubs)", Column::new() .push( Container::new( - text("Generate an extended public key by selecting a signing device:").bold(), + text("Import an extended public key by selecting a signing device:").bold(), ) .width(Length::Fill), ) + .push_maybe(if hws.is_empty() { + Some(p1_regular("No signing device connected").style(color::GREY_3)) + } else { + None + }) .spacing(10) .push(Column::with_children(hws).spacing(10)) + .push(Container::new(text("Or create a new random key:").bold()).width(Length::Fill)) .push(signer) + .push(Space::with_height(10)) .width(Length::Fill), true, Some(Message::Previous),