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

29 lines
838 B
Python
Raw Normal View History

from trezor import wire
from trezor.utils import unimport
@unimport
2016-09-26 11:06:28 +00:00
async def confirm(session_id, content=None, code=None, **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
2016-06-10 09:43:37 +00:00
dialog = ConfirmDialog(content, **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
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')