mirror of
https://github.com/trezor/trezor-firmware.git
synced 2025-07-09 16:18:10 +00:00
refactor(core): convert apps.binance to layouts
This commit is contained in:
parent
ddac852acf
commit
3ffbae5d17
@ -1,4 +1,3 @@
|
|||||||
from trezor import ui
|
|
||||||
from trezor.enums import BinanceOrderSide, ButtonRequestType
|
from trezor.enums import BinanceOrderSide, ButtonRequestType
|
||||||
from trezor.messages import (
|
from trezor.messages import (
|
||||||
BinanceCancelMsg,
|
BinanceCancelMsg,
|
||||||
@ -7,77 +6,67 @@ from trezor.messages import (
|
|||||||
BinanceTransferMsg,
|
BinanceTransferMsg,
|
||||||
)
|
)
|
||||||
from trezor.strings import format_amount
|
from trezor.strings import format_amount
|
||||||
from trezor.ui.components.tt.scroll import Paginated
|
from trezor.ui.layouts import confirm_properties, confirm_transfer_binance
|
||||||
from trezor.ui.components.tt.text import Text
|
|
||||||
|
|
||||||
from apps.common.confirm import require_hold_to_confirm
|
|
||||||
from apps.common.layout import split_address
|
|
||||||
|
|
||||||
from . import helpers
|
from . import helpers
|
||||||
|
|
||||||
|
|
||||||
async def require_confirm_transfer(ctx, msg: BinanceTransferMsg):
|
async def require_confirm_transfer(ctx, msg: BinanceTransferMsg):
|
||||||
|
items = []
|
||||||
|
|
||||||
def make_input_output_pages(msg: BinanceInputOutput, direction):
|
def make_input_output_pages(msg: BinanceInputOutput, direction):
|
||||||
pages = []
|
|
||||||
for coin in msg.coins:
|
for coin in msg.coins:
|
||||||
coin_page = Text("Confirm " + direction, ui.ICON_SEND, icon_color=ui.GREEN)
|
items.append(
|
||||||
coin_page.bold(
|
(
|
||||||
format_amount(coin.amount, helpers.DECIMALS) + " " + coin.denom
|
direction,
|
||||||
|
format_amount(coin.amount, helpers.DECIMALS) + " " + coin.denom,
|
||||||
|
msg.address,
|
||||||
|
)
|
||||||
)
|
)
|
||||||
coin_page.normal("to")
|
|
||||||
coin_page.mono(*split_address(msg.address))
|
|
||||||
pages.append(coin_page)
|
|
||||||
|
|
||||||
return pages
|
|
||||||
|
|
||||||
pages = []
|
|
||||||
for txinput in msg.inputs:
|
for txinput in msg.inputs:
|
||||||
pages.extend(make_input_output_pages(txinput, "input"))
|
make_input_output_pages(txinput, "Confirm input")
|
||||||
|
|
||||||
for txoutput in msg.outputs:
|
for txoutput in msg.outputs:
|
||||||
pages.extend(make_input_output_pages(txoutput, "output"))
|
make_input_output_pages(txoutput, "Confirm output")
|
||||||
|
|
||||||
return await require_hold_to_confirm(
|
await confirm_transfer_binance(ctx, items)
|
||||||
ctx, Paginated(pages), ButtonRequestType.ConfirmOutput
|
|
||||||
)
|
|
||||||
|
|
||||||
|
|
||||||
async def require_confirm_cancel(ctx, msg: BinanceCancelMsg):
|
async def require_confirm_cancel(ctx, msg: BinanceCancelMsg):
|
||||||
page1 = Text("Confirm cancel 1/2", ui.ICON_SEND, icon_color=ui.GREEN)
|
await confirm_properties(
|
||||||
page1.normal("Sender address:")
|
ctx,
|
||||||
page1.bold(msg.sender)
|
"confirm_cancel",
|
||||||
page1.normal("Pair:")
|
title="Confirm cancel",
|
||||||
page1.bold(msg.symbol)
|
props=[
|
||||||
|
("Sender address:", msg.sender),
|
||||||
page2 = Text("Confirm cancel 2/2", ui.ICON_SEND, icon_color=ui.GREEN)
|
("Pair:", msg.symbol),
|
||||||
page2.normal("Order ID:")
|
("Order ID:", msg.refid),
|
||||||
page2.bold(msg.refid)
|
],
|
||||||
|
hold=True,
|
||||||
return await require_hold_to_confirm(
|
br_code=ButtonRequestType.SignTx,
|
||||||
ctx, Paginated([page1, page2]), ButtonRequestType.SignTx
|
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
async def require_confirm_order(ctx, msg: BinanceOrderMsg):
|
async def require_confirm_order(ctx, msg: BinanceOrderMsg):
|
||||||
page1 = Text("Confirm order 1/3", ui.ICON_SEND, icon_color=ui.GREEN)
|
|
||||||
page1.normal("Sender address:")
|
|
||||||
page1.bold(msg.sender)
|
|
||||||
|
|
||||||
page2 = Text("Confirm order 2/3", ui.ICON_SEND, icon_color=ui.GREEN)
|
|
||||||
page2.normal("Pair:")
|
|
||||||
page2.bold(msg.symbol)
|
|
||||||
page2.normal("Side:")
|
|
||||||
if msg.side == BinanceOrderSide.BUY:
|
if msg.side == BinanceOrderSide.BUY:
|
||||||
page2.bold("Buy")
|
side = "Buy"
|
||||||
elif msg.side == BinanceOrderSide.SELL:
|
elif msg.side == BinanceOrderSide.SELL:
|
||||||
page2.bold("Sell")
|
side = "Sell"
|
||||||
|
else:
|
||||||
|
side = "?"
|
||||||
|
|
||||||
page3 = Text("Confirm order 3/3", ui.ICON_SEND, icon_color=ui.GREEN)
|
await confirm_properties(
|
||||||
page3.normal("Quantity:")
|
ctx,
|
||||||
page3.bold(format_amount(msg.quantity, helpers.DECIMALS))
|
"confirm_order",
|
||||||
page3.normal("Price:")
|
title="Confirm order",
|
||||||
page3.bold(format_amount(msg.price, helpers.DECIMALS))
|
props=[
|
||||||
|
("Sender address:", msg.sender),
|
||||||
return await require_hold_to_confirm(
|
("Pair:", msg.symbol),
|
||||||
ctx, Paginated([page1, page2, page3]), ButtonRequestType.SignTx
|
("Side:", side),
|
||||||
|
("Quantity:", format_amount(msg.quantity, helpers.DECIMALS)),
|
||||||
|
("Price:", format_amount(msg.price, helpers.DECIMALS)),
|
||||||
|
],
|
||||||
|
hold=True,
|
||||||
|
br_code=ButtonRequestType.SignTx,
|
||||||
)
|
)
|
||||||
|
@ -67,6 +67,7 @@ __all__ = (
|
|||||||
"confirm_coinjoin",
|
"confirm_coinjoin",
|
||||||
"confirm_timebounds_stellar",
|
"confirm_timebounds_stellar",
|
||||||
"confirm_proposals_tezos",
|
"confirm_proposals_tezos",
|
||||||
|
"confirm_transfer_binance",
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
@ -864,3 +865,24 @@ async def confirm_proposals_tezos(
|
|||||||
await raise_if_cancelled(
|
await raise_if_cancelled(
|
||||||
interact(ctx, paginated, "confirm_proposals", ButtonRequestType.SignTx)
|
interact(ctx, paginated, "confirm_proposals", ButtonRequestType.SignTx)
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
|
# TODO cleanup @ redesign
|
||||||
|
async def confirm_transfer_binance(
|
||||||
|
ctx: wire.GenericContext, inputs_outputs: Sequence[Tuple[str, str, str]]
|
||||||
|
) -> None:
|
||||||
|
pages: list[ui.Component] = []
|
||||||
|
for title, amount, address in inputs_outputs:
|
||||||
|
coin_page = Text(title, ui.ICON_SEND, icon_color=ui.GREEN, new_lines=False)
|
||||||
|
coin_page.bold(amount)
|
||||||
|
coin_page.normal("\nto\n")
|
||||||
|
coin_page.mono(*_split_address(address))
|
||||||
|
pages.append(coin_page)
|
||||||
|
|
||||||
|
pages[-1] = HoldToConfirm(pages[-1])
|
||||||
|
|
||||||
|
await raise_if_cancelled(
|
||||||
|
interact(
|
||||||
|
ctx, Paginated(pages), "confirm_transfer", ButtonRequestType.ConfirmOutput
|
||||||
|
)
|
||||||
|
)
|
||||||
|
@ -35,5 +35,5 @@ BINANCE_ADDRESS_TEST_VECTORS = [
|
|||||||
def test_binance_get_address(client, path, expected_address):
|
def test_binance_get_address(client, path, expected_address):
|
||||||
# data from https://github.com/binance-chain/javascript-sdk/blob/master/__tests__/crypto.test.js#L50
|
# data from https://github.com/binance-chain/javascript-sdk/blob/master/__tests__/crypto.test.js#L50
|
||||||
|
|
||||||
address = get_address(client, parse_path(path))
|
address = get_address(client, parse_path(path), show_display=True)
|
||||||
assert address == expected_address
|
assert address == expected_address
|
||||||
|
@ -29,7 +29,7 @@ BINANCE_PATH = parse_path("m/44h/714h/0h/0/0")
|
|||||||
mnemonic="offer caution gift cross surge pretty orange during eye soldier popular holiday mention east eight office fashion ill parrot vault rent devote earth cousin"
|
mnemonic="offer caution gift cross surge pretty orange during eye soldier popular holiday mention east eight office fashion ill parrot vault rent devote earth cousin"
|
||||||
)
|
)
|
||||||
def test_binance_get_public_key(client):
|
def test_binance_get_public_key(client):
|
||||||
sig = binance.get_public_key(client, BINANCE_PATH)
|
sig = binance.get_public_key(client, BINANCE_PATH, show_display=True)
|
||||||
assert (
|
assert (
|
||||||
sig.hex()
|
sig.hex()
|
||||||
== "029729a52e4e3c2b4a4e52aa74033eedaf8ba1df5ab6d1f518fd69e67bbd309b0e"
|
== "029729a52e4e3c2b4a4e52aa74033eedaf8ba1df5ab6d1f518fd69e67bbd309b0e"
|
||||||
|
Loading…
Reference in New Issue
Block a user