1
0
mirror of https://github.com/trezor/trezor-firmware.git synced 2025-07-30 18:38:27 +00:00

refactor(core): allow any layout for menu details

[no changelog]
This commit is contained in:
Roman Zeyde 2025-07-15 19:15:58 +03:00 committed by Roman Zeyde
parent ee40c89f11
commit ccc565d531

View File

@ -6,12 +6,14 @@ from trezor.ui.layouts.common import interact
from trezor.wire import ActionCancelled from trezor.wire import ActionCancelled
if TYPE_CHECKING: if TYPE_CHECKING:
from typing import Callable, Iterable, Sequence from typing import Callable, Iterable, Sequence, TypeVar
from typing_extensions import Self from typing_extensions import Self
from common import ExceptionType from common import ExceptionType
T = TypeVar("T")
class Menu: class Menu:
def __init__( def __init__(
@ -29,13 +31,13 @@ class Menu:
class Details: class Details:
def __init__(self, name: str, factory: Callable[[], Awaitable[None]]) -> None: def __init__(self, name: str, factory: Callable[[], Awaitable[T]]) -> None:
self.name = name self.name = name
self.factory = factory self.factory = factory
@classmethod @classmethod
def from_layout( def from_layout(
cls, name: str, layout_factory: Callable[[], trezorui_api.LayoutObj[None]] cls, name: str, layout_factory: Callable[[], trezorui_api.LayoutObj[T]]
) -> Self: ) -> Self:
return cls( return cls(
name, name,
@ -71,7 +73,7 @@ async def show_menu(
else: else:
assert isinstance(menu, Details) assert isinstance(menu, Details)
# Details' layout is created on-demand (saving memory) # Details' layout is created on-demand (saving memory)
await menu.factory() await menu.factory() # the result is ignored
# go one level up, or exit the menu # go one level up, or exit the menu
if menu_path: if menu_path: