1
0
mirror of https://github.com/trezor/trezor-firmware.git synced 2024-11-13 19:18:56 +00:00
trezor-firmware/src/apps/common/confirm.py

50 lines
1.7 KiB
Python
Raw Normal View History

from trezor import wire, ui
from trezor.utils import unimport
@unimport
2016-09-27 14:08:02 +00:00
async def confirm(session_id, content=None, code=None, *args, **kwargs):
from trezor.ui.confirm import ConfirmDialog, CONFIRMED
from trezor.messages.ButtonRequest import ButtonRequest
from trezor.messages.ButtonRequestType import Other
2016-09-26 11:06:28 +00:00
from trezor.messages.wire_types import ButtonAck
ui.display.clear()
2016-09-27 14:08:02 +00:00
dialog = ConfirmDialog(content, *args, **kwargs)
dialog.render()
if code is None:
code = Other
2016-09-26 11:06:28 +00:00
await wire.reply_message(session_id, ButtonRequest(code=code), ButtonAck)
return await dialog == CONFIRMED
2016-09-26 11:06:28 +00:00
@unimport
2016-09-27 14:08:02 +00:00
async def hold_to_confirm(session_id, content=None, code=None, *args, **kwargs):
from trezor.ui.button import Button, CONFIRM_BUTTON, CONFIRM_BUTTON_ACTIVE
from trezor.ui.confirm import HoldToConfirmDialog, CONFIRMED
from trezor.messages.ButtonRequest import ButtonRequest
from trezor.messages.ButtonRequestType import Other
from trezor.messages.wire_types import ButtonAck
ui.display.clear()
button = Button((0, 240 - 48, 240, 48), 'Hold to confirm',
normal_style=CONFIRM_BUTTON,
active_style=CONFIRM_BUTTON_ACTIVE)
2016-09-27 14:08:02 +00:00
dialog = HoldToConfirmDialog(button, content, *args, **kwargs)
if code is None:
code = Other
await wire.reply_message(session_id, ButtonRequest(code=code), ButtonAck)
return await dialog == CONFIRMED
2016-09-26 11:06:28 +00:00
@unimport
async def require_confirm(*args, **kwargs):
2016-09-26 11:06:28 +00:00
from trezor.messages.FailureType import ActionCancelled
confirmed = await confirm(*args, **kwargs)
if not confirmed:
raise wire.FailureError(ActionCancelled, 'Cancelled')