feat(cardano): add tx signing show details prompt

pull/2374/head
gabrielkerekes 2 years ago committed by matejcik
parent 11f8e81083
commit 2f9435570d

@ -16,6 +16,7 @@ from trezor.ui.layouts import (
confirm_path_warning,
confirm_properties,
confirm_text,
should_show_more,
show_address,
)
@ -177,25 +178,25 @@ async def show_script_hash(
)
async def show_multisig_tx(ctx: wire.Context) -> None:
await confirm_metadata(
async def show_tx_init(ctx: wire.Context, title: str) -> bool:
should_show_details = await should_show_more(
ctx,
"confirm_signing_mode",
title="Confirm transaction",
content="Confirming a multisig transaction.",
larger_vspace=True,
br_code=ButtonRequestType.Other,
"Confirm transaction",
(
(
ui.BOLD,
title,
),
(ui.NORMAL, "Choose level of details:"),
),
button_text="Show All",
icon=ui.ICON_SEND,
icon_color=ui.GREEN,
confirm="Show Simple",
major_confirm=True,
)
async def show_plutus_tx(ctx: wire.Context) -> None:
await confirm_metadata(
ctx,
"confirm_signing_mode",
title="Confirm transaction",
content="Confirming a Plutus transaction.",
br_code=ButtonRequestType.Other,
)
return should_show_details
async def confirm_input(ctx: wire.Context, input: messages.CardanoTxInput) -> None:

@ -11,13 +11,7 @@ class MultisigSigner(Signer):
The multisig signing mode only allows signing with multisig (and minting) keys.
"""
def __init__(
self,
ctx: wire.Context,
msg: messages.CardanoSignTxInit,
keychain: seed.Keychain,
) -> None:
super().__init__(ctx, msg, keychain)
SIGNING_MODE_TITLE = "Confirming a multisig transaction."
def _validate_tx_init(self) -> None:
super()._validate_tx_init()
@ -26,10 +20,6 @@ class MultisigSigner(Signer):
self._assert_tx_init_cond(self.msg.total_collateral is None)
self._assert_tx_init_cond(self.msg.reference_inputs_count == 0)
async def _show_tx_init(self) -> None:
await layout.show_multisig_tx(self.ctx)
await super()._show_tx_init()
async def _confirm_tx(self, tx_hash: bytes) -> None:
# super() omitted intentionally
is_network_id_verifiable = self._is_network_id_verifiable()

@ -17,13 +17,7 @@ class OrdinarySigner(Signer):
controlled by 1852' keys, dealing with staking and minting/burning tokens.
"""
def __init__(
self,
ctx: wire.Context,
msg: messages.CardanoSignTxInit,
keychain: seed.Keychain,
) -> None:
super().__init__(ctx, msg, keychain)
SIGNING_MODE_TITLE = "Confirming a transaction."
def _validate_tx_init(self) -> None:
super()._validate_tx_init()

@ -13,16 +13,9 @@ class PlutusSigner(Signer):
validation rules are less strict, but more tx items/warnings are shown to the user.
"""
def __init__(
self,
ctx: wire.Context,
msg: messages.CardanoSignTxInit,
keychain: seed.Keychain,
) -> None:
super().__init__(ctx, msg, keychain)
SIGNING_MODE_TITLE = "Confirming a Plutus transaction."
async def _show_tx_init(self) -> None:
await layout.show_plutus_tx(self.ctx)
await super()._show_tx_init()
# These items should be present if a Plutus script is to be executed.

@ -1,7 +1,7 @@
from trezor import messages, wire
from trezor.enums import CardanoCertificateType
from .. import layout, seed
from .. import layout
from ..helpers.paths import SCHEMA_STAKING_ANY_ACCOUNT
from .signer import Signer
@ -19,13 +19,7 @@ class PoolOwnerSigner(Signer):
staking key in the list of pool owners.
"""
def __init__(
self,
ctx: wire.Context,
msg: messages.CardanoSignTxInit,
keychain: seed.Keychain,
) -> None:
super().__init__(ctx, msg, keychain)
SIGNING_MODE_TITLE = "Confirming pool registration as owner."
def _validate_tx_init(self) -> None:
super()._validate_tx_init()

@ -43,7 +43,7 @@ from ..helpers.utils import (
)
if TYPE_CHECKING:
from typing import Any
from typing import Any, Awaitable, ClassVar
from apps.common.paths import PathSchema
CardanoTxResponseType = (
@ -92,6 +92,8 @@ class Signer:
user confirmation and serialization of the tx item.
"""
SIGNING_MODE_TITLE: ClassVar[str]
def __init__(
self,
ctx: wire.Context,
@ -131,6 +133,8 @@ class Signer:
tx_dict_items_count, wire.ProcessError("Invalid tx signing request")
)
self.should_show_details = False
async def sign(self) -> None:
hash_fn = hashlib.blake2b(outlen=32)
self.tx_dict.start(hash_fn)
@ -243,6 +247,10 @@ class Signer:
validate_network_info(self.msg.network_id, self.msg.protocol_magic)
async def _show_tx_init(self) -> None:
self.should_show_details = await layout.show_tx_init(
self.ctx, self.SIGNING_MODE_TITLE
)
if not self._is_network_id_verifiable():
await layout.warn_tx_network_unverifiable(self.ctx)

@ -553,6 +553,8 @@ async def should_show_more(
br_code: ButtonRequestType = ButtonRequestType.Other,
icon: str = ui.ICON_DEFAULT,
icon_color: int = ui.ORANGE_ICON,
confirm: ButtonContent = Confirm.DEFAULT_CONFIRM,
major_confirm: bool = False,
) -> bool:
"""Return True if the user wants to show more (they click a special button)
and False when the user wants to continue without showing details.
@ -568,7 +570,12 @@ async def should_show_more(
)
for font, text in para:
page.content.extend((font, text, "\n"))
ask_dialog = Confirm(AskPaginated(page, button_text))
ask_dialog = Confirm(
AskPaginated(page, button_text),
confirm=confirm,
major_confirm=major_confirm,
)
result = await raise_if_cancelled(interact(ctx, ask_dialog, br_type, br_code))
assert result in (SHOW_PAGINATED, CONFIRMED)

@ -6,6 +6,8 @@ from trezor.enums import ButtonRequestType
import trezorui2
from ...components.tt.button import ButtonContent
from ...components.tt.confirm import Confirm
from ...constants.tt import MONO_ADDR_PER_LINE
from ..common import button_request, interact
@ -493,6 +495,8 @@ async def should_show_more(
br_code: ButtonRequestType = ButtonRequestType.Other,
icon: str = ui.ICON_DEFAULT,
icon_color: int = ui.ORANGE_ICON,
confirm: ButtonContent = Confirm.DEFAULT_CONFIRM,
major_confirm: bool = False,
) -> bool:
raise NotImplementedError

Loading…
Cancel
Save