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

request_pin, request_passphrase: ui fixes

This commit is contained in:
Jan Pochyla 2018-02-27 20:21:54 +01:00
parent c1f097f2b4
commit 9f48e3d471
7 changed files with 29 additions and 18 deletions

View File

@ -9,7 +9,7 @@ class PinCancelled(Exception):
@ui.layout
async def request_pin(code: int = None, cancellable: bool = True) -> str:
async def request_pin(code = None, cancellable: bool = True) -> str:
def onchange():
c = dialog.cancel
@ -18,15 +18,20 @@ async def request_pin(code: int = None, cancellable: bool = True) -> str:
if c.content is not back:
c.normal_style = ui.BTN_CLEAR['normal']
c.content = back
c.enable()
c.taint()
c.render()
else:
lock = res.load(ui.ICON_LOCK)
if c.content is not lock and cancellable:
if not cancellable and c.content:
c.content = ''
c.disable()
c.taint()
elif c.content is not lock:
c.normal_style = ui.BTN_CANCEL['normal']
c.content = lock
c.enable()
c.taint()
c.render()
c.render()
label = _get_label(code)
matrix = PinMatrix(label, with_zero=True)
@ -35,9 +40,6 @@ async def request_pin(code: int = None, cancellable: bool = True) -> str:
dialog.cancel.area = ui.grid(12)
dialog.confirm.area = ui.grid(14)
matrix.onchange()
if not cancellable:
dialog.cancel.content = ''
dialog.cancel.disable()
while True:
result = await dialog
@ -50,7 +52,9 @@ async def request_pin(code: int = None, cancellable: bool = True) -> str:
raise PinCancelled()
def _get_label(code: int):
def _get_label(code):
if isinstance(code, str):
return code
if code is None:
code = PinMatrixRequestType.Current
if code == PinMatrixRequestType.NewFirst:

View File

@ -1,4 +1,4 @@
from trezor import config, loop, ui
from trezor import config, loop, ui, wire
from trezor.messages import FailureType, PinMatrixRequestType
from trezor.messages.ButtonRequest import ButtonRequest
from trezor.messages.ButtonRequestType import Other
@ -8,7 +8,7 @@ from trezor.messages import wire_types
from trezor.pin import pin_to_int, show_pin_timeout
from trezor.ui.text import Text
from apps.common.confirm import require_confirm
from apps.common.request_pin import request_pin
from apps.common.request_pin import request_pin, PinCancelled
async def change_pin(ctx, msg):
@ -62,11 +62,13 @@ def confirm_change_pin(ctx, msg):
'set new PIN?'))
async def request_pin_ack(ctx, code=None, *args, **kwargs):
if code is None:
code = Other
await ctx.call(ButtonRequest(code=code), wire_types.ButtonAck)
return await request_pin(*args, **kwargs)
async def request_pin_ack(ctx, *args, **kwargs):
# TODO: send PinMatrixRequest here, with specific code?
await ctx.call(ButtonRequest(code=Other), wire_types.ButtonAck)
try:
return await request_pin(*args, **kwargs)
except PinCancelled:
raise wire.FailureError(FailureType.ActionCancelled, 'Cancelled')
async def request_pin_confirm(ctx, *args, **kwargs):

View File

@ -6,7 +6,7 @@ from trezor.messages.FailureType import ProcessError, UnexpectedMessage
from trezor.messages.Success import Success
from trezor.messages.wire_types import ButtonAck
from trezor.pin import pin_to_int
from trezor.ui.keyboard import MnemonicKeyboard
from trezor.ui.mnemonic import MnemonicKeyboard
from trezor.ui.text import Text
from trezor.ui.word_select import WordSelector
from trezor.utils import format_ordinal

View File

@ -7,7 +7,7 @@ from trezor.messages.EntropyRequest import EntropyRequest
from trezor.messages.Success import Success
from trezor.pin import pin_to_int
from trezor.ui.confirm import HoldToConfirmDialog
from trezor.ui.keyboard import MnemonicKeyboard
from trezor.ui.mnemonic import MnemonicKeyboard
from trezor.ui.scroll import Scrollpage, animate_swipe, paginate
from trezor.ui.text import Text
from trezor.utils import chunks, format_ordinal

View File

@ -4,6 +4,7 @@ from apps.common.request_pin import request_pin
async def bootscreen():
label = None
while True:
try:
if not config.has_pin():
@ -11,9 +12,11 @@ async def bootscreen():
return
await lockscreen()
while True:
pin = await request_pin()
pin = await request_pin(label)
if config.unlock(pin_to_int(pin), show_pin_timeout):
return
else:
label = 'Wrong PIN, enter again'
except: # noqa: E722
pass

View File

@ -189,3 +189,5 @@ class PassphraseKeyboard(ui.Widget):
else:
self.page = (self.page - 1) % len(KEYBOARD_KEYS)
self.keys = key_buttons(KEYBOARD_KEYS[self.page])
self.back.taint()
self.done.taint()