apps/common/request_passphrase: update UI dialog of pp entry and keyboard

This commit is contained in:
Peter Jensen 2018-02-13 15:39:50 +01:00
parent 7b2fd6ae4c
commit 07c11228e6
2 changed files with 19 additions and 12 deletions

View File

@ -2,13 +2,12 @@ from trezor import res, ui, wire
async def request_passphrase_on_display(ctx):
from trezor.messages.FailureType import ActionCancelled
from trezor.ui.passphrase import PassphraseKeyboard, CANCELLED
ui.display.clear()
passphrase = await PassphraseKeyboard('Enter passphrase')
if passphrase == CANCELLED:
raise wire.FailureError(ActionCancelled, 'Passphrase cancelled')
return False
return passphrase
@ -33,17 +32,22 @@ async def request_passphrase(ctx):
from trezor.ui.text import Text
from trezor.ui.entry_select import EntrySelector
ui.display.clear()
res = False
text = Text(
'Enter passphrase', ui.ICON_RESET,
'Where to enter your', 'passphrase?')
entry = EntrySelector(text)
entry_type = await entry
if entry_type == 1:
return await request_passphrase_on_host(ctx)
else:
return await request_passphrase_on_display(ctx)
while not res:
ui.display.clear()
entry = EntrySelector(text)
entry_type = await entry
if entry_type == 1:
res = await request_passphrase_on_host(ctx)
else:
res = await request_passphrase_on_display(ctx)
return res
async def protect_by_passphrase(ctx):

View File

@ -87,7 +87,7 @@ class PassphraseKeyboard(ui.Widget):
self.prompt = prompt
self.page = page
self.input = Input(ui.grid(0, n_x=1, n_y=6), '')
self.back = Button(ui.grid(12), res.load(ui.ICON_BACK), style=ui.BTN_CLEAR)
self.back = Button(ui.grid(12), res.load(ui.ICON_CLEAR), style=ui.BTN_CANCEL)
self.done = Button(ui.grid(14), res.load(ui.ICON_CONFIRM), style=ui.BTN_CONFIRM)
self.keys = key_buttons(KEYBOARD_KEYS[self.page])
self.pbutton = None # pending key button
@ -146,9 +146,12 @@ class PassphraseKeyboard(ui.Widget):
self.pindex = index
self.input.edit(content, button is not None)
if content:
self.back.enable()
self.back = Button(ui.grid(12), res.load(ui.ICON_BACK), style=ui.BTN_CLEAR)
self.back.render()
else:
self.back.disable()
self.back.content = res.load(ui.ICON_CLEAR)
self.back.normal_style = ui.BTN_CANCEL['normal']
self.back.enable()
async def __iter__(self):
self.edit(self.input.content) # init button state