mirror of
https://github.com/trezor/trezor-firmware.git
synced 2025-07-10 00:28:07 +00:00
113 lines
2.9 KiB
Python
113 lines
2.9 KiB
Python
from typing import TYPE_CHECKING
|
|
|
|
from trezor import log, ui, wire
|
|
from trezor.enums import ButtonRequestType
|
|
|
|
from trezorui2 import layout_new_confirm_action, layout_new_confirm_text
|
|
|
|
from .common import interact
|
|
|
|
if TYPE_CHECKING:
|
|
from typing import NoReturn, Type
|
|
|
|
ExceptionType = BaseException | Type[BaseException]
|
|
|
|
|
|
async def confirm_action(
|
|
ctx: wire.GenericContext,
|
|
br_type: str,
|
|
title: str,
|
|
action: str | None = None,
|
|
description: str | None = None,
|
|
description_param: str | None = None,
|
|
description_param_font: int = ui.BOLD,
|
|
verb: str | bytes | None = "OK",
|
|
verb_cancel: str | bytes | None = "cancel",
|
|
hold: bool = False,
|
|
hold_danger: bool = False,
|
|
icon: str | None = None,
|
|
icon_color: int | None = None,
|
|
reverse: bool = False,
|
|
larger_vspace: bool = False,
|
|
exc: ExceptionType = wire.ActionCancelled,
|
|
br_code: ButtonRequestType = ButtonRequestType.Other,
|
|
) -> None:
|
|
if isinstance(verb, bytes) or isinstance(verb_cancel, bytes):
|
|
raise NotImplementedError
|
|
|
|
if description is not None and description_param is not None:
|
|
if description_param_font != ui.BOLD:
|
|
log.error(__name__, "confirm_action description_param_font not implemented")
|
|
description = description.format(description_param)
|
|
|
|
if hold:
|
|
log.error(__name__, "confirm_action hold not implemented")
|
|
|
|
result = await interact(
|
|
ctx,
|
|
ui.RustLayout(
|
|
layout_new_confirm_action(
|
|
title=title.upper(),
|
|
action=action,
|
|
description=description,
|
|
verb=verb,
|
|
verb_cancel=verb_cancel,
|
|
hold=hold,
|
|
reverse=reverse,
|
|
)
|
|
),
|
|
br_type,
|
|
br_code,
|
|
)
|
|
if result == 1:
|
|
raise exc
|
|
|
|
|
|
async def confirm_text(
|
|
ctx: wire.GenericContext,
|
|
br_type: str,
|
|
title: str,
|
|
data: str,
|
|
description: str | None = None,
|
|
br_code: ButtonRequestType = ButtonRequestType.Other,
|
|
icon: str = ui.ICON_SEND, # TODO cleanup @ redesign
|
|
icon_color: int = ui.GREEN, # TODO cleanup @ redesign
|
|
) -> None:
|
|
result = await interact(
|
|
ctx,
|
|
ui.RustLayout(
|
|
layout_new_confirm_text(
|
|
title=title.upper(),
|
|
data=data,
|
|
description=description,
|
|
)
|
|
),
|
|
br_type,
|
|
br_code,
|
|
)
|
|
if result == 0:
|
|
raise wire.ActionCancelled
|
|
|
|
|
|
async def show_error_and_raise(
|
|
ctx: wire.GenericContext,
|
|
br_type: str,
|
|
content: str,
|
|
header: str = "Error",
|
|
subheader: str | None = None,
|
|
button: str = "Close",
|
|
red: bool = False,
|
|
exc: ExceptionType = wire.ActionCancelled,
|
|
) -> NoReturn:
|
|
raise NotImplementedError
|
|
|
|
|
|
async def show_popup(
|
|
title: str,
|
|
description: str,
|
|
subtitle: str | None = None,
|
|
description_param: str = "",
|
|
timeout_ms: int = 3000,
|
|
) -> None:
|
|
raise NotImplementedError
|