1
0
mirror of https://github.com/trezor/trezor-firmware.git synced 2024-11-20 14:39:22 +00:00

feat(core): implement loader based on time in milliseconds

[no changelog]
This commit is contained in:
grdddj 2023-01-13 16:21:27 +01:00 committed by matejcik
parent cd5425884f
commit 25dc6ff130
3 changed files with 51 additions and 22 deletions

View File

@ -25,11 +25,14 @@ _DEFAULT_BACKUP_TYPE = BAK_T_BIP39
async def reset_device(ctx: Context, msg: ResetDevice) -> Success:
from trezor import config
from trezor.ui.loader import LoadingAnimation
from apps.common.request_pin import request_pin_confirm
from trezor.ui.layouts import confirm_backup, confirm_reset_device
from trezor.ui.layouts import (
confirm_backup,
confirm_reset_device,
)
from trezor.crypto import bip39, random
from trezor.messages import Success, EntropyAck, EntropyRequest
from trezor.pin import render_empty_loader
backup_type = msg.backup_type # local_cache_attribute
@ -44,7 +47,9 @@ async def reset_device(ctx: Context, msg: ResetDevice) -> Success:
else:
prompt = "Do you want to create\na new wallet?"
await confirm_reset_device(ctx, prompt)
await LoadingAnimation()
# Rendering empty loader so users do not feel a freezing screen
render_empty_loader("PROCESSING", "")
# wipe storage to make sure the device is in a clear state
storage.reset()

View File

@ -7,15 +7,30 @@ if TYPE_CHECKING:
_previous_seconds: int | None = None
_previous_remaining: str | None = None
_progress_layout: ProgressLayout | None = None
_started_with_empty_loader = False
keepalive_callback: Any = None
def render_empty_loader(message: str, description: str) -> None:
"""Render empty loader to prevent the screen appear to be frozen."""
from trezor.ui.layouts import pin_progress
global _progress_layout
global _started_with_empty_loader
_progress_layout = pin_progress(message, description)
_progress_layout.report(0, None)
_started_with_empty_loader = True
def show_pin_timeout(seconds: int, progress: int, message: str) -> bool:
from trezor.ui.layouts import pin_progress
global _previous_seconds
global _previous_remaining
global _progress_layout
global _started_with_empty_loader
if callable(keepalive_callback):
keepalive_callback()
@ -35,9 +50,18 @@ def show_pin_timeout(seconds: int, progress: int, message: str) -> bool:
else:
remaining = _previous_remaining
if progress == 0 or _progress_layout is None:
# create the layout if it doesn't exist yet or should be started again
if _progress_layout is None or (progress == 0 and not _started_with_empty_loader):
_progress_layout = pin_progress(message, description=remaining or "")
# reset the flag - the render_empty_loader() has the effect only in the first call
# of this function, where we do not want to re-initialize the layout
# to avoid a screen flicker
_started_with_empty_loader = False
# update the progress layout
_progress_layout.report(progress, remaining)
# drop the layout when done so trezor.ui doesn't have to remain in memory
if seconds == 0:
_progress_layout = None

View File

