1
0
mirror of https://github.com/trezor/trezor-firmware.git synced 2025-07-04 13:52:35 +00:00

WIP - backup bigger font

This commit is contained in:
grdddj 2022-11-04 13:08:45 +01:00
parent acccee56fc
commit c96ce4e13e
3 changed files with 62 additions and 75 deletions

View File

@ -603,6 +603,15 @@ impl ButtonLayout<&'static str> {
) )
} }
/// Cancel cross on left and right arrow facing down.
pub fn cancel_and_arrow_down() -> Self {
Self::new(
Some(ButtonDetails::cancel_icon()),
None,
Some(ButtonDetails::down_arrow_icon_wide()),
)
}
/// Cancel cross on left and text on the right. /// Cancel cross on left and text on the right.
pub fn cancel_and_text(text: &'static str) -> Self { pub fn cancel_and_text(text: &'static str) -> Self {
Self::new( Self::new(
@ -643,6 +652,15 @@ impl ButtonLayout<&'static str> {
pub fn middle_armed_text(text: &'static str) -> Self { pub fn middle_armed_text(text: &'static str) -> Self {
Self::new(None, Some(ButtonDetails::armed_text(text)), None) Self::new(None, Some(ButtonDetails::armed_text(text)), None)
} }
/// Only hold-to-confirm with text on the right.
pub fn htc_only(text: &'static str, duration: Duration) -> Self {
Self::new(
None,
None,
Some(ButtonDetails::text(text).with_duration(duration)),
)
}
} }
/// What happens when a button is triggered. /// What happens when a button is triggered.
@ -744,6 +762,15 @@ impl ButtonActions {
) )
} }
/// Previous with left, confirming with right
pub fn prev_confirm() -> Self {
Self::new(
Some(ButtonAction::PrevPage),
None,
Some(ButtonAction::Confirm),
)
}
/// Going to last page with left, to the next page with right /// Going to last page with left, to the next page with right
pub fn last_next() -> Self { pub fn last_next() -> Self {
Self::new( Self::new(

View File

@ -1,18 +1,10 @@
use core::convert::TryInto; use core::convert::TryInto;
use heapless::{String, Vec}; use heapless::Vec;
use crate::{ use crate::{
error::Error, error::Error,
micropython::{ micropython::{buffer::StrBuffer, map::Map, module::Module, obj::Obj, qstr::Qstr, util},
buffer::StrBuffer,
iter::{Iter, IterBuf},
map::Map,
module::Module,
obj::Obj,
qstr::Qstr,
util,
},
time::Duration, time::Duration,
ui::{ ui::{
component::{ component::{
@ -158,9 +150,6 @@ extern "C" fn new_confirm_action(n_args: usize, args: *const Obj, kwargs: *mut M
confirm_btn = confirm_btn.map(|btn| btn.with_duration(Duration::from_secs(2))); confirm_btn = confirm_btn.map(|btn| btn.with_duration(Duration::from_secs(2)));
} }
// TODO: make sure the text will not be colliding with the buttons
// - make there some space on the bottom of the text
let obj = LayoutObj::new(Frame::new( let obj = LayoutObj::new(Frame::new(
title, title,
ButtonPage::new_str_buf( ButtonPage::new_str_buf(
@ -474,69 +463,37 @@ extern "C" fn request_pin(n_args: usize, args: *const Obj, kwargs: *mut Map) ->
extern "C" fn show_share_words(n_args: usize, args: *const Obj, kwargs: *mut Map) -> Obj { extern "C" fn show_share_words(n_args: usize, args: *const Obj, kwargs: *mut Map) -> Obj {
let block = |_args: &[Obj], kwargs: &Map| { let block = |_args: &[Obj], kwargs: &Map| {
let share_words_obj: Obj = kwargs.get(Qstr::MP_QSTR_share_words)?; let share_words: StrBuffer = kwargs.get(Qstr::MP_QSTR_share_words)?.try_into()?;
let title = "RECOVERY SEED";
// Parsing the list of share words. let get_page = move |page_index| match page_index {
// Assume there is always up to 24 words in the newly generated seed 0 => Page::<10>::new(
// (for now, later we might support SLIP39 with up to 33 words) ButtonLayout::cancel_and_arrow_down(),
let mut iter_buf = IterBuf::new(); ButtonActions::cancel_next(),
let iter_words = Iter::try_from_obj_with_buf(share_words_obj, &mut iter_buf)?; Font::BOLD,
let mut share_words: Vec<StrBuffer, 24> = Vec::new();
for word in iter_words {
share_words.push(word.try_into()?).unwrap();
}
let share_words_len = share_words.len() as u8;
let beginning_text = build_string!(
40,
"Write down these ",
inttostr!(share_words_len),
" words:\n\n"
);
let mut middle_words: String<360> = String::new();
// Vec<StrBuffer> does not support `enumerate()`
let mut index: u8 = 0;
for word in share_words {
index += 1;
let line = build_string!(15, inttostr!(index), ". ", word.as_ref(), "\n");
middle_words.push_str(&line).unwrap();
}
let end_text = build_string!(
40,
"I wrote down all ",
inttostr!(share_words_len),
" words in order."
);
// TODO: instead of this could create a new paragraph for the beginning,
// each word and the end
let text_to_show = build_string!(
440,
beginning_text.as_str(),
middle_words.as_str(),
end_text.as_str()
);
// Adding hold-to-confirm button at the end
// Also no possibility of cancelling
let cancel_btn = None;
let confirm_btn =
Some(ButtonDetails::text("CONFIRM").with_duration(Duration::from_secs(2)));
let obj = LayoutObj::new(Frame::new(
title,
ButtonPage::new_str(
Paragraphs::new([Paragraph::new(&theme::TEXT_BOLD, text_to_show)]),
theme::BG,
) )
.with_cancel_btn(cancel_btn) .text_bold("Write all words in order on recovery seed card.".into())
.with_confirm_btn(confirm_btn), .newline()
))?; .newline()
.text_mono("Do NOT make digital copies.".into()),
1 => Page::<10>::new(
ButtonLayout::cancel_and_arrow_down(),
ButtonActions::cancel_next(),
Font::NORMAL,
)
.text_normal(share_words.clone()),
2 => Page::<10>::new(
ButtonLayout::back_and_htc_text("HOLD TO CONFIRM", Duration::from_millis(1000)),
ButtonActions::prev_confirm(),
Font::MONO,
)
.newline()
.newline()
.text_mono("I wrote down all words in order.".into()),
_ => unreachable!(),
};
let pages = FlowPages::new(get_page, 1);
let obj = LayoutObj::new(Flow::new(pages).into_child())?;
Ok(obj.into()) Ok(obj.into())
}; };
unsafe { util::try_with_args_and_kwargs(n_args, args, kwargs, block) } unsafe { util::try_with_args_and_kwargs(n_args, args, kwargs, block) }

View File

@ -19,11 +19,14 @@ async def show_share_words(
share_index: int | None = None, share_index: int | None = None,
group_index: int | None = None, group_index: int | None = None,
) -> None: ) -> None:
share_word_str = ""
for i, word in enumerate(share_words):
share_word_str += f"{i + 1} {word}\n"
await interact( await interact(
ctx, ctx,
RustLayout( RustLayout(
trezorui2.show_share_words( trezorui2.show_share_words(
share_words=share_words, share_words=share_word_str.rstrip(),
) )
), ),
br_type="backup_words", br_type="backup_words",