Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

UI tweaks for ETH contract flow #4346

Open
wants to merge 12 commits into
base: main
Choose a base branch
from
2 changes: 1 addition & 1 deletion core/embed/rust/librust_qstr.h
Original file line number Diff line number Diff line change
Expand Up @@ -194,6 +194,7 @@ static void _librust_qstrs(void) {
MP_QSTR_confirm_address;
MP_QSTR_confirm_backup;
MP_QSTR_confirm_blob;
MP_QSTR_confirm_blob_intro;
MP_QSTR_confirm_coinjoin;
MP_QSTR_confirm_emphasized;
MP_QSTR_confirm_fido;
Expand Down Expand Up @@ -359,7 +360,6 @@ static void _librust_qstrs(void) {
MP_QSTR_notification_level;
MP_QSTR_page_count;
MP_QSTR_page_counter;
MP_QSTR_page_limit;
MP_QSTR_pages;
MP_QSTR_paint;
MP_QSTR_passphrase__access_wallet;
Expand Down
23 changes: 19 additions & 4 deletions core/embed/rust/src/ui/model_mercury/component/frame.rs
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,7 @@ pub struct Frame<T> {
swipe: SwipeConfig,
internal_page_cnt: usize,
horizontal_swipe: HorizontalSwipe,
margin: usize,
}

pub enum FrameMsg<T> {
Expand All @@ -111,6 +112,7 @@ where
swipe: SwipeConfig::new(),
internal_page_cnt: 1,
horizontal_swipe: HorizontalSwipe::new(),
margin: 0,
}
}

Expand Down Expand Up @@ -262,12 +264,18 @@ where
..self
}
}

pub fn with_vertical_pages(self) -> Self {
Self {
swipe: self.swipe.with_vertical_pages(),
..self
}
}

pub fn with_margin(mut self, margin: usize) -> Self {
self.margin = margin;
self
}
}

impl<T> Component for Frame<T>
Expand All @@ -278,7 +286,7 @@ where

fn place(&mut self, bounds: Rect) -> Rect {
self.bounds = bounds;
let content_area = frame_place(&mut self.header, &mut self.footer, bounds);
let content_area = frame_place(&mut self.header, &mut self.footer, bounds, self.margin);

self.content.place(content_area);

Expand Down Expand Up @@ -347,9 +355,16 @@ fn frame_event(
header.event(ctx, event)
}

fn frame_place(header: &mut Header, footer: &mut Option<Footer>, bounds: Rect) -> Rect {
fn frame_place(
header: &mut Header,
footer: &mut Option<Footer>,
bounds: Rect,
margin: usize,
) -> Rect {
let (mut header_area, mut content_area) = bounds.split_top(TITLE_HEIGHT);
content_area = content_area.inset(Insets::top(theme::SPACING));
content_area = content_area
.inset(Insets::top(theme::SPACING))
.inset(Insets::top(margin as i16));
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This makes the real margin now SPACING + margin. It's quite confusing but probably fine.

header_area = header_area.inset(Insets::sides(theme::SPACING));

header.place(header_area);
Expand All @@ -360,7 +375,7 @@ fn frame_place(header: &mut Header, footer: &mut Option<Footer>, bounds: Rect) -
content_area = content_area.inset(Insets::bottom(theme::SPACING));
let (remaining, footer_area) = content_area.split_bottom(footer.height());
footer.place(footer_area);
content_area = remaining;
content_area = remaining.inset(Insets::bottom(margin as i16));
}
content_area
}
Expand Down
17 changes: 16 additions & 1 deletion core/embed/rust/src/ui/model_mercury/flow/confirm_action.rs
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ pub struct ConfirmActionStrings {
subtitle: Option<TString<'static>>,
verb: Option<TString<'static>>,
prompt_screen: Option<TString<'static>>,
footer_description: Option<TString<'static>>,
}

impl ConfirmActionStrings {
Expand All @@ -56,8 +57,14 @@ impl ConfirmActionStrings {
subtitle,
verb,
prompt_screen,
footer_description: None,
}
}

pub fn with_footer_description(mut self, footer_description: Option<TString<'static>>) -> Self {
self.footer_description = footer_description;
self
}
}

