mirror of
https://github.com/trezor/trezor-firmware.git
synced 2024-12-19 04:48:12 +00:00
src/apps/common: refactor address_n_to_str into apps.common.layout
This commit is contained in:
parent
cc25069064
commit
addbdd8937
@ -1,5 +1,3 @@
|
|||||||
from micropython import const
|
|
||||||
|
|
||||||
from trezor import wire
|
from trezor import wire
|
||||||
from trezor.crypto import base58, crc, hashlib
|
from trezor.crypto import base58, crc, hashlib
|
||||||
|
|
||||||
@ -56,23 +54,3 @@ def derive_address_and_node(root_node, path: list):
|
|||||||
)
|
)
|
||||||
)
|
)
|
||||||
return (address, derived_node)
|
return (address, derived_node)
|
||||||
|
|
||||||
|
|
||||||
def _break_address_n_to_lines(address_n: list) -> list:
|
|
||||||
def path_item(i: int):
|
|
||||||
if i & HARDENED:
|
|
||||||
return str(i ^ HARDENED) + "'"
|
|
||||||
else:
|
|
||||||
return str(i)
|
|
||||||
|
|
||||||
lines = []
|
|
||||||
path_str = "m/" + "/".join([path_item(i) for i in address_n])
|
|
||||||
|
|
||||||
per_line = const(17)
|
|
||||||
while len(path_str) > per_line:
|
|
||||||
i = path_str[:per_line].rfind("/")
|
|
||||||
lines.append(path_str[:i])
|
|
||||||
path_str = path_str[i:]
|
|
||||||
lines.append(path_str)
|
|
||||||
|
|
||||||
return lines
|
|
||||||
|
@ -6,11 +6,12 @@ from trezor.messages.CardanoTxRequest import CardanoTxRequest
|
|||||||
from trezor.messages.MessageType import CardanoTxAck
|
from trezor.messages.MessageType import CardanoTxAck
|
||||||
from trezor.ui.text import BR
|
from trezor.ui.text import BR
|
||||||
|
|
||||||
from .address import _break_address_n_to_lines, derive_address_and_node
|
from .address import derive_address_and_node
|
||||||
from .layout import confirm_with_pagination, progress
|
from .layout import confirm_with_pagination, progress
|
||||||
|
|
||||||
from apps.cardano import cbor
|
from apps.cardano import cbor
|
||||||
from apps.common import seed, storage
|
from apps.common import seed, storage
|
||||||
|
from apps.common.layout import address_n_to_str, split_address
|
||||||
from apps.homescreen.homescreen import display_homescreen
|
from apps.homescreen.homescreen import display_homescreen
|
||||||
|
|
||||||
|
|
||||||
@ -53,7 +54,7 @@ async def show_tx(
|
|||||||
for index, change in enumerate(change_derivation_paths):
|
for index, change in enumerate(change_derivation_paths):
|
||||||
if not await confirm_with_pagination(
|
if not await confirm_with_pagination(
|
||||||
ctx,
|
ctx,
|
||||||
_break_address_n_to_lines(change),
|
split_address(address_n_to_str(change)),
|
||||||
"Confirm change",
|
"Confirm change",
|
||||||
ui.ICON_SEND,
|
ui.ICON_SEND,
|
||||||
ui.GREEN,
|
ui.GREEN,
|
||||||
|
@ -8,11 +8,13 @@ from trezor.ui.qr import Qr
|
|||||||
from trezor.ui.text import Text
|
from trezor.ui.text import Text
|
||||||
from trezor.utils import chunks
|
from trezor.utils import chunks
|
||||||
|
|
||||||
|
from apps.common import HARDENED
|
||||||
from apps.common.confirm import confirm, require_confirm
|
from apps.common.confirm import confirm, require_confirm
|
||||||
|
|
||||||
|
|
||||||
async def show_address(ctx, address: str, network: str = None):
|
async def show_address(ctx, address: str, address_n: list, network: str = None):
|
||||||
text = Text("Confirm address", ui.ICON_RECEIVE, icon_color=ui.GREEN)
|
text = Text("Confirm address", ui.ICON_RECEIVE, icon_color=ui.GREEN)
|
||||||
|
# TODO: print address_n via address_n_to_str(address_n)
|
||||||
if network:
|
if network:
|
||||||
text.normal("%s network" % network)
|
text.normal("%s network" % network)
|
||||||
text.mono(*split_address(address))
|
text.mono(*split_address(address))
|
||||||
@ -38,12 +40,22 @@ async def show_qr(ctx, address: str):
|
|||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
def split_address(address: str):
|
|
||||||
return chunks(address, 17)
|
|
||||||
|
|
||||||
|
|
||||||
async def show_pubkey(ctx, pubkey: bytes):
|
async def show_pubkey(ctx, pubkey: bytes):
|
||||||
lines = chunks(hexlify(pubkey).decode(), 18)
|
lines = chunks(hexlify(pubkey).decode(), 18)
|
||||||
text = Text("Confirm public key", ui.ICON_RECEIVE, icon_color=ui.GREEN)
|
text = Text("Confirm public key", ui.ICON_RECEIVE, icon_color=ui.GREEN)
|
||||||
text.mono(*lines)
|
text.mono(*lines)
|
||||||
return await require_confirm(ctx, text, code=ButtonRequestType.PublicKey)
|
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)
|
||||||
|
|
||||||
|
return "m/" + "/".join([path_item(i) for i in address_n])
|
||||||
|
@ -24,7 +24,7 @@ async def get_address(ctx, msg):
|
|||||||
hex_addr = _ethereum_address_hex(address, network)
|
hex_addr = _ethereum_address_hex(address, network)
|
||||||
|
|
||||||
while True:
|
while True:
|
||||||
if await show_address(ctx, hex_addr):
|
if await show_address(ctx, hex_addr, address_n):
|
||||||
break
|
break
|
||||||
if await show_qr(ctx, hex_addr):
|
if await show_qr(ctx, hex_addr):
|
||||||
break
|
break
|
||||||
|
@ -16,7 +16,7 @@ async def get_address(ctx, msg):
|
|||||||
|
|
||||||
if msg.show_display:
|
if msg.show_display:
|
||||||
while True:
|
while True:
|
||||||
if await show_address(ctx, address):
|
if await show_address(ctx, address, address_n):
|
||||||
break
|
break
|
||||||
if await show_qr(ctx, address):
|
if await show_qr(ctx, address):
|
||||||
break
|
break
|
||||||
|
@ -14,7 +14,9 @@ async def get_address(ctx, msg):
|
|||||||
|
|
||||||
if msg.show_display:
|
if msg.show_display:
|
||||||
while True:
|
while True:
|
||||||
if await show_address(ctx, address, get_network_str(network)):
|
if await show_address(
|
||||||
|
ctx, address, msg.address_n, network=get_network_str(network)
|
||||||
|
):
|
||||||
break
|
break
|
||||||
if await show_qr(ctx, address.upper()):
|
if await show_qr(ctx, address.upper()):
|
||||||
break
|
break
|
||||||
|
@ -14,7 +14,7 @@ async def get_address(ctx, msg: RippleGetAddress):
|
|||||||
|
|
||||||
if msg.show_display:
|
if msg.show_display:
|
||||||
while True:
|
while True:
|
||||||
if await show_address(ctx, address):
|
if await show_address(ctx, address, msg.address_n):
|
||||||
break
|
break
|
||||||
if await show_qr(ctx, address.upper()):
|
if await show_qr(ctx, address.upper()):
|
||||||
break
|
break
|
||||||
|
@ -13,7 +13,7 @@ async def get_address(ctx, msg: StellarGetAddress):
|
|||||||
|
|
||||||
if msg.show_display:
|
if msg.show_display:
|
||||||
while True:
|
while True:
|
||||||
if await show_address(ctx, address):
|
if await show_address(ctx, address, msg.address_n):
|
||||||
break
|
break
|
||||||
if await show_qr(ctx, address.upper()):
|
if await show_qr(ctx, address.upper()):
|
||||||
break
|
break
|
||||||
|
@ -20,7 +20,7 @@ async def get_address(ctx, msg):
|
|||||||
|
|
||||||
if msg.show_display:
|
if msg.show_display:
|
||||||
while True:
|
while True:
|
||||||
if await show_address(ctx, address):
|
if await show_address(ctx, address, address_n):
|
||||||
break
|
break
|
||||||
if await show_qr(ctx, address):
|
if await show_qr(ctx, address):
|
||||||
break
|
break
|
||||||
|
@ -16,7 +16,7 @@ async def get_address(ctx, msg):
|
|||||||
|
|
||||||
if msg.show_display:
|
if msg.show_display:
|
||||||
while True:
|
while True:
|
||||||
if await show_address(ctx, address_short):
|
if await show_address(ctx, address_short, msg.address_n):
|
||||||
break
|
break
|
||||||
if await show_qr(
|
if await show_qr(
|
||||||
ctx,
|
ctx,
|
||||||
|
Loading…
Reference in New Issue
Block a user