2016-10-06 10:31:03 +00:00
|
|
|
from trezor import wire, ui
|
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-27 14:08:02 +00:00
|
|
|
async def confirm(session_id, content=None, code=None, *args, **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-10-06 10:31:03 +00:00
|
|
|
ui.display.clear()
|
2016-09-27 14:08:02 +00:00
|
|
|
dialog = ConfirmDialog(content, *args, **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
|
|
|
|
2016-09-27 13:32:12 +00:00
|
|
|
@unimport
|
2016-09-27 14:08:02 +00:00
|
|
|
async def hold_to_confirm(session_id, content=None, code=None, *args, **kwargs):
|
2016-09-27 13:32:12 +00:00
|
|
|
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
|
|
|
|
|
2016-10-06 10:31:03 +00:00
|
|
|
ui.display.clear()
|
2016-09-27 13:32:12 +00:00
|
|
|
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)
|
2016-09-27 13:32:12 +00:00
|
|
|
|
|
|
|
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
|
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')
|