From 8d7fc11b87e8696b601a9ad9dac78ade13cff8c2 Mon Sep 17 00:00:00 2001 From: grdddj Date: Sun, 13 Nov 2022 11:14:46 +0100 Subject: [PATCH] WIP - after rebase fixes --- .../src/ui/model_tr/component/flow_pages.rs | 9 +++++-- core/embed/rust/src/ui/model_tr/layout.rs | 24 +++++++------------ core/src/apps/bitcoin/sign_tx/layout.py | 8 ++++--- core/src/apps/common/passphrase.py | 3 ++- core/src/apps/common/request_pin.py | 3 ++- core/src/apps/ethereum/layout.py | 1 + .../apps/management/get_next_u2f_counter.py | 4 ++-- .../apps/management/recovery_device/layout.py | 2 +- .../apps/management/reset_device/__init__.py | 2 +- core/src/apps/management/set_u2f_counter.py | 4 ++-- core/src/storage/sd_salt.py | 5 ++-- core/src/trezor/ui/layouts/tr/__init__.py | 2 +- core/src/trezor/ui/layouts/tt_v2/__init__.py | 8 +++---- 13 files changed, 40 insertions(+), 35 deletions(-) diff --git a/core/embed/rust/src/ui/model_tr/component/flow_pages.rs b/core/embed/rust/src/ui/model_tr/component/flow_pages.rs index 18adb93c57..e8a4a22ce4 100644 --- a/core/embed/rust/src/ui/model_tr/component/flow_pages.rs +++ b/core/embed/rust/src/ui/model_tr/component/flow_pages.rs @@ -102,14 +102,19 @@ impl Page { pub fn btn_layout(&self) -> ButtonLayout<&'static str> { // When we are in pagination inside this flow, - // show the up and down arrows on appropriate sides + // show the up and down arrows on appropriate sides. let current = self.btn_layout.clone(); - let btn_left = if self.has_prev_page() { + // On the last page showing only the narrow arrow, so the right + // button with possibly long text has enough space. + let btn_left = if self.has_prev_page() && !self.has_next_page() { + Some(ButtonDetails::up_arrow_icon()) + } else if self.has_prev_page() { Some(ButtonDetails::up_arrow_icon_wide()) } else { current.btn_left }; + let btn_right = if self.has_next_page() { Some(ButtonDetails::down_arrow_icon_wide()) } else { diff --git a/core/embed/rust/src/ui/model_tr/layout.rs b/core/embed/rust/src/ui/model_tr/layout.rs index 5a87cd3327..fc607837bb 100644 --- a/core/embed/rust/src/ui/model_tr/layout.rs +++ b/core/embed/rust/src/ui/model_tr/layout.rs @@ -16,7 +16,7 @@ use crate::{ time::Duration, ui::{ component::{ - base::{Component, ComponentExt}, + base::Component, paginated::{PageMsg, Paginate}, painter, text::paragraphs::{Paragraph, ParagraphSource, ParagraphVecLong, Paragraphs, VecExt}, @@ -318,7 +318,7 @@ extern "C" fn confirm_output(n_args: usize, args: *const Obj, kwargs: *mut Map) }; let pages = FlowPages::new(get_page, 2); - let obj = LayoutObj::new(Flow::new(pages).with_common_title(title).into_child())?; + let obj = LayoutObj::new(Flow::new(pages).with_common_title(title))?; Ok(obj.into()) }; unsafe { util::try_with_args_and_kwargs(n_args, args, kwargs, block) } @@ -362,7 +362,7 @@ extern "C" fn confirm_total(n_args: usize, args: *const Obj, kwargs: *mut Map) - }; let pages = FlowPages::new(get_page, 1); - let obj = LayoutObj::new(Flow::new(pages).with_common_title(title).into_child())?; + let obj = LayoutObj::new(Flow::new(pages).with_common_title(title))?; Ok(obj.into()) }; unsafe { util::try_with_args_and_kwargs(n_args, args, kwargs, block) } @@ -499,7 +499,7 @@ extern "C" fn tutorial(n_args: usize, args: *const Obj, kwargs: *mut Map) -> Obj let pages = FlowPages::new(get_page, PAGE_COUNT); - let obj = LayoutObj::new(Flow::new(pages).into_child())?; + let obj = LayoutObj::new(Flow::new(pages))?; Ok(obj.into()) }; unsafe { util::try_with_args_and_kwargs(n_args, args, kwargs, block) } @@ -512,7 +512,7 @@ extern "C" fn request_pin(n_args: usize, args: *const Obj, kwargs: *mut Map) -> let _allow_cancel: Option = kwargs.get(Qstr::MP_QSTR_allow_cancel)?.try_into_option()?; - let obj = LayoutObj::new(PinEntry::new(prompt).into_child())?; + let obj = LayoutObj::new(PinEntry::new(prompt))?; Ok(obj.into()) }; unsafe { util::try_with_args_and_kwargs(n_args, args, kwargs, block) } @@ -544,10 +544,7 @@ extern "C" fn select_word(n_args: usize, args: *const Obj, kwargs: *mut Map) -> let words: Vec = iter_into_vec(words_iterable)?; // TODO: should return int, to be consistent with TT's select_word - let obj = LayoutObj::new(Frame::new( - title, - SimpleChoice::new(words, true, true).into_child(), - ))?; + let obj = LayoutObj::new(Frame::new(title, SimpleChoice::new(words, true, true)))?; Ok(obj.into()) }; unsafe { util::try_with_args_and_kwargs(n_args, args, kwargs, block) } @@ -559,10 +556,7 @@ extern "C" fn request_word_count(n_args: usize, args: *const Obj, kwargs: *mut M let choices: Vec<&str, 3> = ["12", "18", "24"].into_iter().collect(); - let obj = LayoutObj::new(Frame::new( - title, - SimpleChoice::new(choices, false, false).into_child(), - ))?; + let obj = LayoutObj::new(Frame::new(title, SimpleChoice::new(choices, false, false)))?; Ok(obj.into()) }; unsafe { util::try_with_args_and_kwargs(n_args, args, kwargs, block) } @@ -572,7 +566,7 @@ extern "C" fn request_word_bip39(n_args: usize, args: *const Obj, kwargs: *mut M let block = |_args: &[Obj], kwargs: &Map| { let prompt: StrBuffer = kwargs.get(Qstr::MP_QSTR_prompt)?.try_into()?; - let obj = LayoutObj::new(Frame::new(prompt, Bip39Entry::new().into_child()))?; + let obj = LayoutObj::new(Frame::new(prompt, Bip39Entry::new()))?; Ok(obj.into()) }; unsafe { util::try_with_args_and_kwargs(n_args, args, kwargs, block) } @@ -583,7 +577,7 @@ extern "C" fn request_passphrase(n_args: usize, args: *const Obj, kwargs: *mut M let prompt: StrBuffer = kwargs.get(Qstr::MP_QSTR_prompt)?.try_into()?; let _max_len: u8 = kwargs.get(Qstr::MP_QSTR_max_len)?.try_into()?; - let obj = LayoutObj::new(Frame::new(prompt, PassphraseEntry::new().into_child()))?; + let obj = LayoutObj::new(Frame::new(prompt, PassphraseEntry::new()))?; Ok(obj.into()) }; unsafe { util::try_with_args_and_kwargs(n_args, args, kwargs, block) } diff --git a/core/src/apps/bitcoin/sign_tx/layout.py b/core/src/apps/bitcoin/sign_tx/layout.py index a1d0bb602c..aad81fa0c7 100644 --- a/core/src/apps/bitcoin/sign_tx/layout.py +++ b/core/src/apps/bitcoin/sign_tx/layout.py @@ -6,6 +6,8 @@ from trezor.strings import format_amount from trezor.ui import layouts from trezor.ui.layouts import confirm_metadata +from apps.management import text_r + from .. import addresses from ..common import format_fee_rate @@ -261,15 +263,15 @@ async def confirm_nondefault_locktime( if lock_time_disabled: title = "Warning" - text = "Locktime is set but will\nhave no effect.\n" + text = text_r("Locktime is set but will\nhave no effect.\n") param: str | None = None elif lock_time < _LOCKTIME_TIMESTAMP_MIN_VALUE: title = "Confirm locktime" - text = "Locktime for this\ntransaction is set to\nblockheight:\n{}" + text = text_r("Locktime for this\ntransaction is set to\nblockheight:\n{}") param = str(lock_time) else: title = "Confirm locktime" - text = "Locktime for this\ntransaction is set to:\n{}" + text = text_r("Locktime for this\ntransaction is set to:\n{}") param = format_timestamp(lock_time) await confirm_metadata( diff --git a/core/src/apps/common/passphrase.py b/core/src/apps/common/passphrase.py index cd56c5577e..7ffc1fcf2a 100644 --- a/core/src/apps/common/passphrase.py +++ b/core/src/apps/common/passphrase.py @@ -4,10 +4,11 @@ from typing import TYPE_CHECKING import storage.device as storage_device from trezor.wire import DataError +from apps.management import text_r + if TYPE_CHECKING: from trezor.wire import Context -from apps.management import text_r _MAX_PASSPHRASE_LEN = const(50) diff --git a/core/src/apps/common/request_pin.py b/core/src/apps/common/request_pin.py index fc0f5df103..f2ef2a1d3e 100644 --- a/core/src/apps/common/request_pin.py +++ b/core/src/apps/common/request_pin.py @@ -4,9 +4,10 @@ from typing import TYPE_CHECKING import storage.cache as storage_cache from trezor import config, wire -from .sdcard import request_sd_salt from apps.management import text_r +from .sdcard import request_sd_salt + if TYPE_CHECKING: from typing import Any, NoReturn from trezor.wire import Context, GenericContext diff --git a/core/src/apps/ethereum/layout.py b/core/src/apps/ethereum/layout.py index 72513517f9..fdc3937580 100644 --- a/core/src/apps/ethereum/layout.py +++ b/core/src/apps/ethereum/layout.py @@ -11,6 +11,7 @@ from trezor.ui.layouts import ( should_show_more, ) +from ..management import text_r from . import networks from .helpers import decode_typed_data diff --git a/core/src/apps/management/get_next_u2f_counter.py b/core/src/apps/management/get_next_u2f_counter.py index 48d73216ac..e9bee31039 100644 --- a/core/src/apps/management/get_next_u2f_counter.py +++ b/core/src/apps/management/get_next_u2f_counter.py @@ -1,11 +1,11 @@ from typing import TYPE_CHECKING +from . import text_r + if TYPE_CHECKING: from trezor.messages import GetNextU2FCounter, NextU2FCounter from trezor.wire import Context -from . import text_r - async def get_next_u2f_counter(ctx: Context, msg: GetNextU2FCounter) -> NextU2FCounter: import storage.device as storage_device diff --git a/core/src/apps/management/recovery_device/layout.py b/core/src/apps/management/recovery_device/layout.py index c6cbd0bfd4..9d5366bed6 100644 --- a/core/src/apps/management/recovery_device/layout.py +++ b/core/src/apps/management/recovery_device/layout.py @@ -1,7 +1,7 @@ from typing import TYPE_CHECKING from trezor.enums import ButtonRequestType -from trezor.ui.layouts import show_warning, confirm_action +from trezor.ui.layouts import confirm_action, show_warning from trezor.ui.layouts.recovery import ( # noqa: F401 request_word_count, show_group_share_success, diff --git a/core/src/apps/management/reset_device/__init__.py b/core/src/apps/management/reset_device/__init__.py index b4f57b06c5..1ab8b632a1 100644 --- a/core/src/apps/management/reset_device/__init__.py +++ b/core/src/apps/management/reset_device/__init__.py @@ -6,8 +6,8 @@ from trezor.crypto import slip39 from trezor.enums import BackupType from trezor.wire import ProcessError -from . import layout from .. import text_r +from . import layout if __debug__: import storage.debug diff --git a/core/src/apps/management/set_u2f_counter.py b/core/src/apps/management/set_u2f_counter.py index b45a8c8608..f263184926 100644 --- a/core/src/apps/management/set_u2f_counter.py +++ b/core/src/apps/management/set_u2f_counter.py @@ -1,11 +1,11 @@ from typing import TYPE_CHECKING +from . import text_r + if TYPE_CHECKING: from trezor.messages import SetU2FCounter, Success from trezor.wire import Context -from . import text_r - async def set_u2f_counter(ctx: Context, msg: SetU2FCounter) -> Success: import storage.device as storage_device diff --git a/core/src/storage/sd_salt.py b/core/src/storage/sd_salt.py index d1e350ef03..482096b616 100644 --- a/core/src/storage/sd_salt.py +++ b/core/src/storage/sd_salt.py @@ -10,8 +10,9 @@ if TYPE_CHECKING: T = TypeVar("T", bound=Callable) - -fatfs = io.fatfs # global_import_cache +# TODO: solve this for model R, which does not have a filesystem +if hasattr(io, "fatfs"): + fatfs = io.fatfs # global_import_cache SD_CARD_HOT_SWAPPABLE = False SD_SALT_LEN_BYTES = const(32) diff --git a/core/src/trezor/ui/layouts/tr/__init__.py b/core/src/trezor/ui/layouts/tr/__init__.py index ad686464d7..435bc4ea32 100644 --- a/core/src/trezor/ui/layouts/tr/__init__.py +++ b/core/src/trezor/ui/layouts/tr/__init__.py @@ -1134,7 +1134,7 @@ async def confirm_coinjoin( ctx=ctx, br_type="coinjoin_final", title="AUTHORIZE COINJOIN", - data=f"Maximum rounds: {max_rounds}\n\nMaximum mining fee:\n{max_fee_per_vbyte} sats/vbyte", + data=f"Maximum rounds: {max_rounds}\n\nMaximum mining fee:\n{max_fee_per_vbyte}", description="", br_code=ButtonRequestType.Other, ) diff --git a/core/src/trezor/ui/layouts/tt_v2/__init__.py b/core/src/trezor/ui/layouts/tt_v2/__init__.py index a9e5605753..354ddcabe0 100644 --- a/core/src/trezor/ui/layouts/tt_v2/__init__.py +++ b/core/src/trezor/ui/layouts/tt_v2/__init__.py @@ -1119,7 +1119,7 @@ async def request_pin_on_device( async def confirm_pin_action( - ctx: wire.GenericContext, + ctx: GenericContext, br_type: str, title: str, action: str | None, @@ -1138,7 +1138,7 @@ async def confirm_pin_action( async def confirm_reenter_pin( - ctx: wire.GenericContext, + ctx: GenericContext, br_type: str = "set_pin", br_code: ButtonRequestType = ButtonRequestType.Other, ) -> None: @@ -1153,7 +1153,7 @@ async def confirm_reenter_pin( async def pin_mismatch( - ctx: wire.GenericContext, + ctx: GenericContext, br_type: str = "set_pin", br_code: ButtonRequestType = ButtonRequestType.Other, ) -> None: @@ -1169,7 +1169,7 @@ async def pin_mismatch( async def confirm_set_new_pin( - ctx: wire.GenericContext, + ctx: GenericContext, br_type: str, title: str, action: str,