1
0
mirror of https://github.com/trezor/trezor-firmware.git synced 2024-12-22 06:18:07 +00:00

refactor(core): convert apps.lisk to layouts

This commit is contained in:
Martin Milata 2021-03-03 17:57:34 +01:00 committed by matejcik
parent ebf6ef1666
commit a143fe34d0
2 changed files with 59 additions and 32 deletions

View File

@ -3,36 +3,50 @@ from ubinascii import hexlify
from trezor import ui
from trezor.enums import ButtonRequestType
from trezor.strings import format_amount
from trezor.ui.components.tt.text import Text
from trezor.ui.layouts import show_pubkey
from trezor.ui.layouts import (
confirm_metadata,
confirm_output,
confirm_total,
show_pubkey,
)
from trezor.utils import chunks
from apps.common.confirm import require_confirm, require_hold_to_confirm
from apps.common.layout import split_address
from .helpers import get_vote_tx_text
async def require_confirm_tx(ctx, to, value):
text = Text("Confirm sending", ui.ICON_SEND, ui.GREEN)
text.bold(format_coin_amount(value))
text.normal("to")
text.mono(*split_address(to))
await require_confirm(ctx, text, ButtonRequestType.SignTx)
await confirm_output(
ctx,
to,
format_coin_amount(value),
font_amount=ui.BOLD,
to_str="\nto\n",
br_code=ButtonRequestType.SignTx,
)
async def require_confirm_delegate_registration(ctx, delegate_name):
text = Text("Confirm transaction", ui.ICON_SEND, ui.GREEN)
text.normal("Do you really want to")
text.normal("register a delegate?")
text.bold(*chunks(delegate_name, 20))
await require_confirm(ctx, text, ButtonRequestType.SignTx)
await confirm_metadata(
ctx,
"confirm_delegate",
title="Confirm transaction",
content="Do you really want to register a delegate?\n{}",
param="\n".join(chunks(delegate_name, 20)),
param_font=ui.BOLD,
hide_continue=True,
br_code=ButtonRequestType.SignTx,
)
async def require_confirm_vote_tx(ctx, votes):
text = Text("Confirm transaction", ui.ICON_SEND, ui.GREEN)
text.normal(*get_vote_tx_text(votes))
await require_confirm(ctx, text, ButtonRequestType.SignTx)
await confirm_metadata(
ctx,
"confirm_vote",
title="Confirm transaction",
content="\n".join(get_vote_tx_text(votes)),
hide_continue=True,
br_code=ButtonRequestType.SignTx,
)
async def require_confirm_public_key(ctx, public_key):
@ -40,19 +54,30 @@ async def require_confirm_public_key(ctx, public_key):
async def require_confirm_multisig(ctx, multisignature):
text = Text("Confirm transaction", ui.ICON_SEND, ui.GREEN)
text.normal("Keys group length: %s" % len(multisignature.keys_group))
text.normal("Life time: %s" % multisignature.life_time)
text.normal("Min: %s" % multisignature.min)
await require_confirm(ctx, text, ButtonRequestType.SignTx)
content = "Keys group length: %s\nLife time: %s\nMin: %s" % (
len(multisignature.keys_group),
multisignature.life_time,
multisignature.min,
)
await confirm_metadata(
ctx,
"confirm_multisig",
title="Confirm transaction",
content=content,
hide_continue=True,
br_code=ButtonRequestType.SignTx,
)
async def require_confirm_fee(ctx, value, fee):
text = Text("Confirm transaction", ui.ICON_SEND, ui.GREEN)
text.bold(format_coin_amount(value))
text.normal("fee:")
text.bold(format_coin_amount(fee))
await require_hold_to_confirm(ctx, text, ButtonRequestType.ConfirmOutput)
await confirm_total(
ctx,
total_amount=format_coin_amount(value),
total_label="",
fee_amount=format_coin_amount(fee),
fee_label="\nfee:\n",
br_code=ButtonRequestType.ConfirmOutput,
)
def format_coin_amount(value):

View File

@ -557,15 +557,14 @@ async def confirm_total(
fee_label: str = "\nincluding fee:\n",
icon_color: int = ui.GREEN,
br_type: str = "confirm_total",
br_code: ButtonRequestType = ButtonRequestType.SignTx,
) -> None:
text = Text(title, ui.ICON_SEND, icon_color, new_lines=False)
text.normal(total_label)
text.bold(total_amount)
text.normal(fee_label)
text.bold(fee_amount)
await raise_if_cancelled(
interact(ctx, HoldToConfirm(text), br_type, ButtonRequestType.SignTx)
)
await raise_if_cancelled(interact(ctx, HoldToConfirm(text), br_type, br_code))
# TODO cleanup @ redesign
@ -624,11 +623,14 @@ async def confirm_metadata(
br_code: ButtonRequestType = ButtonRequestType.SignTx,
hide_continue: bool = False,
hold: bool = False,
param_font: int = ui.BOLD,
icon: str = ui.ICON_SEND, # TODO cleanup @ redesign
icon_color: int = ui.GREEN, # TODO cleanup @ redesign
) -> None:
text = Text(title, icon, icon_color, new_lines=False)
text.format_parametrized(content, param if param is not None else "")
text.format_parametrized(
content, param if param is not None else "", param_font=param_font
)
if not hide_continue:
text.br()