Skip to content

Commit

Permalink
chore(core): middle button to confirm on TS3
Browse files Browse the repository at this point in the history
  • Loading branch information
ibz committed Feb 13, 2025
1 parent 850b52c commit 7dd41df
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 34 deletions.
39 changes: 22 additions & 17 deletions core/embed/rust/src/ui/layout_caesar/component/page.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ where
pad: Pad,
cancel_btn_details: Option<ButtonDetails>,
confirm_btn_details: Option<ButtonDetails>,
middle_confirm: bool,
back_btn_details: Option<ButtonDetails>,
next_btn_details: Option<ButtonDetails>,
buttons: Child<ButtonController>,
Expand All @@ -40,6 +41,7 @@ where
pad: Pad::with_background(background).with_clear(),
cancel_btn_details: Some(ButtonDetails::cancel_icon()),
confirm_btn_details: Some(ButtonDetails::text(TR::buttons__confirm.into())),
middle_confirm: false,
back_btn_details: Some(ButtonDetails::up_arrow_icon()),
next_btn_details: Some(ButtonDetails::down_arrow_icon_wide()),
// Setting empty layout for now, we do not yet know the page count.
Expand All @@ -59,6 +61,14 @@ where
self
}

pub fn with_middle_confirm(mut self, middle_confirm: bool) -> Self {
self.middle_confirm = middle_confirm;
self.confirm_btn_details =
self.confirm_btn_details
.map(|btn| if middle_confirm { btn.with_arms() } else { btn });
self
}

pub fn with_back_btn(mut self, btn_details: Option<ButtonDetails>) -> Self {
self.back_btn_details = btn_details;
self
Expand Down Expand Up @@ -114,25 +124,17 @@ where
}

fn get_button_layout(&self, has_prev: bool, has_next: bool) -> ButtonLayout {
let btn_left = self.get_left_button_details(!has_prev);
let btn_right = self.get_right_button_details(has_next);
ButtonLayout::new(btn_left, None, btn_right)
}

fn get_left_button_details(&self, is_first: bool) -> Option<ButtonDetails> {
if is_first {
let btn_left = if !has_prev {
self.cancel_btn_details.clone()
} else {
self.back_btn_details.clone()
}
}

fn get_right_button_details(&self, has_next_page: bool) -> Option<ButtonDetails> {
if has_next_page {
self.next_btn_details.clone()
} else {
self.confirm_btn_details.clone()
}
};
let (btn_middle, btn_right) = match (has_next, self.middle_confirm) {
(true, _) => (None, self.next_btn_details.clone()),
(false, true) => (self.confirm_btn_details.clone(), None),
(false, false) => (None, self.confirm_btn_details.clone()),
};
ButtonLayout::new(btn_left, btn_middle, btn_right)
}
}

Expand Down Expand Up @@ -186,6 +188,10 @@ where
return None;
}
}
ButtonPos::Middle => {
// Clicked CONFIRM. Send result.
return Some(PageMsg::Confirmed);
}
ButtonPos::Right => {
if self.has_next_page() {
// Clicked NEXT. Scroll down.
Expand All @@ -196,7 +202,6 @@ where
return Some(PageMsg::Confirmed);
}
}
_ => {}
}
}

Expand Down
23 changes: 7 additions & 16 deletions core/embed/rust/src/ui/layout_caesar/ui_firmware.rs
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ impl FirmwareUI for UICaesar {
content_in_button_page(
title,
paragraphs,
verb.unwrap_or(TString::empty()),
verb.unwrap_or(TR::buttons__confirm.into()),
verb_cancel,
hold,
)
Expand Down Expand Up @@ -210,7 +210,7 @@ impl FirmwareUI for UICaesar {
content_in_button_page(
TR::coinjoin__title.into(),
paragraphs,
TR::buttons__hold_to_confirm.into(),
TR::buttons__confirm.into(),
None,
true,
)
Expand Down Expand Up @@ -405,7 +405,7 @@ impl FirmwareUI for UICaesar {
paragraphs.into_paragraphs(),
button,
Some("<".into()),
false,
true,
)
}

Expand Down Expand Up @@ -444,16 +444,11 @@ impl FirmwareUI for UICaesar {
paragraphs.add(Paragraph::new(style, value));
}
}
let button_text = if hold {
TR::buttons__hold_to_confirm.into()
} else {
TR::buttons__confirm.into()
};

content_in_button_page(
title,
paragraphs.into_paragraphs(),
button_text,
TR::buttons__confirm.into(),
Some("".into()),
hold,
)
Expand Down Expand Up @@ -1296,20 +1291,16 @@ fn content_in_button_page<T: Component + Paginate + MaybeTrace + 'static>(
// Left button - icon, text or nothing.
let cancel_btn = verb_cancel.map(ButtonDetails::from_text_possible_icon);

// Right button - text or nothing.
// Optional HoldToConfirm
let mut confirm_btn = if !verb.is_empty() {
let confirm_btn = if !verb.is_empty() {
Some(ButtonDetails::text(verb))
} else {
None
};
if hold {
confirm_btn = confirm_btn.map(|btn| btn.with_default_duration());
}

let content = ButtonPage::new(content, theme::BG)
.with_cancel_btn(cancel_btn)
.with_confirm_btn(confirm_btn);
.with_confirm_btn(confirm_btn)
.with_middle_confirm(hold);

let mut frame = ScrollableFrame::new(content);
if !title.is_empty() {
Expand Down
1 change: 0 additions & 1 deletion core/src/apps/ethereum/layout.py
Original file line number Diff line number Diff line change
Expand Up @@ -195,7 +195,6 @@ async def confirm_typed_data_final() -> None:
"confirm_typed_data_final",
TR.ethereum__title_confirm_typed_data,
TR.ethereum__sign_eip712,
verb=TR.buttons__hold_to_confirm,
hold=True,
)

Expand Down

0 comments on commit 7dd41df

Please sign in to comment.