2019-05-13 13:06:34 +00:00
|
|
|
from trezor import wire
|
2018-07-02 18:40:51 +00:00
|
|
|
from trezor.messages import ButtonRequestType, MessageType
|
2018-02-27 15:35:21 +00:00
|
|
|
from trezor.messages.ButtonRequest import ButtonRequest
|
2019-05-13 13:06:34 +00:00
|
|
|
from trezor.ui.confirm import CONFIRMED, Confirm, HoldToConfirm
|
2016-11-15 12:48:31 +00:00
|
|
|
|
2019-05-13 13:06:34 +00:00
|
|
|
if __debug__:
|
|
|
|
from apps.debug import confirm_signal
|
2016-06-06 12:10:36 +00:00
|
|
|
|
2019-05-13 13:06:34 +00:00
|
|
|
|
|
|
|
async def confirm(
|
|
|
|
ctx,
|
|
|
|
content,
|
|
|
|
code=ButtonRequestType.Other,
|
|
|
|
confirm=Confirm.DEFAULT_CONFIRM,
|
|
|
|
confirm_style=Confirm.DEFAULT_CONFIRM_STYLE,
|
|
|
|
cancel=Confirm.DEFAULT_CANCEL,
|
|
|
|
cancel_style=Confirm.DEFAULT_CANCEL_STYLE,
|
2019-06-23 10:18:59 +00:00
|
|
|
major_confirm=None,
|
2019-05-13 13:06:34 +00:00
|
|
|
):
|
2018-07-02 18:40:51 +00:00
|
|
|
await ctx.call(ButtonRequest(code=code), MessageType.ButtonAck)
|
2017-09-16 13:00:31 +00:00
|
|
|
|
2019-05-13 13:06:34 +00:00
|
|
|
if content.__class__.__name__ == "Paginated":
|
|
|
|
content.pages[-1] = Confirm(
|
2019-06-23 10:18:59 +00:00
|
|
|
content.pages[-1],
|
|
|
|
confirm,
|
|
|
|
confirm_style,
|
|
|
|
cancel,
|
|
|
|
cancel_style,
|
|
|
|
major_confirm,
|
2019-05-13 13:06:34 +00:00
|
|
|
)
|
|
|
|
dialog = content
|
|
|
|
else:
|
2019-06-23 10:18:59 +00:00
|
|
|
dialog = Confirm(
|
|
|
|
content, confirm, confirm_style, cancel, cancel_style, major_confirm
|
|
|
|
)
|
2018-02-26 17:40:44 +00:00
|
|
|
|
2019-05-13 13:06:34 +00:00
|
|
|
if __debug__:
|
|
|
|
return await ctx.wait(dialog, confirm_signal) is CONFIRMED
|
|
|
|
else:
|
|
|
|
return await ctx.wait(dialog) is CONFIRMED
|
2016-06-06 12:10:36 +00:00
|
|
|
|
2016-09-26 11:06:28 +00:00
|
|
|
|
2019-05-13 13:06:34 +00:00
|
|
|
async def hold_to_confirm(
|
|
|
|
ctx,
|
|
|
|
content,
|
|
|
|
code=ButtonRequestType.Other,
|
|
|
|
confirm=HoldToConfirm.DEFAULT_CONFIRM,
|
|
|
|
confirm_style=HoldToConfirm.DEFAULT_CONFIRM_STYLE,
|
|
|
|
loader_style=HoldToConfirm.DEFAULT_LOADER_STYLE,
|
|
|
|
):
|
2018-07-02 18:40:51 +00:00
|
|
|
await ctx.call(ButtonRequest(code=code), MessageType.ButtonAck)
|
2017-09-16 13:00:31 +00:00
|
|
|
|
2019-05-13 13:06:34 +00:00
|
|
|
if content.__class__.__name__ == "Paginated":
|
|
|
|
content.pages[-1] = HoldToConfirm(
|
|
|
|
content.pages[-1], confirm, confirm_style, loader_style
|
|
|
|
)
|
|
|
|
dialog = content
|
|
|
|
else:
|
|
|
|
dialog = HoldToConfirm(content, confirm, confirm_style, loader_style)
|
2018-02-26 17:40:44 +00:00
|
|
|
|
2019-05-13 13:06:34 +00:00
|
|
|
if __debug__:
|
|
|
|
return await ctx.wait(dialog, confirm_signal) is CONFIRMED
|
|
|
|
else:
|
|
|
|
return await ctx.wait(dialog) is 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
|
|
|
confirmed = await confirm(*args, **kwargs)
|
|
|
|
if not confirmed:
|
2018-07-03 14:20:58 +00:00
|
|
|
raise wire.ActionCancelled("Cancelled")
|
2018-02-28 19:20:39 +00:00
|
|
|
|
|
|
|
|
|
|
|
async def require_hold_to_confirm(*args, **kwargs):
|
|
|
|
confirmed = await hold_to_confirm(*args, **kwargs)
|
|
|
|
if not confirmed:
|
2018-07-03 14:20:58 +00:00
|
|
|
raise wire.ActionCancelled("Cancelled")
|