-
-
Notifications
You must be signed in to change notification settings - Fork 665
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
base: main
Are you sure you want to change the base?
Changes from 1 commit
95a874f
8313c30
2bc787a
33d1def
815316a
c25b4bc
4e780f5
17cba95
d2cc6c0
fc0bb63
1eff1d8
f4a6756
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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 { | ||
|
@@ -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)] | ||
|
@@ -222,6 +229,7 @@ pub fn new_confirm_action( | |
ConfirmActionStrings::new(title, subtitle, None, prompt_screen.then_some(prompt_title)), | ||
hold, | ||
None, | ||
0, | ||
false, | ||
) | ||
} | ||
|
@@ -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 { .. } => { | ||
|
@@ -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, | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. could probably be also named |
||
) -> 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, | ||
) | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -62,6 +62,8 @@ use crate::{ | |
}, | ||
}; | ||
|
||
const CONFIRM_BLOB_INTRO_MARGIN: usize = 24; | ||
|
||
impl TryFrom<SelectWordCountMsg> for Obj { | ||
type Error = Error; | ||
|
||
|
@@ -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) | ||
|
@@ -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) | ||
|
@@ -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) | ||
|
@@ -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 { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I don't love it as it creates |
||
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()?; | ||
|
@@ -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) | ||
|
@@ -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) | ||
|
@@ -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) | ||
|
@@ -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) | ||
|
@@ -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) | ||
|
@@ -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, | ||
|
There was a problem hiding this comment.
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.