1
0
mirror of https://github.com/trezor/trezor-firmware.git synced 2024-11-18 05:28:40 +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 import ui
from trezor.enums import ButtonRequestType from trezor.enums import ButtonRequestType
from trezor.strings import format_amount from trezor.strings import format_amount
from trezor.ui.components.tt.text import Text from trezor.ui.layouts import (
from trezor.ui.layouts import show_pubkey confirm_metadata,
confirm_output,
confirm_total,
show_pubkey,
)
from trezor.utils import chunks 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 from .helpers import get_vote_tx_text
async def require_confirm_tx(ctx, to, value): async def require_confirm_tx(ctx, to, value):
text = Text("Confirm sending", ui.ICON_SEND, ui.GREEN) await confirm_output(
text.bold(format_coin_amount(value)) ctx,
text.normal("to") to,
text.mono(*split_address(to)) format_coin_amount(value),
await require_confirm(ctx, text, ButtonRequestType.SignTx) font_amount=ui.BOLD,
to_str="\nto\n",
br_code=ButtonRequestType.SignTx,
)
async def require_confirm_delegate_registration(ctx, delegate_name): async def require_confirm_delegate_registration(ctx, delegate_name):
text = Text("Confirm transaction", ui.ICON_SEND, ui.GREEN) await confirm_metadata(
text.normal("Do you really want to") ctx,
text.normal("register a delegate?") "confirm_delegate",
text.bold(*chunks(delegate_name, 20)) title="Confirm transaction",
await require_confirm(ctx, text, ButtonRequestType.SignTx) 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): async def require_confirm_vote_tx(ctx, votes):
text = Text("Confirm transaction", ui.ICON_SEND, ui.GREEN) await confirm_metadata(
text.normal(*get_vote_tx_text(votes)) ctx,
await require_confirm(ctx, text, ButtonRequestType.SignTx) "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): 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): async def require_confirm_multisig(ctx, multisignature):
text = Text("Confirm transaction", ui.ICON_SEND, ui.GREEN) content = "Keys group length: %s\nLife time: %s\nMin: %s" % (
text.normal("Keys group length: %s" % len(multisignature.keys_group)) len(multisignature.keys_group),
text.normal("Life time: %s" % multisignature.life_time) multisignature.life_time,
text.normal("Min: %s" % multisignature.min) multisignature.min,
await require_confirm(ctx, text, ButtonRequestType.SignTx) )
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): async def require_confirm_fee(ctx, value, fee):
text = Text("Confirm transaction", ui.ICON_SEND, ui.GREEN) await confirm_total(
text.bold(format_coin_amount(value)) ctx,
text.normal("fee:") total_amount=format_coin_amount(value),
text.bold(format_coin_amount(fee)) total_label="",
await require_hold_to_confirm(ctx, text, ButtonRequestType.ConfirmOutput) fee_amount=format_coin_amount(fee),
fee_label="\nfee:\n",
br_code=ButtonRequestType.ConfirmOutput,
)
def format_coin_amount(value): def format_coin_amount(value):

View File

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