2016-11-15 12:48:31 +00:00
|
|
|
from trezor import wire, ui, loop
|
2018-02-21 14:04:49 +00:00
|
|
|
from apps.common import cache
|
2016-06-06 12:10:36 +00:00
|
|
|
|
2016-11-15 12:48:31 +00:00
|
|
|
# used to confirm/cancel the dialogs from outside of this module (i.e.
|
|
|
|
# through debug link)
|
2017-09-16 13:00:31 +00:00
|
|
|
if __debug__:
|
2018-02-21 14:04:49 +00:00
|
|
|
signal = cache.memory.setdefault('confirm_signal', loop.signal())
|
2016-11-15 12:48:31 +00:00
|
|
|
|
2016-06-06 12:10:36 +00:00
|
|
|
|
2017-10-10 13:34:23 +00:00
|
|
|
@ui.layout
|
2017-08-15 13:09:09 +00:00
|
|
|
async def confirm(ctx, content, 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
|
2017-08-15 13:09:09 +00:00
|
|
|
await ctx.call(ButtonRequest(code=code), ButtonAck)
|
2017-09-16 13:00:31 +00:00
|
|
|
|
|
|
|
if __debug__:
|
|
|
|
waiter = loop.wait(signal, dialog)
|
|
|
|
else:
|
|
|
|
waiter = dialog
|
|
|
|
return await waiter == CONFIRMED
|
2016-06-06 12:10:36 +00:00
|
|
|
|
2016-09-26 11:06:28 +00:00
|
|
|
|
2017-10-10 13:34:23 +00:00
|
|
|
@ui.layout
|
2017-08-15 13:09:09 +00:00
|
|
|
async def hold_to_confirm(ctx, content, code=None, *args, **kwargs):
|
2016-09-27 13:32:12 +00:00
|
|
|
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()
|
2017-03-20 20:40:53 +00:00
|
|
|
|
|
|
|
dialog = HoldToConfirmDialog(content, 'Hold to confirm', *args, **kwargs)
|
2016-09-27 13:32:12 +00:00
|
|
|
|
|
|
|
if code is None:
|
|
|
|
code = Other
|
2017-08-15 13:09:09 +00:00
|
|
|
await ctx.call(ButtonRequest(code=code), ButtonAck)
|
2017-09-16 13:00:31 +00:00
|
|
|
|
|
|
|
if __debug__:
|
|
|
|
waiter = loop.wait(signal, dialog)
|
|
|
|
else:
|
|
|
|
waiter = dialog
|
|
|
|
return await waiter == CONFIRMED
|
2016-09-27 13:32:12 +00:00
|
|
|
|
|
|
|
|
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')
|