From 1275140334d3cf41292230fe380e38f4f5442b69 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Peter=20Jas=CC=8Cko?= Date: Thu, 23 Nov 2023 23:38:25 +0100 Subject: [PATCH] feat(cardano): drep ui --- core/src/apps/cardano/layout.py | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) diff --git a/core/src/apps/cardano/layout.py b/core/src/apps/cardano/layout.py index 0205c624062..6858c2cb59c 100644 --- a/core/src/apps/cardano/layout.py +++ b/core/src/apps/cardano/layout.py @@ -5,6 +5,7 @@ ButtonRequestType, CardanoAddressType, CardanoCertificateType, + CardanoDRepType, CardanoNativeScriptType, ) from trezor.strings import format_amount @@ -559,6 +560,10 @@ async def confirm_certificate( assert certificate.deposit is not None # validate_certificate props.append(("Deposit:", format_coin_amount(certificate.deposit, network_id))) + elif certificate.type == CardanoCertificateType.VOTE_DELEGATION: + assert certificate.drep is not None # validate_certificate + props.append(_format_drep(certificate.drep)) + await confirm_properties( "confirm_certificate", "Confirm transaction", @@ -734,6 +739,28 @@ def _format_stake_credential( raise ValueError +def _format_drep(drep: messages.CardanoDRep) -> tuple[str, str]: + if drep.type == CardanoDRepType.KEY_HASH: + assert drep.key_hash is not None # validate_drep + return ( + "Delegating to key hash:", + bech32.encode(bech32.HRP_KEY_HASH, drep.key_hash), + ) + elif drep.type == CardanoDRepType.SCRIPT_HASH: + assert drep.script_hash is not None # validate_drep + return ( + "Delegating to script:", + bech32.encode(bech32.HRP_SCRIPT_HASH, drep.script_hash), + ) + elif drep.type == CardanoDRepType.ABSTAIN: + return ("Delegating to:", "Abstain") + elif drep.type == CardanoDRepType.NO_CONFIDENCE: + return ("Delegating to:", "No Confidence") + else: + # should be unreachable unless there's a bug in validation + raise ValueError + + async def confirm_cvote_registration_delegation( public_key: str, weight: int,