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