1
0
mirror of https://github.com/trezor/trezor-firmware.git synced 2025-07-15 19:18:11 +00:00
trezor-firmware/core/src/apps/common/request_pin.py
2019-05-28 13:12:46 +02:00

34 lines
814 B
Python

from trezor import loop
from trezor.ui.pin import CANCELLED, PinDialog
if __debug__:
from apps.debug import input_signal
class PinCancelled(Exception):
pass
async def request_pin(
prompt: str = "Enter your PIN",
attempts_remaining: int = None,
allow_cancel: bool = True,
) -> str:
if attempts_remaining is None:
subprompt = None
elif attempts_remaining == 1:
subprompt = "This is your last attempt"
else:
subprompt = "%s attempts remaining" % attempts_remaining
dialog = PinDialog(prompt, subprompt, allow_cancel)
while True:
if __debug__:
result = await loop.spawn(dialog, input_signal)
else:
result = await dialog
if result is CANCELLED:
raise PinCancelled()
return result