2019-12-09 16:01:04 +00:00
|
|
|
from trezor import ui, utils
|
2018-02-05 14:13:33 +00:00
|
|
|
|
2019-08-08 14:27:49 +00:00
|
|
|
if False:
|
2019-09-06 17:53:28 +00:00
|
|
|
from typing import Any, Optional
|
2019-08-08 14:27:49 +00:00
|
|
|
|
2018-02-05 14:13:33 +00:00
|
|
|
|
|
|
|
def pin_to_int(pin: str) -> int:
|
2018-07-03 14:20:58 +00:00
|
|
|
return int("1" + pin)
|
2017-12-15 20:06:29 +00:00
|
|
|
|
2017-12-15 20:11:46 +00:00
|
|
|
|
2019-09-06 17:53:28 +00:00
|
|
|
_previous_progress = None # type: Optional[int]
|
|
|
|
_previous_seconds = None # type: Optional[int]
|
2019-08-08 14:27:49 +00:00
|
|
|
keepalive_callback = None # type: Any
|
|
|
|
|
2019-04-11 10:32:37 +00:00
|
|
|
|
2019-02-22 20:53:37 +00:00
|
|
|
def show_pin_timeout(seconds: int, progress: int, message: str) -> bool:
|
2019-04-11 10:32:37 +00:00
|
|
|
global _previous_progress
|
2019-09-06 17:53:28 +00:00
|
|
|
global _previous_seconds
|
2019-04-11 10:32:37 +00:00
|
|
|
|
2019-08-08 14:27:49 +00:00
|
|
|
if callable(keepalive_callback):
|
|
|
|
keepalive_callback()
|
|
|
|
|
2018-02-24 20:02:14 +00:00
|
|
|
if progress == 0:
|
2019-04-11 10:32:37 +00:00
|
|
|
if progress != _previous_progress:
|
|
|
|
# avoid overdraw in case of repeated progress calls
|
|
|
|
ui.display.clear()
|
2019-09-06 17:53:28 +00:00
|
|
|
_previous_seconds = None
|
2020-08-06 10:58:17 +00:00
|
|
|
ui.display.text_center(ui.WIDTH // 2, 37, message, ui.BOLD, ui.FG, ui.BG)
|
2019-12-09 16:01:04 +00:00
|
|
|
|
|
|
|
if not utils.DISABLE_ANIMATION:
|
|
|
|
ui.display.loader(progress, False, 0, ui.FG, ui.BG)
|
2019-09-06 17:53:28 +00:00
|
|
|
|
|
|
|
if seconds != _previous_seconds:
|
|
|
|
if seconds == 0:
|
|
|
|
remaining = "Done"
|
|
|
|
elif seconds == 1:
|
|
|
|
remaining = "1 second left"
|
|
|
|
else:
|
|
|
|
remaining = "%d seconds left" % seconds
|
2020-08-06 10:58:17 +00:00
|
|
|
ui.display.bar(0, ui.HEIGHT - 42, ui.WIDTH, 25, ui.BG)
|
2018-07-03 14:20:58 +00:00
|
|
|
ui.display.text_center(
|
2020-08-06 10:58:17 +00:00
|
|
|
ui.WIDTH // 2, ui.HEIGHT - 22, remaining, ui.BOLD, ui.FG, ui.BG
|
2018-07-03 14:20:58 +00:00
|
|
|
)
|
2019-09-06 17:53:28 +00:00
|
|
|
_previous_seconds = seconds
|
2019-04-11 10:32:37 +00:00
|
|
|
|
2019-12-09 16:01:04 +00:00
|
|
|
ui.refresh()
|
2019-04-11 10:32:37 +00:00
|
|
|
_previous_progress = progress
|
2019-02-07 11:01:08 +00:00
|
|
|
return False
|