Skip to content

Commit

Permalink
refactor(core): send out ButtonRequest name
Browse files Browse the repository at this point in the history
  • Loading branch information
ibz committed Jul 4, 2024
1 parent e30a0e6 commit ea74f62
Show file tree
Hide file tree
Showing 40 changed files with 429 additions and 356 deletions.
7 changes: 6 additions & 1 deletion common/protob/messages-common.proto
Original file line number Diff line number Diff line change
Expand Up @@ -49,8 +49,13 @@ message Failure {
* @next ButtonAck
*/
message ButtonRequest {
optional ButtonRequestType code = 1; // enum identifier of the screen
optional ButtonRequestType code = 1; // enum identifier of the screen (deprecated)
optional uint32 pages = 2; // if the screen is paginated, number of pages

// NB: we skip 3 because it existed briefly: https://github.com/trezor/trezor-firmware/commit/1012ee8497b241e8ca559e386d936fa549bc0357

optional string name = 4; // name of the screen

/**
* Type of button request
*/
Expand Down
2 changes: 1 addition & 1 deletion core/embed/rust/librust_qstr.h
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ static void _librust_qstrs(void) {
MP_QSTR_bootscreen;
MP_QSTR_bounds;
MP_QSTR_br_code;
MP_QSTR_br_type;
MP_QSTR_br_name;
MP_QSTR_brightness__title;
MP_QSTR_button;
MP_QSTR_button_event;
Expand Down
14 changes: 7 additions & 7 deletions core/embed/rust/src/ui/button_request.rs
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,8 @@ impl ButtonRequestCode {
*self as u16
}

pub fn with_type(self, br_type: &'static str) -> ButtonRequest {
ButtonRequest::new(self, br_type.into())
pub fn with_name(self, br_name: &'static str) -> ButtonRequest {
ButtonRequest::new(self, br_name.into())
}

pub fn from(i: u16) -> Self {
Expand All @@ -44,15 +44,15 @@ impl ButtonRequestCode {
#[derive(Clone)]
pub struct ButtonRequest {
pub code: ButtonRequestCode,
pub br_type: TString<'static>,
pub br_name: TString<'static>,
}

impl ButtonRequest {
pub fn new(code: ButtonRequestCode, br_type: TString<'static>) -> Self {
ButtonRequest { code, br_type }
pub fn new(code: ButtonRequestCode, br_name: TString<'static>) -> Self {
ButtonRequest { code, br_name }
}

pub fn from_num(code: u16, br_type: TString<'static>) -> Self {
ButtonRequest::new(ButtonRequestCode::from(code), br_type)
pub fn from_num(code: u16, br_name: TString<'static>) -> Self {
ButtonRequest::new(ButtonRequestCode::from(code), br_name)
}
}
4 changes: 2 additions & 2 deletions core/embed/rust/src/ui/component/base.rs
Original file line number Diff line number Diff line change
Expand Up @@ -630,10 +630,10 @@ impl EventCtx {
self.page_count
}

pub fn send_button_request(&mut self, code: ButtonRequestCode, br_type: TString<'static>) {
pub fn send_button_request(&mut self, code: ButtonRequestCode, br_name: TString<'static>) {
#[cfg(feature = "ui_debug")]
assert!(self.button_request.is_none());
self.button_request = Some(ButtonRequest::new(code, br_type));
self.button_request = Some(ButtonRequest::new(code, br_name));
}

pub fn button_request(&mut self) -> Option<ButtonRequest> {
Expand Down
2 changes: 1 addition & 1 deletion core/embed/rust/src/ui/component/button_request.rs
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ impl<T: Component> Component for OneButtonRequest<T> {
fn event(&mut self, ctx: &mut EventCtx, event: Event) -> Option<Self::Msg> {
if matches!(event, Event::Attach(_)) {
if let Some(button_request) = self.button_request.take() {
ctx.send_button_request(button_request.code, button_request.br_type)
ctx.send_button_request(button_request.code, button_request.br_name)
}
}
self.inner.event(ctx, event)
Expand Down
4 changes: 2 additions & 2 deletions core/embed/rust/src/ui/layout/obj.rs
Original file line number Diff line number Diff line change
Expand Up @@ -306,8 +306,8 @@ impl LayoutObj {

match inner.event_ctx.button_request() {
None => Ok(Obj::const_none()),
Some(ButtonRequest { code, br_type }) => {
(code.num().into(), br_type.try_into()?).try_into()
Some(ButtonRequest { code, br_name }) => {
(code.num().into(), br_name.try_into()?).try_into()
}
}
}
Expand Down
6 changes: 3 additions & 3 deletions core/embed/rust/src/ui/model_mercury/flow/confirm_output.rs
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ impl ConfirmOutput {
let account: Option<TString> = kwargs.get(Qstr::MP_QSTR_account)?.try_into_option()?;
let account_path: Option<TString> =
kwargs.get(Qstr::MP_QSTR_account_path)?.try_into_option()?;
let br_type: TString = kwargs.get(Qstr::MP_QSTR_br_type)?.try_into()?;
let br_name: TString = kwargs.get(Qstr::MP_QSTR_br_name)?.try_into()?;
let br_code: u16 = kwargs.get(Qstr::MP_QSTR_br_code)?.try_into()?;

let address: Obj = kwargs.get(Qstr::MP_QSTR_address)?;
Expand All @@ -112,7 +112,7 @@ impl ConfirmOutput {
.with_chunkify(chunkify)
.with_text_mono(text_mono)
.into_layout()?
.one_button_request(ButtonRequest::from_num(br_code, br_type));
.one_button_request(ButtonRequest::from_num(br_code, br_name));

// Amount
let content_amount = ConfirmBlobParams::new(TR::words__amount.into(), amount, None)
Expand All @@ -122,7 +122,7 @@ impl ConfirmOutput {
.with_text_mono(text_mono)
.with_swipe_down()
.into_layout()?
.one_button_request(ButtonRequest::from_num(br_code, br_type));
.one_button_request(ButtonRequest::from_num(br_code, br_name));

// Menu
let content_menu = Frame::left_aligned(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ impl ConfirmResetCreate {
.with_swipe(SwipeDirection::Up, SwipeSettings::default())
.with_swipe(SwipeDirection::Left, SwipeSettings::default())
.map(|msg| matches!(msg, FrameMsg::Button(_)).then_some(FlowMsg::Info))
.one_button_request(ButtonRequestCode::ResetDevice.with_type("setup_device"));
.one_button_request(ButtonRequestCode::ResetDevice.with_name("setup_device"));

// FIXME: TR::reset__cancel_create_wallet should be used but Button text on
// multiple lines not supported yet
Expand All @@ -122,7 +122,7 @@ impl ConfirmResetCreate {
FrameMsg::Content(()) => Some(FlowMsg::Confirmed),
FrameMsg::Button(_) => Some(FlowMsg::Info),
})
.one_button_request(ButtonRequestCode::ResetDevice.with_type("confirm_setup_device"));
.one_button_request(ButtonRequestCode::ResetDevice.with_name("confirm_setup_device"));

let store = flow_store()
.add(content_intro)?
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ impl ConfirmResetRecover {
.with_swipe(SwipeDirection::Up, SwipeSettings::default())
.with_swipe(SwipeDirection::Left, SwipeSettings::default())
.map(|msg| matches!(msg, FrameMsg::Button(_)).then_some(FlowMsg::Info))
.one_button_request(ButtonRequestCode::ProtectCall.with_type("recover_device"));
.one_button_request(ButtonRequestCode::ProtectCall.with_name("recover_device"));

let content_menu = Frame::left_aligned(
"".into(),
Expand Down
4 changes: 2 additions & 2 deletions core/embed/rust/src/ui/model_mercury/flow/confirm_summary.rs
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ impl ConfirmSummary {
let items: Obj = kwargs.get(Qstr::MP_QSTR_items)?;
let account_items: Obj = kwargs.get(Qstr::MP_QSTR_account_items)?;
let fee_items: Obj = kwargs.get(Qstr::MP_QSTR_fee_items)?;
let br_type: TString = kwargs.get(Qstr::MP_QSTR_br_type)?.try_into()?;
let br_name: TString = kwargs.get(Qstr::MP_QSTR_br_name)?.try_into()?;
let br_code: u16 = kwargs.get(Qstr::MP_QSTR_br_code)?.try_into()?;

// Summary
Expand All @@ -109,7 +109,7 @@ impl ConfirmSummary {
}
let content_summary = summary
.into_layout()?
.one_button_request(ButtonRequest::from_num(br_code, br_type))
.one_button_request(ButtonRequest::from_num(br_code, br_name))
// Summary(1) + Hold(1)
.with_pages(|summary_pages| summary_pages + 1);

Expand Down
4 changes: 2 additions & 2 deletions core/embed/rust/src/ui/model_mercury/flow/get_address.rs
Original file line number Diff line number Diff line change
Expand Up @@ -156,7 +156,7 @@ impl GetAddress {
let path: Option<TString> = kwargs.get(Qstr::MP_QSTR_path)?.try_into_option()?;
let xpubs: Obj = kwargs.get(Qstr::MP_QSTR_xpubs)?;

let br_type: TString = kwargs.get(Qstr::MP_QSTR_br_type)?.try_into()?;
let br_name: TString = kwargs.get(Qstr::MP_QSTR_br_name)?.try_into()?;
let br_code: u16 = kwargs.get(Qstr::MP_QSTR_br_code)?.try_into()?;

// Address
Expand All @@ -183,7 +183,7 @@ impl GetAddress {
.with_swipe(SwipeDirection::Left, SwipeSettings::default())
.with_vertical_pages()
.map(|msg| matches!(msg, FrameMsg::Button(_)).then_some(FlowMsg::Info))
.one_button_request(ButtonRequest::from_num(br_code, br_type))
.one_button_request(ButtonRequest::from_num(br_code, br_name))
// Count tap-to-confirm screen towards page count
.with_pages(|address_pages| address_pages + 1);

Expand Down
4 changes: 2 additions & 2 deletions core/embed/rust/src/ui/model_mercury/flow/request_number.rs
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ impl RequestNumber {
let info: Obj = kwargs.get(Qstr::MP_QSTR_info)?;
assert!(description != Obj::const_none());
assert!(info != Obj::const_none());
let br_type: TString = kwargs.get(Qstr::MP_QSTR_br_type)?.try_into()?;
let br_name: TString = kwargs.get(Qstr::MP_QSTR_br_name)?.try_into()?;
let br_code: u16 = kwargs.get(Qstr::MP_QSTR_br_code)?.try_into()?;

let description_cb = move |i: u32| {
Expand All @@ -114,7 +114,7 @@ impl RequestNumber {
FrameMsg::Button(_) => Some(FlowMsg::Info),
FrameMsg::Content(NumberInputDialogMsg(n)) => Some(FlowMsg::Choice(n as usize)),
})
.one_button_request(ButtonRequest::from_num(br_code, br_type));
.one_button_request(ButtonRequest::from_num(br_code, br_name));

let content_menu = Frame::left_aligned(
"".into(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ impl ShowShareWords {
.with_footer(TR::instructions__swipe_up.into(), description)
.with_swipe(SwipeDirection::Up, SwipeSettings::default())
.map(|msg| matches!(msg, FrameMsg::Content(_)).then_some(FlowMsg::Confirmed))
.one_button_request(ButtonRequestCode::ResetDevice.with_type("share_words"))
.one_button_request(ButtonRequestCode::ResetDevice.with_name("share_words"))
.with_pages(move |_| nwords + 2);

let content_words =
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ impl WarningHiPrio {
.with_swipe(SwipeDirection::Up, SwipeSettings::default())
.with_swipe(SwipeDirection::Left, SwipeSettings::default())
.map(|msg| matches!(msg, FrameMsg::Button(_)).then_some(FlowMsg::Info));
// .one_button_request(ButtonRequestCode::Warning, br_type);
// .one_button_request(ButtonRequestCode::Warning, br_name);

// Menu
let content_menu = Frame::left_aligned(
Expand Down
8 changes: 4 additions & 4 deletions core/embed/rust/src/ui/model_mercury/layout.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1727,7 +1727,7 @@ pub static mp_module_trezorui2: Module = obj_module! {
/// description: Callable[[int], str] | None = None,
/// info: Callable[[int], str] | None = None,
/// br_code: ButtonRequestType,
/// br_type: str,
/// br_name: str,
/// ) -> LayoutObj[tuple[UiResult, int]]:
/// """Numer input with + and - buttons, description, and context menu with cancel and
/// info."""
Expand Down Expand Up @@ -1855,7 +1855,7 @@ pub static mp_module_trezorui2: Module = obj_module! {
/// path: str | None,
/// xpubs: list[tuple[str, str]],
/// br_code: ButtonRequestType,
/// br_type: str,
/// br_name: str,
/// ) -> LayoutObj[UiResult]:
/// """Get address / receive funds."""
Qstr::MP_QSTR_flow_get_address => obj_fn_kw!(0, flow::get_address::new_get_address).as_obj(),
Expand All @@ -1878,7 +1878,7 @@ pub static mp_module_trezorui2: Module = obj_module! {
/// account: str | None,
/// account_path: str | None,
/// br_code: ButtonRequestType,
/// br_type: str,
/// br_name: str,
/// ) -> LayoutObj[UiResult]:
/// """Confirm recipient."""
Qstr::MP_QSTR_flow_confirm_output => obj_fn_kw!(0, flow::new_confirm_output).as_obj(),
Expand All @@ -1890,7 +1890,7 @@ pub static mp_module_trezorui2: Module = obj_module! {
/// account_items: Iterable[tuple[str, str]],
/// fee_items: Iterable[tuple[str, str]],
/// br_code: ButtonRequestType,
/// br_type: str,
/// br_name: str,
/// ) -> LayoutObj[UiResult]:
/// """Total summary and hold to confirm."""
Qstr::MP_QSTR_flow_confirm_summary => obj_fn_kw!(0, flow::new_confirm_summary).as_obj(),
Expand Down
8 changes: 4 additions & 4 deletions core/mocks/generated/trezorui2.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -428,7 +428,7 @@ def flow_request_number(
description: Callable[[int], str] | None = None,
info: Callable[[int], str] | None = None,
br_code: ButtonRequestType,
br_type: str,
br_name: str,
) -> LayoutObj[tuple[UiResult, int]]:
"""Numer input with + and - buttons, description, and context menu with cancel and
info."""
Expand Down Expand Up @@ -570,7 +570,7 @@ def flow_get_address(
path: str | None,
xpubs: list[tuple[str, str]],
br_code: ButtonRequestType,
br_type: str,
br_name: str,
) -> LayoutObj[UiResult]:
"""Get address / receive funds."""

Expand All @@ -595,7 +595,7 @@ def flow_confirm_output(
account: str | None,
account_path: str | None,
br_code: ButtonRequestType,
br_type: str,
br_name: str,
) -> LayoutObj[UiResult]:
"""Confirm recipient."""

Expand All @@ -608,7 +608,7 @@ def flow_confirm_summary(
account_items: Iterable[tuple[str, str]],
fee_items: Iterable[tuple[str, str]],
br_code: ButtonRequestType,
br_type: str,
br_name: str,
) -> LayoutObj[UiResult]:
"""Total summary and hold to confirm."""

Expand Down
2 changes: 1 addition & 1 deletion core/src/apps/bitcoin/get_public_key.py
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ async def get_public_key(
account=account,
path=path,
mismatch_title=TR.addr_mismatch__xpub_mismatch,
br_type="show_xpub",
br_name="show_xpub",
)

return PublicKey(
Expand Down
4 changes: 2 additions & 2 deletions core/src/apps/cardano/layout.py
Original file line number Diff line number Diff line change
Expand Up @@ -294,7 +294,7 @@ async def confirm_reference_script(


async def _confirm_data_chunk(
br_type: str, title: str, first_chunk: bytes, data_size: int
br_name: str, title: str, first_chunk: bytes, data_size: int
) -> None:
MAX_DISPLAYED_SIZE = 56
displayed_bytes = first_chunk[:MAX_DISPLAYED_SIZE]
Expand All @@ -308,7 +308,7 @@ async def _confirm_data_chunk(
if data_size > MAX_DISPLAYED_SIZE:
props.append(("...", None))
await confirm_properties(
br_type,
br_name,
title=TR.cardano__confirm_transaction,
props=props,
br_code=BRT_Other,
Expand Down
4 changes: 2 additions & 2 deletions core/src/apps/eos/actions/layout.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,12 +36,12 @@
# Because icon and br_code are almost always the same
# (and also calling with positional arguments takes less space)
async def _confirm_properties(
br_type: str,
br_name: str,
title: str,
props: Iterable[PropertyType],
) -> None:
await confirm_properties(
br_type,
br_name,
title,
props,
hold=is_last,
Expand Down
6 changes: 3 additions & 3 deletions core/src/apps/solana/layout.py
Original file line number Diff line number Diff line change
Expand Up @@ -269,7 +269,7 @@ async def confirm_system_transfer(
title=TR.words__recipient,
value=base58.encode(transfer_instruction.recipient_account[0]),
description="",
br_type="confirm_recipient",
br_name="confirm_recipient",
br_code=ButtonRequestType.ConfirmOutput,
verb=TR.buttons__continue,
)
Expand Down Expand Up @@ -298,7 +298,7 @@ async def confirm_token_transfer(
title=TR.words__recipient,
value=base58.encode(destination_account),
description="",
br_type="confirm_recipient",
br_name="confirm_recipient",
br_code=ButtonRequestType.ConfirmOutput,
verb=TR.buttons__continue,
info_items=(
Expand All @@ -312,7 +312,7 @@ async def confirm_token_transfer(
title=TR.solana__token_address,
value=base58.encode(token_mint),
description="",
br_type="confirm_token_address",
br_name="confirm_token_address",
br_code=ButtonRequestType.ConfirmOutput,
verb=TR.buttons__continue,
)
Expand Down
2 changes: 2 additions & 0 deletions core/src/trezor/messages.py

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit ea74f62

Please sign in to comment.