1
0
mirror of https://github.com/trezor/trezor-firmware.git synced 2025-01-08 14:31:06 +00:00

fixup! feat(core/ui): add cancel button to paginated blobs

This commit is contained in:
Ioan Bizău 2024-11-20 10:41:58 +01:00
parent 2bc787a652
commit 33d1def00d
4 changed files with 53 additions and 57 deletions

View File

@ -32,11 +32,7 @@ const MENU_ITEM_INFO: usize = 1;
#[derive(PartialEq)]
pub enum ConfirmActionExtra {
// Opens a menu which can (optionally) lead to an extra Info screen, or cancel the action
Menu {
verb_cancel: Option<TString<'static>>,
has_info: bool,
verb_info: Option<TString<'static>>,
},
Menu(ConfirmActionMenuStrings),
// Shows a cancel button directly
Cancel,
}
@ -64,6 +60,34 @@ impl ConfirmActionStrings {
}
}
#[derive(PartialEq)]
pub struct ConfirmActionMenuStrings {
verb_cancel: Option<TString<'static>>,
has_info: bool,
verb_info: Option<TString<'static>>,
}
impl ConfirmActionMenuStrings {
pub fn new() -> Self {
Self {
verb_cancel: None,
has_info: false,
verb_info: None,
}
}
pub const fn with_verb_cancel(mut self, verb_cancel: Option<TString<'static>>) -> Self {
self.verb_cancel = verb_cancel;
self
}
pub const fn with_info(mut self, has_info: bool, verb_info: Option<TString<'static>>) -> Self {
self.has_info = has_info;
self.verb_info = verb_info;
self
}
}
/// The simplest form of the ConfirmAction flow:
/// no menu, nor a separate "Tap to confirm" or "Hold to confirm".
#[derive(Copy, Clone, PartialEq, Eq)]
@ -194,11 +218,7 @@ pub fn new_confirm_action(
new_confirm_action_simple(
paragraphs,
ConfirmActionExtra::Menu {
verb_cancel,
has_info: false,
verb_info: None,
},
ConfirmActionExtra::Menu(ConfirmActionMenuStrings::new().with_verb_cancel(verb_cancel)),
ConfirmActionStrings::new(title, subtitle, None, prompt_screen.then_some(prompt_title)),
hold,
None,
@ -299,27 +319,26 @@ fn create_menu(
extra: ConfirmActionExtra,
prompt_screen: Option<TString<'static>>,
) -> Result<SwipeFlow, Error> {
if let ConfirmActionExtra::Menu {
verb_cancel,
has_info,
verb_info,
} = extra
{
if let ConfirmActionExtra::Menu(menu_strings) = extra {
// NB: The Cancel menu item is always the first,
// because of the MENU_ITEM_CANCEL = 0.
// If we want the cancel item to be somewhere else,
// we would need to account for that and we could not use a constant.
let mut menu_choices = VerticalMenu::empty().danger(
theme::ICON_CANCEL,
verb_cancel.unwrap_or(TR::buttons__cancel.into()),
menu_strings
.verb_cancel
.unwrap_or(TR::buttons__cancel.into()),
);
if has_info {
if menu_strings.has_info {
// The Info menu item (if present) has to be the 2nd,
// because of MENU_ITEM_INFO = 1!
menu_choices = menu_choices.item(
theme::ICON_CHEVRON_RIGHT,
verb_info.unwrap_or(TR::words__title_information.into()),
menu_strings
.verb_info
.unwrap_or(TR::words__title_information.into()),
);
}

View File

@ -19,7 +19,8 @@ pub mod util;
pub mod warning_hi_prio;
pub use confirm_action::{
new_confirm_action, new_confirm_action_simple, ConfirmActionExtra, ConfirmActionStrings,
new_confirm_action, new_confirm_action_simple, ConfirmActionExtra, ConfirmActionMenuStrings,
ConfirmActionStrings,
};
#[cfg(feature = "universal_fw")]
pub use confirm_fido::new_confirm_fido;

View File

@ -3,7 +3,7 @@ use super::{
component::{Frame, FrameMsg},
theme,
},
ConfirmActionExtra, ConfirmActionStrings,
ConfirmActionExtra, ConfirmActionMenuStrings, ConfirmActionStrings,
};
use crate::{
error::Error,
@ -272,11 +272,11 @@ impl ConfirmBlobParams {
let confirm_extra = if self.cancel {
ConfirmActionExtra::Cancel
} else {
ConfirmActionExtra::Menu {
verb_cancel: self.verb_cancel,
has_info: self.info_button,
verb_info: self.verb_info,
}
ConfirmActionExtra::Menu(
ConfirmActionMenuStrings::new()
.with_verb_cancel(self.verb_cancel)
.with_info(self.info_button, self.verb_info),
)
};
flow::new_confirm_action_simple(

View File

@ -55,7 +55,7 @@ use crate::{
flow::{
new_confirm_action_simple,
util::{ConfirmBlobParams, ShowInfoParams},
ConfirmActionExtra, ConfirmActionStrings,
ConfirmActionExtra, ConfirmActionMenuStrings, ConfirmActionStrings,
},
theme::ICON_BULLET_CHECKMARK,
},
@ -246,11 +246,7 @@ extern "C" fn new_confirm_emphasized(n_args: usize, args: *const Obj, kwargs: *m
new_confirm_action_simple(
FormattedText::new(ops).vertically_centered(),
ConfirmActionExtra::Menu {
verb_cancel: None,
has_info: false,
verb_info: None,
},
ConfirmActionExtra::Menu(ConfirmActionMenuStrings::new()),
ConfirmActionStrings::new(title, None, None, Some(title)),
false,
None,
@ -395,11 +391,7 @@ extern "C" fn new_confirm_address(n_args: usize, args: *const Obj, kwargs: *mut
flow::new_confirm_action_simple(
paragraphs,
ConfirmActionExtra::Menu {
verb_cancel: None,
has_info: false,
verb_info: None,
},
ConfirmActionExtra::Menu(ConfirmActionMenuStrings::new()),
ConfirmActionStrings::new(title, None, None, None),
false,
None,
@ -442,11 +434,7 @@ extern "C" fn new_confirm_properties(n_args: usize, args: *const Obj, kwargs: *m
new_confirm_action_simple(
paragraphs.into_paragraphs(),
ConfirmActionExtra::Menu {
verb_cancel: None,
has_info: false,
verb_info: None,
},
ConfirmActionExtra::Menu(ConfirmActionMenuStrings::new()),
ConfirmActionStrings::new(title, None, None, hold.then_some(title)),
hold,
None,
@ -476,11 +464,7 @@ extern "C" fn new_confirm_homescreen(n_args: usize, args: *const Obj, kwargs: *m
new_confirm_action_simple(
paragraphs,
ConfirmActionExtra::Menu {
verb_cancel: None,
has_info: false,
verb_info: None,
},
ConfirmActionExtra::Menu(ConfirmActionMenuStrings::new()),
ConfirmActionStrings::new(
TR::homescreen__settings_title.into(),
Some(TR::homescreen__settings_subtitle.into()),
@ -792,11 +776,7 @@ extern "C" fn new_confirm_total(n_args: usize, args: *const Obj, kwargs: *mut Ma
new_confirm_action_simple(
paragraphs.into_paragraphs(),
ConfirmActionExtra::Menu {
verb_cancel: None,
has_info: true,
verb_info: None,
},
ConfirmActionExtra::Menu(ConfirmActionMenuStrings::new()),
ConfirmActionStrings::new(title, None, None, Some(title)),
true,
None,
@ -1113,11 +1093,7 @@ extern "C" fn new_confirm_coinjoin(n_args: usize, args: *const Obj, kwargs: *mut
new_confirm_action_simple(
paragraphs,
ConfirmActionExtra::Menu {
verb_cancel: None,
has_info: false,
verb_info: None,
},
ConfirmActionExtra::Menu(ConfirmActionMenuStrings::new()),
ConfirmActionStrings::new(
TR::coinjoin__title.into(),
None,