1
0
mirror of https://github.com/trezor/trezor-firmware.git synced 2024-12-17 11:58:13 +00:00
trezor-firmware/core/src/apps/common/layout.py

68 lines
1.8 KiB
Python
Raw Normal View History

from micropython import const
2018-08-21 08:21:39 +00:00
from ubinascii import hexlify
2018-07-03 14:20:26 +00:00
from trezor import ui
from trezor.messages import ButtonRequestType
from trezor.ui.container import Container
from trezor.ui.qr import Qr
from trezor.ui.text import Text
from trezor.utils import chunks
from apps.common import HARDENED
2018-08-20 17:07:58 +00:00
from apps.common.confirm import confirm, require_confirm
2018-07-03 14:20:26 +00:00
async def show_address(ctx, address: str, desc: str = None, network: str = None):
text = Text(
desc if desc else "Confirm address", ui.ICON_RECEIVE, icon_color=ui.GREEN
)
if network:
text.normal("%s network" % network)
text.mono(*split_address(address))
return await confirm(
2018-07-03 14:20:58 +00:00
ctx, text, code=ButtonRequestType.Address, cancel="QR", cancel_style=ui.BTN_KEY
)
async def show_qr(ctx, address: str, desc: str = None):
qr_x = const(120)
qr_y = const(115)
qr_coef = const(4)
2018-07-02 13:19:04 +00:00
qr = Qr(address, (qr_x, qr_y), qr_coef)
text = Text(
desc if desc else "Confirm address", ui.ICON_RECEIVE, icon_color=ui.GREEN
)
2018-07-02 13:19:04 +00:00
content = Container(qr, text)
return await confirm(
ctx,
content,
code=ButtonRequestType.Address,
2018-07-03 14:20:58 +00:00
cancel="Address",
cancel_style=ui.BTN_KEY,
)
2018-08-21 08:21:39 +00:00
async def show_pubkey(ctx, pubkey: bytes):
lines = chunks(hexlify(pubkey).decode(), 18)
text = Text("Confirm public key", ui.ICON_RECEIVE, icon_color=ui.GREEN)
text.mono(*lines)
return await require_confirm(ctx, text, code=ButtonRequestType.PublicKey)
def split_address(address: str):
return chunks(address, 17)
def address_n_to_str(address_n: list) -> str:
def path_item(i: int):
if i & HARDENED:
return str(i ^ HARDENED) + "'"
else:
return str(i)
if not address_n:
return "m"
return "m/" + "/".join([path_item(i) for i in address_n])