1
0
mirror of https://github.com/trezor/trezor-firmware.git synced 2024-12-18 04:18:10 +00:00

refactor(core): enable mypy for apps.management

This commit is contained in:
Martin Milata 2021-03-24 18:11:58 +01:00
parent e57027fc5c
commit 31052007ff
7 changed files with 40 additions and 15 deletions

View File

@ -109,6 +109,7 @@ mypy:
src/main.py \ src/main.py \
src/apps/bitcoin \ src/apps/bitcoin \
src/apps/cardano \ src/apps/cardano \
src/apps/management \
src/apps/misc \ src/apps/misc \
src/apps/webauthn \ src/apps/webauthn \
src/trezor/ui src/trezor/ui

View File

@ -3,8 +3,11 @@ from storage.device import set_flags
from trezor import wire from trezor import wire
from trezor.messages import Success from trezor.messages import Success
if False:
from trezor.messages import ApplyFlags
async def apply_flags(ctx, msg):
async def apply_flags(ctx: wire.GenericContext, msg: ApplyFlags) -> Success:
if not storage.device.is_initialized(): if not storage.device.is_initialized():
raise wire.NotInitialized("Device is not initialized") raise wire.NotInitialized("Device is not initialized")
set_flags(msg.flags) set_flags(msg.flags)

View File