@ -1502,24 +1502,24 @@
"TT_reset_recovery-test_recovery_slip39_basic.py::test_wrong_nth_word[2]": "c1049deb7f23adce659bca00b4dea30934d07b6c032ff1665b4a437bbac0922e",
"TT_reset_recovery-test_recovery_slip39_basic_dryrun.py::test_2of3_dryrun": "9934aa382734f20429059b3fe4f82a617db10d03e7c5e88f7af2c1067b5b8a78",
"TT_reset_recovery-test_recovery_slip39_basic_dryrun.py::test_2of3_invalid_seed_dryrun": "b3350f1244b9062c7e1743d9a8ed871676c68ce09edd1efc9bce31a3cb1b94bd",
"TT_reset_recovery-test_reset_backup.py::test_skip_backup_manual[BackupType.Bip39-backup_flow_bip39]": "1855bf449ae73a4f04750c250a08472b559f824cbcc1f73d5ff1874542e29b28",
"TT_reset_recovery-test_reset_backup.py::test_skip_backup_manual[BackupType.Slip39_Advanced-bac-f67baa1c": "c0c73e3b9a4df165244bcc27f2204ae38128c107bfd37ba7ef912fd7eacd4daa",
"TT_reset_recovery-test_reset_backup.py::test_skip_backup_manual[BackupType.Slip39_Basic-backup-6348e7fe": "1a4549228b7c76529c5a4cad07d05b15e0b7c7b3ce5e8128e8658e2080ef12ca",
"TT_reset_recovery-test_reset_backup.py::test_skip_backup_msg[BackupType.Bip39-backup_flow_bip39]": "aa8996e46b5bc798f9695139194077f4d86a27457fc53f86d971c8cede60da07",
"TT_reset_recovery-test_reset_backup.py::test_skip_backup_msg[BackupType.Slip39_Advanced-backup-dcbda5cf": "a906389f39ec320e597b73794002c2de9e89646c145a7c671bb79bceb103d219",
"TT_reset_recovery-test_reset_backup.py::test_skip_backup_msg[BackupType.Slip39_Basic-backup_fl-1577de4d": "f97e9b37e8fb9c622dce7e9228e2197773d7ed1856a80ce112dc8a6b8170cc17",
"TT_reset_recovery-test_reset_backup.py::test_skip_backup_manual[BackupType.Bip39-backup_flow_bip39]": "1026ce67dd329048c2ce7c88cdaaed90c164cf6d49fb4f730ed97e843bb610a6",
"TT_reset_recovery-test_reset_backup.py::test_skip_backup_manual[BackupType.Slip39_Advanced-bac-f67baa1c": "eed4e55650b7fd3a1fb1be2067910bb8c31049377608692c52dac833a7a6149a",
"TT_reset_recovery-test_reset_backup.py::test_skip_backup_manual[BackupType.Slip39_Basic-backup-6348e7fe": "005d7f70cac5f813040facd959cf1017f2c0a8c0679af12e571dc6ab377f417f",
"TT_reset_recovery-test_reset_backup.py::test_skip_backup_msg[BackupType.Bip39-backup_flow_bip39]": "ad673f99ca0e17be01efc93836c03005e1b2c3829235a8a579396e5a8c836a68",
"TT_reset_recovery-test_reset_backup.py::test_skip_backup_msg[BackupType.Slip39_Advanced-backup-dcbda5cf": "5fdc01e665654e77de7040d65406c92b47d9e698458e8f730a881939d310e744",
"TT_reset_recovery-test_reset_backup.py::test_skip_backup_msg[BackupType.Slip39_Basic-backup_fl-1577de4d": "ce1245792507b7f92561900cb800ff6e0ddf6a95f129c911d1b3c2e63ac38d9c",
"TT_reset_recovery-test_reset_bip39_t2.py::test_already_initialized": "72d6d1cdc13cd36c83c4e6dff0e1533515be8fe181a3305a29cd88a18fbaf4ba",
"TT_reset_recovery-test_reset_bip39_t2.py::test_failed_pin": "1d0135d6074f396ffa67ac396c195ede30f1fdb81e70ea1eb05a80866c7a1640",
"TT_reset_recovery-test_reset_bip39_t2.py::test_reset_device": "c76fd805dab221e86abba8c6701dd9e379a7a79ea7b2ceae2148eb6ed43c7521",
"TT_reset_recovery-test_reset_bip39_t2.py::test_reset_device_192": "a1f24c0be0728440c4bcef3b44e0b5c184351c04e20c4a11d4363a575ba6610e",
"TT_reset_recovery-test_reset_bip39_t2.py::test_reset_device_pin": "1c3411d5c96b1f07ad134867f0337c1b6ecfd7b232c6208a200996678655aba4",
"TT_reset_recovery-test_reset_bip39_t2.py::test_reset_failed_check": "357cf8c96fe0fc0b23d853af6115f43960a7a6d636f8c3d0a0009148d450fcdf",
"TT_reset_recovery-test_reset_recovery_bip39.py::test_reset_recovery": "8fe96b89846b69a4418b6dd040cc12d465fbde202160a983497a54f60418d509",
"TT_reset_recovery-test_reset_recovery_slip39_advanced.py::test_reset_recovery": "62e8d0a81d3bc5da2884a6a6b1486347d30e63de44f6c8f146d32c8cbd20f9ff",
"TT_reset_recovery-test_reset_recovery_slip39_basic.py::test_reset_recovery": "a48c75bd9af28c4c6c533a450e2e7be9c4fe44975e9c6e2b392e7cfd2ad008fb",
"TT_reset_recovery-test_reset_slip39_advanced.py::test_reset_device_slip39_advanced": "04ac301574263d3aac1b38ba06674b1e212a2262d28d836bdcdc208b775c579d",
"TT_reset_recovery-test_reset_slip39_basic.py::test_reset_device_slip39_basic": "4106461447a03b26e993f29810f8f8f9bd4f68965358d3e8e35c42dff5dc026b",
"TT_reset_recovery-test_reset_slip39_basic.py::test_reset_device_slip39_basic_256": "109099401a251c7c5a24d82bf96ae3c5e27649689be15cff13f215cde80c1f4b",
"TT_reset_recovery-test_reset_bip39_t2.py::test_failed_pin": "0febe48e64f03c8ea31735eac4099cacb408516d3e537db29a772130cd2b20e0",
"TT_reset_recovery-test_reset_bip39_t2.py::test_reset_device": "6b3bbc8676a70a074a7d62bf7f9001b93f0755839dc56de11f4f22409d1aa1ce",
"TT_reset_recovery-test_reset_bip39_t2.py::test_reset_device_192": "b28ef5748a9360d483104b1404b4d677b878045db09f0cae013cd3d25258cd3b",
"TT_reset_recovery-test_reset_bip39_t2.py::test_reset_device_pin": "1d442aa3d018c4dffc749566de16356bbaee67146f8a9de1ac7f8daa3f9ebf1f",
"TT_reset_recovery-test_reset_bip39_t2.py::test_reset_failed_check": "31834fe49e6988ddfbf8cca220aecb6271aaa3721914c0bc854ad6a5f899d717",
"TT_reset_recovery-test_reset_recovery_bip39.py::test_reset_recovery": "e5a53714cef4f4fd69bfb30a53cc9d560e528c57a9aba4ead5f727458ec1234d",
"TT_reset_recovery-test_reset_recovery_slip39_advanced.py::test_reset_recovery": "968c451afbce1b7323fb28374446b89c549347b7ecc78e672653d619fc7a822a",
"TT_reset_recovery-test_reset_recovery_slip39_basic.py::test_reset_recovery": "dfc6f83b7cb8bedcd796883060748017e221afec3b7324e77e33856c7e28bb94",
"TT_reset_recovery-test_reset_slip39_advanced.py::test_reset_device_slip39_advanced": "e50b93834692641ae99f3af8ab7ece3f35fd5c5e00f9a3700e9199f46a98749e",
"TT_reset_recovery-test_reset_slip39_basic.py::test_reset_device_slip39_basic": "ebc7f32b929cb65367355f70c0758e6b0116402508a435d2f702590b131b892a",
"TT_reset_recovery-test_reset_slip39_basic.py::test_reset_device_slip39_basic_256": "9450975c99307643997159f7ec4e2a63cf59811af7696ef581207a5e5e804aaa",
"TT_ripple-test_get_address.py::test_ripple_get_address": "72d6d1cdc13cd36c83c4e6dff0e1533515be8fe181a3305a29cd88a18fbaf4ba",
"TT_ripple-test_get_address.py::test_ripple_get_address_other": "72d6d1cdc13cd36c83c4e6dff0e1533515be8fe181a3305a29cd88a18fbaf4ba",
"TT_ripple-test_sign_tx.py::test_ripple_sign_invalid_fee": "72d6d1cdc13cd36c83c4e6dff0e1533515be8fe181a3305a29cd88a18fbaf4ba",
@ -1629,7 +1629,7 @@
"TT_test_msg_sd_protect.py::test_enable_disable": "ad58555b94ccb0f557a35530b536015a0a7c3143a4ce1b78b2612a9430b763eb",
"TT_test_msg_sd_protect.py::test_refresh": "2951a86d450d965dea7b27d46bdcd135bcc12bedf1a93b59251bf4f8e87297b1",
"TT_test_msg_sd_protect.py::test_wipe": "71fee372a637cd97a81e2e36a893674d2fa08e98eec996c6e5dd84f0579b0a64",
"TT_test_msg_wipedevice.py::test_autolock_not_retained": "1317e6f3f64cad65b1e8195331f12ce3b4e983b13df8a452a3c1343f1b767b07",
"TT_test_msg_wipedevice.py::test_autolock_not_retained": "2cc04a76de7911ea52afc1b3d819bde80aec607ba52111f2907d89ffbd2836a5",
"TT_test_msg_wipedevice.py::test_wipe_device": "d97a8029a951298c21cabd3518aa840e01b16a3a303d4f40387a6eb5f69ecf56",
"TT_test_passphrase_slip39_advanced.py::test_128bit_passphrase": "c897a0866515243f852057f3f74e783a21f8532544a07638295fb46b0ea5e7fc",
"TT_test_passphrase_slip39_advanced.py::test_256bit_passphrase": "c897a0866515243f852057f3f74e783a21f8532544a07638295fb46b0ea5e7fc",