Skip to content

Commit

Permalink
gui: grey out hws with addr verif unimplemented
Browse files Browse the repository at this point in the history
  • Loading branch information
edouardparis committed Dec 7, 2023
1 parent 0ef49ed commit 3372e2f
Show file tree
Hide file tree
Showing 2 changed files with 75 additions and 18 deletions.
62 changes: 45 additions & 17 deletions gui/src/app/view/hw.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ use crate::{
app::view::message::*,
hw::{HardwareWallet, UnsupportedReason},
};
use async_hwi::DeviceKind;

pub fn hw_list_view(
i: usize,
Expand Down Expand Up @@ -52,7 +53,6 @@ pub fn hw_list_view(
UnsupportedReason::NotPartOfWallet(fg) => {
hw::unrelated_hardware_wallet(&kind.to_string(), version.as_ref(), fg)
}

_ => hw::unsupported_hardware_wallet(&kind.to_string(), version.as_ref()),
},
HardwareWallet::Locked {
Expand Down Expand Up @@ -111,7 +111,6 @@ pub fn hw_list_view_for_registration(
UnsupportedReason::NotPartOfWallet(fg) => {
hw::unrelated_hardware_wallet(&kind.to_string(), version.as_ref(), fg)
}

_ => hw::unsupported_hardware_wallet(&kind.to_string(), version.as_ref()),
},
HardwareWallet::Locked {
Expand All @@ -134,7 +133,7 @@ pub fn hw_list_view_verify_address(
hw: &HardwareWallet,
chosen: bool,
) -> Element<Message> {
let mut bttn = Button::new(match hw {
let (content, selectable) = match hw {
HardwareWallet::Supported {
kind,
version,
Expand All @@ -143,30 +142,59 @@ pub fn hw_list_view_verify_address(
..
} => {
if chosen {
hw::processing_hardware_wallet(kind, version.as_ref(), fingerprint, alias.as_ref())
(
hw::processing_hardware_wallet(
kind,
version.as_ref(),
fingerprint,
alias.as_ref(),
),
false,
)
} else {
hw::supported_hardware_wallet(kind, version.as_ref(), fingerprint, alias.as_ref())
match kind {
DeviceKind::Specter | DeviceKind::SpecterSimulator => {
(hw::unimplemented_method_hardware_wallet(
&kind.to_string(),
version.as_ref(),
fingerprint,
"Liana cannot request the device to display the address. \n The verification must be done manually with the device control."
), false)
}
_ => (hw::supported_hardware_wallet(
kind,
version.as_ref(),
fingerprint,
alias.as_ref(),
), true),
}
}
}
HardwareWallet::Unsupported {
version,
kind,
reason,
..
} => match reason {
UnsupportedReason::NotPartOfWallet(fg) => {
hw::unrelated_hardware_wallet(&kind.to_string(), version.as_ref(), fg)
}

_ => hw::unsupported_hardware_wallet(&kind.to_string(), version.as_ref()),
},
} => (
match reason {
UnsupportedReason::NotPartOfWallet(fg) => {
hw::unrelated_hardware_wallet(&kind.to_string(), version.as_ref(), fg)
}
_ => hw::unsupported_hardware_wallet(&kind.to_string(), version.as_ref()),
},
false,
),
HardwareWallet::Locked {
kind, pairing_code, ..
} => hw::locked_hardware_wallet(kind, pairing_code.as_ref()),
})
.style(theme::Button::Border)
.width(Length::Fill);
if !chosen && hw.is_supported() {
} => (
hw::locked_hardware_wallet(kind, pairing_code.as_ref()),
false,
),
};
let mut bttn = Button::new(content)
.style(theme::Button::Border)
.width(Length::Fill);
if selectable && hw.is_supported() {
bttn = bttn.on_press(Message::SelectHardwareWallet(i));
}
Container::new(bttn)
Expand Down
31 changes: 30 additions & 1 deletion gui/ui/src/component/hw.rs
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,35 @@ pub fn unregistered_hardware_wallet<'a, T: 'a, K: Display, V: Display, F: Displa
.padding(10)
}

pub fn unimplemented_method_hardware_wallet<'a, T: 'a, K: Display, V: Display, F: Display>(
kind: K,
version: Option<V>,
fingerprint: F,
message: &'static str,
) -> Container<'a, T> {
container(
tooltip::Tooltip::new(
container(
column(vec![
text::p1_regular(format!("#{}", fingerprint)).into(),
Row::new()
.spacing(5)
.push(text::caption(kind.to_string()))
.push_maybe(version.map(|v| text::caption(v.to_string())))
.into(),
])
.width(Length::Fill),
)
.width(Length::Fill)
.padding(10),
message,
tooltip::Position::Bottom,
)
.style(theme::Container::Card(theme::Card::Simple)),
)
.width(Length::Fill)
}

pub fn unrelated_hardware_wallet<'a, T: 'a, K: Display, V: Display, F: Display>(
kind: K,
version: Option<V>,
Expand All @@ -107,7 +136,7 @@ pub fn unrelated_hardware_wallet<'a, T: 'a, K: Display, V: Display, F: Display>(
)
.width(Length::Fill)
.padding(10),
"The signing device is not part of the wallet setup",
"This signer does not have a key in this wallet.",
tooltip::Position::Bottom,
)
.style(theme::Container::Card(theme::Card::Simple)),
Expand Down

0 comments on commit 3372e2f

Please sign in to comment.