Skip to content

Commit

Permalink
fixup! fixup! feat(core/ui): add cancel button to paginated blobs
Browse files Browse the repository at this point in the history
  • Loading branch information
ibz committed Nov 20, 2024
1 parent d2cc6c0 commit b0a3a4a
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 34 deletions.
23 changes: 8 additions & 15 deletions core/embed/rust/src/ui/model_mercury/flow/confirm_action.rs
Original file line number Diff line number Diff line change
Expand Up @@ -69,25 +69,20 @@ impl ConfirmActionStrings {

#[derive(PartialEq)]
pub struct ConfirmActionMenuStrings {
verb_cancel: Option<TString<'static>>,
verb_cancel: TString<'static>,
has_info: bool,
verb_info: Option<TString<'static>>,
}

impl ConfirmActionMenuStrings {
pub fn new() -> Self {
pub fn new(verb_cancel: TString<'static>) -> Self {
Self {
verb_cancel: None,
verb_cancel: verb_cancel,
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;
Expand Down Expand Up @@ -225,7 +220,9 @@ pub fn new_confirm_action(

new_confirm_action_simple(
paragraphs,
ConfirmActionExtra::Menu(ConfirmActionMenuStrings::new().with_verb_cancel(verb_cancel)),
ConfirmActionExtra::Menu(ConfirmActionMenuStrings::new(
verb_cancel.unwrap_or(TR::buttons__cancel.into()),
)),
ConfirmActionStrings::new(title, subtitle, None, prompt_screen.then_some(prompt_title)),
hold,
None,
Expand Down Expand Up @@ -337,12 +334,8 @@ fn create_menu(
// 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,
menu_strings
.verb_cancel
.unwrap_or(TR::buttons__cancel.into()),
);
let mut menu_choices =
VerticalMenu::empty().danger(theme::ICON_CANCEL, menu_strings.verb_cancel);

if menu_strings.has_info {
// The Info menu item (if present) has to be the 2nd,
Expand Down
16 changes: 6 additions & 10 deletions core/embed/rust/src/ui/model_mercury/flow/util.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ use crate::{
maybe_trace::MaybeTrace,
micropython::obj::Obj,
strutil::TString,
translations::TR,
ui::{
component::{
base::ComponentExt,
Expand Down Expand Up @@ -38,7 +39,7 @@ pub struct ConfirmBlobParams {
description_font: &'static TextStyle,
extra: Option<TString<'static>>,
verb: Option<TString<'static>>,
verb_cancel: Option<TString<'static>>,
verb_cancel: TString<'static>,
verb_info: Option<TString<'static>>,
info_button: bool,
cancel_button: bool,
Expand All @@ -57,11 +58,7 @@ pub struct ConfirmBlobParams {
}

impl ConfirmBlobParams {
pub const fn new(
title: TString<'static>,
data: Obj,
description: Option<TString<'static>>,
) -> Self {
pub fn new(title: TString<'static>, data: Obj, description: Option<TString<'static>>) -> Self {
Self {
title,
subtitle: None,
Expand All @@ -72,7 +69,7 @@ impl ConfirmBlobParams {
description_font: &theme::TEXT_NORMAL,
extra: None,
verb: None,
verb_cancel: None,
verb_cancel: TR::buttons__cancel.into(),
verb_info: None,
info_button: false,
cancel_button: false,
Expand Down Expand Up @@ -121,7 +118,7 @@ impl ConfirmBlobParams {
self
}

pub const fn with_verb_cancel(mut self, verb_cancel: Option<TString<'static>>) -> Self {
pub const fn with_verb_cancel(mut self, verb_cancel: TString<'static>) -> Self {
self.verb_cancel = verb_cancel;
self
}
Expand Down Expand Up @@ -288,8 +285,7 @@ impl ConfirmBlobParams {
ConfirmActionExtra::Cancel
} else {
ConfirmActionExtra::Menu(
ConfirmActionMenuStrings::new()
.with_verb_cancel(self.verb_cancel)
ConfirmActionMenuStrings::new(self.verb_cancel)
.with_info(self.info_button, self.verb_info),
)
};
Expand Down
18 changes: 9 additions & 9 deletions core/embed/rust/src/ui/model_mercury/layout.rs
Original file line number Diff line number Diff line change
Expand Up @@ -248,7 +248,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(ConfirmActionMenuStrings::new()),
ConfirmActionExtra::Menu(ConfirmActionMenuStrings::new(TR::buttons__cancel.into())),
ConfirmActionStrings::new(title, None, None, Some(title)),
false,
None,
Expand Down Expand Up @@ -301,7 +301,7 @@ extern "C" fn new_confirm_blob(n_args: usize, args: *const Obj, kwargs: *mut Map
.with_text_mono(text_mono)
.with_subtitle(subtitle)
.with_verb(verb)
.with_verb_cancel(verb_cancel)
.with_verb_cancel(verb_cancel.unwrap_or(TR::buttons__cancel.into()))
.with_verb_info(verb_info)
.with_extra(extra)
.with_info_button(info)
Expand Down Expand Up @@ -340,7 +340,7 @@ extern "C" fn new_confirm_blob_intro(n_args: usize, args: *const Obj, kwargs: *m
.with_verb_info(Some(TR::buttons__view_all_data.into()))
.with_description_font(&theme::TEXT_SUB_GREEN_LIME)
.with_subtitle(subtitle)
.with_verb_cancel(verb_cancel)
.with_verb_cancel(verb_cancel.unwrap_or(TR::buttons__cancel.into()))
.with_footer_description(Some(
TR::buttons__confirm.into(), /* or words__confirm?? */
))
Expand Down Expand Up @@ -417,7 +417,7 @@ extern "C" fn new_confirm_address(n_args: usize, args: *const Obj, kwargs: *mut

flow::new_confirm_action_simple(
paragraphs,
ConfirmActionExtra::Menu(ConfirmActionMenuStrings::new()),
ConfirmActionExtra::Menu(ConfirmActionMenuStrings::new(TR::buttons__cancel.into())),
ConfirmActionStrings::new(title, None, None, None),
false,
None,
Expand Down Expand Up @@ -461,7 +461,7 @@ extern "C" fn new_confirm_properties(n_args: usize, args: *const Obj, kwargs: *m

new_confirm_action_simple(
paragraphs.into_paragraphs(),
ConfirmActionExtra::Menu(ConfirmActionMenuStrings::new()),
ConfirmActionExtra::Menu(ConfirmActionMenuStrings::new(TR::buttons__cancel.into())),
ConfirmActionStrings::new(title, None, None, hold.then_some(title)),
hold,
None,
Expand Down Expand Up @@ -492,7 +492,7 @@ extern "C" fn new_confirm_homescreen(n_args: usize, args: *const Obj, kwargs: *m

new_confirm_action_simple(
paragraphs,
ConfirmActionExtra::Menu(ConfirmActionMenuStrings::new()),
ConfirmActionExtra::Menu(ConfirmActionMenuStrings::new(TR::buttons__cancel.into())),
ConfirmActionStrings::new(
TR::homescreen__settings_title.into(),
Some(TR::homescreen__settings_subtitle.into()),
Expand Down Expand Up @@ -777,7 +777,7 @@ extern "C" fn new_confirm_value(n_args: usize, args: *const Obj, kwargs: *mut Ma
ConfirmBlobParams::new(title, value, description)
.with_subtitle(subtitle)
.with_verb(verb)
.with_verb_cancel(verb_cancel)
.with_verb_cancel(verb_cancel.unwrap_or(TR::buttons__cancel.into()))
.with_info_button(info_button)
.with_chunkify(chunkify)
.with_text_mono(text_mono)
Expand Down Expand Up @@ -805,7 +805,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(ConfirmActionMenuStrings::new()),
ConfirmActionExtra::Menu(ConfirmActionMenuStrings::new(TR::buttons__cancel.into())),
ConfirmActionStrings::new(title, None, None, Some(title)),
true,
None,
Expand Down Expand Up @@ -1098,7 +1098,7 @@ extern "C" fn new_confirm_coinjoin(n_args: usize, args: *const Obj, kwargs: *mut

new_confirm_action_simple(
paragraphs,
ConfirmActionExtra::Menu(ConfirmActionMenuStrings::new()),
ConfirmActionExtra::Menu(ConfirmActionMenuStrings::new(TR::buttons__cancel.into())),
ConfirmActionStrings::new(
TR::coinjoin__title.into(),
None,
Expand Down

0 comments on commit b0a3a4a

Please sign in to comment.