Esempio n. 1
0
async def confirm(
    ctx: wire.GenericContext,
    content: ui.Component,
    code: EnumTypeButtonRequestType = ButtonRequestType.Other,
    confirm: Optional[ButtonContent] = Confirm.DEFAULT_CONFIRM,
    confirm_style: ButtonStyleType = Confirm.DEFAULT_CONFIRM_STYLE,
    cancel: Optional[ButtonContent] = Confirm.DEFAULT_CANCEL,
    cancel_style: ButtonStyleType = Confirm.DEFAULT_CANCEL_STYLE,
    major_confirm: bool = False,
) -> bool:
    await button_request(ctx, code=code)

    if content.__class__.__name__ == "Paginated":
        # The following works because asserts are omitted in non-debug builds.
        # IOW if the assert runs, that means __debug__ is True and Paginated is imported
        assert isinstance(content, Paginated)

        content.pages[-1] = Confirm(
            content.pages[-1],
            confirm,
            confirm_style,
            cancel,
            cancel_style,
            major_confirm,
        )
        dialog = content  # type: ui.Layout
    else:
        dialog = Confirm(content, confirm, confirm_style, cancel, cancel_style,
                         major_confirm)

    return await ctx.wait(dialog) is CONFIRMED
Esempio n. 2
0
async def confirm(
    ctx: wire.Context,
    content: ui.Control,
    code: int = ButtonRequestType.Other,
    confirm: ButtonContent = Confirm.DEFAULT_CONFIRM,
    confirm_style: ButtonStyleType = Confirm.DEFAULT_CONFIRM_STYLE,
    cancel: ButtonContent = Confirm.DEFAULT_CANCEL,
    cancel_style: ButtonStyleType = Confirm.DEFAULT_CANCEL_STYLE,
    major_confirm: bool = False,
) -> bool:
    await ctx.call(ButtonRequest(code=code), ButtonAck)

    if content.__class__.__name__ == "Paginated":
        content.pages[-1] = Confirm(
            content.pages[-1],
            confirm,
            confirm_style,
            cancel,
            cancel_style,
            major_confirm,
        )
        dialog = content
    else:
        dialog = Confirm(content, confirm, confirm_style, cancel, cancel_style,
                         major_confirm)

    if __debug__:
        return await ctx.wait(dialog, confirm_signal) is CONFIRMED
    else:
        return await ctx.wait(dialog) is CONFIRMED
Esempio n. 3
0
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,
    major_confirm=None,
):
    await ctx.call(ButtonRequest(code=code), MessageType.ButtonAck)

    if content.__class__.__name__ == "Paginated":
        content.pages[-1] = Confirm(
            content.pages[-1],
            confirm,
            confirm_style,
            cancel,
            cancel_style,
            major_confirm,
        )
        dialog = content
    else:
        dialog = Confirm(content, confirm, confirm_style, cancel, cancel_style,
                         major_confirm)

    if __debug__:
        return await ctx.wait(dialog, confirm_signal) is CONFIRMED
    else:
        return await ctx.wait(dialog) is CONFIRMED
Esempio n. 4
0
    async def confirm_layout(self) -> None:
        from trezor.ui.confirm import Confirm, 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, ui.RED)
            text.normal("Another U2F device", "was used to register",
                        "in this application.")
            dialog = Confirm(text)
        else:
            content = ConfirmContent(self.action, app_id)
            dialog = Confirm(content)

        self.confirmed = await dialog is CONFIRMED
Esempio n. 5
0
async def _require_confirm_properties(ctx, definition: NEMMosaicDefinition):
    # TODO: we should send a button request here
    pages = _get_mosaic_properties(definition)
    pages[-1] = Confirm(pages[-1])
    paginated = Paginated(pages)

    if __debug__:
        result = await ctx.wait(paginated, confirm_signal)
    else:
        result = await ctx.wait(paginated)
    if result is not CONFIRMED:
        raise wire.ActionCancelled("Action cancelled")