async def confirm(session_id, content, code=None, *args, **kwargs): from trezor.ui.confirm import ConfirmDialog, CONFIRMED from trezor.messages.ButtonRequest import ButtonRequest from trezor.messages.ButtonRequestType import Other from trezor.messages.wire_types import ButtonAck ui.display.clear() dialog = ConfirmDialog(content, *args, **kwargs) dialog.render() if code is None: code = Other await wire.call(session_id, ButtonRequest(code=code), ButtonAck) return await loop.Wait((signal, dialog)) == CONFIRMED
async def tx_dialog( ctx, code, content, cancel_btn, confirm_btn, cancel_style, confirm_style, scroll_tuple=None, ): from trezor.messages import MessageType from trezor.messages.ButtonRequest import ButtonRequest from trezor.ui.confirm import ConfirmDialog from trezor.ui.scroll import Scrollpage await ctx.call(ButtonRequest(code=code), MessageType.ButtonAck) if scroll_tuple and scroll_tuple[1] > 1: content = Scrollpage(content, scroll_tuple[0], scroll_tuple[1]) dialog = ConfirmDialog( content, cancel=cancel_btn, confirm=confirm_btn, cancel_style=cancel_style, confirm_style=confirm_style, ) return await ctx.wait(dialog)
async def request_pin_on_display(ctx: wire.Context, code: int=None) -> str: from trezor.messages.ButtonRequest import ButtonRequest from trezor.messages.ButtonRequestType import ProtectCall from trezor.messages.FailureType import PinCancelled from trezor.messages.wire_types import ButtonAck from trezor.ui.confirm import ConfirmDialog, CONFIRMED from trezor.ui.pin import PinMatrix if __debug__: global matrix _, label = _get_code_and_label(code) await ctx.call(ButtonRequest(code=ProtectCall), ButtonAck) ui.display.clear() matrix = PinMatrix(label) dialog = ConfirmDialog(matrix) pin = matrix.pin matrix = None if await dialog != CONFIRMED: raise wire.FailureError(PinCancelled, 'PIN cancelled') return pin
async def request_pin(code: int = None) -> str: from trezor.ui.confirm import ConfirmDialog, CONFIRMED from trezor.ui.pin import PinMatrix label = _get_label(code) def onchange(): c = dialog.cancel if matrix.pin: c.content = res.load(ui.ICON_CLEAR) else: c.content = res.load(ui.ICON_LOCK) c.taint() c.render() ui.display.clear() matrix = PinMatrix(label, with_zero=True) matrix.onchange = onchange dialog = ConfirmDialog(matrix) dialog.cancel.area = ui.grid(12) dialog.confirm.area = ui.grid(14) matrix.onchange() while True: result = await dialog if result == CONFIRMED: return matrix.pin elif result != CONFIRMED and matrix.pin: matrix.change('') continue else: raise PinCancelled()
async def confirm(ctx, content, code=None, *args, **kwargs): if code is None: code = ButtonRequestType.Other await ctx.call(ButtonRequest(code=code), wire_types.ButtonAck) dialog = ConfirmDialog(content, *args, **kwargs) return await ctx.wait(dialog) == CONFIRMED
async def confirm_layout(self) -> None: from trezor.ui.confirm import ConfirmDialog, CONFIRMED from trezor.ui.text import Text app_id = bytes(self.app_id) # could be bytearray, which doesn't have __hash__ if app_id == _BOGUS_APPID and self.action == _CONFIRM_REGISTER: text = Text("U2F", ui.ICON_WRONG, icon_color=ui.RED) text.normal( "Another U2F device", "was used to register", "in this application." ) text.render() dialog = ConfirmDialog(text) else: content = ConfirmContent(self.action, app_id) dialog = ConfirmDialog(content) self.confirmed = await dialog == CONFIRMED
async def confirm(ctx, content, code=None, *args, **kwargs): from trezor.ui.confirm import ConfirmDialog, CONFIRMED from trezor.messages.ButtonRequest import ButtonRequest from trezor.messages.ButtonRequestType import Other from trezor.messages.wire_types import ButtonAck ui.display.clear() dialog = ConfirmDialog(content, *args, **kwargs) dialog.render() if code is None: code = Other await ctx.call(ButtonRequest(code=code), ButtonAck) if __debug__: waiter = loop.wait(signal, dialog) else: waiter = dialog return await waiter == CONFIRMED
async def request_pin(label=None, attempts_remaining=None, cancellable: bool = True) -> str: def onchange(): c = dialog.cancel if matrix.pin: back = res.load(ui.ICON_BACK) if c.content is not back: c.normal_style = ui.BTN_CLEAR["normal"] c.content = back c.enable() c.taint() else: lock = res.load(ui.ICON_LOCK) if not cancellable and c.content: c.content = "" c.disable() c.taint() elif c.content is not lock: c.normal_style = ui.BTN_CANCEL["normal"] c.content = lock c.enable() c.taint() c.render() if label is None: label = "Enter your PIN" sublabel = None if attempts_remaining: if attempts_remaining == 1: sublabel = "This is your last attempt" else: sublabel = "{} attempts remaining".format(attempts_remaining) matrix = PinMatrix(label, sublabel) matrix.onchange = onchange dialog = ConfirmDialog(matrix) dialog.cancel.area = ui.grid(12) dialog.confirm.area = ui.grid(14) matrix.onchange() while True: if __debug__: result = await loop.spawn(dialog, input_signal) if isinstance(result, str): return result else: result = await dialog if result == CONFIRMED: return matrix.pin elif matrix.pin: # reset matrix.change("") continue else: # cancel raise PinCancelled()
async def confirm(ctx, content, code=None, *args, **kwargs): if code is None: code = ButtonRequestType.Other await ctx.call(ButtonRequest(code=code), wire_types.ButtonAck) dialog = ConfirmDialog(content, *args, **kwargs) if __debug__: waiter = ctx.wait(signal, dialog) else: waiter = ctx.wait(dialog) return await waiter == CONFIRMED
async def confirm_layout(self) -> None: from trezor.ui.confirm import ConfirmDialog, CONFIRMED from trezor.ui.text import Text if bytes(self.app_id) == _BOGUS_APPID: text = Text('U2F mismatch', ui.ICON_WRONG, icon_color=ui.RED) text.normal('Another U2F device', 'was used to register', 'in this application.') text.render() await loop.sleep(3 * 1000 * 1000) self.confirmed = True else: content = ConfirmContent(self.action, self.app_id) dialog = ConfirmDialog(content, ) self.confirmed = await dialog == CONFIRMED
async def request_pin(label=None, cancellable: bool=True) -> str: def onchange(): c = dialog.cancel if matrix.pin: back = res.load(ui.ICON_BACK) if c.content is not back: c.normal_style = ui.BTN_CLEAR['normal'] c.content = back c.enable() c.taint() else: lock = res.load(ui.ICON_LOCK) if not cancellable and c.content: c.content = '' c.disable() c.taint() elif c.content is not lock: c.normal_style = ui.BTN_CANCEL['normal'] c.content = lock c.enable() c.taint() c.render() if label is None: label = 'Enter your PIN' matrix = PinMatrix(label) matrix.onchange = onchange dialog = ConfirmDialog(matrix) dialog.cancel.area = ui.grid(12) dialog.confirm.area = ui.grid(14) matrix.onchange() while True: if __debug__: result = await loop.wait(dialog, input_signal) if isinstance(result, str): return result else: result = await dialog if result == CONFIRMED: return matrix.pin elif matrix.pin: # reset matrix.change('') continue else: # cancel raise PinCancelled()
async def request_pin_on_display(ctx: wire.Context, code: int = None) -> str: from trezor.messages.ButtonRequest import ButtonRequest from trezor.messages.ButtonRequestType import ProtectCall from trezor.messages.FailureType import PinCancelled from trezor.messages.wire_types import ButtonAck from trezor.ui.confirm import ConfirmDialog, CONFIRMED from trezor.ui.pin import PinMatrix if __debug__: global matrix _, label = _get_code_and_label(code) await ctx.call(ButtonRequest(code=ProtectCall), ButtonAck) def onchange(): c = dialog.cancel if matrix.pin: c.content = DEFAULT_CANCEL else: c.content = DEFAULT_LOCK c.taint() c.render() ui.display.clear() matrix = PinMatrix(label, with_zero=True) matrix.onchange = onchange dialog = ConfirmDialog(matrix) dialog.cancel.area = (0, 240 - 48, 80, 48) dialog.confirm.area = (240 - 80, 240 - 48, 80, 48) matrix.onchange() while True: res = await dialog pin = matrix.pin if res == CONFIRMED: matrix = None return pin elif res != CONFIRMED and pin: matrix.change('') continue else: matrix = None raise wire.FailureError(PinCancelled, 'PIN cancelled')
async def request_pin(code=None, cancellable: bool = True) -> str: def onchange(): c = dialog.cancel if matrix.pin: back = res.load(ui.ICON_BACK) if c.content is not back: c.normal_style = ui.BTN_CLEAR['normal'] c.content = back c.enable() c.taint() else: lock = res.load(ui.ICON_LOCK) if not cancellable and c.content: c.content = '' c.disable() c.taint() elif c.content is not lock: c.normal_style = ui.BTN_CANCEL['normal'] c.content = lock c.enable() c.taint() c.render() label = _get_label(code) matrix = PinMatrix(label, with_zero=True) matrix.onchange = onchange dialog = ConfirmDialog(matrix) dialog.cancel.area = ui.grid(12) dialog.confirm.area = ui.grid(14) matrix.onchange() while True: result = await dialog if result == CONFIRMED: return matrix.pin elif result != CONFIRMED and matrix.pin: matrix.change('') continue else: raise PinCancelled()