mirror of
https://github.com/trezor/trezor-firmware.git
synced 2024-11-20 06:28:09 +00:00
fix(cardano): display tADA in testnet transactions
This commit is contained in:
parent
1f20c49536
commit
a36fc6cadc
@ -25,7 +25,7 @@ from apps.common.paths import address_n_to_str
|
|||||||
|
|
||||||
from . import seed
|
from . import seed
|
||||||
from .address import derive_human_readable_address, encode_human_readable_address
|
from .address import derive_human_readable_address, encode_human_readable_address
|
||||||
from .helpers import bech32, protocol_magics
|
from .helpers import bech32, network_ids, protocol_magics
|
||||||
from .helpers.utils import (
|
from .helpers.utils import (
|
||||||
format_account_number,
|
format_account_number,
|
||||||
format_asset_fingerprint,
|
format_asset_fingerprint,
|
||||||
@ -85,8 +85,9 @@ CERTIFICATE_TYPE_NAMES = {
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
def format_coin_amount(amount: int) -> str:
|
def format_coin_amount(amount: int, network_id: int) -> str:
|
||||||
return f"{format_amount(amount, 6)} ADA"
|
currency = "ADA" if network_ids.is_mainnet(network_id) else "tADA"
|
||||||
|
return f"{format_amount(amount, 6)} {currency}"
|
||||||
|
|
||||||
|
|
||||||
def is_printable_ascii_bytestring(bytestr: bytes) -> bool:
|
def is_printable_ascii_bytestring(bytestr: bytes) -> bool:
|
||||||
@ -232,12 +233,13 @@ async def confirm_sending(
|
|||||||
ada_amount: int,
|
ada_amount: int,
|
||||||
to: str,
|
to: str,
|
||||||
is_change_output: bool,
|
is_change_output: bool,
|
||||||
|
network_id: int,
|
||||||
) -> None:
|
) -> None:
|
||||||
subtitle = "Change amount:" if is_change_output else "Confirm sending:"
|
subtitle = "Change amount:" if is_change_output else "Confirm sending:"
|
||||||
await confirm_output(
|
await confirm_output(
|
||||||
ctx,
|
ctx,
|
||||||
to,
|
to,
|
||||||
format_coin_amount(ada_amount),
|
format_coin_amount(ada_amount, network_id),
|
||||||
title="Confirm transaction",
|
title="Confirm transaction",
|
||||||
subtitle=subtitle,
|
subtitle=subtitle,
|
||||||
font_amount=ui.BOLD,
|
font_amount=ui.BOLD,
|
||||||
@ -459,6 +461,7 @@ async def confirm_witness_request(
|
|||||||
async def confirm_transaction(
|
async def confirm_transaction(
|
||||||
ctx: wire.Context,
|
ctx: wire.Context,
|
||||||
fee: int,
|
fee: int,
|
||||||
|
network_id: int,
|
||||||
protocol_magic: int,
|
protocol_magic: int,
|
||||||
ttl: int | None,
|
ttl: int | None,
|
||||||
validity_interval_start: int | None,
|
validity_interval_start: int | None,
|
||||||
@ -466,7 +469,7 @@ async def confirm_transaction(
|
|||||||
tx_hash: bytes | None,
|
tx_hash: bytes | None,
|
||||||
) -> None:
|
) -> None:
|
||||||
props: list[PropertyType] = [
|
props: list[PropertyType] = [
|
||||||
("Transaction fee:", format_coin_amount(fee)),
|
("Transaction fee:", format_coin_amount(fee, network_id)),
|
||||||
]
|
]
|
||||||
|
|
||||||
if is_network_id_verifiable:
|
if is_network_id_verifiable:
|
||||||
@ -516,7 +519,7 @@ async def confirm_certificate(
|
|||||||
|
|
||||||
|
|
||||||
async def confirm_stake_pool_parameters(
|
async def confirm_stake_pool_parameters(
|
||||||
ctx: wire.Context, pool_parameters: CardanoPoolParametersType
|
ctx: wire.Context, pool_parameters: CardanoPoolParametersType, network_id: int
|
||||||
) -> None:
|
) -> None:
|
||||||
margin_percentage = (
|
margin_percentage = (
|
||||||
100.0 * pool_parameters.margin_numerator / pool_parameters.margin_denominator
|
100.0 * pool_parameters.margin_numerator / pool_parameters.margin_denominator
|
||||||
@ -533,8 +536,8 @@ async def confirm_stake_pool_parameters(
|
|||||||
),
|
),
|
||||||
("Pool reward account:", pool_parameters.reward_account),
|
("Pool reward account:", pool_parameters.reward_account),
|
||||||
(
|
(
|
||||||
f"Pledge: {format_coin_amount(pool_parameters.pledge)}\n"
|
f"Pledge: {format_coin_amount(pool_parameters.pledge, network_id)}\n"
|
||||||
+ f"Cost: {format_coin_amount(pool_parameters.cost)}\n"
|
+ f"Cost: {format_coin_amount(pool_parameters.cost, network_id)}\n"
|
||||||
+ f"Margin: {percentage_formatted}%",
|
+ f"Margin: {percentage_formatted}%",
|
||||||
None,
|
None,
|
||||||
),
|
),
|
||||||
@ -641,7 +644,10 @@ async def confirm_stake_pool_registration_final(
|
|||||||
|
|
||||||
|
|
||||||
async def confirm_withdrawal(
|
async def confirm_withdrawal(
|
||||||
ctx: wire.Context, withdrawal: CardanoTxWithdrawal, reward_address_bytes: bytes
|
ctx: wire.Context,
|
||||||
|
withdrawal: CardanoTxWithdrawal,
|
||||||
|
reward_address_bytes: bytes,
|
||||||
|
network_id: int,
|
||||||
) -> None:
|
) -> None:
|
||||||
address_type_name = "script reward" if withdrawal.script_hash else "reward"
|
address_type_name = "script reward" if withdrawal.script_hash else "reward"
|
||||||
reward_address = encode_human_readable_address(reward_address_bytes)
|
reward_address = encode_human_readable_address(reward_address_bytes)
|
||||||
@ -656,7 +662,7 @@ async def confirm_withdrawal(
|
|||||||
)
|
)
|
||||||
)
|
)
|
||||||
|
|
||||||
props.append(("Amount:", format_coin_amount(withdrawal.amount)))
|
props.append(("Amount:", format_coin_amount(withdrawal.amount, network_id)))
|
||||||
|
|
||||||
await confirm_properties(
|
await confirm_properties(
|
||||||
ctx,
|
ctx,
|
||||||
|
@ -372,6 +372,7 @@ async def _confirm_transaction(
|
|||||||
await confirm_transaction(
|
await confirm_transaction(
|
||||||
ctx,
|
ctx,
|
||||||
msg.fee,
|
msg.fee,
|
||||||
|
msg.network_id,
|
||||||
msg.protocol_magic,
|
msg.protocol_magic,
|
||||||
msg.ttl,
|
msg.ttl,
|
||||||
msg.validity_interval_start,
|
msg.validity_interval_start,
|
||||||
@ -385,6 +386,7 @@ async def _confirm_transaction(
|
|||||||
await confirm_transaction(
|
await confirm_transaction(
|
||||||
ctx,
|
ctx,
|
||||||
msg.fee,
|
msg.fee,
|
||||||
|
msg.network_id,
|
||||||
msg.protocol_magic,
|
msg.protocol_magic,
|
||||||
msg.ttl,
|
msg.ttl,
|
||||||
msg.validity_interval_start,
|
msg.validity_interval_start,
|
||||||
@ -547,7 +549,7 @@ async def _process_certificates(
|
|||||||
validate_certificate(
|
validate_certificate(
|
||||||
certificate, signing_mode, protocol_magic, network_id, account_path_checker
|
certificate, signing_mode, protocol_magic, network_id, account_path_checker
|
||||||
)
|
)
|
||||||
await _show_certificate(ctx, certificate, signing_mode)
|
await _show_certificate(ctx, certificate, signing_mode, network_id)
|
||||||
|
|
||||||
if certificate.type == CardanoCertificateType.STAKE_POOL_REGISTRATION:
|
if certificate.type == CardanoCertificateType.STAKE_POOL_REGISTRATION:
|
||||||
pool_parameters = certificate.pool_parameters
|
pool_parameters = certificate.pool_parameters
|
||||||
@ -658,7 +660,7 @@ async def _process_withdrawals(
|
|||||||
)
|
)
|
||||||
previous_reward_address_bytes = reward_address_bytes
|
previous_reward_address_bytes = reward_address_bytes
|
||||||
|
|
||||||
await confirm_withdrawal(ctx, withdrawal, reward_address_bytes)
|
await confirm_withdrawal(ctx, withdrawal, reward_address_bytes, network_id)
|
||||||
|
|
||||||
withdrawals_dict.add(reward_address_bytes, withdrawal.amount)
|
withdrawals_dict.add(reward_address_bytes, withdrawal.amount)
|
||||||
|
|
||||||
@ -999,7 +1001,7 @@ async def _show_output(
|
|||||||
assert output.address is not None # _validate_output
|
assert output.address is not None # _validate_output
|
||||||
address = output.address
|
address = output.address
|
||||||
|
|
||||||
await confirm_sending(ctx, output.amount, address, is_change_output)
|
await confirm_sending(ctx, output.amount, address, is_change_output, network_id)
|
||||||
|
|
||||||
|
|
||||||
def _validate_asset_group(
|
def _validate_asset_group(
|
||||||
@ -1043,6 +1045,7 @@ async def _show_certificate(
|
|||||||
ctx: wire.Context,
|
ctx: wire.Context,
|
||||||
certificate: CardanoTxCertificate,
|
certificate: CardanoTxCertificate,
|
||||||
signing_mode: CardanoTxSigningMode,
|
signing_mode: CardanoTxSigningMode,
|
||||||
|
network_id: int,
|
||||||
) -> None:
|
) -> None:
|
||||||
if signing_mode == CardanoTxSigningMode.ORDINARY_TRANSACTION:
|
if signing_mode == CardanoTxSigningMode.ORDINARY_TRANSACTION:
|
||||||
assert certificate.path # validate_certificate
|
assert certificate.path # validate_certificate
|
||||||
@ -1056,7 +1059,7 @@ async def _show_certificate(
|
|||||||
):
|
):
|
||||||
await confirm_certificate(ctx, certificate)
|
await confirm_certificate(ctx, certificate)
|
||||||
elif signing_mode == CardanoTxSigningMode.POOL_REGISTRATION_AS_OWNER:
|
elif signing_mode == CardanoTxSigningMode.POOL_REGISTRATION_AS_OWNER:
|
||||||
await _show_stake_pool_registration_certificate(ctx, certificate)
|
await _show_stake_pool_registration_certificate(ctx, certificate, network_id)
|
||||||
else:
|
else:
|
||||||
raise RuntimeError # we didn't cover all signing modes
|
raise RuntimeError # we didn't cover all signing modes
|
||||||
|
|
||||||
@ -1174,7 +1177,9 @@ def _sign_tx_hash(
|
|||||||
|
|
||||||
|
|
||||||
async def _show_stake_pool_registration_certificate(
|
async def _show_stake_pool_registration_certificate(
|
||||||
ctx: wire.Context, stake_pool_registration_certificate: CardanoTxCertificate
|
ctx: wire.Context,
|
||||||
|
stake_pool_registration_certificate: CardanoTxCertificate,
|
||||||
|
network_id: int,
|
||||||
) -> None:
|
) -> None:
|
||||||
pool_parameters = stake_pool_registration_certificate.pool_parameters
|
pool_parameters = stake_pool_registration_certificate.pool_parameters
|
||||||
# _validate_stake_pool_registration_tx_structure ensures that there is only one
|
# _validate_stake_pool_registration_tx_structure ensures that there is only one
|
||||||
@ -1182,7 +1187,7 @@ async def _show_stake_pool_registration_certificate(
|
|||||||
assert pool_parameters is not None
|
assert pool_parameters is not None
|
||||||
|
|
||||||
# display the transaction (certificate) in UI
|
# display the transaction (certificate) in UI
|
||||||
await confirm_stake_pool_parameters(ctx, pool_parameters)
|
await confirm_stake_pool_parameters(ctx, pool_parameters, network_id)
|
||||||
|
|
||||||
await confirm_stake_pool_metadata(ctx, pool_parameters.metadata)
|
await confirm_stake_pool_metadata(ctx, pool_parameters.metadata)
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user