#[derive(PartialEq)]
Expand Down Expand Up @@ -222,6 +229,7 @@ pub fn new_confirm_action(
ConfirmActionStrings::new(title, subtitle, None, prompt_screen.then_some(prompt_title)),
hold,
None,
0,
false,
)
}
Expand All @@ -232,16 +240,21 @@ fn new_confirm_action_uni<T: Component + Paginate + MaybeTrace + 'static>(
extra: ConfirmActionExtra,
strings: ConfirmActionStrings,
hold: bool,
frame_margin: usize,
show_page_counter: bool,
) -> Result<SwipeFlow, error::Error> {
let (prompt_screen, prompt_pages, flow, page) =
create_flow(strings.title, strings.prompt_screen, hold, &extra);

let mut content = Frame::left_aligned(strings.title, content)
.with_margin(frame_margin)
.with_swipe(Direction::Up, SwipeSettings::default())
.with_swipe(Direction::Left, SwipeSettings::default())
.with_vertical_pages()
.with_footer(TR::instructions__swipe_up.into(), None);
.with_footer(
TR::instructions__swipe_up.into(),
strings.footer_description,
);

match extra {
ConfirmActionExtra::Menu { .. } => {
Expand Down Expand Up @@ -413,13 +426,15 @@ pub fn new_confirm_action_simple<T: Component + Paginate + MaybeTrace + 'static>
strings: ConfirmActionStrings,
hold: bool,
page_limit: Option<usize>,
frame_margin: usize,
show_page_counter: bool,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

could probably be also named page_counter just like in `ConfirmBlobParams.

) -> Result<SwipeFlow, error::Error> {
new_confirm_action_uni(
SwipeContent::new(SwipePage::vertical(content).with_limit(page_limit)),
extra,
strings,
hold,
frame_margin,
show_page_counter,
)
}
19 changes: 18 additions & 1 deletion core/embed/rust/src/ui/model_mercury/flow/util.rs
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ pub struct ConfirmBlobParams {
swipe_up: bool,
swipe_down: bool,
swipe_right: bool,
frame_margin: usize,
cancel: bool,
}

Expand Down Expand Up @@ -85,6 +86,7 @@ impl ConfirmBlobParams {
swipe_up: false,
swipe_down: false,
swipe_right: false,
frame_margin: 0,
cancel: false,
}
}
Expand Down Expand Up @@ -154,6 +156,19 @@ impl ConfirmBlobParams {
self
}

pub const fn with_frame_margin(mut self, frame_margin: usize) -> Self {
self.frame_margin = frame_margin;
self
}

pub const fn with_footer_description(
mut self,
footer_description: Option<TString<'static>>,
) -> Self {
self.footer_description = footer_description;
self
}

pub const fn with_cancel(mut self, cancel: bool) -> Self {
self.cancel = cancel;
self
Expand Down Expand Up @@ -287,9 +302,11 @@ impl ConfirmBlobParams {
self.subtitle,
self.verb,
self.prompt.then_some(self.title),
),
)
.with_footer_description(self.footer_description),
self.hold,
self.page_limit,
self.frame_margin,
self.page_counter,
)
}
Expand Down
76 changes: 60 additions & 16 deletions core/embed/rust/src/ui/model_mercury/layout.rs
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,8 @@ use crate::{
},
};

const CONFIRM_BLOB_INTRO_MARGIN: usize = 24;

impl TryFrom<SelectWordCountMsg> for Obj {
type Error = Error;

Expand Down Expand Up @@ -250,6 +252,7 @@ extern "C" fn new_confirm_emphasized(n_args: usize, args: *const Obj, kwargs: *m
ConfirmActionStrings::new(title, None, None, Some(title)),
false,
None,
0,
false,
)
.and_then(LayoutObj::new_root)
Expand Down Expand Up @@ -292,23 +295,9 @@ extern "C" fn new_confirm_blob(n_args: usize, args: *const Obj, kwargs: *mut Map
let chunkify: bool = kwargs.get_or(Qstr::MP_QSTR_chunkify, false)?;
let page_counter: bool = kwargs.get_or(Qstr::MP_QSTR_page_counter, false)?;
let prompt_screen: bool = kwargs.get_or(Qstr::MP_QSTR_prompt_screen, true)?;
let page_limit: Option<usize> = kwargs
.get(Qstr::MP_QSTR_page_limit)
.unwrap_or_else(|_| Obj::const_none())
.try_into_option()?;
let cancel: bool = kwargs.get_or(Qstr::MP_QSTR_cancel, false)?;

let (description, description_font) = if page_limit == Some(1) {
(
Some(TR::instructions__view_all_data.into()),
&theme::TEXT_SUB_GREEN_LIME,
)
} else {
(description, &theme::TEXT_NORMAL)
};

ConfirmBlobParams::new(title, data, description)
.with_description_font(description_font)
.with_text_mono(text_mono)
.with_subtitle(subtitle)
.with_verb(verb)
Expand All @@ -318,7 +307,6 @@ extern "C" fn new_confirm_blob(n_args: usize, args: *const Obj, kwargs: *mut Map
.with_info_button(info)
.with_chunkify(chunkify)
.with_page_counter(page_counter)
.with_page_limit(page_limit)
.with_cancel(cancel)
.with_prompt(prompt_screen)
.with_hold(hold)
Expand All @@ -329,6 +317,44 @@ extern "C" fn new_confirm_blob(n_args: usize, args: *const Obj, kwargs: *mut Map
unsafe { util::try_with_args_and_kwargs(n_args, args, kwargs, block) }
}

extern "C" fn new_confirm_blob_intro(n_args: usize, args: *const Obj, kwargs: *mut Map) -> Obj {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't love it as it creates mercury specific layout. But probably fine for now.

let block = move |_args: &[Obj], kwargs: &Map| {
let title: TString = kwargs.get(Qstr::MP_QSTR_title)?.try_into()?;
let data: Obj = kwargs.get(Qstr::MP_QSTR_data)?;
let subtitle: Option<TString> = kwargs
.get(Qstr::MP_QSTR_subtitle)
.unwrap_or_else(|_| Obj::const_none())
.try_into_option()?;
let verb: Option<TString> = kwargs
.get(Qstr::MP_QSTR_verb)
.unwrap_or_else(|_| Obj::const_none())
.try_into_option()?;
let verb_cancel: Option<TString> = kwargs
.get(Qstr::MP_QSTR_verb_cancel)
.unwrap_or_else(|_| Obj::const_none())
.try_into_option()?;
let chunkify: bool = kwargs.get_or(Qstr::MP_QSTR_chunkify, false)?;

ConfirmBlobParams::new(title, data, Some(TR::instructions__view_all_data.into()))
.with_verb(verb)
.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_footer_description(Some(
TR::buttons__confirm.into(), /* or words__confirm?? */
))
.with_info_button(true)
.with_chunkify(chunkify)
.with_page_limit(Some(1))
.with_frame_margin(CONFIRM_BLOB_INTRO_MARGIN)
.into_flow()
.and_then(LayoutObj::new_root)
.map(Into::into)
};
unsafe { util::try_with_args_and_kwargs(n_args, args, kwargs, block) }
}

extern "C" fn new_confirm_action(n_args: usize, args: *const Obj, kwargs: *mut Map) -> Obj {
let block = move |_args: &[Obj], kwargs: &Map| {
let title: TString = kwargs.get(Qstr::MP_QSTR_title)?.try_into()?;
Expand Down Expand Up @@ -395,6 +421,7 @@ extern "C" fn new_confirm_address(n_args: usize, args: *const Obj, kwargs: *mut
ConfirmActionStrings::new(title, None, None, None),
false,
None,
0,
false,
)
.and_then(LayoutObj::new_root)
Expand Down Expand Up @@ -438,6 +465,7 @@ extern "C" fn new_confirm_properties(n_args: usize, args: *const Obj, kwargs: *m
ConfirmActionStrings::new(title, None, None, hold.then_some(title)),
hold,
None,
0,
false,
)
.and_then(LayoutObj::new_root)
Expand Down Expand Up @@ -473,6 +501,7 @@ extern "C" fn new_confirm_homescreen(n_args: usize, args: *const Obj, kwargs: *m
),
false,
None,
0,
false,
)
.and_then(LayoutObj::new_root)
Expand Down Expand Up @@ -780,6 +809,7 @@ extern "C" fn new_confirm_total(n_args: usize, args: *const Obj, kwargs: *mut Ma
ConfirmActionStrings::new(title, None, None, Some(title)),
true,
None,
0,
false,
)
.and_then(LayoutObj::new_root)
Expand Down Expand Up @@ -1102,6 +1132,7 @@ extern "C" fn new_confirm_coinjoin(n_args: usize, args: *const Obj, kwargs: *mut
),
true,
None,
0,
false,
)
.and_then(LayoutObj::new_root)
Expand Down Expand Up @@ -1588,12 +1619,25 @@ pub static mp_module_trezorui2: Module = obj_module! {
/// chunkify: bool = False,
/// page_counter: bool = False,
/// prompt_screen: bool = False,
/// page_limit: int | None = None,
/// cancel: bool = False,
/// ) -> LayoutObj[UiResult]:
/// """Confirm byte sequence data."""
Qstr::MP_QSTR_confirm_blob => obj_fn_kw!(0, new_confirm_blob).as_obj(),

/// def confirm_blob_intro(
/// *,
/// title: str,
/// data: str | bytes,
/// subtitle: str | None = None,
/// verb: str | None = None,
/// verb_cancel: str | None = None,
/// chunkify: bool = False,
/// ) -> LayoutObj[UiResult]:
/// """Confirm byte sequence data by showing only the first page of the data
/// and instructing the user to access the menu in order to view all the data,
/// which can then be confirmed using confirm_blob."""
Qstr::MP_QSTR_confirm_blob_intro => obj_fn_kw!(0, new_confirm_blob_intro).as_obj(),

/// def confirm_address(
/// *,
/// title: str,
Expand Down
1 change: 0 additions & 1 deletion core/embed/rust/src/ui/model_tr/layout.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1711,7 +1711,6 @@ pub static mp_module_trezorui2: Module = obj_module! {
/// chunkify: bool = False,
/// page_counter: bool = False,
/// prompt_screen: bool = False,
/// page_limit: int | None = None,
/// cancel: bool = False,
/// ) -> LayoutObj[UiResult]:
/// """Confirm byte sequence data."""
Expand Down
Loading