diff --git a/core/src/trezor/ui/layouts/tr/__init__.py b/core/src/trezor/ui/layouts/tr/__init__.py index 2bd179e6cd..2a5adb9e81 100644 --- a/core/src/trezor/ui/layouts/tr/__init__.py +++ b/core/src/trezor/ui/layouts/tr/__init__.py @@ -442,11 +442,12 @@ async def _placeholder_confirm( ctx: GenericContext, br_type: str, title: str, - data: str, + data: str | None = None, + description: str | None = None, + *, verb: str = "CONFIRM", verb_cancel: str | bytes | None = "", hold: bool = False, - description: str | None = None, br_code: ButtonRequestType = BR_TYPE_OTHER, ) -> Any: return await confirm_action( @@ -573,11 +574,9 @@ async def confirm_reset_device( to_show += "\nUse you backup to recover your wallet." return await _placeholder_confirm( - ctx=ctx, - br_type="recover_device" if recovery else "setup_device", - title="WALLET RECOVERY" if recovery else "WALLET BACKUP", - # data=f"{common_data}\n\n{special_data}", - data="", + ctx, + "recover_device" if recovery else "setup_device", + "WALLET RECOVERY" if recovery else "WALLET BACKUP", description=to_show, br_code=ButtonRequestType.ProtectCall if recovery @@ -588,24 +587,24 @@ async def confirm_reset_device( # TODO cleanup @ redesign async def confirm_backup(ctx: GenericContext) -> bool: if await get_bool( - ctx=ctx, - title="SUCCESS", - data="New wallet created successfully!\nYou should back up your new wallet right now.", + ctx, + "backup_device", + "SUCCESS", + "New wallet created successfully!\nYou should back up your new wallet right now.", verb="BACK UP", verb_cancel="SKIP", - br_type="backup_device", br_code=ButtonRequestType.ResetDevice, ): return True confirmed = await get_bool( - ctx=ctx, - title="WARNING", - data="Are you sure you want to skip the backup?\n", - description="You can back up your Trezor once, at any time.", + ctx, + "backup_device", + "WARNING", + "Are you sure you want to skip the backup?\n", + "You can back up your Trezor once, at any time.", verb="BACK UP", verb_cancel="SKIP", - br_type="backup_device", br_code=ButtonRequestType.ResetDevice, ) return confirmed @@ -615,11 +614,10 @@ async def confirm_path_warning( ctx: GenericContext, path: str, path_type: str = "Path" ) -> None: return await _placeholder_confirm( - ctx=ctx, - br_type="path_warning", - title="CONFIRM PATH", - data=f"{path_type}\n{path} is unknown.\nAre you sure?", - description="", + ctx, + "path_warning", + "CONFIRM PATH", + f"{path_type}\n{path} is unknown.\nAre you sure?", br_code=ButtonRequestType.UnknownDerivationPath, ) @@ -694,9 +692,9 @@ def show_pubkey( ) -> Awaitable[None]: return confirm_blob( ctx, - br_type="show_pubkey", - title=title.upper(), - data=pubkey, + "show_pubkey", + title.upper(), + pubkey, br_code=ButtonRequestType.PublicKey, ) @@ -704,24 +702,24 @@ def show_pubkey( async def _show_modal( ctx: GenericContext, br_type: str, - br_code: ButtonRequestType, header: str, subheader: str | None, content: str, button_confirm: str | None, button_cancel: str | None, + br_code: ButtonRequestType, exc: ExceptionType = ActionCancelled, ) -> None: await confirm_action( - ctx=ctx, - br_type=br_type, - br_code=br_code, - title=header.upper(), - action=subheader, - description=content, + ctx, + br_type, + header.upper(), + subheader, + content, verb=button_confirm or "", verb_cancel=button_cancel, exc=exc, + br_code=br_code, ) @@ -736,14 +734,14 @@ async def show_error_and_raise( exc: ExceptionType = ActionCancelled, ) -> NoReturn: await _show_modal( - ctx=ctx, - br_type=br_type, - br_code=BR_TYPE_OTHER, - header=header, - subheader=subheader, - content=content, + ctx, + br_type, + header, + subheader, + content, button_confirm=None, button_cancel=button, + br_code=BR_TYPE_OTHER, exc=exc, ) raise exc @@ -760,13 +758,13 @@ def show_warning( ) -> Awaitable[None]: return _show_modal( ctx, - br_type=br_type, - br_code=br_code, - header=header, - subheader=subheader, - content=content, + br_type, + header, + subheader, + content, button_confirm=button, button_cancel=None, + br_code=br_code, ) @@ -779,13 +777,13 @@ def show_success( ) -> Awaitable[None]: return _show_modal( ctx, - br_type=br_type, - br_code=ButtonRequestType.Success, - header="Success", - subheader=subheader, - content=content, + br_type, + "Success", + subheader, + content, button_confirm=button, button_cancel=None, + br_code=ButtonRequestType.Success, ) @@ -837,11 +835,10 @@ async def confirm_payment_request( ) -> Any: memos_str = "\n".join(memos) return await _placeholder_confirm( - ctx=ctx, - br_type="confirm_payment_request", - title="CONFIRM SENDING", - data=f"{amount} to\n{recipient_name}\n{memos_str}", - description="", + ctx, + "confirm_payment_request", + "CONFIRM SENDING", + f"{amount} to\n{recipient_name}\n{memos_str}", br_code=ButtonRequestType.ConfirmOutput, ) @@ -1028,11 +1025,10 @@ async def confirm_joint_total( ctx: GenericContext, spending_amount: str, total_amount: str ) -> None: await _placeholder_confirm( - ctx=ctx, - br_type="confirm_joint_total", - title="JOINT TRANSACTION", - data=f"You are contributing:\n{spending_amount}\nto the total amount:\n{total_amount}", - description="", + ctx, + "confirm_joint_total", + "JOINT TRANSACTION", + f"You are contributing:\n{spending_amount}\nto the total amount:\n{total_amount}", br_code=ButtonRequestType.SignTx, ) @@ -1047,10 +1043,10 @@ async def confirm_metadata( hold: bool = False, ) -> None: await _placeholder_confirm( - ctx=ctx, - br_type=br_type, - title=title.upper(), - data=content.format(param), + ctx, + br_type, + title.upper(), + content.format(param), hold=hold, br_code=br_code, ) @@ -1058,10 +1054,10 @@ async def confirm_metadata( async def confirm_replacement(ctx: GenericContext, description: str, txid: str) -> None: await _placeholder_confirm( - ctx=ctx, - br_type="confirm_replacement", - title=description.upper(), - data=f"Confirm transaction ID:\n{txid}", + ctx, + "confirm_replacement", + description.upper(), + f"Confirm transaction ID:\n{txid}", br_code=ButtonRequestType.SignTx, ) @@ -1081,10 +1077,10 @@ async def confirm_modify_output( text += f"New amount:\n{amount_new}" await _placeholder_confirm( - ctx=ctx, - br_type="modify_output", - title="MODIFY AMOUNT", - data=text, + ctx, + "modify_output", + "MODIFY AMOUNT", + text, br_code=ButtonRequestType.ConfirmOutput, ) @@ -1110,10 +1106,10 @@ async def confirm_modify_fee( text += "\n" + fee_rate_amount await _placeholder_confirm( - ctx=ctx, - br_type="modify_fee", - title="MODIFY FEE", - data=text, + ctx, + "modify_fee", + "MODIFY FEE", + text, br_code=ButtonRequestType.SignTx, ) @@ -1122,10 +1118,10 @@ async def confirm_coinjoin( ctx: GenericContext, max_rounds: int, max_fee_per_vbyte: str ) -> None: await _placeholder_confirm( - ctx=ctx, - br_type="coinjoin_final", - title="AUTHORIZE COINJOIN", - data=f"Maximum rounds: {max_rounds}\n\nMaximum mining fee:\n{max_fee_per_vbyte}", + ctx, + "coinjoin_final", + "AUTHORIZE COINJOIN", + f"Maximum rounds: {max_rounds}\n\nMaximum mining fee:\n{max_fee_per_vbyte}", br_code=BR_TYPE_OTHER, ) @@ -1144,10 +1140,10 @@ async def confirm_sign_identity( text += identity await _placeholder_confirm( - ctx=ctx, - br_type="confirm_sign_identity", - title=f"Sign {proto}".upper(), - data=text, + ctx, + "confirm_sign_identity", + f"Sign {proto}".upper(), + text, br_code=BR_TYPE_OTHER, ) @@ -1171,10 +1167,10 @@ async def confirm_signverify( ) await _placeholder_confirm( - ctx=ctx, - br_type=br_type, - title=header.upper(), - data=f"Confirm message:\n{message}", + ctx, + br_type, + header.upper(), + f"Confirm message:\n{message}", br_code=BR_TYPE_OTHER, ) @@ -1268,7 +1264,7 @@ async def confirm_reenter_pin( ctx, br_type, "CHECK PIN", - action="Please re-enter to confirm.", + "Please re-enter to confirm.", verb="BEGIN", br_code=br_code, ) @@ -1283,7 +1279,7 @@ async def pin_mismatch( ctx, br_type, "PIN MISMATCH", - action="The PINs you entered do not match.\nPlease try again.", + "The PINs you entered do not match.\nPlease try again.", verb="TRY AGAIN", verb_cancel=None, br_code=br_code, @@ -1302,7 +1298,7 @@ async def confirm_pin_action( ctx, br_type, title, - action=f"{description} {action}", + f"{description} {action}", br_code=br_code, ) diff --git a/core/src/trezor/ui/layouts/tr/recovery.py b/core/src/trezor/ui/layouts/tr/recovery.py index e9dc61cb7c..bdb9a46834 100644 --- a/core/src/trezor/ui/layouts/tr/recovery.py +++ b/core/src/trezor/ui/layouts/tr/recovery.py @@ -17,8 +17,8 @@ async def request_word_count(ctx: wire.GenericContext, dry_run: bool) -> int: count = await interact( ctx, RustLayout(trezorui2.select_word_count(dry_run=dry_run)), - br_type="word_count", - br_code=ButtonRequestType.MnemonicWordCount, + "word_count", + ButtonRequestType.MnemonicWordCount, ) # It can be returning a string return int(count) @@ -34,13 +34,9 @@ async def request_word( else: word = await interact( ctx, - RustLayout( - trezorui2.request_word_bip39( - prompt=prompt, - ) - ), - br_type="request_word", - br_code=ButtonRequestType.MnemonicInput, + RustLayout(trezorui2.request_word_bip39(prompt=prompt)), + "request_word", + ButtonRequestType.MnemonicInput, ) return word diff --git a/core/src/trezor/ui/layouts/tr/reset.py b/core/src/trezor/ui/layouts/tr/reset.py index d8cdad2057..2c51d5e3b7 100644 --- a/core/src/trezor/ui/layouts/tr/reset.py +++ b/core/src/trezor/ui/layouts/tr/reset.py @@ -26,11 +26,11 @@ async def show_share_words( ctx, RustLayout( trezorui2.show_share_words( # type: ignore [Arguments missing for parameters "title", "pages"] - share_words=share_words, # type: ignore [No parameter named "share_words"] + share_words=share_words # type: ignore [No parameter named "share_words"] ) ), - br_type="backup_words", - br_code=ButtonRequestType.ResetDevice, + "backup_words", + ButtonRequestType.ResetDevice, ) ready_to_check = await get_bool(