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

refactor(core/ui): remove dependencies on old layouts

[no changelog]
This commit is contained in:
Martin Milata 2022-03-31 17:40:07 +02:00
parent 2a3f0c16bd
commit 2f987c3c5e
22 changed files with 251 additions and 44 deletions

View File

@ -517,13 +517,19 @@ if FROZEN:
SOURCE_PY.extend(Glob(SOURCE_PY_DIR + 'trezor/ui/constants/__init__.py'))
SOURCE_PY.extend(Glob(SOURCE_PY_DIR + 'trezor/ui/layouts/__init__.py'))
SOURCE_PY.extend(Glob(SOURCE_PY_DIR + 'trezor/ui/layouts/common.py'))
SOURCE_PY.extend(Glob(SOURCE_PY_DIR + 'trezor/ui/layouts/reset.py'))
SOURCE_PY.extend(Glob(SOURCE_PY_DIR + 'trezor/ui/layouts/recovery.py'))
if EVERYTHING:
SOURCE_PY.extend(Glob(SOURCE_PY_DIR + 'trezor/ui/layouts/altcoin.py'))
SOURCE_PY.extend(Glob(SOURCE_PY_DIR + 'trezor/ui/layouts/webauthn.py'))
if TREZOR_MODEL == 'T' and UI2:
SOURCE_PY.extend(Glob(SOURCE_PY_DIR + 'trezor/ui/components/tt/*.py'))
SOURCE_PY.extend(Glob(SOURCE_PY_DIR + 'trezor/ui/constants/tt.py'))
SOURCE_PY.extend(Glob(SOURCE_PY_DIR + 'trezor/ui/layouts/tt_v2/__init__.py'))
SOURCE_PY.extend(Glob(SOURCE_PY_DIR + 'trezor/ui/layouts/tt/__init__.py'))
SOURCE_PY.extend(Glob(SOURCE_PY_DIR + 'trezor/ui/layouts/tt_v2/reset.py'))
SOURCE_PY.extend(Glob(SOURCE_PY_DIR + 'trezor/ui/layouts/tt_v2/recovery.py'))
if EVERYTHING:
SOURCE_PY.extend(Glob(SOURCE_PY_DIR + 'trezor/ui/layouts/tt/webauthn.py'))
SOURCE_PY.extend(Glob(SOURCE_PY_DIR + 'trezor/ui/layouts/tt_v2/altcoin.py'))
SOURCE_PY.extend(Glob(SOURCE_PY_DIR + 'trezor/ui/layouts/tt_v2/webauthn.py'))
elif TREZOR_MODEL == 'T':
SOURCE_PY.extend(Glob(SOURCE_PY_DIR + 'trezor/ui/components/tt/*.py'))
SOURCE_PY.extend(Glob(SOURCE_PY_DIR + 'trezor/ui/constants/tt.py'))

View File

@ -192,8 +192,14 @@ trezor.ui.container
import trezor.ui.container
trezor.ui.layouts
import trezor.ui.layouts
trezor.ui.layouts.altcoin
import trezor.ui.layouts.altcoin
trezor.ui.layouts.common
import trezor.ui.layouts.common
trezor.ui.layouts.recovery
import trezor.ui.layouts.recovery
trezor.ui.layouts.reset
import trezor.ui.layouts.reset
trezor.ui.layouts.t1
import trezor.ui.layouts.t1
trezor.ui.layouts.tt
@ -206,6 +212,12 @@ trezor.ui.layouts.tt.reset
import trezor.ui.layouts.tt.reset
trezor.ui.layouts.tt_v2
import trezor.ui.layouts.tt_v2
trezor.ui.layouts.tt_v2.altcoin
import trezor.ui.layouts.tt_v2.altcoin
trezor.ui.layouts.tt_v2.recovery
import trezor.ui.layouts.tt_v2.recovery
trezor.ui.layouts.tt_v2.reset
import trezor.ui.layouts.tt_v2.reset
trezor.ui.loader
import trezor.ui.loader
trezor.ui.popup
@ -438,6 +450,10 @@ if not utils.BITCOIN_ONLY:
import trezor.ui.components.tt.webauthn
trezor.ui.layouts.tt.webauthn
import trezor.ui.layouts.tt.webauthn
trezor.ui.layouts.tt_v2.webauthn
import trezor.ui.layouts.tt_v2.webauthn
trezor.ui.layouts.webauthn
import trezor.ui.layouts.webauthn
apps.binance
import apps.binance
apps.binance.get_address

