Skip to content
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

T3T1 UI: SignTx flow #3822

Merged
merged 5 commits into from
May 20, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 15 additions & 1 deletion core/embed/rust/librust_qstr.h
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,9 @@ static void _librust_qstrs(void) {
MP_QSTR___dict__;
MP_QSTR___name__;
MP_QSTR_account;
MP_QSTR_account_items;
MP_QSTR_account_label;
MP_QSTR_account_path;
MP_QSTR_accounts;
MP_QSTR_action;
MP_QSTR_active;
Expand Down Expand Up @@ -99,8 +101,11 @@ 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;
MP_QSTR_buttons__abort;
MP_QSTR_buttons__access;
MP_QSTR_buttons__again;
Expand Down Expand Up @@ -174,6 +179,7 @@ static void _librust_qstrs(void) {
MP_QSTR_confirm_reset_device;
MP_QSTR_confirm_total;
MP_QSTR_confirm_total__fee_rate;
MP_QSTR_confirm_total__fee_rate_colon;
MP_QSTR_confirm_total__sending_from_account;
MP_QSTR_confirm_total__title_fee;
MP_QSTR_confirm_total__title_sending_from;
Expand Down Expand Up @@ -204,16 +210,19 @@ static void _librust_qstrs(void) {
MP_QSTR_experimental_mode__title;
MP_QSTR_extra;
MP_QSTR_fee_amount;
MP_QSTR_fee_items;
MP_QSTR_fee_label;
MP_QSTR_fee_rate_amount;
MP_QSTR_fee_title;
MP_QSTR_fee_value;
MP_QSTR_fingerprint;
MP_QSTR_firmware_update__title;
MP_QSTR_firmware_update__title_fingerprint;
MP_QSTR_flow_confirm_output;
MP_QSTR_flow_confirm_reset_create;
MP_QSTR_flow_confirm_reset_recover;
MP_QSTR_flow_confirm_set_new_pin;
MP_QSTR_flow_confirm_summary;
MP_QSTR_flow_get_address;
MP_QSTR_flow_prompt_backup;
MP_QSTR_flow_show_share_words;
Expand Down Expand Up @@ -247,6 +256,7 @@ static void _librust_qstrs(void) {
MP_QSTR_inputs__space;
MP_QSTR_instructions__continue_in_app;
MP_QSTR_instructions__hold_to_confirm;
MP_QSTR_instructions__hold_to_sign;
MP_QSTR_instructions__swipe_up;
MP_QSTR_instructions__tap_to_confirm;
MP_QSTR_is_type_of;
Expand Down Expand Up @@ -520,11 +530,15 @@ static void _librust_qstrs(void) {
MP_QSTR_select_word;
MP_QSTR_select_word_count;
MP_QSTR_send__address_path;
MP_QSTR_send__cancel_sign;
MP_QSTR_send__confirm_sending;
MP_QSTR_send__from_multiple_accounts;
MP_QSTR_send__incl_transaction_fee;
MP_QSTR_send__including_fee;
MP_QSTR_send__maximum_fee;
MP_QSTR_send__receiving_to_multisig;
MP_QSTR_send__send_from;
MP_QSTR_send__sign_transaction;
MP_QSTR_send__title_confirm_sending;
MP_QSTR_send__title_joint_transaction;
MP_QSTR_send__title_receiving_to;
Expand All @@ -533,6 +547,7 @@ static void _librust_qstrs(void) {
MP_QSTR_send__title_sending_to;
MP_QSTR_send__to_the_total_amount;
MP_QSTR_send__total_amount;
MP_QSTR_send__total_amount_colon;
MP_QSTR_send__transaction_id;
MP_QSTR_send__you_are_contributing;
MP_QSTR_share_words;
Expand Down Expand Up @@ -826,7 +841,6 @@ static void _librust_qstrs(void) {
MP_QSTR_eos__requirement;
MP_QSTR_eos__sell_ram;
MP_QSTR_eos__sender;
MP_QSTR_eos__sign_transaction;
MP_QSTR_eos__threshold;
MP_QSTR_eos__to;
MP_QSTR_eos__transfer;
Expand Down
43 changes: 29 additions & 14 deletions core/embed/rust/src/translations/generated/translated_string.rs

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

60 changes: 60 additions & 0 deletions core/embed/rust/src/ui/button_request.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
use crate::strutil::TString;
use num_traits::FromPrimitive;

// ButtonRequestType from messages-common.proto
// Eventually this should be generated
#[derive(Clone, Copy, FromPrimitive)]
#[repr(u16)]
pub enum ButtonRequestCode {
Other = 1,
FeeOverThreshold = 2,
ConfirmOutput = 3,
ResetDevice = 4,
ConfirmWord = 5,
WipeDevice = 6,
ProtectCall = 7,
SignTx = 8,
FirmwareCheck = 9,
Address = 10,
PublicKey = 11,
MnemonicWordCount = 12,
MnemonicInput = 13,
UnknownDerivationPath = 15,
RecoveryHomepage = 16,
Success = 17,
Warning = 18,
PassphraseEntry = 19,
PinEntry = 20,
}

impl ButtonRequestCode {
pub fn num(&self) -> u16 {
*self as u16
}

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

pub fn from(i: u16) -> Self {
unwrap!(Self::from_u16(i))
}
}

const MAX_TYPE_LEN: usize = 32;

#[derive(Clone)]
pub struct ButtonRequest {
pub code: ButtonRequestCode,
pub br_type: TString<'static>,
}

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

pub fn from_tstring(code: u16, br_type: TString<'static>) -> Self {
ButtonRequest::new(ButtonRequestCode::from(code), br_type)
}
}
16 changes: 16 additions & 0 deletions core/embed/rust/src/ui/component/base.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ use crate::{
strutil::TString,
time::Duration,
ui::{
button_request::{ButtonRequest, ButtonRequestCode},
component::{maybe::PaintOverlapping, MsgMap},
display::{self, Color},
geometry::{Offset, Rect},
Expand Down Expand Up @@ -487,6 +488,7 @@ pub struct EventCtx {
paint_requested: bool,
anim_frame_scheduled: bool,
page_count: Option<usize>,
button_request: Option<ButtonRequest>,
root_repaint_requested: bool,
}

Expand All @@ -513,6 +515,7 @@ impl EventCtx {
* `Child::marked_for_paint` being true. */
anim_frame_scheduled: false,
page_count: None,
button_request: None,
root_repaint_requested: false,
}
}
Expand Down Expand Up @@ -570,6 +573,16 @@ impl EventCtx {
self.page_count
}

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

pub fn button_request(&mut self) -> Option<ButtonRequest> {
self.button_request.take()
}

pub fn pop_timer(&mut self) -> Option<(TimerToken, Duration)> {
self.timers.pop()
}
Expand All @@ -579,6 +592,9 @@ impl EventCtx {
self.paint_requested = false;
self.anim_frame_scheduled = false;
self.page_count = None;
#[cfg(feature = "ui_debug")]
assert!(self.button_request.is_none());
self.button_request = None;
self.root_repaint_requested = false;
}

Expand Down
Loading
Loading