Skip to content

Commit

Permalink
Merge #1211: Add list of words for new generated mnemonic in share xp…
Browse files Browse the repository at this point in the history
…ubs panel

c638350 Add list of words for new generated mnemonic in share xpubs panel (edouardparis)

Pull request description:

  Because the share xpubs is not anymore a install process, no information is stored. If user want to generate a new mnemonic and share it xpubs he must be aware that he has to backup it.
  ![20240719_15h22m12s_grim](https://github.com/user-attachments/assets/2caacffd-1698-422e-9cd3-c5cf4aee795a)

  close #1203

ACKs for top commit:
  jp1ac4:
    Tested ACK c638350.

Tree-SHA512: 616d208e4923a442dc4b0306a157fe069679b8b78f28cb0ba0b2ad075f811ba527e84d48ff45e706cb0d62c68d56b761f50d4993bc76c3365b9579888b8c26f8
  • Loading branch information
edouardparis committed Jul 19, 2024
2 parents e81a2d3 + c638350 commit ee9cfb9
Show file tree
Hide file tree
Showing 2 changed files with 63 additions and 14 deletions.
15 changes: 9 additions & 6 deletions gui/src/installer/step/share_xpubs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -32,14 +32,19 @@ pub struct SignerXpubs {
signer: Arc<Mutex<Signer>>,
xpubs: Vec<String>,
next_account: ChildNumber,
words: [&'static str; 12],
did_backup: bool,
}

impl SignerXpubs {
fn new(signer: Arc<Mutex<Signer>>) -> Self {
let words = { signer.lock().unwrap().mnemonic() };
Self {
words,
signer,
xpubs: Vec::new(),
next_account: ChildNumber::from_hardened_idx(0).unwrap(),
did_backup: false,
}
}

Expand All @@ -57,15 +62,12 @@ impl SignerXpubs {
}

pub fn view(&self) -> Element<Message> {
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<HardwareWalletXpubs>,
xpubs_signer: SignerXpubs,
}
Expand All @@ -75,7 +77,6 @@ impl ShareXpubs {
Self {
network,
hw_xpubs: Vec::new(),
shared: false,
xpubs_signer: SignerXpubs::new(signer),
}
}
Expand All @@ -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<Message> {
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;
Expand All @@ -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,
Expand Down
62 changes: 54 additions & 8 deletions gui/src/installer/view.rs
Original file line number Diff line number Diff line change
Expand Up @@ -422,18 +422,22 @@ pub fn import_descriptor<'a>(
)
}

pub fn signer_xpubs(xpubs: &[String]) -> Element<Message> {
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),
),
Expand All @@ -451,6 +455,39 @@ pub fn signer_xpubs(xpubs: &[String]) -> Element<Message> {
.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()
Expand All @@ -475,6 +512,8 @@ pub fn signer_xpubs(xpubs: &[String]) -> Element<Message> {
),
)
}))
} else {
None
}),
)
.style(theme::Container::Card(theme::Card::Simple))
Expand Down Expand Up @@ -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),
Expand Down

0 comments on commit ee9cfb9

Please sign in to comment.