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

refactor(core): move confirm_coinjoin

This commit is contained in:
obrusvit 2024-11-01 21:42:26 +01:00
parent 1791f2cae3
commit 97db2560f8
13 changed files with 108 additions and 135 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) } 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? // TODO: there was `no_mangle` attribute in TT, should we apply it?
extern "C" fn new_confirm_firmware_update( extern "C" fn new_confirm_firmware_update(
n_args: usize, n_args: usize,
@ -496,6 +508,14 @@ pub static mp_module_trezorui_api: Module = obj_module! {
/// """Confirm action.""" /// """Confirm action."""
Qstr::MP_QSTR_confirm_action => obj_fn_kw!(0, new_confirm_action).as_obj(), 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( /// def confirm_firmware_update(
/// *, /// *,
/// description: str, /// description: str,

View File

@ -919,39 +919,6 @@ extern "C" fn new_confirm_with_info(n_args: usize, args: *const Obj, kwargs: *mu
unsafe { util::try_with_args_and_kwargs(n_args, args, kwargs, block) } 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,
ConfirmActionExtra::Menu(ConfirmActionMenuStrings::new()),
ConfirmActionStrings::new(
TR::coinjoin__title.into(),
None,
None,
Some(TR::coinjoin__title.into()),
),
true,
None,
0,
false,
)
.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 { extern "C" fn new_continue_recovery(n_args: usize, args: *const Obj, kwargs: *mut Map) -> Obj {
let block = move |_args: &[Obj], kwargs: &Map| { let block = move |_args: &[Obj], kwargs: &Map| {
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()?;
@ -1289,14 +1256,6 @@ pub static mp_module_trezorui2: Module = obj_module! {
/// context menu.""" /// context menu."""
Qstr::MP_QSTR_confirm_with_info => obj_fn_kw!(0, new_confirm_with_info).as_obj(), Qstr::MP_QSTR_confirm_with_info => obj_fn_kw!(0, new_confirm_with_info).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]: /// def flow_prompt_backup() -> LayoutObj[UiResult]:
/// """Prompt a user to create backup with an option to skip.""" /// """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(), Qstr::MP_QSTR_flow_prompt_backup => obj_fn_0!(new_prompt_backup).as_obj(),

View File

@ -103,6 +103,35 @@ impl UIFeaturesFirmware for ModelMercuryFeatures {
Ok(layout) 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,
ConfirmActionExtra::Menu(ConfirmActionMenuStrings::new()),
ConfirmActionStrings::new(
TR::coinjoin__title.into(),
None,
None,
Some(TR::coinjoin__title.into()),
),
true,
None,
0,
false,
)?;
Ok(flow)
}
fn confirm_firmware_update( fn confirm_firmware_update(
description: TString<'static>, description: TString<'static>,
fingerprint: 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) } 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 { extern "C" fn new_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_obj: Obj = kwargs.get(Qstr::MP_QSTR_share_words)?;
@ -1344,14 +1318,6 @@ pub static mp_module_trezorui2: Module = obj_module! {
/// Meant to be used with confirm_with_info.""" /// Meant to be used with confirm_with_info."""
Qstr::MP_QSTR_confirm_more => obj_fn_kw!(0, new_confirm_more).as_obj(), 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( /// def show_share_words(
/// *, /// *,
/// share_words: Iterable[str], /// share_words: Iterable[str],

View File

@ -89,6 +89,29 @@ impl UIFeaturesFirmware for ModelTRFeatures {
Ok(layout) 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( fn confirm_firmware_update(
description: TString<'static>, description: TString<'static>,
fingerprint: TString<'static>, fingerprint: TString<'static>,

View File

@ -1020,28 +1020,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) } 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 { 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 block = move |_args: &[Obj], kwargs: &Map| {
let title: TString = kwargs.get(Qstr::MP_QSTR_title)?.try_into()?; let title: TString = kwargs.get(Qstr::MP_QSTR_title)?.try_into()?;
@ -1362,14 +1340,6 @@ pub static mp_module_trezorui2: Module = obj_module! {
/// Meant to be used with confirm_with_info.""" /// Meant to be used with confirm_with_info."""
Qstr::MP_QSTR_confirm_more => obj_fn_kw!(0, new_confirm_more).as_obj(), 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( /// def show_share_words(
/// *, /// *,
/// title: str, /// title: str,

View File

@ -99,6 +99,25 @@ impl UIFeaturesFirmware for ModelTTFeatures {
Ok(layout) 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( fn confirm_firmware_update(
description: TString<'static>, description: TString<'static>,
fingerprint: TString<'static>, fingerprint: TString<'static>,

View File

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

View File

@ -219,15 +219,6 @@ def confirm_with_info(
context menu.""" context menu."""
# 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 # rust/src/ui/model_mercury/layout.rs
def flow_prompt_backup() -> LayoutObj[UiResult]: def flow_prompt_backup() -> LayoutObj[UiResult]:
"""Prompt a user to create backup with an option to skip.""" """Prompt a user to create backup with an option to skip."""
@ -556,15 +547,6 @@ def confirm_more(
Meant to be used with confirm_with_info.""" 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 # rust/src/ui/model_tr/layout.rs
def show_share_words( def show_share_words(
*, *,
@ -843,15 +825,6 @@ def confirm_more(
Meant to be used with confirm_with_info.""" 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 # rust/src/ui/model_tt/layout.rs
def show_share_words( def show_share_words(
*, *,

View File

@ -96,6 +96,15 @@ def confirm_action(
"""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 # rust/src/ui/api/firmware_upy.rs
def confirm_firmware_update( def confirm_firmware_update(
*, *,

View File

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

View File

@ -1052,7 +1052,7 @@ def confirm_modify_fee(
def confirm_coinjoin(max_rounds: int, max_fee_per_vbyte: str) -> Awaitable[None]: def confirm_coinjoin(max_rounds: int, max_fee_per_vbyte: str) -> Awaitable[None]:
return raise_if_not_confirmed( return raise_if_not_confirmed(
trezorui2.confirm_coinjoin( trezorui_api.confirm_coinjoin(
max_rounds=str(max_rounds), max_rounds=str(max_rounds),
max_feerate=max_fee_per_vbyte, 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]: def confirm_coinjoin(max_rounds: int, max_fee_per_vbyte: str) -> Awaitable[None]:
return raise_if_not_confirmed( return raise_if_not_confirmed(
trezorui2.confirm_coinjoin( trezorui_api.confirm_coinjoin(
max_rounds=str(max_rounds), max_rounds=str(max_rounds),
max_feerate=max_fee_per_vbyte, max_feerate=max_fee_per_vbyte,
), ),