-
-
Notifications
You must be signed in to change notification settings - Fork 677
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(core/ui): T3T1 instruction screens between shares
Changes the visual appearance of the screens between shares during multi-share (shamir) recovery. [no changelog]
- Loading branch information
Showing
9 changed files
with
274 additions
and
152 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
134 changes: 134 additions & 0 deletions
134
core/embed/rust/src/ui/model_mercury/flow/continue_recovery.rs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,134 @@ | ||
use crate::{ | ||
error, | ||
micropython::{map::Map, obj::Obj, qstr::Qstr, util}, | ||
strutil::TString, | ||
translations::TR, | ||
ui::{ | ||
component::{ | ||
swipe_detect::SwipeSettings, | ||
text::paragraphs::{Paragraph, ParagraphVecShort, Paragraphs, VecExt}, | ||
ComponentExt, SwipeDirection, | ||
}, | ||
flow::{ | ||
base::{DecisionBuilder as _, StateChange}, | ||
FlowMsg, FlowState, SwipeFlow, | ||
}, | ||
layout::obj::LayoutObj, | ||
model_mercury::component::SwipeContent, | ||
}, | ||
}; | ||
|
||
use super::super::{ | ||
component::{Frame, FrameMsg, VerticalMenu, VerticalMenuChoiceMsg}, | ||
theme, | ||
}; | ||
|
||
const RECOVERY_TYPE_DRY_RUN: u32 = 1; | ||
const RECOVERY_TYPE_UNLOCK_REPEATED_BACKUP: u32 = 2; | ||
|
||
#[derive(Copy, Clone, PartialEq, Eq)] | ||
pub enum ContinueRecovery { | ||
Main, | ||
Menu, | ||
} | ||
|
||
impl FlowState for ContinueRecovery { | ||
#[inline] | ||
fn index(&'static self) -> usize { | ||
*self as usize | ||
} | ||
|
||
fn handle_swipe(&'static self, direction: SwipeDirection) -> StateChange { | ||
match (self, direction) { | ||
(Self::Main, SwipeDirection::Left) => Self::Menu.swipe(direction), | ||
(Self::Menu, SwipeDirection::Right) => Self::Main.swipe(direction), | ||
(Self::Main, SwipeDirection::Up) => self.return_msg(FlowMsg::Confirmed), | ||
_ => self.do_nothing(), | ||
} | ||
} | ||
|
||
fn handle_event(&'static self, msg: FlowMsg) -> StateChange { | ||
match (self, msg) { | ||
(Self::Main, FlowMsg::Info) => Self::Menu.transit(), | ||
(Self::Menu, FlowMsg::Cancelled) => Self::Main.swipe_right(), | ||
(Self::Menu, FlowMsg::Choice(0)) => self.return_msg(FlowMsg::Cancelled), | ||
_ => self.do_nothing(), | ||
} | ||
} | ||
} | ||
|
||
#[allow(clippy::not_unsafe_ptr_arg_deref)] | ||
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, ContinueRecovery::new_obj) } | ||
} | ||
|
||
impl ContinueRecovery { | ||
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 recovery_type: u32 = kwargs.get(Qstr::MP_QSTR_recovery_type)?.try_into()?; | ||
let text: TString = kwargs.get(Qstr::MP_QSTR_text)?.try_into()?; // #shares entered | ||
let subtext: Option<TString> = kwargs.get(Qstr::MP_QSTR_subtext)?.try_into_option()?; // #shares remaining | ||
|
||
let (title, cancel_btn) = match recovery_type { | ||
RECOVERY_TYPE_DRY_RUN => ( | ||
TR::recovery__title_dry_run.into(), | ||
TR::recovery__cancel_dry_run.into(), | ||
), | ||
RECOVERY_TYPE_UNLOCK_REPEATED_BACKUP => ( | ||
TR::recovery__title_dry_run.into(), | ||
TR::recovery__cancel_dry_run.into(), | ||
), | ||
_ => ( | ||
TR::recovery__title.into(), | ||
TR::recovery__title_cancel_recovery.into(), | ||
), | ||
}; | ||
|
||
let mut pars = ParagraphVecShort::new(); | ||
if first_screen { | ||
pars.add(Paragraph::new( | ||
&theme::TEXT_MAIN_GREY_EXTRA_LIGHT, | ||
TR::recovery__enter_each_word, | ||
)); | ||
} else { | ||
pars.add(Paragraph::new(&theme::TEXT_MAIN_GREY_EXTRA_LIGHT, text)); | ||
if let Some(sub) = subtext { | ||
pars.add(Paragraph::new(&theme::TEXT_SUB_GREY, sub)); | ||
} | ||
} | ||
|
||
let (footer_instruction, footer_description) = if first_screen { | ||
(TR::instructions__swipe_up.into(), None) | ||
} else { | ||
( | ||
TR::instructions__swipe_up.into(), | ||
Some(TR::instructions__enter_next_share.into()), | ||
) | ||
}; | ||
|
||
let paragraphs = Paragraphs::new(pars); | ||
let content_main = Frame::left_aligned(title, SwipeContent::new(paragraphs)) | ||
.with_subtitle(TR::words__instructions.into()) | ||
.with_menu_button() | ||
.with_footer(footer_instruction, footer_description) | ||
.with_swipe(SwipeDirection::Up, SwipeSettings::default()) | ||
.with_swipe(SwipeDirection::Left, SwipeSettings::default()) | ||
.map(|msg| matches!(msg, FrameMsg::Button(_)).then_some(FlowMsg::Info)); | ||
|
||
let content_menu = Frame::left_aligned( | ||
TString::empty(), | ||
VerticalMenu::empty().danger(theme::ICON_CANCEL, cancel_btn), | ||
) | ||
.with_cancel_button() | ||
.with_swipe(SwipeDirection::Right, SwipeSettings::immediate()) | ||
.map(|msg| match msg { | ||
FrameMsg::Content(VerticalMenuChoiceMsg::Selected(i)) => Some(FlowMsg::Choice(i)), | ||
FrameMsg::Button(_) => Some(FlowMsg::Cancelled), | ||
}); | ||
|
||
let res = SwipeFlow::new(&ContinueRecovery::Main)? | ||
.with_page(&ContinueRecovery::Main, content_main)? | ||
.with_page(&ContinueRecovery::Menu, content_menu)?; | ||
Ok(LayoutObj::new(res)?.into()) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.