mirror of
https://github.com/trezor/trezor-firmware.git
synced 2024-11-27 01:48:17 +00:00
apps: show_qr and show_address moved to common
This commit is contained in:
parent
1bfbb34f88
commit
9329b0e16b
39
src/apps/common/display_address.py
Normal file
39
src/apps/common/display_address.py
Normal file
@ -0,0 +1,39 @@
|
||||
from micropython import const
|
||||
from apps.common.confirm import confirm
|
||||
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
|
||||
|
||||
|
||||
async def show_address(ctx, address: str):
|
||||
lines = split_address(address)
|
||||
content = Text('Confirm address', ui.ICON_RECEIVE, ui.MONO, *lines, icon_color=ui.GREEN)
|
||||
return await confirm(
|
||||
ctx,
|
||||
content,
|
||||
code=ButtonRequestType.Address,
|
||||
cancel='QR',
|
||||
cancel_style=ui.BTN_KEY)
|
||||
|
||||
|
||||
async def show_qr(ctx, address: str):
|
||||
qr_x = const(120)
|
||||
qr_y = const(115)
|
||||
qr_coef = const(4)
|
||||
|
||||
content = Container(
|
||||
Qr(address, (qr_x, qr_y), qr_coef),
|
||||
Text('Confirm address', ui.ICON_RECEIVE, ui.MONO, icon_color=ui.GREEN))
|
||||
return await confirm(
|
||||
ctx,
|
||||
content,
|
||||
code=ButtonRequestType.Address,
|
||||
cancel='Address',
|
||||
cancel_style=ui.BTN_KEY)
|
||||
|
||||
|
||||
def split_address(address: str):
|
||||
return chunks(address, 17)
|
@ -1,4 +1,4 @@
|
||||
from apps.wallet.get_address import _show_address, _show_qr
|
||||
from apps.common.display_address import show_address, show_qr
|
||||
from apps.ethereum import networks
|
||||
|
||||
|
||||
@ -21,9 +21,9 @@ async def ethereum_get_address(ctx, msg):
|
||||
hex_addr = _ethereum_address_hex(address, network)
|
||||
|
||||
while True:
|
||||
if await _show_address(ctx, hex_addr):
|
||||
if await show_address(ctx, hex_addr):
|
||||
break
|
||||
if await _show_qr(ctx, hex_addr):
|
||||
if await show_qr(ctx, hex_addr):
|
||||
break
|
||||
|
||||
return EthereumAddress(address=address)
|
||||
|
@ -5,9 +5,9 @@ from trezor import ui
|
||||
from trezor.ui.text import Text
|
||||
from trezor.messages.Success import Success
|
||||
from apps.common.confirm import require_confirm
|
||||
from apps.common.display_address import split_address
|
||||
from apps.common.signverify import split_message
|
||||
from apps.ethereum.sign_message import message_digest
|
||||
from apps.wallet.get_address import _split_address
|
||||
|
||||
|
||||
async def ethereum_verify_message(ctx, msg):
|
||||
@ -32,7 +32,7 @@ async def ethereum_verify_message(ctx, msg):
|
||||
|
||||
|
||||
async def require_confirm_verify_message(ctx, address, message):
|
||||
lines = _split_address(address)
|
||||
lines = split_address(address)
|
||||
content = Text('Confirm address', ui.ICON_DEFAULT, ui.MONO, *lines)
|
||||
await require_confirm(ctx, content)
|
||||
|
||||
|
@ -1,5 +1,5 @@
|
||||
from apps.common import seed
|
||||
from apps.wallet.get_address import _show_address, _show_qr
|
||||
from apps.common.display_address import show_address, show_qr
|
||||
from trezor.messages.LiskAddress import LiskAddress
|
||||
|
||||
from .helpers import LISK_CURVE, get_address_from_public_key
|
||||
@ -15,9 +15,9 @@ async def layout_lisk_get_address(ctx, msg):
|
||||
|
||||
if msg.show_display:
|
||||
while True:
|
||||
if await _show_address(ctx, address):
|
||||
if await show_address(ctx, address):
|
||||
break
|
||||
if await _show_qr(ctx, address):
|
||||
if await show_qr(ctx, address):
|
||||
break
|
||||
|
||||
return LiskAddress(address=address)
|
||||
|
@ -1,13 +1,7 @@
|
||||
from micropython import const
|
||||
from trezor import ui
|
||||
from trezor.messages import ButtonRequestType, InputScriptType
|
||||
from trezor.messages import InputScriptType
|
||||
from trezor.messages.Address import Address
|
||||
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 coins, seed
|
||||
from apps.common.confirm import confirm
|
||||
from apps.common.display_address import show_qr, show_address
|
||||
from apps.wallet.sign_tx import addresses
|
||||
|
||||
|
||||
@ -21,40 +15,9 @@ async def get_address(ctx, msg):
|
||||
|
||||
if msg.show_display:
|
||||
while True:
|
||||
if await _show_address(ctx, address_short):
|
||||
if await show_address(ctx, address_short):
|
||||
break
|
||||
if await _show_qr(ctx, address.upper() if msg.script_type == InputScriptType.SPENDWITNESS else address):
|
||||
if await show_qr(ctx, address.upper() if msg.script_type == InputScriptType.SPENDWITNESS else address):
|
||||
break
|
||||
|
||||
return Address(address=address)
|
||||
|
||||
|
||||
async def _show_address(ctx, address: str):
|
||||
lines = _split_address(address)
|
||||
content = Text('Confirm address', ui.ICON_RECEIVE, ui.MONO, *lines, icon_color=ui.GREEN)
|
||||
return await confirm(
|
||||
ctx,
|
||||
content,
|
||||
code=ButtonRequestType.Address,
|
||||
cancel='QR',
|
||||
cancel_style=ui.BTN_KEY)
|
||||
|
||||
|
||||
async def _show_qr(ctx, address: str):
|
||||
qr_x = const(120)
|
||||
qr_y = const(115)
|
||||
qr_coef = const(4)
|
||||
|
||||
content = Container(
|
||||
Qr(address, (qr_x, qr_y), qr_coef),
|
||||
Text('Confirm address', ui.ICON_RECEIVE, ui.MONO, icon_color=ui.GREEN))
|
||||
return await confirm(
|
||||
ctx,
|
||||
content,
|
||||
code=ButtonRequestType.Address,
|
||||
cancel='Address',
|
||||
cancel_style=ui.BTN_KEY)
|
||||
|
||||
|
||||
def _split_address(address: str):
|
||||
return chunks(address, 17)
|
||||
|
@ -5,9 +5,9 @@ from trezor.messages.Success import Success
|
||||
from trezor.ui.text import Text
|
||||
from apps.common import coins
|
||||
from apps.common.confirm import require_confirm
|
||||
from apps.common.display_address import split_address
|
||||
from apps.common.signverify import message_digest, split_message
|
||||
from apps.wallet.sign_tx.addresses import address_pkh, address_p2wpkh_in_p2sh, address_p2wpkh, address_to_cashaddr
|
||||
from apps.wallet.get_address import _split_address
|
||||
|
||||
|
||||
async def verify_message(ctx, msg):
|
||||
@ -59,7 +59,7 @@ async def verify_message(ctx, msg):
|
||||
|
||||
|
||||
async def require_confirm_verify_message(ctx, address, message):
|
||||
lines = _split_address(address)
|
||||
lines = split_address(address)
|
||||
content = Text('Confirm address', ui.ICON_DEFAULT, ui.MONO, *lines)
|
||||
await require_confirm(ctx, content)
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user