mirror of
https://github.com/trezor/trezor-firmware.git
synced 2025-01-22 13:21:03 +00:00
fix(core): use interact() as appropriate
This commit is contained in:
parent
8c5c2f4204
commit
20805af8a5
@ -25,10 +25,7 @@ async def button_request(
|
||||
if __debug__:
|
||||
log.debug(__name__, "ButtonRequest.type=%s", br_type)
|
||||
workflow.close_others()
|
||||
if pages is not None:
|
||||
await context.maybe_call(ButtonRequest(code=code, pages=pages), ButtonAck)
|
||||
else:
|
||||
await context.maybe_call(ButtonRequest(code=code), ButtonAck)
|
||||
await context.maybe_call(ButtonRequest(code=code, pages=pages), ButtonAck)
|
||||
|
||||
|
||||
async def interact(
|
||||
@ -36,10 +33,9 @@ async def interact(
|
||||
br_type: str,
|
||||
br_code: ButtonRequestType = ButtonRequestType.Other,
|
||||
) -> Any:
|
||||
pages = None
|
||||
if hasattr(layout, "page_count") and layout.page_count() > 1: # type: ignore [Cannot access member "page_count" for type "LayoutType"]
|
||||
# We know for certain how many pages the layout will have
|
||||
await button_request(br_type, br_code, pages=layout.page_count()) # type: ignore [Cannot access member "page_count" for type "LayoutType"]
|
||||
return await context.wait(layout)
|
||||
else:
|
||||
await button_request(br_type, br_code)
|
||||
return await context.wait(layout)
|
||||
pages = layout.page_count() # type: ignore [Cannot access member "page_count" for type "LayoutType"]
|
||||
await button_request(br_type, br_code, pages)
|
||||
return await context.wait(layout)
|
||||
|
@ -1098,15 +1098,15 @@ def request_passphrase_on_host() -> None:
|
||||
|
||||
|
||||
async def request_passphrase_on_device(max_len: int) -> str:
|
||||
await button_request("passphrase_device", code=ButtonRequestType.PassphraseEntry)
|
||||
|
||||
result = await ctx_wait(
|
||||
result = await interact(
|
||||
RustLayout(
|
||||
trezorui2.request_passphrase(
|
||||
prompt="ENTER PASSPHRASE",
|
||||
max_len=max_len,
|
||||
)
|
||||
)
|
||||
),
|
||||
"passphrase_device",
|
||||
ButtonRequestType.PassphraseEntry,
|
||||
)
|
||||
if result is CANCELLED:
|
||||
raise ActionCancelled("Passphrase entry cancelled")
|
||||
@ -1132,18 +1132,19 @@ async def request_pin_on_device(
|
||||
else:
|
||||
subprompt = f"{attempts_remaining} tries left"
|
||||
|
||||
await button_request("pin_device", code=ButtonRequestType.PinEntry)
|
||||
|
||||
dialog = RustLayout(
|
||||
trezorui2.request_pin(
|
||||
prompt=prompt,
|
||||
subprompt=subprompt,
|
||||
allow_cancel=allow_cancel,
|
||||
wrong_pin=wrong_pin,
|
||||
)
|
||||
result = await interact(
|
||||
RustLayout(
|
||||
trezorui2.request_pin(
|
||||
prompt=prompt,
|
||||
subprompt=subprompt,
|
||||
allow_cancel=allow_cancel,
|
||||
wrong_pin=wrong_pin,
|
||||
)
|
||||
),
|
||||
"pin_device",
|
||||
ButtonRequestType.PinEntry,
|
||||
)
|
||||
|
||||
result = await ctx_wait(dialog)
|
||||
if result is CANCELLED:
|
||||
raise wire.PinCancelled
|
||||
assert isinstance(result, str)
|
||||
|
@ -1137,12 +1137,13 @@ def request_passphrase_on_host() -> None:
|
||||
|
||||
|
||||
async def request_passphrase_on_device(max_len: int) -> str:
|
||||
await button_request("passphrase_device", code=ButtonRequestType.PassphraseEntry)
|
||||
|
||||
keyboard = RustLayout(
|
||||
trezorui2.request_passphrase(prompt="Enter passphrase", max_len=max_len)
|
||||
result = await interact(
|
||||
RustLayout(
|
||||
trezorui2.request_passphrase(prompt="Enter passphrase", max_len=max_len)
|
||||
),
|
||||
"passphrase_device",
|
||||
ButtonRequestType.PassphraseEntry,
|
||||
)
|
||||
result = await ctx_wait(keyboard)
|
||||
if result is CANCELLED:
|
||||
raise ActionCancelled("Passphrase entry cancelled")
|
||||
|
||||
@ -1158,8 +1159,6 @@ async def request_pin_on_device(
|
||||
) -> str:
|
||||
from trezor.wire import PinCancelled
|
||||
|
||||
await button_request("pin_device", code=ButtonRequestType.PinEntry)
|
||||
|
||||
if attempts_remaining is None:
|
||||
subprompt = ""
|
||||
elif attempts_remaining == 1:
|
||||
@ -1167,15 +1166,18 @@ async def request_pin_on_device(
|
||||
else:
|
||||
subprompt = f"{attempts_remaining} tries left"
|
||||
|
||||
dialog = RustLayout(
|
||||
trezorui2.request_pin(
|
||||
prompt=prompt,
|
||||
subprompt=subprompt,
|
||||
allow_cancel=allow_cancel,
|
||||
wrong_pin=wrong_pin,
|
||||
)
|
||||
result = await interact(
|
||||
RustLayout(
|
||||
trezorui2.request_pin(
|
||||
prompt=prompt,
|
||||
subprompt=subprompt,
|
||||
allow_cancel=allow_cancel,
|
||||
wrong_pin=wrong_pin,
|
||||
)
|
||||
),
|
||||
"pin_device",
|
||||
ButtonRequestType.PinEntry,
|
||||
)
|
||||
result = await ctx_wait(dialog)
|
||||
if result is CANCELLED:
|
||||
raise PinCancelled
|
||||
assert isinstance(result, str)
|
||||
|
Loading…
Reference in New Issue
Block a user