fix(core): use interact() as appropriate

pull/3138/head
matejcik 11 months ago committed by matejcik
parent 8c5c2f4204
commit 20805af8a5

@ -25,10 +25,7 @@ async def button_request(
if __debug__: if __debug__:
log.debug(__name__, "ButtonRequest.type=%s", br_type) log.debug(__name__, "ButtonRequest.type=%s", br_type)
workflow.close_others() workflow.close_others()
if pages is not None: await context.maybe_call(ButtonRequest(code=code, pages=pages), ButtonAck)
await context.maybe_call(ButtonRequest(code=code, pages=pages), ButtonAck)
else:
await context.maybe_call(ButtonRequest(code=code), ButtonAck)
async def interact( async def interact(
@ -36,10 +33,9 @@ async def interact(
br_type: str, br_type: str,
br_code: ButtonRequestType = ButtonRequestType.Other, br_code: ButtonRequestType = ButtonRequestType.Other,
) -> Any: ) -> Any:
pages = None
if hasattr(layout, "page_count") and layout.page_count() > 1: # type: ignore [Cannot access member "page_count" for type "LayoutType"] 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 # 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"] pages = layout.page_count() # type: ignore [Cannot access member "page_count" for type "LayoutType"]
return await context.wait(layout) await button_request(br_type, br_code, pages)
else: return await context.wait(layout)
await button_request(br_type, br_code)
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: async def request_passphrase_on_device(max_len: int) -> str:
await button_request("passphrase_device", code=ButtonRequestType.PassphraseEntry) result = await interact(
result = await ctx_wait(
RustLayout( RustLayout(
trezorui2.request_passphrase( trezorui2.request_passphrase(
prompt="ENTER PASSPHRASE", prompt="ENTER PASSPHRASE",
max_len=max_len, max_len=max_len,
) )
) ),
"passphrase_device",
ButtonRequestType.PassphraseEntry,
) )
if result is CANCELLED: if result is CANCELLED:
raise ActionCancelled("Passphrase entry cancelled") raise ActionCancelled("Passphrase entry cancelled")
@ -1132,18 +1132,19 @@ async def request_pin_on_device(
else: else:
subprompt = f"{attempts_remaining} tries left" subprompt = f"{attempts_remaining} tries left"
await button_request("pin_device", code=ButtonRequestType.PinEntry) result = await interact(
RustLayout(
dialog = RustLayout( trezorui2.request_pin(
trezorui2.request_pin( prompt=prompt,
prompt=prompt, subprompt=subprompt,
subprompt=subprompt, allow_cancel=allow_cancel,
allow_cancel=allow_cancel, wrong_pin=wrong_pin,
wrong_pin=wrong_pin, )
) ),
"pin_device",
ButtonRequestType.PinEntry,
) )
result = await ctx_wait(dialog)
if result is CANCELLED: if result is CANCELLED:
raise wire.PinCancelled raise wire.PinCancelled
assert isinstance(result, str) assert isinstance(result, str)

@ -1137,12 +1137,13 @@ def request_passphrase_on_host() -> None:
async def request_passphrase_on_device(max_len: int) -> str: async def request_passphrase_on_device(max_len: int) -> str:
await button_request("passphrase_device", code=ButtonRequestType.PassphraseEntry) result = await interact(
RustLayout(
keyboard = RustLayout( trezorui2.request_passphrase(prompt="Enter passphrase", max_len=max_len)
trezorui2.request_passphrase(prompt="Enter passphrase", max_len=max_len) ),
"passphrase_device",
ButtonRequestType.PassphraseEntry,
) )
result = await ctx_wait(keyboard)
if result is CANCELLED: if result is CANCELLED:
raise ActionCancelled("Passphrase entry cancelled") raise ActionCancelled("Passphrase entry cancelled")
@ -1158,8 +1159,6 @@ async def request_pin_on_device(
) -> str: ) -> str:
from trezor.wire import PinCancelled from trezor.wire import PinCancelled
await button_request("pin_device", code=ButtonRequestType.PinEntry)
if attempts_remaining is None: if attempts_remaining is None:
subprompt = "" subprompt = ""
elif attempts_remaining == 1: elif attempts_remaining == 1:
@ -1167,15 +1166,18 @@ async def request_pin_on_device(
else: else:
subprompt = f"{attempts_remaining} tries left" subprompt = f"{attempts_remaining} tries left"
dialog = RustLayout( result = await interact(
trezorui2.request_pin( RustLayout(
prompt=prompt, trezorui2.request_pin(
subprompt=subprompt, prompt=prompt,
allow_cancel=allow_cancel, subprompt=subprompt,
wrong_pin=wrong_pin, allow_cancel=allow_cancel,
) wrong_pin=wrong_pin,
)
),
"pin_device",
ButtonRequestType.PinEntry,
) )
result = await ctx_wait(dialog)
if result is CANCELLED: if result is CANCELLED:
raise PinCancelled raise PinCancelled
assert isinstance(result, str) assert isinstance(result, str)

Loading…
Cancel
Save