1
0
mirror of https://github.com/trezor/trezor-firmware.git synced 2024-11-23 07:58:09 +00:00

src/apps/common/request_pin: cancel is optional

This commit is contained in:
Jan Pochyla 2018-02-22 15:20:20 +01:00
parent 168cbabbf5
commit 76590c44ad
2 changed files with 12 additions and 7 deletions

View File

@ -7,7 +7,7 @@ class PinCancelled(Exception):
@ui.layout
async def request_pin(code: int = None) -> str:
async def request_pin(code: int = None, cancellable: bool = True) -> str:
from trezor.ui.confirm import ConfirmDialog, CONFIRMED
from trezor.ui.pin import PinMatrix
@ -24,7 +24,7 @@ async def request_pin(code: int = None) -> str:
c.render()
else:
lock = res.load(ui.ICON_LOCK)
if c.content is not lock:
if c.content is not lock and cancellable:
c.normal_style = ui.BTN_CANCEL['normal']
c.content = lock
c.taint()
@ -37,6 +37,9 @@ async def request_pin(code: int = None) -> 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

View File

@ -3,22 +3,24 @@ from trezor import config
from trezor.pin import pin_to_int, show_pin_timeout
async def request_pin(ctx, code: int = None):
async def request_pin(ctx, *args, **kwargs):
from trezor.messages.ButtonRequest import ButtonRequest
from trezor.messages.wire_types import ButtonAck
from apps.common.request_pin import request_pin
await ctx.call(ButtonRequest(), ButtonAck)
return await request_pin(code)
return await request_pin(*args, **kwargs)
async def request_pin_confirm(ctx):
async def request_pin_confirm(ctx, *args, **kwargs):
from trezor.messages import PinMatrixRequestType
while True:
pin1 = await request_pin(ctx, PinMatrixRequestType.NewFirst)
pin2 = await request_pin(ctx, PinMatrixRequestType.NewSecond)
pin1 = await request_pin(
ctx, code=PinMatrixRequestType.NewFirst, *args, **kwargs)
pin2 = await request_pin(
ctx, code=PinMatrixRequestType.NewSecond, *args, **kwargs)
if pin1 == pin2:
return pin1
# TODO: display a message and wait