1
0
mirror of https://github.com/trezor/trezor-firmware.git synced 2024-11-19 14:08:11 +00:00

feat(core/mercury): impl footer in RemainingShares

This commit is contained in:
obrusvit 2024-09-05 13:32:39 +02:00 committed by Vít Obrusník
parent d15ecfb859
commit aab68b9dfa
3 changed files with 34 additions and 5 deletions

View File

@ -0,0 +1 @@
[T3T1] Fixed missing footer page hints in info about remaining shares in super-shamir recovery.

View File

@ -103,6 +103,12 @@ where
result.unwrap_or(self.area) result.unwrap_or(self.area)
} }
pub fn current_page(&self) -> usize {
self.break_pages()
.position(|offset| offset == self.offset)
.unwrap_or(0)
}
/// Update bounding boxes of paragraphs on the current page. First determine /// Update bounding boxes of paragraphs on the current page. First determine
/// the number of visible paragraphs and their sizes. These are then /// the number of visible paragraphs and their sizes. These are then
/// arranged according to the layout. /// arranged according to the layout.

View File

@ -9,9 +9,9 @@ use crate::{
button_request::ButtonRequestExt, button_request::ButtonRequestExt,
swipe_detect::SwipeSettings, swipe_detect::SwipeSettings,
text::paragraphs::{ text::paragraphs::{
Paragraph, ParagraphSource, ParagraphVecLong, ParagraphVecShort, VecExt, Paragraph, ParagraphSource, ParagraphVecLong, ParagraphVecShort, Paragraphs, VecExt,
}, },
ComponentExt, SwipeDirection, ComponentExt, EventCtx, SwipeDirection,
}, },
flow::{ flow::{
base::{DecisionBuilder as _, StateChange}, base::{DecisionBuilder as _, StateChange},
@ -23,7 +23,8 @@ use crate::{
use super::super::{ use super::super::{
component::{ component::{
Frame, FrameMsg, PromptMsg, PromptScreen, SwipeContent, VerticalMenu, VerticalMenuChoiceMsg, Footer, Frame, FrameMsg, PromptMsg, PromptScreen, SwipeContent, VerticalMenu,
VerticalMenuChoiceMsg,
}, },
theme, theme,
}; };
@ -145,6 +146,17 @@ impl FlowState for ContinueRecoveryBetweenSharesAdvanced {
pub extern "C" fn new_continue_recovery(n_args: usize, args: *const Obj, kwargs: *mut Map) -> Obj { pub extern "C" fn new_continue_recovery(n_args: usize, args: *const Obj, kwargs: *mut Map) -> Obj {
unsafe { util::try_with_args_and_kwargs(n_args, args, kwargs, new_obj) } unsafe { util::try_with_args_and_kwargs(n_args, args, kwargs, new_obj) }
} }
fn footer_update_fn(
content: &SwipeContent<SwipePage<Paragraphs<ParagraphVecLong>>>,
ctx: &mut EventCtx,
footer: &mut Footer,
) {
// FIXME: current_page is implemented for Paragraphs and we have to use Vec::len
// to get total pages instead of using Paginate because it borrows mutably
let current_page = content.inner().inner().current_page();
let total_pages = content.inner().inner().inner().len() / 2; // 2 paragraphs per page
footer.update_page_counter(ctx, current_page, Some(total_pages));
}
fn new_obj(_args: &[Obj], kwargs: &Map) -> Result<Obj, error::Error> { fn new_obj(_args: &[Obj], kwargs: &Map) -> Result<Obj, error::Error> {
let first_screen: bool = kwargs.get(Qstr::MP_QSTR_first_screen)?.try_into()?; let first_screen: bool = kwargs.get(Qstr::MP_QSTR_first_screen)?.try_into()?;
@ -304,13 +316,23 @@ fn new_obj(_args: &[Obj], kwargs: &Map) -> Result<Obj, error::Error> {
FrameMsg::Button(_) => Some(FlowMsg::Cancelled), FrameMsg::Button(_) => Some(FlowMsg::Cancelled),
}); });
let n_remaining_shares = pars_show_shares.len(); let (footer_instruction, footer_description) = (
TR::instructions__swipe_up.into(),
TR::recovery__more_shares_needed.into(),
);
let n_remaining_shares = pars_show_shares.len() / 2;
let content_remaining_shares = Frame::left_aligned( let content_remaining_shares = Frame::left_aligned(
TR::recovery__title_remaining_shares.into(), TR::recovery__title_remaining_shares.into(),
SwipeContent::new(SwipePage::vertical(pars_show_shares.into_paragraphs())), SwipeContent::new(SwipePage::vertical(pars_show_shares.into_paragraphs())),
) )
.with_cancel_button() .with_cancel_button()
// .with_footer(TR::instructions__swipe_up.into(), None) .with_footer_page_hint(
footer_description,
TString::empty(),
footer_instruction,
TR::instructions__swipe_down.into(),
)
.register_footer_update_fn(footer_update_fn)
.with_swipe(SwipeDirection::Up, SwipeSettings::default()) .with_swipe(SwipeDirection::Up, SwipeSettings::default())
.with_swipe(SwipeDirection::Left, SwipeSettings::default()) .with_swipe(SwipeDirection::Left, SwipeSettings::default())
.with_vertical_pages() .with_vertical_pages()