1
0
mirror of https://github.com/trezor/trezor-firmware.git synced 2024-11-26 01:18:28 +00:00

refactor(core): move confirm_coinjoin

This commit is contained in:
obrusvit 2024-11-01 21:42:26 +01:00
parent 36f4c46389
commit 664597374b
13 changed files with 106 additions and 133 deletions

View File

@ -80,6 +80,18 @@ extern "C" fn new_confirm_action(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_confirm_coinjoin(n_args: usize, args: *const Obj, kwargs: *mut Map) -> Obj {
let block = move |_args: &[Obj], kwargs: &Map| {
let max_rounds: TString = kwargs.get(Qstr::MP_QSTR_max_rounds)?.try_into()?;
let max_feerate: TString = kwargs.get(Qstr::MP_QSTR_max_feerate)?.try_into()?;
let layout = ModelUI::confirm_coinjoin(max_rounds, max_feerate)?;
Ok(LayoutObj::new_root(layout)?.into())
};
unsafe { util::try_with_args_and_kwargs(n_args, args, kwargs, block) }
}
// TODO: there was `no_mangle` attribute in TT, should we apply it?
extern "C" fn new_confirm_firmware_update(
n_args: usize,
@ -496,6 +508,14 @@ pub static mp_module_trezorui_api: Module = obj_module! {
/// """Confirm action."""
Qstr::MP_QSTR_confirm_action => obj_fn_kw!(0, new_confirm_action).as_obj(),
/// def confirm_coinjoin(
/// *,
/// max_rounds: str,
/// max_feerate: str,
/// ) -> LayoutObj[UiResult]:
/// """Confirm coinjoin authorization."""
Qstr::MP_QSTR_confirm_coinjoin => obj_fn_kw!(0, new_confirm_coinjoin).as_obj(),
/// def confirm_firmware_update(
/// *,
/// description: str,

View File

@ -908,37 +908,6 @@ extern "C" fn new_confirm_more(n_args: usize, args: *const Obj, kwargs: *mut Map
unsafe { util::try_with_args_and_kwargs(n_args, args, kwargs, block) }
}
extern "C" fn new_confirm_coinjoin(n_args: usize, args: *const Obj, kwargs: *mut Map) -> Obj {
let block = move |_args: &[Obj], kwargs: &Map| {
let max_rounds: TString = kwargs.get(Qstr::MP_QSTR_max_rounds)?.try_into()?;
let max_feerate: TString = kwargs.get(Qstr::MP_QSTR_max_feerate)?.try_into()?;
let paragraphs = ParagraphVecShort::from_iter([
Paragraph::new(&theme::TEXT_NORMAL, TR::coinjoin__max_rounds),
Paragraph::new(&theme::TEXT_MONO, max_rounds),
Paragraph::new(&theme::TEXT_NORMAL, TR::coinjoin__max_mining_fee),
Paragraph::new(&theme::TEXT_MONO, max_feerate),
])
.into_paragraphs();
new_confirm_action_simple(
paragraphs,
ConfirmActionMenu::new(None, false, None),
ConfirmActionStrings::new(
TR::coinjoin__title.into(),
None,
None,
Some(TR::coinjoin__title.into()),
),
true,
None,
)
.and_then(LayoutObj::new_root)
.map(Into::into)
};
unsafe { util::try_with_args_and_kwargs(n_args, args, kwargs, block) }
}
extern "C" fn new_continue_recovery(n_args: usize, args: *const Obj, kwargs: *mut Map) -> Obj {
let block = move |_args: &[Obj], kwargs: &Map| {
let first_screen: bool = kwargs.get(Qstr::MP_QSTR_first_screen)?.try_into()?;
@ -1271,14 +1240,6 @@ pub static mp_module_trezorui2: Module = obj_module! {
/// Meant to be used with confirm_with_info."""
Qstr::MP_QSTR_confirm_more => obj_fn_kw!(0, new_confirm_more).as_obj(),
/// def confirm_coinjoin(
/// *,
/// max_rounds: str,
/// max_feerate: str,
/// ) -> LayoutObj[UiResult]:
/// """Confirm coinjoin authorization."""
Qstr::MP_QSTR_confirm_coinjoin => obj_fn_kw!(0, new_confirm_coinjoin).as_obj(),
/// def flow_prompt_backup() -> LayoutObj[UiResult]:
/// """Prompt a user to create backup with an option to skip."""
Qstr::MP_QSTR_flow_prompt_backup => obj_fn_0!(new_prompt_backup).as_obj(),

View File

@ -98,6 +98,33 @@ impl UIFeaturesFirmware for ModelMercuryFeatures {
Ok(layout)
}
fn confirm_coinjoin(
max_rounds: TString<'static>,
max_feerate: TString<'static>,
) -> Result<impl LayoutMaybeTrace, Error> {
let paragraphs = ParagraphVecShort::from_iter([
Paragraph::new(&theme::TEXT_NORMAL, TR::coinjoin__max_rounds),
Paragraph::new(&theme::TEXT_MONO, max_rounds),
Paragraph::new(&theme::TEXT_NORMAL, TR::coinjoin__max_mining_fee),
Paragraph::new(&theme::TEXT_MONO, max_feerate),
])
.into_paragraphs();
let flow = flow::new_confirm_action_simple(
paragraphs,
ConfirmActionMenu::new(None, false, None),
ConfirmActionStrings::new(
TR::coinjoin__title.into(),
None,
None,
Some(TR::coinjoin__title.into()),
),
true,
None,
)?;
Ok(flow)
}
fn confirm_firmware_update(
description: TString<'static>,
fingerprint: TString<'static>,

View File

@ -1026,32 +1026,6 @@ extern "C" fn new_confirm_more(n_args: usize, args: *const Obj, kwargs: *mut Map
unsafe { util::try_with_args_and_kwargs(n_args, args, kwargs, block) }
}
extern "C" fn new_confirm_coinjoin(n_args: usize, args: *const Obj, kwargs: *mut Map) -> Obj {
let block = move |_args: &[Obj], kwargs: &Map| {
let max_rounds: TString = kwargs.get(Qstr::MP_QSTR_max_rounds)?.try_into()?;
let max_feerate: TString = kwargs.get(Qstr::MP_QSTR_max_feerate)?.try_into()?;
// Decreasing bottom padding between paragraphs to fit one screen
let paragraphs = Paragraphs::new([
Paragraph::new(&theme::TEXT_BOLD, TR::coinjoin__max_rounds).with_bottom_padding(2),
Paragraph::new(&theme::TEXT_MONO, max_rounds),
Paragraph::new(&theme::TEXT_BOLD, TR::coinjoin__max_mining_fee)
.with_bottom_padding(2)
.no_break(),
Paragraph::new(&theme::TEXT_MONO, max_feerate).with_bottom_padding(2),
]);
content_in_button_page(
TR::coinjoin__title.into(),
paragraphs,
TR::buttons__hold_to_confirm.into(),
None,
true,
)
};
unsafe { util::try_with_args_and_kwargs(n_args, args, kwargs, block) }
}
extern "C" fn new_show_share_words(n_args: usize, args: *const Obj, kwargs: *mut Map) -> Obj {
let block = |_args: &[Obj], kwargs: &Map| {
let share_words_obj: Obj = kwargs.get(Qstr::MP_QSTR_share_words)?;
@ -1343,14 +1317,6 @@ pub static mp_module_trezorui2: Module = obj_module! {
/// Meant to be used with confirm_with_info."""
Qstr::MP_QSTR_confirm_more => obj_fn_kw!(0, new_confirm_more).as_obj(),
/// def confirm_coinjoin(
/// *,
/// max_rounds: str,
/// max_feerate: str,
/// ) -> LayoutObj[UiResult]:
/// """Confirm coinjoin authorization."""
Qstr::MP_QSTR_confirm_coinjoin => obj_fn_kw!(0, new_confirm_coinjoin).as_obj(),
/// def show_share_words(
/// *,
/// share_words: Iterable[str],

View File

@ -89,6 +89,29 @@ impl UIFeaturesFirmware for ModelTRFeatures {
Ok(layout)
}
fn confirm_coinjoin(
max_rounds: TString<'static>,
max_feerate: TString<'static>,
) -> Result<impl LayoutMaybeTrace, Error> {
// Decreasing bottom padding between paragraphs to fit one screen
let paragraphs = Paragraphs::new([
Paragraph::new(&theme::TEXT_BOLD, TR::coinjoin__max_rounds).with_bottom_padding(2),
Paragraph::new(&theme::TEXT_MONO, max_rounds),
Paragraph::new(&theme::TEXT_BOLD, TR::coinjoin__max_mining_fee)
.with_bottom_padding(2)
.no_break(),
Paragraph::new(&theme::TEXT_MONO, max_feerate).with_bottom_padding(2),
]);
content_in_button_page(
TR::coinjoin__title.into(),
paragraphs,
TR::buttons__hold_to_confirm.into(),
None,
true,
)
}
fn confirm_firmware_update(
description: TString<'static>,
fingerprint: TString<'static>,

View File

@ -1033,28 +1033,6 @@ extern "C" fn new_confirm_more(n_args: usize, args: *const Obj, kwargs: *mut Map
unsafe { util::try_with_args_and_kwargs(n_args, args, kwargs, block) }
}
extern "C" fn new_confirm_coinjoin(n_args: usize, args: *const Obj, kwargs: *mut Map) -> Obj {
let block = move |_args: &[Obj], kwargs: &Map| {
let max_rounds: TString = kwargs.get(Qstr::MP_QSTR_max_rounds)?.try_into()?;
let max_feerate: TString = kwargs.get(Qstr::MP_QSTR_max_feerate)?.try_into()?;
let paragraphs = Paragraphs::new([
Paragraph::new(&theme::TEXT_NORMAL, TR::coinjoin__max_rounds),
Paragraph::new(&theme::TEXT_MONO, max_rounds),
Paragraph::new(&theme::TEXT_NORMAL, TR::coinjoin__max_mining_fee),
Paragraph::new(&theme::TEXT_MONO, max_feerate),
]);
let obj = LayoutObj::new(Frame::left_aligned(
theme::label_title(),
TR::coinjoin__title.into(),
ButtonPage::new(paragraphs, theme::BG).with_hold()?,
))?;
Ok(obj.into())
};
unsafe { util::try_with_args_and_kwargs(n_args, args, kwargs, block) }
}
extern "C" fn new_show_share_words(n_args: usize, args: *const Obj, kwargs: *mut Map) -> Obj {
let block = move |_args: &[Obj], kwargs: &Map| {
let title: TString = kwargs.get(Qstr::MP_QSTR_title)?.try_into()?;
@ -1374,14 +1352,6 @@ pub static mp_module_trezorui2: Module = obj_module! {
/// Meant to be used with confirm_with_info."""
Qstr::MP_QSTR_confirm_more => obj_fn_kw!(0, new_confirm_more).as_obj(),
/// def confirm_coinjoin(
/// *,
/// max_rounds: str,
/// max_feerate: str,
/// ) -> LayoutObj[UiResult]:
/// """Confirm coinjoin authorization."""
Qstr::MP_QSTR_confirm_coinjoin => obj_fn_kw!(0, new_confirm_coinjoin).as_obj(),
/// def show_share_words(
/// *,
/// title: str,

View File

@ -99,6 +99,25 @@ impl UIFeaturesFirmware for ModelTTFeatures {
Ok(layout)
}
fn confirm_coinjoin(
max_rounds: TString<'static>,
max_feerate: TString<'static>,
) -> Result<impl LayoutMaybeTrace, Error> {
let paragraphs = Paragraphs::new([
Paragraph::new(&theme::TEXT_NORMAL, TR::coinjoin__max_rounds),
Paragraph::new(&theme::TEXT_MONO, max_rounds),
Paragraph::new(&theme::TEXT_NORMAL, TR::coinjoin__max_mining_fee),
Paragraph::new(&theme::TEXT_MONO, max_feerate),
]);
let layout = RootComponent::new(Frame::left_aligned(
theme::label_title(),
TR::coinjoin__title.into(),
ButtonPage::new(paragraphs, theme::BG).with_hold()?,
));
Ok(layout)
}
fn confirm_firmware_update(
description: TString<'static>,
fingerprint: TString<'static>,

View File

@ -25,6 +25,11 @@ pub trait UIFeaturesFirmware {
image: BinaryData<'static>,
) -> Result<impl LayoutMaybeTrace, Error>;
fn confirm_coinjoin(
max_rounds: TString<'static>,
max_feerate: TString<'static>,
) -> Result<impl LayoutMaybeTrace, Error>;
fn confirm_firmware_update(
description: TString<'static>,
fingerprint: TString<'static>,

View File

@ -214,15 +214,6 @@ def confirm_more(
Meant to be used with confirm_with_info."""
# rust/src/ui/model_mercury/layout.rs
def confirm_coinjoin(
*,
max_rounds: str,
max_feerate: str,
) -> LayoutObj[UiResult]:
"""Confirm coinjoin authorization."""
# rust/src/ui/model_mercury/layout.rs
def flow_prompt_backup() -> LayoutObj[UiResult]:
"""Prompt a user to create backup with an option to skip."""
@ -550,15 +541,6 @@ def confirm_more(
Meant to be used with confirm_with_info."""
# rust/src/ui/model_tr/layout.rs
def confirm_coinjoin(
*,
max_rounds: str,
max_feerate: str,
) -> LayoutObj[UiResult]:
"""Confirm coinjoin authorization."""
# rust/src/ui/model_tr/layout.rs
def show_share_words(
*,
@ -836,15 +818,6 @@ def confirm_more(
Meant to be used with confirm_with_info."""
# rust/src/ui/model_tt/layout.rs
def confirm_coinjoin(
*,
max_rounds: str,
max_feerate: str,
) -> LayoutObj[UiResult]:
"""Confirm coinjoin authorization."""
# rust/src/ui/model_tt/layout.rs
def show_share_words(
*,

View File

@ -96,6 +96,15 @@ def confirm_action(
"""Confirm action."""
# rust/src/ui/api/firmware_upy.rs
def confirm_coinjoin(
*,
max_rounds: str,
max_feerate: str,
) -> LayoutObj[UiResult]:
"""Confirm coinjoin authorization."""
# rust/src/ui/api/firmware_upy.rs
def confirm_firmware_update(
*,

View File

@ -966,7 +966,7 @@ def confirm_modify_fee(
def confirm_coinjoin(max_rounds: int, max_fee_per_vbyte: str) -> Awaitable[None]:
return raise_if_not_confirmed(
trezorui2.confirm_coinjoin(
trezorui_api.confirm_coinjoin(
max_rounds=str(max_rounds),
max_feerate=max_fee_per_vbyte,
),

View File

@ -1047,7 +1047,7 @@ def confirm_modify_fee(
def confirm_coinjoin(max_rounds: int, max_fee_per_vbyte: str) -> Awaitable[None]:
return raise_if_not_confirmed(
trezorui2.confirm_coinjoin(
trezorui_api.confirm_coinjoin(
max_rounds=str(max_rounds),
max_feerate=max_fee_per_vbyte,
),

View File

@ -1012,7 +1012,7 @@ def confirm_modify_fee(
def confirm_coinjoin(max_rounds: int, max_fee_per_vbyte: str) -> Awaitable[None]:
return raise_if_not_confirmed(
trezorui2.confirm_coinjoin(
trezorui_api.confirm_coinjoin(
max_rounds=str(max_rounds),
max_feerate=max_fee_per_vbyte,
),