From 1e7108f6d2bd688f2299198719e9be8f337949d9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ioan=20Biz=C4=83u?= Date: Mon, 7 Jul 2025 11:39:21 +0200 Subject: [PATCH] refactor(core/ui): allow custom exception on menu cancelation [no changelog] --- core/src/trezor/ui/layouts/menu.py | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/core/src/trezor/ui/layouts/menu.py b/core/src/trezor/ui/layouts/menu.py index 254f50e792..c111314404 100644 --- a/core/src/trezor/ui/layouts/menu.py +++ b/core/src/trezor/ui/layouts/menu.py @@ -3,12 +3,15 @@ from typing import TYPE_CHECKING, Awaitable import trezorui_api from trezor.enums import ButtonRequestType from trezor.ui.layouts.common import interact +from trezor.wire import ActionCancelled if TYPE_CHECKING: from typing import Callable, Iterable, Sequence from typing_extensions import Self + from common import ExceptionType + class Menu: def __init__( @@ -42,6 +45,7 @@ class Details: async def show_menu( root: Menu, + raise_on_cancel: ExceptionType = ActionCancelled, ) -> None: menu_path = [] current_item = 0 @@ -56,7 +60,9 @@ async def show_menu( current=current_item, cancel=menu.cancel, ) - choice = await interact(layout, br_name=None) + choice = await interact( + layout, br_name=None, raise_on_cancel=raise_on_cancel + ) if isinstance(choice, int): # go one level down menu_path.append(choice) @@ -79,11 +85,12 @@ async def confirm_with_menu( menu: Menu, br_name: str | None, br_code: ButtonRequestType = ButtonRequestType.Other, + raise_on_cancel: ExceptionType = ActionCancelled, ) -> None: while True: - result = await interact(main, br_name, br_code) + result = await interact(main, br_name, br_code, raise_on_cancel) br_name = None # ButtonRequest should be sent once (for the main layout) if result is trezorui_api.INFO: - await show_menu(menu) + await show_menu(menu, raise_on_cancel) else: break