Skip to content

Commit

Permalink
fix(core/ui): T3T1 ButtonRequests from rust
Browse files Browse the repository at this point in the history
[no changelog]
  • Loading branch information
mmilata committed May 20, 2024
1 parent e8cf782 commit 4d7a816
Show file tree
Hide file tree
Showing 10 changed files with 163 additions and 91 deletions.
2 changes: 2 additions & 0 deletions core/embed/rust/librust_qstr.h
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,8 @@ static void _librust_qstrs(void) {
MP_QSTR_bitcoin__voting_rights;
MP_QSTR_bootscreen;
MP_QSTR_bounds;
MP_QSTR_br_code;
MP_QSTR_br_type;
MP_QSTR_button;
MP_QSTR_button_event;
MP_QSTR_button_request;
Expand Down
18 changes: 18 additions & 0 deletions core/embed/rust/src/ui/component/button_request.rs
Original file line number Diff line number Diff line change
Expand Up @@ -63,3 +63,21 @@ pub trait ButtonRequestExt {
}

impl<T: Component> ButtonRequestExt for T {}

#[cfg(all(feature = "micropython", feature = "touch"))]
impl<T> crate::ui::flow::Swipable for OneButtonRequest<T>
where
T: Component + crate::ui::flow::Swipable,
{
fn swipe_start(
&mut self,
ctx: &mut EventCtx,
direction: crate::ui::component::SwipeDirection,
) -> bool {
self.inner.swipe_start(ctx, direction)
}

fn swipe_finished(&self) -> bool {
self.inner.swipe_finished()
}
}
13 changes: 8 additions & 5 deletions core/embed/rust/src/ui/model_mercury/flow/confirm_output.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@ use crate::{
strutil::TString,
translations::TR,
ui::{
component::{ComponentExt, SwipeDirection},
button_request::ButtonRequest,
component::{ButtonRequestExt, ComponentExt, SwipeDirection},
flow::{base::Decision, flow_store, FlowMsg, FlowState, FlowStore, SwipeFlow, SwipePage},
},
};
Expand Down Expand Up @@ -91,6 +92,8 @@ 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_code: u16 = kwargs.get(Qstr::MP_QSTR_br_code)?.try_into()?;

let address: Obj = kwargs.get(Qstr::MP_QSTR_address)?;
let amount: Obj = kwargs.get(Qstr::MP_QSTR_amount)?;
Expand All @@ -105,17 +108,17 @@ impl ConfirmOutput {
.with_footer(TR::instructions__swipe_up.into(), None)
.with_chunkify(chunkify)
.with_text_mono(text_mono)
.into_layout()?;
// .one_button_request(ButtonRequestCode::ConfirmOutput, br_type);
.into_layout()?
.one_button_request(ButtonRequest::from_tstring(br_code, br_type));

// Amount
let content_amount = ConfirmBlobParams::new(TR::words__amount.into(), amount, None)
.with_subtitle(title)
.with_menu_button()
.with_footer(TR::instructions__swipe_up.into(), None)
.with_text_mono(text_mono)
.into_layout()?;
// .one_button_request(ButtonRequestCode::ConfirmOutput, br_type);
.into_layout()?
.one_button_request(ButtonRequest::from_tstring(br_code, br_type));

// Menu
let content_menu = Frame::left_aligned(
Expand Down
9 changes: 7 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 @@ -4,7 +4,8 @@ use crate::{
strutil::TString,
translations::TR,
ui::{
component::{ComponentExt, SwipeDirection},
button_request::ButtonRequest,
component::{ButtonRequestExt, ComponentExt, SwipeDirection},
flow::{base::Decision, flow_store, FlowMsg, FlowState, FlowStore, SwipeFlow},
},
};
Expand Down Expand Up @@ -91,6 +92,8 @@ 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_code: u16 = kwargs.get(Qstr::MP_QSTR_br_code)?.try_into()?;

// Summary
let mut summary = ShowInfoParams::new(title)
Expand All @@ -100,7 +103,9 @@ impl ConfirmSummary {
let [label, value]: [TString; 2] = util::iter_into_array(pair)?;
summary = unwrap!(summary.add(label, value));
}
let content_summary = summary.into_layout()?;
let content_summary = summary
.into_layout()?
.one_button_request(ButtonRequest::from_tstring(br_code, br_type));

// Hold to confirm
let content_hold = Frame::left_aligned(
Expand Down
10 changes: 7 additions & 3 deletions core/embed/rust/src/ui/model_mercury/flow/get_address.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,10 @@ use crate::{
strutil::TString,
translations::TR,
ui::{
button_request::ButtonRequest,
component::{
text::paragraphs::{Paragraph, ParagraphSource, Paragraphs},
ComponentExt, Qr, SwipeDirection,
ButtonRequestExt, ComponentExt, Qr, SwipeDirection,
},
flow::{
base::Decision, flow_store, FlowMsg, FlowState, FlowStore, IgnoreSwipe, SwipeFlow,
Expand Down Expand Up @@ -147,6 +148,9 @@ 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_code: u16 = kwargs.get(Qstr::MP_QSTR_br_code)?.try_into()?;

// Address
let data_style = if chunkify {
let address: TString = address.try_into()?;
Expand All @@ -166,8 +170,8 @@ impl GetAddress {
let content_address = Frame::left_aligned(title, SwipePage::vertical(paragraphs))
.with_menu_button()
.with_footer(TR::instructions__swipe_up.into(), None)
.map(|msg| matches!(msg, FrameMsg::Button(_)).then_some(FlowMsg::Info));
// .one_button_request(ButtonRequestCode::Address, "show_address");
.map(|msg| matches!(msg, FrameMsg::Button(_)).then_some(FlowMsg::Info))
.one_button_request(ButtonRequest::from_tstring(br_code, br_type));

// Tap
let content_tap = Frame::left_aligned(title, PromptScreen::new_tap_to_confirm())
Expand Down
6 changes: 6 additions & 0 deletions core/embed/rust/src/ui/model_mercury/layout.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1980,6 +1980,8 @@ pub static mp_module_trezorui2: Module = obj_module! {
/// account: str | None,
/// path: str | None,
/// xpubs: list[tuple[str, str]],
/// br_code: ButtonRequestType,
/// br_type: 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 @@ -2001,6 +2003,8 @@ pub static mp_module_trezorui2: Module = obj_module! {
/// chunkify: bool,
/// account: str | None,
/// account_path: str | None,
/// br_code: ButtonRequestType,
/// br_type: str,
/// ) -> LayoutObj[UiResult]:
/// """Confirm recipient."""
Qstr::MP_QSTR_flow_confirm_output => obj_fn_kw!(0, flow::new_confirm_output).as_obj(),
Expand All @@ -2011,6 +2015,8 @@ pub static mp_module_trezorui2: Module = obj_module! {
/// items: Iterable[tuple[str, str]],
/// account_items: Iterable[tuple[str, str]],
/// fee_items: Iterable[tuple[str, str]],
/// br_code: ButtonRequestType,
/// br_type: 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
6 changes: 6 additions & 0 deletions core/mocks/generated/trezorui2.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -537,6 +537,8 @@ def flow_get_address(
account: str | None,
path: str | None,
xpubs: list[tuple[str, str]],
br_code: ButtonRequestType,
br_type: str,
) -> LayoutObj[UiResult]:
"""Get address / receive funds."""

Expand All @@ -560,6 +562,8 @@ def flow_confirm_output(
chunkify: bool,
account: str | None,
account_path: str | None,
br_code: ButtonRequestType,
br_type: str,
) -> LayoutObj[UiResult]:
"""Confirm recipient."""

Expand All @@ -571,6 +575,8 @@ def flow_confirm_summary(
items: Iterable[tuple[str, str]],
account_items: Iterable[tuple[str, str]],
fee_items: Iterable[tuple[str, str]],
br_code: ButtonRequestType,
br_type: str,
) -> LayoutObj[UiResult]:
"""Total summary and hold to confirm."""
CONFIRMED: UiResult
Expand Down
Loading

0 comments on commit 4d7a816

Please sign in to comment.