1
0
mirror of https://github.com/trezor/trezor-firmware.git synced 2024-12-01 20:08:26 +00:00

refactor(core): move show_group_share_success

This commit is contained in:
obrusvit 2024-11-03 17:22:42 +01:00
parent 17b5dbd260
commit b76e916aa1
13 changed files with 89 additions and 157 deletions

View File

@ -299,6 +299,21 @@ extern "C" fn new_show_checklist(n_args: usize, args: *const Obj, kwargs: *mut M
unsafe { util::try_with_args_and_kwargs(n_args, args, kwargs, block) }
}
extern "C" fn new_show_group_share_success(
n_args: usize,
args: *const Obj,
kwargs: *mut Map,
) -> Obj {
let block = move |_args: &[Obj], kwargs: &Map| {
let lines_iterable: Obj = kwargs.get(Qstr::MP_QSTR_lines)?;
let lines: [TString; 4] = util::iter_into_array(lines_iterable)?;
let layout = ModelUI::show_group_share_success(lines)?;
Ok(LayoutObj::new_root(layout)?.into())
};
unsafe { util::try_with_args_and_kwargs(n_args, args, kwargs, block) }
}
extern "C" fn new_show_homescreen(n_args: usize, args: *const Obj, kwargs: *mut Map) -> Obj {
let block = move |_args: &[Obj], kwargs: &Map| {
let label: TString<'static> = kwargs
@ -676,6 +691,13 @@ pub static mp_module_trezorui_api: Module = obj_module! {
/// mark next to them. Limited to 3 items."""
Qstr::MP_QSTR_show_checklist => obj_fn_kw!(0, new_show_checklist).as_obj(),
/// def show_group_share_success(
/// *,
/// lines: Iterable[str],
/// ) -> LayoutObj[UiResult]:
/// """Shown after successfully finishing a group."""
Qstr::MP_QSTR_show_group_share_success => obj_fn_kw!(0, new_show_group_share_success).as_obj(),
/// def show_homescreen(
/// *,
/// label: str | None,

View File

@ -920,35 +920,6 @@ extern "C" fn new_prompt_backup() -> Obj {
unsafe { util::try_or_raise(block) }
}
extern "C" fn new_show_group_share_success(
n_args: usize,
args: *const Obj,
kwargs: *mut Map,
) -> Obj {
let block = move |_args: &[Obj], kwargs: &Map| {
let lines_iterable: Obj = kwargs.get(Qstr::MP_QSTR_lines)?;
let lines: [TString; 4] = util::iter_into_array(lines_iterable)?;
let paragraphs = ParagraphVecShort::from_iter([
Paragraph::new(&theme::TEXT_NORMAL_GREY_EXTRA_LIGHT, lines[0]).centered(),
Paragraph::new(&theme::TEXT_DEMIBOLD, lines[1]).centered(),
Paragraph::new(&theme::TEXT_NORMAL_GREY_EXTRA_LIGHT, lines[2]).centered(),
Paragraph::new(&theme::TEXT_DEMIBOLD, lines[3]).centered(),
])
.into_paragraphs()
.with_placement(geometry::LinearPlacement::vertical().align_at_center());
let obj = LayoutObj::new(SwipeUpScreen::new(
Frame::left_aligned("".into(), SwipeContent::new(paragraphs))
.with_footer(TR::instructions__swipe_up.into(), None)
.with_swipe(Direction::Up, SwipeSettings::default()),
))?;
Ok(obj.into())
};
unsafe { util::try_with_args_and_kwargs(n_args, args, kwargs, block) }
}
extern "C" fn new_confirm_fido(n_args: usize, args: *const Obj, kwargs: *mut Map) -> Obj {
#[cfg(feature = "universal_fw")]
return flow::confirm_fido::new_confirm_fido(n_args, args, kwargs);
@ -1189,13 +1160,6 @@ pub static mp_module_trezorui2: Module = obj_module! {
/// """Device recovery homescreen."""
Qstr::MP_QSTR_flow_continue_recovery => obj_fn_kw!(0, new_continue_recovery).as_obj(),
/// def show_group_share_success(
/// *,
/// lines: Iterable[str]
/// ) -> LayoutObj[UiResult]:
/// """Shown after successfully finishing a group."""
Qstr::MP_QSTR_show_group_share_success => obj_fn_kw!(0, new_show_group_share_success).as_obj(),
/// def flow_get_address(
/// *,
/// address: str | bytes,

View File

@ -16,7 +16,7 @@ use crate::{
},
CachedJpeg, ComponentExt, Never, Timeout,
},
geometry::Direction,
geometry::{self, Direction},
layout::{
obj::{LayoutMaybeTrace, LayoutObj, RootComponent},
util::RecoveryType,
@ -364,6 +364,26 @@ impl UIFeaturesFirmware for ModelMercuryFeatures {
Ok(layout)
}
fn show_group_share_success(
lines: [TString<'static>; 4],
) -> Result<impl LayoutMaybeTrace, Error> {
let paragraphs = ParagraphVecShort::from_iter([
Paragraph::new(&theme::TEXT_NORMAL_GREY_EXTRA_LIGHT, lines[0]).centered(),
Paragraph::new(&theme::TEXT_DEMIBOLD, lines[1]).centered(),
Paragraph::new(&theme::TEXT_NORMAL_GREY_EXTRA_LIGHT, lines[2]).centered(),
Paragraph::new(&theme::TEXT_DEMIBOLD, lines[3]).centered(),
])
.into_paragraphs()
.with_placement(geometry::LinearPlacement::vertical().align_at_center());
let layout = RootComponent::new(SwipeUpScreen::new(
Frame::left_aligned("".into(), SwipeContent::new(paragraphs))
.with_footer(TR::instructions__swipe_up.into(), None)
.with_swipe(Direction::Up, SwipeSettings::default()),
));
Ok(layout)
}
fn show_homescreen(
label: TString<'static>,
hold: bool,

View File

@ -1014,35 +1014,6 @@ extern "C" fn new_confirm_recovery(n_args: usize, args: *const Obj, kwargs: *mut
unsafe { util::try_with_args_and_kwargs(n_args, args, kwargs, block) }
}
extern "C" fn new_show_group_share_success(
n_args: usize,
args: *const Obj,
kwargs: *mut Map,
) -> Obj {
let block = move |_args: &[Obj], kwargs: &Map| {
let lines_iterable: Obj = kwargs.get(Qstr::MP_QSTR_lines)?;
let lines: [TString; 4] = util::iter_into_array(lines_iterable)?;
let [l0, l1, l2, l3] = lines;
let paragraphs = Paragraphs::new([
Paragraph::new(&theme::TEXT_MONO, l0),
Paragraph::new(&theme::TEXT_BOLD, l1),
Paragraph::new(&theme::TEXT_MONO, l2),
Paragraph::new(&theme::TEXT_BOLD, l3),
]);
content_in_button_page(
"".into(),
paragraphs,
TR::buttons__continue.into(),
None,
false,
)
};
unsafe { util::try_with_args_and_kwargs(n_args, args, kwargs, block) }
}
#[no_mangle]
pub static mp_module_trezorui2: Module = obj_module! {
/// from trezor import utils
@ -1247,11 +1218,4 @@ pub static mp_module_trezorui2: Module = obj_module! {
/// ) -> LayoutObj[UiResult]:
/// """Device recovery homescreen."""
Qstr::MP_QSTR_confirm_recovery => obj_fn_kw!(0, new_confirm_recovery).as_obj(),
/// def show_group_share_success(
/// *,
/// lines: Iterable[str],
/// ) -> LayoutObj[int]:
/// """Shown after successfully finishing a group."""
Qstr::MP_QSTR_show_group_share_success => obj_fn_kw!(0, new_show_group_share_success).as_obj(),
};

View File

@ -375,6 +375,24 @@ impl UIFeaturesFirmware for ModelTRFeatures {
Ok(layout)
}
fn show_group_share_success(
lines: [TString<'static>; 4],
) -> Result<impl LayoutMaybeTrace, Error> {
let paragraphs = Paragraphs::new([
Paragraph::new(&theme::TEXT_MONO, lines[0]),
Paragraph::new(&theme::TEXT_BOLD, lines[1]),
Paragraph::new(&theme::TEXT_MONO, lines[2]),
Paragraph::new(&theme::TEXT_BOLD, lines[3]),
]);
content_in_button_page(
"".into(),
paragraphs,
TR::buttons__continue.into(),
None,
false,
)
}
fn show_homescreen(
label: TString<'static>,
hold: bool,

View File

@ -1010,26 +1010,6 @@ extern "C" fn new_confirm_recovery(n_args: usize, args: *const Obj, kwargs: *mut
unsafe { util::try_with_args_and_kwargs(n_args, args, kwargs, block) }
}
extern "C" fn new_show_group_share_success(
n_args: usize,
args: *const Obj,
kwargs: *mut Map,
) -> Obj {
let block = move |_args: &[Obj], kwargs: &Map| {
let lines_iterable: Obj = kwargs.get(Qstr::MP_QSTR_lines)?;
let lines: [TString; 4] = util::iter_into_array(lines_iterable)?;
let obj = LayoutObj::new(IconDialog::new_shares(
lines,
theme::button_bar(Button::with_text(TR::buttons__continue.into()).map(|msg| {
(matches!(msg, ButtonMsg::Clicked)).then(|| CancelConfirmMsg::Confirmed)
})),
))?;
Ok(obj.into())
};
unsafe { util::try_with_args_and_kwargs(n_args, args, kwargs, block) }
}
extern "C" fn new_show_remaining_shares(n_args: usize, args: *const Obj, kwargs: *mut Map) -> Obj {
let block = move |_args: &[Obj], kwargs: &Map| {
let pages_iterable: Obj = kwargs.get(Qstr::MP_QSTR_pages)?;
@ -1263,13 +1243,6 @@ pub static mp_module_trezorui2: Module = obj_module! {
/// """Device recovery homescreen."""
Qstr::MP_QSTR_confirm_recovery => obj_fn_kw!(0, new_confirm_recovery).as_obj(),
/// def show_group_share_success(
/// *,
/// lines: Iterable[str]
/// ) -> LayoutObj[UiResult]:
/// """Shown after successfully finishing a group."""
Qstr::MP_QSTR_show_group_share_success => obj_fn_kw!(0, new_show_group_share_success).as_obj(),
/// def show_remaining_shares(
/// *,
/// pages: Iterable[tuple[str, str]],

View File

@ -406,6 +406,18 @@ impl UIFeaturesFirmware for ModelTTFeatures {
Ok(layout)
}
fn show_group_share_success(
lines: [TString<'static>; 4],
) -> Result<impl LayoutMaybeTrace, Error> {
let layout = RootComponent::new(IconDialog::new_shares(
lines,
theme::button_bar(Button::with_text(TR::buttons__continue.into()).map(|msg| {
(matches!(msg, ButtonMsg::Clicked)).then(|| CancelConfirmMsg::Confirmed)
})),
));
Ok(layout)
}
fn show_homescreen(
label: TString<'static>,
hold: bool,

View File

@ -103,6 +103,10 @@ pub trait UIFeaturesFirmware {
items: [TString<'static>; 3],
) -> Result<impl LayoutMaybeTrace, Error>;
fn show_group_share_success(
lines: [TString<'static>; 4],
) -> Result<impl LayoutMaybeTrace, Error>;
fn show_homescreen(
label: TString<'static>,
hold: bool,

View File

@ -228,14 +228,6 @@ def flow_continue_recovery(
"""Device recovery homescreen."""
# rust/src/ui/model_mercury/layout.rs
def show_group_share_success(
*,
lines: Iterable[str]
) -> LayoutObj[UiResult]:
"""Shown after successfully finishing a group."""
# rust/src/ui/model_mercury/layout.rs
def flow_get_address(
*,
@ -522,43 +514,6 @@ def confirm_recovery(
show_instructions: bool,
) -> LayoutObj[UiResult]:
"""Device recovery homescreen."""
# rust/src/ui/model_tr/layout.rs
def show_group_share_success(
*,
lines: Iterable[str],
) -> LayoutObj[int]:
"""Shown after successfully finishing a group."""
# rust/src/ui/model_tr/layout.rs
def show_progress(
*,
description: str,
indeterminate: bool = False,
title: str | None = None,
) -> LayoutObj[UiResult]:
"""Show progress loader. Please note that the number of lines reserved on screen for
description is determined at construction time. If you want multiline descriptions
make sure the initial description has at least that amount of lines."""
# rust/src/ui/model_tr/layout.rs
def show_progress_coinjoin(
*,
title: str,
indeterminate: bool = False,
time_ms: int = 0,
skip_first_paint: bool = False,
) -> LayoutObj[UiResult]:
"""Show progress loader for coinjoin. Returns CANCELLED after a specified time when
time_ms timeout is passed."""
# rust/src/ui/model_tr/layout.rs
def show_wait_text(message: str, /) -> None:
"""Show single-line text in the middle of the screen."""
from trezor import utils
from trezorui_api import *
@ -781,14 +736,6 @@ def confirm_recovery(
"""Device recovery homescreen."""
# rust/src/ui/model_tt/layout.rs
def show_group_share_success(
*,
lines: Iterable[str]
) -> LayoutObj[UiResult]:
"""Shown after successfully finishing a group."""
# rust/src/ui/model_tt/layout.rs
def show_remaining_shares(
*,

View File

@ -244,6 +244,14 @@ def show_checklist(
mark next to them. Limited to 3 items."""
# rust/src/ui/api/firmware_upy.rs
def show_group_share_success(
*,
lines: Iterable[str],
) -> LayoutObj[UiResult]:
"""Shown after successfully finishing a group."""
# rust/src/ui/api/firmware_upy.rs
def show_homescreen(
*,

View File

@ -86,7 +86,7 @@ def format_remaining_shares_info(
async def show_group_share_success(share_index: int, group_index: int) -> None:
await raise_if_not_confirmed(
trezorui2.show_group_share_success(
trezorui_api.show_group_share_success(
lines=[
TR.recovery__you_have_entered,
TR.recovery__share_num_template.format(share_index + 1),

View File

@ -65,7 +65,7 @@ def show_group_share_success(
share_index: int, group_index: int
) -> Awaitable[ui.UiResult]:
return interact(
trezorui2.show_group_share_success(
trezorui_api.show_group_share_success(
lines=[
TR.recovery__you_have_entered,
TR.recovery__share_num_template.format(share_index + 1),

View File

@ -92,7 +92,7 @@ def show_group_share_success(
share_index: int, group_index: int
) -> Awaitable[ui.UiResult]:
return interact(
trezorui2.show_group_share_success(
trezorui_api.show_group_share_success(
lines=[
TR.recovery__you_have_entered,
TR.recovery__share_num_template.format(share_index + 1),