@ -33,7 +33,7 @@ def validate_homescreen(homescreen: bytes) -> None:
raise wire.DataError("Homescreen must be full-color TOIF image") raise wire.DataError("Homescreen must be full-color TOIF image")
async def apply_settings(ctx: wire.Context, msg: ApplySettings): async def apply_settings(ctx: wire.Context, msg: ApplySettings) -> Success:
if not storage.device.is_initialized(): if not storage.device.is_initialized():
raise wire.NotInitialized("Device is not initialized") raise wire.NotInitialized("Device is not initialized")
if ( if (
@ -99,7 +99,7 @@ async def apply_settings(ctx: wire.Context, msg: ApplySettings):
return Success(message="Settings applied") return Success(message="Settings applied")
async def require_confirm_change_homescreen(ctx): async def require_confirm_change_homescreen(ctx: wire.GenericContext) -> None:
await confirm_action( await confirm_action(
ctx, ctx,
"set_homescreen", "set_homescreen",
@ -109,7 +109,7 @@ async def require_confirm_change_homescreen(ctx):
) )
async def require_confirm_change_label(ctx, label): async def require_confirm_change_label(ctx: wire.GenericContext, label: str) -> None:
await confirm_action( await confirm_action(
ctx, ctx,
"set_label", "set_label",
@ -120,7 +120,9 @@ async def require_confirm_change_label(ctx, label):
) )
async def require_confirm_change_passphrase(ctx, use): async def require_confirm_change_passphrase(
ctx: wire.GenericContext, use: bool
) -> None:
if use: if use:
description = "Do you really want to enable passphrase encryption?" description = "Do you really want to enable passphrase encryption?"
else: else:
@ -135,8 +137,8 @@ async def require_confirm_change_passphrase(ctx, use):
async def require_confirm_change_passphrase_source( async def require_confirm_change_passphrase_source(
ctx, passphrase_always_on_device: bool ctx: wire.GenericContext, passphrase_always_on_device: bool
): ) -> None:
if passphrase_always_on_device: if passphrase_always_on_device:
description = "Do you really want to enter passphrase always on the device?" description = "Do you really want to enter passphrase always on the device?"
else: else:
@ -150,7 +152,9 @@ async def require_confirm_change_passphrase_source(
) )
async def require_confirm_change_display_rotation(ctx, rotation): async def require_confirm_change_display_rotation(
ctx: wire.GenericContext, rotation: int
) -> None:
if rotation == 0: if rotation == 0:
label = "north" label = "north"
elif rotation == 90: elif rotation == 90:
@ -171,7 +175,9 @@ async def require_confirm_change_display_rotation(ctx, rotation):
) )
async def require_confirm_change_autolock_delay(ctx, delay_ms): async def require_confirm_change_autolock_delay(
ctx: wire.GenericContext, delay_ms: int
) -> None:
await confirm_action( await confirm_action(
ctx, ctx,
"set_autolock_delay", "set_autolock_delay",
@ -182,7 +188,9 @@ async def require_confirm_change_autolock_delay(ctx, delay_ms):
) )
async def require_confirm_safety_checks(ctx, level: SafetyCheckLevel) -> None: async def require_confirm_safety_checks(
ctx: wire.GenericContext, level: SafetyCheckLevel
) -> None:
if level == SafetyCheckLevel.PromptAlways: if level == SafetyCheckLevel.PromptAlways:
await confirm_action( await confirm_action(
ctx, ctx,
@ -220,7 +228,9 @@ async def require_confirm_safety_checks(ctx, level: SafetyCheckLevel) -> None:
raise ValueError # enum value out of range raise ValueError # enum value out of range
async def require_confirm_experimental_features(ctx, enable: bool) -> None: async def require_confirm_experimental_features(
ctx: wire.GenericContext, enable: bool
) -> None:
if enable: if enable:
await confirm_action( await confirm_action(
ctx, ctx,

View File

@ -7,14 +7,19 @@ from apps.common import mnemonic
from .reset_device import backup_seed, layout from .reset_device import backup_seed, layout
if False:
from trezor.messages import BackupDevice
async def backup_device(ctx, msg):
async def backup_device(ctx: wire.Context, msg: BackupDevice) -> Success:
if not storage.device.is_initialized(): if not storage.device.is_initialized():
raise wire.NotInitialized("Device is not initialized") raise wire.NotInitialized("Device is not initialized")
if not storage.device.needs_backup(): if not storage.device.needs_backup():
raise wire.ProcessError("Seed already backed up") raise wire.ProcessError("Seed already backed up")
mnemonic_secret, mnemonic_type = mnemonic.get() mnemonic_secret, mnemonic_type = mnemonic.get()
if mnemonic_secret is None:
raise RuntimeError
storage.device.set_unfinished_backup(True) storage.device.set_unfinished_backup(True)
storage.device.set_backed_up() storage.device.set_backed_up()

View File

@ -11,6 +11,8 @@ from apps.common.request_pin import (
) )
if False: if False:
from typing import Awaitable
from trezor.messages import ChangePin from trezor.messages import ChangePin
@ -57,7 +59,7 @@ async def change_pin(ctx: wire.Context, msg: ChangePin) -> Success:
return Success(message=msg_wire) return Success(message=msg_wire)
def require_confirm_change_pin(ctx: wire.Context, msg: ChangePin) -> None: def require_confirm_change_pin(ctx: wire.Context, msg: ChangePin) -> Awaitable[None]:
has_pin = config.has_pin() has_pin = config.has_pin()
if msg.remove and has_pin: # removing pin if msg.remove and has_pin: # removing pin

View File

@ -6,8 +6,12 @@ from trezor.ui.layouts import confirm_action
from .apply_settings import reload_settings_from_storage from .apply_settings import reload_settings_from_storage
if False:
from trezor import wire
from trezor.messages import WipeDevice
async def wipe_device(ctx, msg):
async def wipe_device(ctx: wire.GenericContext, msg: WipeDevice) -> Success:
await confirm_action( await confirm_action(
ctx, ctx,
"confirm_wipe", "confirm_wipe",

View File

@ -1093,7 +1093,7 @@ async def request_passphrase_on_device(ctx: wire.GenericContext, max_len: int) -
async def request_pin_on_device( async def request_pin_on_device(
ctx: wire.GenericContext, ctx: wire.GenericContext,
prompt: str, prompt: str,
attempts_remaining: int, attempts_remaining: Optional[int],
allow_cancel: bool, allow_cancel: bool,
) -> str: ) -> str:
await button_request(ctx, "pin_device", code=ButtonRequestType.PinEntry) await button_request(ctx, "pin_device", code=ButtonRequestType.PinEntry)