From 0e1696b3edc53a91d639abaa48599e0e2ea31194 Mon Sep 17 00:00:00 2001 From: obrusvit Date: Thu, 5 Dec 2024 23:41:38 +0100 Subject: [PATCH] chore(core): cleanup warnings and clippy errors [no changelog] --- core/embed/rust/src/ui/api/firmware_upy.rs | 71 ++++++-------- .../ui/model_mercury/flow/request_number.rs | 3 +- .../src/ui/model_mercury/ui_features_fw.rs | 85 ++++++++-------- .../rust/src/ui/model_tr/ui_features_fw.rs | 96 +++++++++---------- .../src/ui/model_tt/component/share_words.rs | 2 +- .../rust/src/ui/model_tt/ui_features_fw.rs | 64 ++++++------- core/embed/rust/src/ui/ui_features_fw.rs | 20 +++- core/mocks/generated/trezorui_api.pyi | 30 +++--- .../apps/management/reset_device/__init__.py | 2 +- core/src/trezor/ui/layouts/tr/__init__.py | 2 +- core/src/trezor/ui/layouts/tr/fido.py | 2 +- core/src/trezor/ui/layouts/tr/reset.py | 2 +- 12 files changed, 182 insertions(+), 197 deletions(-) diff --git a/core/embed/rust/src/ui/api/firmware_upy.rs b/core/embed/rust/src/ui/api/firmware_upy.rs index 719b691768d..1677d84f906 100644 --- a/core/embed/rust/src/ui/api/firmware_upy.rs +++ b/core/embed/rust/src/ui/api/firmware_upy.rs @@ -2,7 +2,6 @@ use crate::{ io::BinaryData, micropython::{ gc::Gc, - iter::IterBuf, list::List, macros::{obj_fn_0, obj_fn_1, obj_fn_kw, obj_module}, map::Map, @@ -23,16 +22,18 @@ use crate::{ util::{upy_disable_animation, RecoveryType}, }, ui_features::ModelUI, - ui_features_fw::UIFeaturesFirmware, + ui_features_fw::{ + UIFeaturesFirmware, MAX_CHECKLIST_ITEMS, MAX_GROUP_SHARE_LINES, MAX_WORD_QUIZ_ITEMS, + }, }, }; use heapless::Vec; -/// Dummy implementation so that we can use `Empty` in a return type of unimplemented trait -/// function +/// Dummy implementation so that we can use `Empty` in a return type of +/// unimplemented trait function impl ComponentMsgObj for Empty { fn msg_try_into_obj(&self, _msg: Self::Msg) -> Result { - Ok(Obj::const_none()) + unimplemented!() } } @@ -231,7 +232,6 @@ extern "C" fn new_confirm_fido(n_args: usize, args: *const Obj, kwargs: *mut Map unsafe { util::try_with_args_and_kwargs(n_args, args, kwargs, block) } } -// TODO: there was `no_mangle` attribute in TT, should we apply it? extern "C" fn new_confirm_firmware_update( n_args: usize, args: *const Obj, @@ -637,12 +637,11 @@ extern "C" fn new_request_number(n_args: usize, args: *const Obj, kwargs: *mut M .unwrap_or_else(|_| Obj::const_none()) .try_into_option()?; - let more_info_cb = more_info_callback.and_then(|callback| { - let cb = move |n: u32| { + let more_info_cb = more_info_callback.map(|callback| { + move |n: u32| { let text = callback.call_with_n_args(&[n.try_into().unwrap()]).unwrap(); TString::try_from(text).unwrap() - }; - Some(cb) + } }); let layout = ModelUI::request_number( @@ -687,7 +686,7 @@ extern "C" fn new_select_word(n_args: usize, args: *const Obj, kwargs: *mut Map) let title: TString = kwargs.get(Qstr::MP_QSTR_title)?.try_into()?; let description: TString = kwargs.get(Qstr::MP_QSTR_description)?.try_into()?; let words_iterable: Obj = kwargs.get(Qstr::MP_QSTR_words)?; - let words: [TString<'static>; 3] = util::iter_into_array(words_iterable)?; + let words: [TString<'static>; MAX_WORD_QUIZ_ITEMS] = util::iter_into_array(words_iterable)?; let layout = ModelUI::select_word(title, description, words)?; Ok(LayoutObj::new_root(layout)?.into()) @@ -746,7 +745,7 @@ extern "C" fn new_show_checklist(n_args: usize, args: *const Obj, kwargs: *mut M let active: usize = kwargs.get(Qstr::MP_QSTR_active)?.try_into()?; let items: Obj = kwargs.get(Qstr::MP_QSTR_items)?; - let items: [TString<'static>; 3] = util::iter_into_array(items)?; + let items: [TString<'static>; MAX_CHECKLIST_ITEMS] = util::iter_into_array(items)?; let layout = ModelUI::show_checklist(title, button, active, items)?; Ok(LayoutObj::new_root(layout)?.into()) @@ -791,7 +790,7 @@ extern "C" fn new_show_group_share_success( ) -> Obj { let block = move |_args: &[Obj], kwargs: &Map| { let lines_iterable: Obj = kwargs.get(Qstr::MP_QSTR_lines)?; - let lines: [TString; 4] = util::iter_into_array(lines_iterable)?; + let lines: [TString; MAX_GROUP_SHARE_LINES] = util::iter_into_array(lines_iterable)?; let layout = ModelUI::show_group_share_success(lines)?; Ok(LayoutObj::new_root(layout)?.into()) @@ -825,9 +824,7 @@ extern "C" fn new_show_info(n_args: usize, args: *const Obj, kwargs: *mut Map) - let block = move |_args: &[Obj], kwargs: &Map| { let title: TString = kwargs.get(Qstr::MP_QSTR_title)?.try_into()?; let description: TString = kwargs.get(Qstr::MP_QSTR_description)?.try_into()?; - let button: TString = kwargs - .get_or(Qstr::MP_QSTR_button, TString::empty())? - .try_into()?; + let button: TString = kwargs.get_or(Qstr::MP_QSTR_button, TString::empty())?; let time_ms: u32 = kwargs.get_or(Qstr::MP_QSTR_time_ms, 0)?.try_into()?; let obj = ModelUI::show_info(title, description, button, time_ms)?; @@ -1014,18 +1011,10 @@ extern "C" fn new_show_warning(n_args: usize, args: *const Obj, kwargs: *mut Map let value: TString = kwargs.get_or(Qstr::MP_QSTR_value, "".into())?; let description: TString = kwargs.get_or(Qstr::MP_QSTR_description, "".into())?; let allow_cancel: bool = kwargs.get_or(Qstr::MP_QSTR_allow_cancel, true)?; - let time_ms: u32 = kwargs.get_or(Qstr::MP_QSTR_time_ms, 0)?; let danger: bool = kwargs.get_or(Qstr::MP_QSTR_danger, false)?; - let layout = ModelUI::show_warning( - title, - button, - value, - description, - allow_cancel, - time_ms, - danger, - )?; + let layout = + ModelUI::show_warning(title, button, value, description, allow_cancel, danger)?; Ok(layout.into()) }; unsafe { util::try_with_args_and_kwargs(n_args, args, kwargs, block) } @@ -1059,7 +1048,9 @@ pub static mp_module_trezorui_api: Module = obj_module! { /// see `trezor::ui::layout::obj::LayoutObj`. /// """ /// - /// def attach_timer_fn(self, fn: Callable[[int, int], None], attach_type: AttachType | None) -> LayoutState | None: + /// def attach_timer_fn( + /// self, fn: Callable[[int, int], None], attach_type: AttachType | None + /// ) -> LayoutState | None: /// """Attach a timer setter function. /// /// The layout object can call the timer setter with two arguments, @@ -1129,8 +1120,8 @@ pub static mp_module_trezorui_api: Module = obj_module! { /// """Calls drop on contents of the root component.""" /// /// class UiResult: - /// """Result of a UI operation.""" - /// pass + /// """Result of a UI operation.""" + /// pass /// /// mock:global Qstr::MP_QSTR___name__ => Qstr::MP_QSTR_trezorui_api.to_obj(), @@ -1446,7 +1437,7 @@ pub static mp_module_trezorui_api: Module = obj_module! { /// prefill_word: str, /// can_go_back: bool, /// ) -> LayoutObj[str]: - /// """SLIP39 word input keyboard.""" + /// """SLIP39 word input keyboard.""" Qstr::MP_QSTR_request_slip39 => obj_fn_kw!(0, new_request_slip39).as_obj(), /// def request_number( @@ -1487,7 +1478,7 @@ pub static mp_module_trezorui_api: Module = obj_module! { /// words: Iterable[str], /// ) -> LayoutObj[int]: /// """Select mnemonic word from three possibilities - seed check after backup. The - /// iterable must be of exact size. Returns index in range `0..3`.""" + /// iterable must be of exact size. Returns index in range `0..3`.""" Qstr::MP_QSTR_select_word => obj_fn_kw!(0, new_select_word).as_obj(), /// def select_word_count( @@ -1498,10 +1489,7 @@ pub static mp_module_trezorui_api: Module = obj_module! { /// For unlocking a repeated backup, select from 20 or 33.""" Qstr::MP_QSTR_select_word_count => obj_fn_kw!(0, new_select_word_count).as_obj(), - /// def set_brightness( - /// *, - /// current: int | None = None - /// ) -> LayoutObj[UiResult]: + /// def set_brightness(*, current: int | None = None) -> LayoutObj[UiResult]: /// """Show the brightness configuration dialog.""" Qstr::MP_QSTR_set_brightness => obj_fn_kw!(0, new_set_brightness).as_obj(), @@ -1526,7 +1514,7 @@ pub static mp_module_trezorui_api: Module = obj_module! { /// button: str, /// ) -> LayoutObj[UiResult]: /// """Checklist of backup steps. Active index is highlighted, previous items have check - /// mark next to them. Limited to 3 items.""" + /// mark next to them. Limited to 3 items.""" Qstr::MP_QSTR_show_checklist => obj_fn_kw!(0, new_show_checklist).as_obj(), /// def show_danger( @@ -1554,7 +1542,7 @@ pub static mp_module_trezorui_api: Module = obj_module! { /// *, /// lines: Iterable[str], /// ) -> LayoutObj[UiResult]: - /// """Shown after successfully finishing a group.""" + /// """Shown after successfully finishing a group.""" Qstr::MP_QSTR_show_group_share_success => obj_fn_kw!(0, new_show_group_share_success).as_obj(), /// def show_homescreen( @@ -1581,7 +1569,7 @@ pub static mp_module_trezorui_api: Module = obj_module! { /// def show_info_with_cancel( /// *, /// title: str, - /// items: Iterable[Tuple[str, str]], + /// items: Iterable[tuple[str, str]], /// horizontal: bool = False, /// chunkify: bool = False, /// ) -> LayoutObj[UiResult]: @@ -1609,8 +1597,8 @@ pub static mp_module_trezorui_api: Module = obj_module! { /// title: str | None = None, /// ) -> LayoutObj[UiResult]: /// """Show progress loader. Please note that the number of lines reserved on screen for - /// description is determined at construction time. If you want multiline descriptions - /// make sure the initial description has at least that amount of lines.""" + /// description is determined at construction time. If you want multiline descriptions + /// make sure the initial description has at least that amount of lines.""" Qstr::MP_QSTR_show_progress => obj_fn_kw!(0, new_show_progress).as_obj(), /// def show_progress_coinjoin( @@ -1621,7 +1609,7 @@ pub static mp_module_trezorui_api: Module = obj_module! { /// skip_first_paint: bool = False, /// ) -> LayoutObj[UiResult]: /// """Show progress loader for coinjoin. Returns CANCELLED after a specified time when - /// time_ms timeout is passed.""" + /// time_ms timeout is passed.""" Qstr::MP_QSTR_show_progress_coinjoin => obj_fn_kw!(0, new_show_progress_coinjoin).as_obj(), /// def show_remaining_shares( @@ -1682,7 +1670,6 @@ pub static mp_module_trezorui_api: Module = obj_module! { /// value: str = "", /// description: str = "", /// allow_cancel: bool = True, - /// time_ms: int = 0, /// danger: bool = False, # unused on TT /// ) -> LayoutObj[UiResult]: /// """Warning modal. TT: No buttons shown when `button` is empty string. TR: middle button and centered text.""" diff --git a/core/embed/rust/src/ui/model_mercury/flow/request_number.rs b/core/embed/rust/src/ui/model_mercury/flow/request_number.rs index 2f749391112..54160f838bb 100644 --- a/core/embed/rust/src/ui/model_mercury/flow/request_number.rs +++ b/core/embed/rust/src/ui/model_mercury/flow/request_number.rs @@ -3,8 +3,7 @@ use crate::{ strutil::TString, translations::TR, ui::{ - button_request::ButtonRequest, - component::{swipe_detect::SwipeSettings, ButtonRequestExt, ComponentExt}, + component::{swipe_detect::SwipeSettings, ComponentExt}, flow::{ base::{Decision, DecisionBuilder as _}, FlowController, FlowMsg, SwipeFlow, diff --git a/core/embed/rust/src/ui/model_mercury/ui_features_fw.rs b/core/embed/rust/src/ui/model_mercury/ui_features_fw.rs index 3f1d50520c0..3cfdd4566a6 100644 --- a/core/embed/rust/src/ui/model_mercury/ui_features_fw.rs +++ b/core/embed/rust/src/ui/model_mercury/ui_features_fw.rs @@ -23,9 +23,12 @@ use crate::{ geometry::{self, Direction}, layout::{ obj::{LayoutMaybeTrace, LayoutObj, RootComponent}, - util::{ConfirmBlob, PropsList, RecoveryType, StrOrBytes}, + util::{PropsList, RecoveryType}, + }, + ui_features::ModelUI, + ui_features_fw::{ + UIFeaturesFirmware, MAX_CHECKLIST_ITEMS, MAX_GROUP_SHARE_LINES, MAX_WORD_QUIZ_ITEMS, }, - ui_features_fw::UIFeaturesFirmware, }, }; @@ -48,10 +51,10 @@ impl UIFeaturesFirmware for ModelMercuryFeatures { action: Option>, description: Option>, subtitle: Option>, - verb: Option>, + _verb: Option>, verb_cancel: Option>, hold: bool, - hold_danger: bool, + _hold_danger: bool, reverse: bool, prompt_screen: bool, prompt_title: Option>, @@ -71,15 +74,15 @@ impl UIFeaturesFirmware for ModelMercuryFeatures { } fn confirm_address( - title: TString<'static>, - data: Obj, - description: Option>, + _title: TString<'static>, + _data: Obj, + _description: Option>, _extra: Option>, _verb: Option>, - chunkify: bool, + _chunkify: bool, ) -> Result { // confirm_value is used instead - Err::, Error>(Error::ValueError( + Err::, Error>(Error::ValueError( c"confirm_address not implemented", )) } @@ -218,7 +221,7 @@ impl UIFeaturesFirmware for ModelMercuryFeatures { fn confirm_emphasized( title: TString<'static>, items: Obj, - verb: Option>, + _verb: Option>, ) -> Result { let mut ops = OpTextLayout::new(theme::TEXT_NORMAL); for item in IterBuf::new().try_iterate(items)? { @@ -254,11 +257,9 @@ impl UIFeaturesFirmware for ModelMercuryFeatures { accounts: Gc, ) -> Result { #[cfg(feature = "universal_fw")] - return Ok(flow::confirm_fido::new_confirm_fido( - title, app_name, icon, accounts, - )?); + return flow::confirm_fido::new_confirm_fido(title, app_name, icon, accounts); #[cfg(not(feature = "universal_fw"))] - Err::, Error>(Error::ValueError( + Err::, Error>(Error::ValueError( c"confirm_fido not used in bitcoin-only firmware", )) } @@ -277,7 +278,7 @@ impl UIFeaturesFirmware for ModelMercuryFeatures { sign: i32, user_fee_change: TString<'static>, total_fee_new: TString<'static>, - fee_rate_amount: Option>, + _fee_rate_amount: Option>, ) -> Result { let (description, change, total_label) = match sign { s if s < 0 => ( @@ -353,7 +354,7 @@ impl UIFeaturesFirmware for ModelMercuryFeatures { _button_style_confirm: bool, _items: Obj, ) -> Result { - Err::, Error>(Error::ValueError( + Err::, Error>(Error::ValueError( c"confirm_more not implemented", )) } @@ -474,7 +475,7 @@ impl UIFeaturesFirmware for ModelMercuryFeatures { title: TString<'static>, button: TString<'static>, info_button: TString<'static>, - verb_cancel: Option>, + _verb_cancel: Option>, items: Obj, ) -> Result { let mut paragraphs = ParagraphVecShort::new(); @@ -514,11 +515,11 @@ impl UIFeaturesFirmware for ModelMercuryFeatures { _button: Option>, recovery_type: RecoveryType, show_instructions: bool, - remaining_shares: Option, + remaining_shares: Option, ) -> Result, Error> { let pages_vec = if let Some(pages_obj) = remaining_shares { let mut vec = ParagraphVecLong::new(); - for page in crate::micropython::iter::IterBuf::new().try_iterate(pages_obj)? { + for page in IterBuf::new().try_iterate(pages_obj)? { let [title, description]: [TString; 2] = util::iter_into_array(page)?; vec.add(Paragraph::new(&theme::TEXT_SUB_GREY, title)) .add(Paragraph::new(&theme::TEXT_MONO_GREY_LIGHT, description).break_after()); @@ -675,7 +676,7 @@ impl UIFeaturesFirmware for ModelMercuryFeatures { _verb: TString<'static>, _items: Gc, ) -> Result { - Err::, Error>(Error::ValueError( + Err::, Error>(Error::ValueError( c"multiple_pages_texts not implemented", )) } @@ -756,8 +757,8 @@ impl UIFeaturesFirmware for ModelMercuryFeatures { } fn request_passphrase( - prompt: TString<'static>, - max_len: u32, + _prompt: TString<'static>, + _max_len: u32, ) -> Result { let flow = flow::request_passphrase::new_request_passphrase()?; Ok(flow) @@ -766,7 +767,7 @@ impl UIFeaturesFirmware for ModelMercuryFeatures { fn select_word( title: TString<'static>, description: TString<'static>, - words: [TString<'static>; 3], + words: [TString<'static>; MAX_WORD_QUIZ_ITEMS], ) -> Result { let content = VerticalMenu::select_word(words); let layout = @@ -801,16 +802,16 @@ impl UIFeaturesFirmware for ModelMercuryFeatures { _path: Option>, _xpubs: Obj, ) -> Result { - Err::, Error>(Error::ValueError( + Err::, Error>(Error::ValueError( c"show_address_details not implemented", )) } fn show_checklist( title: TString<'static>, - button: TString<'static>, + _button: TString<'static>, active: usize, - items: [TString<'static>; 3], + items: [TString<'static>; MAX_CHECKLIST_ITEMS], ) -> Result { let mut paragraphs = ParagraphVecLong::new(); for (i, item) in items.into_iter().enumerate() { @@ -855,10 +856,10 @@ impl UIFeaturesFirmware for ModelMercuryFeatures { fn show_error( title: TString<'static>, - button: TString<'static>, + _button: TString<'static>, description: TString<'static>, allow_cancel: bool, - time_ms: u32, + _time_ms: u32, ) -> Result, Error> { let content = Paragraphs::new(Paragraph::new(&theme::TEXT_MAIN_GREY_LIGHT, description)); let frame = if allow_cancel { @@ -879,7 +880,7 @@ impl UIFeaturesFirmware for ModelMercuryFeatures { } fn show_group_share_success( - lines: [TString<'static>; 4], + lines: [TString<'static>; MAX_GROUP_SHARE_LINES], ) -> Result { let paragraphs = ParagraphVecShort::from_iter([ Paragraph::new(&theme::TEXT_NORMAL_GREY_EXTRA_LIGHT, lines[0]).centered(), @@ -1019,10 +1020,10 @@ impl UIFeaturesFirmware for ModelMercuryFeatures { } fn show_share_words( - words: heapless::Vec, 33>, + _words: heapless::Vec, 33>, _title: Option>, ) -> Result { - Err::, Error>(Error::ValueError( + Err::, Error>(Error::ValueError( c"use share_words_mercury instead", )) } @@ -1030,12 +1031,12 @@ impl UIFeaturesFirmware for ModelMercuryFeatures { fn show_share_words_mercury( words: heapless::Vec, 33>, subtitle: Option>, - instructions: crate::micropython::obj::Obj, + instructions: Obj, text_footer: Option>, text_confirm: TString<'static>, ) -> Result { let mut instructions_paragraphs = ParagraphVecShort::new(); - for item in crate::micropython::iter::IterBuf::new().try_iterate(instructions)? { + for item in IterBuf::new().try_iterate(instructions)? { let text: TString = item.try_into()?; instructions_paragraphs.add(Paragraph::new(&theme::TEXT_MAIN_GREY_LIGHT, text)); } @@ -1050,11 +1051,9 @@ impl UIFeaturesFirmware for ModelMercuryFeatures { Ok(flow) } - fn show_remaining_shares( - pages_iterable: crate::micropython::obj::Obj, // TODO: replace Obj - ) -> Result { + fn show_remaining_shares(_pages_iterable: Obj) -> Result { // Mercury: remaining shares is a part of `continue_recovery` flow - Err::, Error>(Error::ValueError( + Err::, Error>(Error::ValueError( c"show_remaining_shares not implemented", )) } @@ -1073,10 +1072,10 @@ impl UIFeaturesFirmware for ModelMercuryFeatures { fn show_success( title: TString<'static>, - button: TString<'static>, + _button: TString<'static>, description: TString<'static>, - allow_cancel: bool, - time_ms: u32, + _allow_cancel: bool, + _time_ms: u32, ) -> Result, Error> { // description used in the Footer let description = if description.is_empty() { @@ -1107,8 +1106,7 @@ impl UIFeaturesFirmware for ModelMercuryFeatures { button: TString<'static>, value: TString<'static>, description: TString<'static>, - allow_cancel: bool, - time_ms: u32, + _allow_cancel: bool, danger: bool, ) -> Result, Error> { let action = if button.is_empty() { @@ -1132,7 +1130,8 @@ impl UIFeaturesFirmware for ModelMercuryFeatures { frame.with_warning_low_icon() }; - Ok(LayoutObj::new(SwipeUpScreen::new(frame_with_icon))?) + let layout = LayoutObj::new(SwipeUpScreen::new(frame_with_icon))?; + Ok(layout) } fn tutorial() -> Result { diff --git a/core/embed/rust/src/ui/model_tr/ui_features_fw.rs b/core/embed/rust/src/ui/model_tr/ui_features_fw.rs index 4225942deb0..e58df99040d 100644 --- a/core/embed/rust/src/ui/model_tr/ui_features_fw.rs +++ b/core/embed/rust/src/ui/model_tr/ui_features_fw.rs @@ -30,7 +30,10 @@ use crate::{ component::{ButtonActions, ButtonLayout, Page}, constant, }, - ui_features_fw::UIFeaturesFirmware, + ui_features::ModelUI, + ui_features_fw::{ + UIFeaturesFirmware, MAX_CHECKLIST_ITEMS, MAX_GROUP_SHARE_LINES, MAX_WORD_QUIZ_ITEMS, + }, }, }; @@ -50,14 +53,14 @@ impl UIFeaturesFirmware for ModelTRFeatures { title: TString<'static>, action: Option>, description: Option>, - subtitle: Option>, + _subtitle: Option>, verb: Option>, verb_cancel: Option>, hold: bool, - hold_danger: bool, + _hold_danger: bool, reverse: bool, - prompt_screen: bool, - prompt_title: Option>, + _prompt_screen: bool, + _prompt_title: Option>, ) -> Result { let paragraphs = { let action = action.unwrap_or("".into()); @@ -87,8 +90,8 @@ impl UIFeaturesFirmware for ModelTRFeatures { fn confirm_address( title: TString<'static>, data: Obj, - description: Option>, - extra: Option>, + _description: Option>, + _extra: Option>, verb: Option>, chunkify: bool, ) -> Result { @@ -207,7 +210,7 @@ impl UIFeaturesFirmware for ModelTRFeatures { _items: Obj, _verb: Option>, ) -> Result { - Err::, Error>(Error::ValueError( + Err::, Error>(Error::ValueError( c"confirm_emphasized not implemented", )) } @@ -215,7 +218,7 @@ impl UIFeaturesFirmware for ModelTRFeatures { fn confirm_fido( title: TString<'static>, app_name: TString<'static>, - icon: Option>, + _icon: Option>, accounts: Gc, ) -> Result { // Cache the page count so that we can move `accounts` into the closure. @@ -305,7 +308,7 @@ impl UIFeaturesFirmware for ModelTRFeatures { } fn confirm_modify_fee( - title: TString<'static>, + _title: TString<'static>, sign: i32, user_fee_change: TString<'static>, total_fee_new: TString<'static>, @@ -468,7 +471,7 @@ impl UIFeaturesFirmware for ModelTRFeatures { amount_label: TString<'static>, fee: TString<'static>, fee_label: TString<'static>, - title: Option>, + _title: Option>, account_items: Option, extra_items: Option, extra_title: Option>, @@ -697,7 +700,7 @@ impl UIFeaturesFirmware for ModelTRFeatures { _summary_br_name: Option>, _cancel_text: Option>, ) -> Result { - Err::, Error>(Error::ValueError( + Err::, Error>(Error::ValueError( c"flow_confirm_output not supported", )) } @@ -706,7 +709,7 @@ impl UIFeaturesFirmware for ModelTRFeatures { _title: TString<'static>, _description: TString<'static>, ) -> Result { - Err::, Error>(Error::ValueError( + Err::, Error>(Error::ValueError( c"flow_confirm_set_new_pin not supported", )) } @@ -726,7 +729,7 @@ impl UIFeaturesFirmware for ModelTRFeatures { _br_code: u16, _br_name: TString<'static>, ) -> Result { - Err::, Error>(Error::ValueError( + Err::, Error>(Error::ValueError( c"flow_get_address not supported", )) } @@ -862,8 +865,8 @@ impl UIFeaturesFirmware for ModelTRFeatures { fn request_pin( prompt: TString<'static>, subprompt: TString<'static>, - allow_cancel: bool, - warning: bool, + _allow_cancel: bool, + _warning: bool, ) -> Result { let layout = RootComponent::new(PinEntry::new(prompt, subprompt)); Ok(layout) @@ -871,7 +874,7 @@ impl UIFeaturesFirmware for ModelTRFeatures { fn request_passphrase( prompt: TString<'static>, - max_len: u32, + _max_len: u32, ) -> Result { let layout = RootComponent::new(Frame::new(prompt, PassphraseEntry::new()).with_title_centered()); @@ -879,9 +882,9 @@ impl UIFeaturesFirmware for ModelTRFeatures { } fn select_word( - title: TString<'static>, + _title: TString<'static>, description: TString<'static>, - words: [TString<'static>; 3], + words: [TString<'static>; MAX_WORD_QUIZ_ITEMS], ) -> Result { let words: Vec, 5> = Vec::from_iter(words); // Returning the index of the selected word, not the word itself @@ -915,8 +918,8 @@ impl UIFeaturesFirmware for ModelTRFeatures { Ok(layout) } - fn set_brightness(current_brightness: Option) -> Result { - Err::, Error>(Error::ValueError( + fn set_brightness(_current_brightness: Option) -> Result { + Err::, Error>(Error::ValueError( c"setting brightness not supported", )) } @@ -942,10 +945,10 @@ impl UIFeaturesFirmware for ModelTRFeatures { } fn show_checklist( - title: TString<'static>, + _title: TString<'static>, button: TString<'static>, active: usize, - items: [TString<'static>; 3], + items: [TString<'static>; MAX_CHECKLIST_ITEMS], ) -> Result { let mut paragraphs = ParagraphVecLong::new(); for (i, item) in items.into_iter().enumerate() { @@ -983,23 +986,21 @@ impl UIFeaturesFirmware for ModelTRFeatures { _value: TString<'static>, _verb_cancel: Option>, ) -> Result { - Err::, Error>(Error::ValueError( - c"show_danger not supported", - )) + Err::, Error>(Error::ValueError(c"show_danger not supported")) } fn show_error( - title: TString<'static>, - button: TString<'static>, - description: TString<'static>, - allow_cancel: bool, - time_ms: u32, + _title: TString<'static>, + _button: TString<'static>, + _description: TString<'static>, + _allow_cancel: bool, + _time_ms: u32, ) -> Result, Error> { Err::, Error>(Error::ValueError(c"show error not supported")) } fn show_group_share_success( - lines: [TString<'static>; 4], + lines: [TString<'static>; MAX_GROUP_SHARE_LINES], ) -> Result { let paragraphs = Paragraphs::new([ Paragraph::new(&theme::TEXT_MONO, lines[0]), @@ -1056,7 +1057,7 @@ impl UIFeaturesFirmware for ModelTRFeatures { _horizontal: bool, _chunkify: bool, ) -> Result { - Err::, Error>(Error::ValueError( + Err::, Error>(Error::ValueError( c"show_info_with_cancel not supported", )) } @@ -1144,19 +1145,15 @@ impl UIFeaturesFirmware for ModelTRFeatures { fn show_share_words_mercury( _words: heapless::Vec, 33>, _subtitle: Option>, - _instructions: crate::micropython::obj::Obj, + _instructions: Obj, _text_footer: Option>, _text_confirm: TString<'static>, ) -> Result { - Err::, Error>(Error::ValueError( - c"use show_share_words", - )) + Err::, Error>(Error::ValueError(c"use show_share_words")) } - fn show_remaining_shares( - pages_iterable: crate::micropython::obj::Obj, // TODO: replace Obj - ) -> Result { - Err::, Error>(Error::ValueError( + fn show_remaining_shares(_pages_iterable: Obj) -> Result { + Err::, Error>(Error::ValueError( c"show remaining shares not supported", )) } @@ -1173,11 +1170,11 @@ impl UIFeaturesFirmware for ModelTRFeatures { } fn show_success( - title: TString<'static>, - button: TString<'static>, - description: TString<'static>, - allow_cancel: bool, - time_ms: u32, + _title: TString<'static>, + _button: TString<'static>, + _description: TString<'static>, + _allow_cancel: bool, + _time_ms: u32, ) -> Result, Error> { Err::, Error>(Error::ValueError(c"show success not supported")) } @@ -1188,13 +1185,12 @@ impl UIFeaturesFirmware for ModelTRFeatures { } fn show_warning( - title: TString<'static>, + _title: TString<'static>, button: TString<'static>, value: TString<'static>, description: TString<'static>, - allow_cancel: bool, - time_ms: u32, - danger: bool, + _allow_cancel: bool, + _danger: bool, ) -> Result, Error> { let get_page = move |page_index| { assert!(page_index == 0); diff --git a/core/embed/rust/src/ui/model_tt/component/share_words.rs b/core/embed/rust/src/ui/model_tt/component/share_words.rs index 13d236e2455..f05e379c2ec 100644 --- a/core/embed/rust/src/ui/model_tt/component/share_words.rs +++ b/core/embed/rust/src/ui/model_tt/component/share_words.rs @@ -45,7 +45,7 @@ impl<'a> Component for ShareWords<'a> { bounds } - fn event(&mut self, ctx: &mut EventCtx, event: Event) -> Option { + fn event(&mut self, _ctx: &mut EventCtx, _event: Event) -> Option { None } diff --git a/core/embed/rust/src/ui/model_tt/ui_features_fw.rs b/core/embed/rust/src/ui/model_tt/ui_features_fw.rs index 885f9983995..bd20da0ce49 100644 --- a/core/embed/rust/src/ui/model_tt/ui_features_fw.rs +++ b/core/embed/rust/src/ui/model_tt/ui_features_fw.rs @@ -25,7 +25,10 @@ use crate::{ obj::{LayoutMaybeTrace, LayoutObj, RootComponent}, util::{ConfirmBlob, PropsList, RecoveryType}, }, - ui_features_fw::UIFeaturesFirmware, + ui_features::ModelUI, + ui_features_fw::{ + UIFeaturesFirmware, MAX_CHECKLIST_ITEMS, MAX_GROUP_SHARE_LINES, MAX_WORD_QUIZ_ITEMS, + }, }, }; @@ -45,14 +48,14 @@ impl UIFeaturesFirmware for ModelTTFeatures { title: TString<'static>, action: Option>, description: Option>, - subtitle: Option>, + _subtitle: Option>, verb: Option>, verb_cancel: Option>, hold: bool, hold_danger: bool, reverse: bool, - prompt_screen: bool, - prompt_title: Option>, + _prompt_screen: bool, + _prompt_title: Option>, ) -> Result { let paragraphs = { let action = action.unwrap_or("".into()); @@ -284,7 +287,7 @@ impl UIFeaturesFirmware for ModelTTFeatures { sign: i32, user_fee_change: TString<'static>, total_fee_new: TString<'static>, - fee_rate_amount: Option>, + _fee_rate_amount: Option>, ) -> Result { let (description, change, total_label) = match sign { s if s < 0 => ( @@ -441,7 +444,7 @@ impl UIFeaturesFirmware for ModelTTFeatures { title: Option>, account_items: Option, extra_items: Option, - extra_title: Option>, + _extra_title: Option>, verb_cancel: Option>, ) -> Result { let info_button: bool = account_items.is_some() || extra_items.is_some(); @@ -520,7 +523,7 @@ impl UIFeaturesFirmware for ModelTTFeatures { Ok(layout) } - fn check_homescreen_format(image: BinaryData, accept_toif: bool) -> bool { + fn check_homescreen_format(image: BinaryData, _accept_toif: bool) -> bool { super::component::check_homescreen_format(image, false) } @@ -530,7 +533,7 @@ impl UIFeaturesFirmware for ModelTTFeatures { button: Option>, recovery_type: RecoveryType, _show_instructions: bool, - remaining_shares: Option, + remaining_shares: Option, ) -> Result, Error> { let paragraphs = Paragraphs::new([ Paragraph::new(&theme::TEXT_DEMIBOLD, text), @@ -587,7 +590,7 @@ impl UIFeaturesFirmware for ModelTTFeatures { _summary_br_name: Option>, _cancel_text: Option>, ) -> Result { - Err::, Error>(Error::ValueError( + Err::, Error>(Error::ValueError( c"flow_confirm_output not supported", )) } @@ -596,7 +599,7 @@ impl UIFeaturesFirmware for ModelTTFeatures { _title: TString<'static>, _description: TString<'static>, ) -> Result { - Err::, Error>(Error::ValueError( + Err::, Error>(Error::ValueError( c"flow_confirm_set_new_pin not supported", )) } @@ -616,7 +619,7 @@ impl UIFeaturesFirmware for ModelTTFeatures { _br_code: u16, _br_name: TString<'static>, ) -> Result { - Err::, Error>(Error::ValueError( + Err::, Error>(Error::ValueError( c"flow_get_address not supported", )) } @@ -626,13 +629,13 @@ impl UIFeaturesFirmware for ModelTTFeatures { _verb: TString<'static>, _items: Gc, ) -> Result { - Err::, Error>(Error::ValueError( + Err::, Error>(Error::ValueError( c"multiple_pages_texts not implemented", )) } fn prompt_backup() -> Result { - Err::, Error>(Error::ValueError( + Err::, Error>(Error::ValueError( c"prompt_backup not implemented", )) } @@ -697,8 +700,8 @@ impl UIFeaturesFirmware for ModelTTFeatures { } fn request_passphrase( - prompt: TString<'static>, - max_len: u32, + _prompt: TString<'static>, + _max_len: u32, ) -> Result { let layout = RootComponent::new(PassphraseKeyboard::new()); Ok(layout) @@ -707,7 +710,7 @@ impl UIFeaturesFirmware for ModelTTFeatures { fn select_word( title: TString<'static>, description: TString<'static>, - words: [TString<'static>; 3], + words: [TString<'static>; MAX_WORD_QUIZ_ITEMS], ) -> Result { let paragraphs = Paragraphs::new([Paragraph::new(&theme::TEXT_DEMIBOLD, description)]); let layout = RootComponent::new(Frame::left_aligned( @@ -788,7 +791,7 @@ impl UIFeaturesFirmware for ModelTTFeatures { title: TString<'static>, button: TString<'static>, active: usize, - items: [TString<'static>; 3], + items: [TString<'static>; MAX_CHECKLIST_ITEMS], ) -> Result { let mut paragraphs = ParagraphVecLong::new(); for (i, item) in items.into_iter().enumerate() { @@ -829,9 +832,7 @@ impl UIFeaturesFirmware for ModelTTFeatures { _value: TString<'static>, _verb_cancel: Option>, ) -> Result { - Err::, Error>(Error::ValueError( - c"show_danger not supported", - )) + Err::, Error>(Error::ValueError(c"show_danger not supported")) } fn show_error( @@ -861,7 +862,7 @@ impl UIFeaturesFirmware for ModelTTFeatures { } fn show_group_share_success( - lines: [TString<'static>; 4], + lines: [TString<'static>; MAX_GROUP_SHARE_LINES], ) -> Result { let layout = RootComponent::new(IconDialog::new_shares( lines, @@ -1049,18 +1050,14 @@ impl UIFeaturesFirmware for ModelTTFeatures { fn show_share_words_mercury( _words: heapless::Vec, 33>, _subtitle: Option>, - _instructions: crate::micropython::obj::Obj, + _instructions: Obj, _text_footer: Option>, _text_confirm: TString<'static>, ) -> Result { - Err::, Error>(Error::ValueError( - c"use show_share_words", - )) + Err::, Error>(Error::ValueError(c"use show_share_words")) } - fn show_remaining_shares( - pages_iterable: crate::micropython::obj::Obj, // TODO: replace Obj - ) -> Result { + fn show_remaining_shares(pages_iterable: Obj) -> Result { let mut paragraphs = ParagraphVecLong::new(); for page in crate::micropython::iter::IterBuf::new().try_iterate(pages_iterable)? { let [title, description]: [TString; 2] = @@ -1156,8 +1153,7 @@ impl UIFeaturesFirmware for ModelTTFeatures { value: TString<'static>, description: TString<'static>, allow_cancel: bool, - time_ms: u32, - danger: bool, + _danger: bool, ) -> Result, Error> { let icon = BlendedImage::new( theme::IMAGE_BG_OCTAGON, @@ -1179,12 +1175,11 @@ impl UIFeaturesFirmware for ModelTTFeatures { } fn tutorial() -> Result { - Err::, Error>(Error::ValueError( - c"tutorial not supported", - )) + Err::, Error>(Error::ValueError(c"tutorial not supported")) } } +#[allow(clippy::too_many_arguments)] fn new_show_modal( title: TString<'static>, value: TString<'static>, @@ -1356,7 +1351,8 @@ mod tests { use crate::{ trace::tests::trace, ui::{ - component::text::op::OpTextLayout, component::Component, geometry::Rect, + component::{text::op::OpTextLayout, Component}, + geometry::Rect, model_tt::constant, }, }; diff --git a/core/embed/rust/src/ui/ui_features_fw.rs b/core/embed/rust/src/ui/ui_features_fw.rs index d124edcef9d..817b2b80fdf 100644 --- a/core/embed/rust/src/ui/ui_features_fw.rs +++ b/core/embed/rust/src/ui/ui_features_fw.rs @@ -11,7 +11,12 @@ use super::layout::{ util::RecoveryType, }; +pub const MAX_CHECKLIST_ITEMS: usize = 3; +pub const MAX_WORD_QUIZ_ITEMS: usize = 3; +pub const MAX_GROUP_SHARE_LINES: usize = 4; + pub trait UIFeaturesFirmware { + #[allow(clippy::too_many_arguments)] fn confirm_action( title: TString<'static>, action: Option>, @@ -35,6 +40,7 @@ pub trait UIFeaturesFirmware { chunkify: bool, ) -> Result; + #[allow(clippy::too_many_arguments)] fn confirm_blob( title: TString<'static>, data: Obj, // TODO: replace Obj @@ -119,6 +125,7 @@ pub trait UIFeaturesFirmware { fn confirm_reset_device(recovery: bool) -> Result; + #[allow(clippy::too_many_arguments)] fn confirm_summary( amount: TString<'static>, amount_label: TString<'static>, @@ -131,6 +138,7 @@ pub trait UIFeaturesFirmware { verb_cancel: Option>, ) -> Result; + #[allow(clippy::too_many_arguments)] fn confirm_value( title: TString<'static>, value: Obj, // TODO: replace Obj @@ -164,6 +172,7 @@ pub trait UIFeaturesFirmware { fn check_homescreen_format(image: BinaryData, accept_toif: bool) -> bool; + #[allow(clippy::too_many_arguments)] fn flow_confirm_output( title: Option>, subtitle: Option>, @@ -190,6 +199,7 @@ pub trait UIFeaturesFirmware { description: TString<'static>, ) -> Result; + #[allow(clippy::too_many_arguments)] fn flow_get_address( address: Obj, // TODO: replace Obj title: TString<'static>, @@ -251,7 +261,7 @@ pub trait UIFeaturesFirmware { fn select_word( title: TString<'static>, description: TString<'static>, - words: [TString<'static>; 3], + words: [TString<'static>; MAX_WORD_QUIZ_ITEMS], ) -> Result; fn select_word_count(recovery_type: RecoveryType) -> Result; @@ -272,7 +282,7 @@ pub trait UIFeaturesFirmware { title: TString<'static>, button: TString<'static>, active: usize, - items: [TString<'static>; 3], + items: [TString<'static>; MAX_CHECKLIST_ITEMS], ) -> Result; fn show_danger( @@ -291,7 +301,7 @@ pub trait UIFeaturesFirmware { ) -> Result, Error>; // TODO: return LayoutMaybeTrace fn show_group_share_success( - lines: [TString<'static>; 4], + lines: [TString<'static>; MAX_GROUP_SHARE_LINES], ) -> Result; fn show_homescreen( @@ -345,7 +355,8 @@ pub trait UIFeaturesFirmware { title: Option>, ) -> Result; - // TODO: merge with `show_share_words` instead of having specific version for mercury + // TODO: merge with `show_share_words` instead of having specific version for + // mercury fn show_share_words_mercury( words: Vec, 33>, subtitle: Option>, @@ -376,7 +387,6 @@ pub trait UIFeaturesFirmware { value: TString<'static>, description: TString<'static>, allow_cancel: bool, - time_ms: u32, danger: bool, ) -> Result, Error>; // TODO: return LayoutMaybeTrace diff --git a/core/mocks/generated/trezorui_api.pyi b/core/mocks/generated/trezorui_api.pyi index 79facf4ece9..6c1316204b4 100644 --- a/core/mocks/generated/trezorui_api.pyi +++ b/core/mocks/generated/trezorui_api.pyi @@ -8,7 +8,9 @@ class LayoutObj(Generic[T]): """Representation of a Rust-based layout object. see `trezor::ui::layout::obj::LayoutObj`. """ - def attach_timer_fn(self, fn: Callable[[int, int], None], attach_type: AttachType | None) -> LayoutState | None: + def attach_timer_fn( + self, fn: Callable[[int, int], None], attach_type: AttachType | None + ) -> LayoutState | None: """Attach a timer setter function. The layout object can call the timer setter with two arguments, `token` and `duration_ms`. When `duration_ms` elapses, the layout object @@ -61,8 +63,8 @@ class LayoutObj(Generic[T]): # rust/src/ui/api/firmware_upy.rs class UiResult: - """Result of a UI operation.""" - pass + """Result of a UI operation.""" + pass CONFIRMED: UiResult CANCELLED: UiResult INFO: UiResult @@ -394,7 +396,7 @@ def request_slip39( prefill_word: str, can_go_back: bool, ) -> LayoutObj[str]: - """SLIP39 word input keyboard.""" + """SLIP39 word input keyboard.""" # rust/src/ui/api/firmware_upy.rs @@ -439,7 +441,7 @@ def select_word( words: Iterable[str], ) -> LayoutObj[int]: """Select mnemonic word from three possibilities - seed check after backup. The - iterable must be of exact size. Returns index in range `0..3`.""" + iterable must be of exact size. Returns index in range `0..3`.""" # rust/src/ui/api/firmware_upy.rs @@ -452,10 +454,7 @@ def select_word_count( # rust/src/ui/api/firmware_upy.rs -def set_brightness( - *, - current: int | None = None -) -> LayoutObj[UiResult]: +def set_brightness(*, current: int | None = None) -> LayoutObj[UiResult]: """Show the brightness configuration dialog.""" @@ -482,7 +481,7 @@ def show_checklist( button: str, ) -> LayoutObj[UiResult]: """Checklist of backup steps. Active index is highlighted, previous items have check - mark next to them. Limited to 3 items.""" + mark next to them. Limited to 3 items.""" # rust/src/ui/api/firmware_upy.rs @@ -513,7 +512,7 @@ def show_group_share_success( *, lines: Iterable[str], ) -> LayoutObj[UiResult]: - """Shown after successfully finishing a group.""" + """Shown after successfully finishing a group.""" # rust/src/ui/api/firmware_upy.rs @@ -543,7 +542,7 @@ def show_info( def show_info_with_cancel( *, title: str, - items: Iterable[Tuple[str, str]], + items: Iterable[tuple[str, str]], horizontal: bool = False, chunkify: bool = False, ) -> LayoutObj[UiResult]: @@ -574,8 +573,8 @@ def show_progress( title: str | None = None, ) -> LayoutObj[UiResult]: """Show progress loader. Please note that the number of lines reserved on screen for - description is determined at construction time. If you want multiline descriptions - make sure the initial description has at least that amount of lines.""" + description is determined at construction time. If you want multiline descriptions + make sure the initial description has at least that amount of lines.""" # rust/src/ui/api/firmware_upy.rs @@ -587,7 +586,7 @@ def show_progress_coinjoin( skip_first_paint: bool = False, ) -> LayoutObj[UiResult]: """Show progress loader for coinjoin. Returns CANCELLED after a specified time when - time_ms timeout is passed.""" + time_ms timeout is passed.""" # rust/src/ui/api/firmware_upy.rs @@ -655,7 +654,6 @@ def show_warning( value: str = "", description: str = "", allow_cancel: bool = True, - time_ms: int = 0, danger: bool = False, # unused on TT ) -> LayoutObj[UiResult]: """Warning modal. TT: No buttons shown when `button` is empty string. TR: middle button and centered text.""" diff --git a/core/src/apps/management/reset_device/__init__.py b/core/src/apps/management/reset_device/__init__.py index f7863675c7a..1977348268f 100644 --- a/core/src/apps/management/reset_device/__init__.py +++ b/core/src/apps/management/reset_device/__init__.py @@ -29,7 +29,7 @@ async def reset_device(msg: ResetDevice) -> Success: - from trezor import TR, config + from trezor import config from trezor.crypto import bip39, random from trezor.messages import EntropyAck, EntropyRequest, Success from trezor.pin import render_empty_loader diff --git a/core/src/trezor/ui/layouts/tr/__init__.py b/core/src/trezor/ui/layouts/tr/__init__.py index 4ee60928a88..96076760afd 100644 --- a/core/src/trezor/ui/layouts/tr/__init__.py +++ b/core/src/trezor/ui/layouts/tr/__init__.py @@ -400,7 +400,7 @@ def show_warning( content = content + "\n" return interact( - trezorui_api.show_warning( # type: ignore [Argument missing for parameter "title"] + trezorui_api.show_warning( title="", button=button, value=content, diff --git a/core/src/trezor/ui/layouts/tr/fido.py b/core/src/trezor/ui/layouts/tr/fido.py index 18bff9df3a7..0d4e60e0f78 100644 --- a/core/src/trezor/ui/layouts/tr/fido.py +++ b/core/src/trezor/ui/layouts/tr/fido.py @@ -12,7 +12,7 @@ async def confirm_fido( accounts: list[str | None], ) -> int: """Webauthn confirmation for one or more credentials.""" - confirm = trezorui_api.confirm_fido( # type: ignore [Argument missing for parameter "icon_name"] + confirm = trezorui_api.confirm_fido( title=header, app_name=app_name, icon_name=None, diff --git a/core/src/trezor/ui/layouts/tr/reset.py b/core/src/trezor/ui/layouts/tr/reset.py index 1dd8d684bd7..fb0218fe06a 100644 --- a/core/src/trezor/ui/layouts/tr/reset.py +++ b/core/src/trezor/ui/layouts/tr/reset.py @@ -1,8 +1,8 @@ from typing import TYPE_CHECKING +import trezorui_api from trezor import TR from trezor.enums import ButtonRequestType -import trezorui_api from ..common import interact, raise_if_not_confirmed from . import confirm_action, show_success, show_warning