View File

@ -9,7 +9,7 @@ from trezor.messages import (
)
from trezor.strings import format_amount
from trezor.ui.layouts import confirm_properties
from trezor.ui.layouts.tt.altcoin import confirm_transfer_binance
from trezor.ui.layouts.altcoin import confirm_transfer_binance
from . import helpers

View File

@ -11,7 +11,7 @@ from .. import addresses
from . import omni
if not utils.BITCOIN_ONLY:
from trezor.ui.layouts.tt import altcoin
from trezor.ui.layouts import altcoin
if TYPE_CHECKING:

View File

@ -15,7 +15,7 @@ from trezor.ui.layouts import (
confirm_total,
should_show_more,
)
from trezor.ui.layouts.tt.altcoin import confirm_total_ethereum
from trezor.ui.layouts.altcoin import confirm_total_ethereum
from . import networks, tokens
from .helpers import address_from_bytes, decode_typed_data, get_type_name

View File

@ -5,7 +5,7 @@ from trezor import ui, wire
from trezor.enums import ButtonRequestType
from trezor.ui.layouts import confirm_action, show_success, show_warning
from trezor.ui.layouts.common import button_request
from trezor.ui.layouts.tt.recovery import ( # noqa: F401
from trezor.ui.layouts.recovery import ( # noqa: F401
continue_recovery,
request_word,
request_word_count,

View File

@ -3,7 +3,7 @@ from typing import Sequence
from trezor import ui, utils, wire
from trezor.enums import ButtonRequestType
from trezor.ui.layouts import confirm_action, confirm_blob, show_success, show_warning
from trezor.ui.layouts.tt.reset import ( # noqa: F401
from trezor.ui.layouts.reset import ( # noqa: F401
confirm_word,
show_share_words,
slip39_advanced_prompt_group_threshold,

View File

@ -3,7 +3,7 @@ from typing import TYPE_CHECKING
from trezor.enums import ButtonRequestType
from trezor.strings import format_amount
from trezor.ui.layouts import confirm_metadata
from trezor.ui.layouts.tt.altcoin import confirm_total_ripple
from trezor.ui.layouts.altcoin import confirm_total_ripple
from . import helpers

View File

@ -3,7 +3,7 @@ from trezor import wire
from trezor.messages import Success, WebAuthnAddResidentCredential
from trezor.ui.components.common.webauthn import ConfirmInfo
from trezor.ui.layouts import show_error_and_raise
from trezor.ui.layouts.tt.webauthn import confirm_webauthn
from trezor.ui.layouts.webauthn import confirm_webauthn
from .credential import Fido2Credential
from .resident_credentials import store_resident_credential

View File

@ -13,7 +13,7 @@ from trezor.crypto.curve import nist256p1
from trezor.ui.components.common.confirm import Pageable
from trezor.ui.components.common.webauthn import ConfirmInfo
from trezor.ui.layouts import show_popup
from trezor.ui.layouts.tt.webauthn import confirm_webauthn, confirm_webauthn_reset
from trezor.ui.layouts.webauthn import confirm_webauthn, confirm_webauthn_reset
from apps.base import set_homescreen
from apps.common import cbor

View File

@ -3,7 +3,7 @@ import storage.resident_credentials
from trezor import wire
from trezor.messages import Success, WebAuthnRemoveResidentCredential
from trezor.ui.components.common.webauthn import ConfirmInfo
from trezor.ui.layouts.tt.webauthn import confirm_webauthn
from trezor.ui.layouts.webauthn import confirm_webauthn
from .credential import Fido2Credential
from .resident_credentials import get_resident_credential

View File

@ -3,17 +3,17 @@ from trezor import utils
from .common import * # noqa: F401,F403
try:
ui2 = True
UI2 = True
import trezorui2 # noqa: F401
except ImportError:
ui2 = False
UI2 = False
# NOTE: using any import magic probably causes mypy not to check equivalence of
# layout type signatures across models
if utils.MODEL == "1":
from .t1 import * # noqa: F401,F403
elif utils.MODEL == "T":
if not ui2:
if not UI2:
from .tt import * # noqa: F401,F403
else:
from .tt_v2 import * # noqa: F401,F403

View File

@ -0,0 +1,6 @@
from . import UI2
if UI2:
from .tt_v2.altcoin import * # noqa: F401,F403
else:
from .tt.altcoin import * # noqa: F401,F403

View File

@ -12,13 +12,6 @@ if TYPE_CHECKING:
ExceptionType = BaseException | type[BaseException]
if __debug__:
from trezor import utils
if utils.MODEL == "T":
from ..components.tt.scroll import Paginated
async def button_request(
ctx: wire.GenericContext,
br_type: str,
@ -37,6 +30,8 @@ async def interact(
br_code: ButtonRequestType = ButtonRequestType.Other,
) -> Any:
if layout.__class__.__name__ == "Paginated":
from ..components.tt.scroll import Paginated
assert isinstance(layout, Paginated)
return await layout.interact(ctx, code=br_code)
else:

View File

@ -0,0 +1,6 @@
from . import UI2
if UI2:
from .tt_v2.recovery import * # noqa: F401,F403
else:
from .tt.recovery import * # noqa: F401,F403

View File

@ -0,0 +1,6 @@
from . import UI2
if UI2:
from .tt_v2.reset import * # noqa: F401,F403
else:
from .tt.reset import * # noqa: F401,F403

View File

@ -111,7 +111,12 @@ async def confirm_action(
async def confirm_reset_device(
ctx: wire.GenericContext, prompt: str, recovery: bool = False
) -> None:
raise NotImplementedError
return await confirm_action(
ctx,
"recover_device" if recovery else "setup_device",
"not implemented",
action="not implemented",
)
# TODO cleanup @ redesign
@ -266,6 +271,15 @@ async def confirm_output(
raise NotImplementedError
async def confirm_payment_request(
ctx: wire.GenericContext,
recipient_name: str,
amount: str,
memos: list[str],
) -> Any:
raise NotImplementedError
async def should_show_more(
ctx: wire.GenericContext,
title: str,
@ -438,7 +452,7 @@ async def show_popup(
def draw_simple_text(title: str, description: str = "") -> None:
raise NotImplementedError
log.error(__name__, "draw_simple_text not implemented")
async def request_passphrase_on_device(ctx: wire.GenericContext, max_len: int) -> str:
@ -486,23 +500,3 @@ async def request_pin_on_device(
raise wire.PinCancelled
assert isinstance(result, str)
return result
async def request_word(
ctx: wire.GenericContext, word_index: int, word_count: int, is_slip39: bool
) -> str:
if is_slip39:
keyboard: Any = _RustLayout(
trezorui2.request_bip39(
prompt=f"Type word {word_index + 1} of {word_count}:"
)
)
else:
keyboard = _RustLayout(
trezorui2.request_slip39(
prompt=f"Type word {word_index + 1} of {word_count}:"
)
)
word: str = await ctx.wait(keyboard)
return word

View File

@ -0,0 +1,36 @@
from typing import TYPE_CHECKING
from trezor import wire
if TYPE_CHECKING:
from typing import Sequence
pass
async def confirm_total_ethereum(
ctx: wire.GenericContext, total_amount: str, gas_price: str, fee_max: str
) -> None:
raise NotImplementedError
async def confirm_total_ripple(
ctx: wire.GenericContext,
address: str,
amount: str,
) -> None:
raise NotImplementedError
async def confirm_transfer_binance(
ctx: wire.GenericContext, inputs_outputs: Sequence[tuple[str, str, str]]
) -> None:
raise NotImplementedError
async def confirm_decred_sstx_submission(
ctx: wire.GenericContext,
address: str,
amount: str,
) -> None:
raise NotImplementedError

View File

@ -0,0 +1,61 @@
from typing import TYPE_CHECKING
from trezor import wire
import trezorui2
from . import _RustLayout
if TYPE_CHECKING:
from typing import Iterable, Callable, Any
pass
async def request_word_count(ctx: wire.GenericContext, dry_run: bool) -> int:
raise NotImplementedError
async def request_word(
ctx: wire.GenericContext, word_index: int, word_count: int, is_slip39: bool
) -> str:
if is_slip39:
keyboard: Any = _RustLayout(
trezorui2.request_bip39(
prompt=f"Type word {word_index + 1} of {word_count}:"
)
)
else:
keyboard = _RustLayout(
trezorui2.request_slip39(
prompt=f"Type word {word_index + 1} of {word_count}:"
)
)
word: str = await ctx.wait(keyboard)
return word
async def show_remaining_shares(
ctx: wire.GenericContext,
groups: Iterable[tuple[int, tuple[str, ...]]], # remaining + list 3 words
shares_remaining: list[int],
group_threshold: int,
) -> None:
raise NotImplementedError
async def show_group_share_success(
ctx: wire.GenericContext, share_index: int, group_index: int
) -> None:
raise NotImplementedError
async def continue_recovery(
ctx: wire.GenericContext,
button_label: str,
text: str,
subtext: str | None,
info_func: Callable | None,
) -> bool:
raise NotImplementedError

View File

@ -0,0 +1,55 @@
from typing import TYPE_CHECKING
from trezor import wire
if TYPE_CHECKING:
from trezor.enums import BackupType
from typing import Sequence
async def show_share_words(
ctx: wire.GenericContext,
share_words: Sequence[str],
share_index: int | None = None,
group_index: int | None = None,
) -> None:
raise NotImplementedError
async def confirm_word(
ctx: wire.GenericContext,
share_index: int | None,
share_words: Sequence[str],
offset: int,
count: int,
group_index: int | None = None,
) -> bool:
raise NotImplementedError
async def slip39_show_checklist(
ctx: wire.GenericContext, step: int, backup_type: BackupType
) -> None:
raise NotImplementedError
async def slip39_prompt_threshold(
ctx: wire.GenericContext, num_of_shares: int, group_id: int | None = None
) -> int:
raise NotImplementedError
async def slip39_prompt_number_of_shares(
ctx: wire.GenericContext, group_id: int | None = None
) -> int:
raise NotImplementedError
async def slip39_advanced_prompt_number_of_groups(ctx: wire.GenericContext) -> int:
raise NotImplementedError
async def slip39_advanced_prompt_group_threshold(
ctx: wire.GenericContext, num_of_groups: int
) -> int:
raise NotImplementedError

View File

@ -0,0 +1,20 @@
from typing import TYPE_CHECKING
from trezor import wire
from ...components.common.webauthn import ConfirmInfo
if TYPE_CHECKING:
Pageable = object
async def confirm_webauthn(
ctx: wire.GenericContext | None,
info: ConfirmInfo,
pageable: Pageable | None = None,
) -> bool:
raise NotImplementedError
async def confirm_webauthn_reset() -> bool:
raise NotImplementedError

View File

@ -0,0 +1,6 @@
from . import UI2
if UI2:
from .tt_v2.webauthn import * # noqa: F401,F403
else:
from .tt.webauthn import * # noqa: F401,F403