From 5a7eaff17ba895418b368deaa74f8ed1b4ac26e7 Mon Sep 17 00:00:00 2001 From: edouard Date: Fri, 16 Dec 2022 18:59:45 +0100 Subject: [PATCH 1/3] fix hws: ledger dongle must load wallet --- gui/src/hw.rs | 22 ++++++++++++++++++++-- 1 file changed, 20 insertions(+), 2 deletions(-) diff --git a/gui/src/hw.rs b/gui/src/hw.rs index feb1a78c..ddca12d2 100644 --- a/gui/src/hw.rs +++ b/gui/src/hw.rs @@ -110,8 +110,26 @@ pub async fn list_hardware_wallets( } } match ledger::Ledger::try_connect_hid() { - Ok(device) => match HardwareWallet::new(Arc::new(device)).await { - Ok(hw) => hws.push(hw), + Ok(mut device) => match device.get_master_fingerprint().await { + Ok(fingerprint) => { + if let Some((name, descriptor)) = wallet { + device + .load_wallet( + name, + descriptor, + cfg.iter() + .find(|cfg| cfg.fingerprint == fingerprint.to_string()) + .map(|cfg| cfg.token()), + ) + .expect("Configuration must be correct"); + } + + hws.push(HardwareWallet { + kind: device.device_kind(), + fingerprint, + device: Arc::new(device), + }); + } Err(e) => { debug!("{}", e); } From d9336c11ea7d3ad4dcb68fbe322d9247cf9ad52e Mon Sep 17 00:00:00 2001 From: edouard Date: Fri, 16 Dec 2022 19:11:18 +0100 Subject: [PATCH 2/3] spend detail: add a refresh button for hws close #246 --- gui/src/app/view/spend/detail.rs | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/gui/src/app/view/spend/detail.rs b/gui/src/app/view/spend/detail.rs index bc0329e0..740ad8e0 100644 --- a/gui/src/app/view/spend/detail.rs +++ b/gui/src/app/view/spend/detail.rs @@ -480,7 +480,16 @@ pub fn sign_action<'a>( Column::new() .push(if !hws.is_empty() { Column::new() - .push(text("Select hardware wallet to sign with:").bold()) + .push( + Row::new() + .push( + text("Select hardware wallet to sign with:") + .bold() + .width(Length::Fill), + ) + .push(button::border(None, "Refresh").on_press(Message::Reload)) + .align_items(Alignment::Center), + ) .spacing(10) .push( hws.iter() @@ -503,7 +512,7 @@ pub fn sign_action<'a>( .spacing(20) .width(Length::Fill) .push("Please connect a hardware wallet") - .push(button::primary(None, "Refresh").on_press(Message::Reload)) + .push(button::border(None, "Refresh").on_press(Message::Reload)) .align_items(Alignment::Center), ) .width(Length::Fill) From 73eb1d38e3612110ad467fd608863519838aa988 Mon Sep 17 00:00:00 2001 From: edouard Date: Fri, 16 Dec 2022 19:14:51 +0100 Subject: [PATCH 3/3] fix state: add new hws in list without dropping the old ones It should be a solution for #238 --- gui/src/app/state/recovery.rs | 7 ++++++- gui/src/app/state/spend/detail.rs | 7 ++++++- 2 files changed, 12 insertions(+), 2 deletions(-) diff --git a/gui/src/app/state/recovery.rs b/gui/src/app/state/recovery.rs index be66c6fe..d7d02333 100644 --- a/gui/src/app/state/recovery.rs +++ b/gui/src/app/state/recovery.rs @@ -118,8 +118,13 @@ impl State for RecoveryPanel { } } }, + // We add the new hws without dropping the reference of the previous ones. Message::ConnectedHardwareWallets(hws) => { - self.hws = hws; + for h in hws { + if !self.hws.iter().any(|hw| hw.fingerprint == h.fingerprint) { + self.hws.push(h); + } + } } Message::Psbt(res) => match res { Ok(psbt) => self.generated = Some(psbt), diff --git a/gui/src/app/state/spend/detail.rs b/gui/src/app/state/spend/detail.rs index fb578841..709a5a73 100644 --- a/gui/src/app/state/spend/detail.rs +++ b/gui/src/app/state/spend/detail.rs @@ -330,8 +330,13 @@ impl Action for SignAction { Ok(()) => self.updated = true, Err(e) => self.error = Some(e), }, + // We add the new hws without dropping the reference of the previous ones. Message::ConnectedHardwareWallets(hws) => { - self.hws = hws; + for h in hws { + if !self.hws.iter().any(|hw| hw.fingerprint == h.fingerprint) { + self.hws.push(h); + } + } } Message::View(view::Message::Reload) => { return self.load(daemon);