src/apps: use more specific ButtonRequestType

This commit is contained in:
Jan Pochyla 2018-02-27 01:50:52 +01:00
parent 0eff62bb5c
commit 5e8ea18cce
4 changed files with 22 additions and 16 deletions

View File

@ -3,30 +3,33 @@ from trezor import ui, wire
async def layout_apply_settings(ctx, msg): async def layout_apply_settings(ctx, msg):
from trezor.messages.Success import Success from trezor.messages.Success import Success
from trezor.messages.FailureType import ProcessError from trezor.messages import ButtonRequestType, FailureType
from trezor.ui.text import Text from trezor.ui.text import Text
from ..common.confirm import require_confirm from ..common.confirm import require_confirm
from ..common import storage from ..common import storage
if msg.homescreen is None and msg.label is None and msg.language is None and msg.use_passphrase is None: if msg.homescreen is None and msg.label is None and msg.language is None and msg.use_passphrase is None:
raise wire.FailureError(ProcessError, 'No setting provided') raise wire.FailureError(FailureType.ProcessError, 'No setting provided')
if msg.homescreen is not None: if msg.homescreen is not None:
await require_confirm(ctx, Text( await require_confirm(ctx, Text(
'Change homescreen', ui.ICON_DEFAULT, 'Change homescreen', ui.ICON_DEFAULT,
'Do you really want to', 'change homescreen?')) 'Do you really want to', 'change homescreen?'),
code=ButtonRequestType.ProtectCall)
if msg.label is not None: if msg.label is not None:
await require_confirm(ctx, Text( await require_confirm(ctx, Text(
'Change label', ui.ICON_DEFAULT, 'Change label', ui.ICON_DEFAULT,
'Do you really want to', 'change label to', 'Do you really want to', 'change label to',
ui.BOLD, '%s?' % msg.label)) # TODO: split label (bold) and '?' (normal) once we support mixed styles on one line ui.BOLD, '%s?' % msg.label), # TODO: split label (bold) and '?' (normal) once we support mixed styles on one line
code=ButtonRequestType.ProtectCall)
if msg.language is not None: if msg.language is not None:
await require_confirm(ctx, Text( await require_confirm(ctx, Text(
'Change language', ui.ICON_DEFAULT, 'Change language', ui.ICON_DEFAULT,
'Do you really want to', 'change language to', 'Do you really want to', 'change language to',
ui.BOLD, '%s?' % msg.language)) # TODO: split lang (bold) and '?' (normal) once we support mixed styles on one line ui.BOLD, '%s?' % msg.language), # TODO: split lang (bold) and '?' (normal) once we support mixed styles on one line
code=ButtonRequestType.ProtectCall)
if msg.use_passphrase is not None: if msg.use_passphrase is not None:
await require_confirm(ctx, Text( await require_confirm(ctx, Text(
@ -34,7 +37,8 @@ async def layout_apply_settings(ctx, msg):
ui.ICON_DEFAULT, ui.ICON_DEFAULT,
'Do you really want to', 'Do you really want to',
'enable passphrase' if msg.use_passphrase else 'disable passphrase', 'enable passphrase' if msg.use_passphrase else 'disable passphrase',
'encryption?')) 'encryption?'),
code=ButtonRequestType.ProtectCall)
storage.load_settings(label=msg.label, storage.load_settings(label=msg.label,
use_passphrase=msg.use_passphrase, use_passphrase=msg.use_passphrase,

View File

@ -2,12 +2,15 @@ from trezor import config, loop, ui
from trezor.pin import pin_to_int, show_pin_timeout from trezor.pin import pin_to_int, show_pin_timeout
async def request_pin(ctx, *args, **kwargs): async def request_pin(ctx, code=None, *args, **kwargs):
from trezor.messages.ButtonRequest import ButtonRequest from trezor.messages.ButtonRequest import ButtonRequest
from trezor.messages.ButtonRequestType import Other
from trezor.messages.wire_types import ButtonAck from trezor.messages.wire_types import ButtonAck
from apps.common.request_pin import request_pin from apps.common.request_pin import request_pin
await ctx.call(ButtonRequest(), ButtonAck) if code is None:
code = Other
await ctx.call(ButtonRequest(code=code), ButtonAck)
return await request_pin(*args, **kwargs) return await request_pin(*args, **kwargs)
@ -21,8 +24,7 @@ async def pin_mismatch():
'Entered PINs do not', 'Entered PINs do not',
'match each other.', 'match each other.',
'', '',
'Please, try again...', 'Please, try again...')
)
text.render() text.render()
await loop.sleep(3 * 1000 * 1000) await loop.sleep(3 * 1000 * 1000)

View File

@ -1,11 +1,12 @@
from trezor import ui from trezor import ui
from trezor.messages import ButtonRequestType
from trezor.messages.Success import Success
from trezor.ui.text import Text
from apps.common import storage
from apps.common.confirm import hold_to_confirm
async def layout_wipe_device(ctx, msg): async def layout_wipe_device(ctx, msg):
from trezor.messages.Success import Success
from trezor.ui.text import Text
from ..common.confirm import hold_to_confirm
from ..common import storage
await hold_to_confirm(ctx, Text( await hold_to_confirm(ctx, Text(
'Wipe device', 'Wipe device',
@ -13,6 +14,7 @@ async def layout_wipe_device(ctx, msg):
ui.NORMAL, 'Do you really want to', 'wipe the device?', ui.NORMAL, 'Do you really want to', 'wipe the device?',
ui.NORMAL, '', 'All data will be lost.', ui.NORMAL, '', 'All data will be lost.',
icon_color=ui.RED), icon_color=ui.RED),
code=ButtonRequestType.WipeDevice,
button_style=ui.BTN_CANCEL, button_style=ui.BTN_CANCEL,
loader_style=ui.LDR_DANGER) loader_style=ui.LDR_DANGER)

View File

@ -8,8 +8,6 @@ from trezor.ui.text import Text
from apps.common import seed from apps.common import seed
from apps.common.confirm import require_confirm from apps.common.confirm import require_confirm
from ubinascii import hexlify
async def cipher_key_value(ctx, msg): async def cipher_key_value(ctx, msg):
if len(msg.value) % 16 > 0: if len(msg.value) % 16 > 0: