1
0
mirror of https://github.com/trezor/trezor-firmware.git synced 2025-01-03 12:00:59 +00:00

refactor(core): use code to append colon to strings

[no changelog]
This commit is contained in:
Ioan Bizău 2024-08-28 18:34:09 +02:00 committed by Martin Milata
parent 74fb627733
commit 32be89a29a
18 changed files with 65 additions and 190 deletions

View File

@ -311,7 +311,6 @@ static void _librust_qstrs(void) {
MP_QSTR_joint__to_the_total_amount;
MP_QSTR_joint__you_are_contributing;
MP_QSTR_label;
MP_QSTR_label_with_colon_template;
MP_QSTR_language;
MP_QSTR_language__change_to_template;
MP_QSTR_language__changed;

View File

@ -1369,7 +1369,6 @@ pub enum TranslatedString {
instructions__swipe_down = 964, // "Swipe down"
#[cfg(feature = "universal_fw")]
fido__title_credential_details = 965, // "Credential details"
label_with_colon_template = 966, // "{0}:"
}
impl TranslatedString {
@ -2733,7 +2732,6 @@ impl TranslatedString {
Self::instructions__swipe_down => "Swipe down",
#[cfg(feature = "universal_fw")]
Self::fido__title_credential_details => "Credential details",
Self::label_with_colon_template => "{0}:",
}
}
@ -4098,7 +4096,6 @@ impl TranslatedString {
Qstr::MP_QSTR_instructions__swipe_down => Some(Self::instructions__swipe_down),
#[cfg(feature = "universal_fw")]
Qstr::MP_QSTR_fido__title_credential_details => Some(Self::fido__title_credential_details),
Qstr::MP_QSTR_label_with_colon_template => Some(Self::label_with_colon_template),
_ => None,
}
}

View File

@ -398,7 +398,6 @@ class TR:
joint__title: str = "Joint transaction"
joint__to_the_total_amount: str = "To the total amount:"
joint__you_are_contributing: str = "You are contributing:"
label_with_colon_template: str = "{0}:"
language__change_to_template: str = "Change language to {0}?"
language__changed: str = "Language changed successfully"
language__progress: str = "Changing language"

View File

@ -564,10 +564,7 @@ async def confirm_certificate(
assert certificate.type != CardanoCertificateType.STAKE_POOL_REGISTRATION
props: list[PropertyType] = [
(
TR.label_with_colon_template.format(TR.words__confirm),
CERTIFICATE_TYPE_NAMES[certificate.type],
),
(f"{TR.words__confirm}:", CERTIFICATE_TYPE_NAMES[certificate.type]),
_format_stake_credential(
certificate.path, certificate.script_hash, certificate.key_hash
),

View File

@ -56,10 +56,7 @@ async def confirm_action_buyram(msg: EosActionBuyRam) -> None:
(
(TR.eos__payer, eos_name_to_string(msg.payer)),
(TR.eos__receiver, eos_name_to_string(msg.receiver)),
(
TR.label_with_colon_template.format(TR.words__amount),
eos_asset_to_string(msg.quantity),
),
(f"{TR.words__amount}:", eos_asset_to_string(msg.quantity)),
),
)
@ -167,10 +164,7 @@ async def confirm_action_transfer(msg: EosActionTransfer, account: str) -> None:
props = [
(TR.eos__from, eos_name_to_string(msg.sender)),
(TR.eos__to, eos_name_to_string(msg.receiver)),
(
TR.label_with_colon_template.format(TR.words__amount),
eos_asset_to_string(msg.quantity),
),
(f"{TR.words__amount}:", eos_asset_to_string(msg.quantity)),
(TR.eos__contract, account),
]
if msg.memo is not None:
@ -184,10 +178,7 @@ async def confirm_action_transfer(msg: EosActionTransfer, account: str) -> None:
async def confirm_action_updateauth(msg: EosActionUpdateAuth) -> None:
props: list[PropertyType] = [
(
TR.label_with_colon_template.format(TR.words__account),
eos_name_to_string(msg.account),
),
(f"{TR.words__account}:", eos_name_to_string(msg.account)),
(TR.eos__permission, eos_name_to_string(msg.permission)),
(TR.eos__parent, eos_name_to_string(msg.parent)),
]
@ -204,10 +195,7 @@ async def confirm_action_deleteauth(msg: EosActionDeleteAuth) -> None:
"confirm_deleteauth",
TR.eos__delete_auth,
(
(
TR.label_with_colon_template.format(TR.words__account),
eos_name_to_string(msg.account),
),
(f"{TR.words__account}:", eos_name_to_string(msg.account)),
(TR.eos__permission, eos_name_to_string(msg.permission)),
),
)
@ -218,10 +206,7 @@ async def confirm_action_linkauth(msg: EosActionLinkAuth) -> None:
"confirm_linkauth",
TR.eos__link_auth,
(
(
TR.label_with_colon_template.format(TR.words__account),
eos_name_to_string(msg.account),
),
(f"{TR.words__account}:", eos_name_to_string(msg.account)),
(TR.eos__code, eos_name_to_string(msg.code)),
(TR.eos__type, eos_name_to_string(msg.type)),
(TR.eos__requirement, eos_name_to_string(msg.requirement)),
@ -234,10 +219,7 @@ async def confirm_action_unlinkauth(msg: EosActionUnlinkAuth) -> None:
"confirm_unlinkauth",
TR.eos__unlink_auth,
(
(
TR.label_with_colon_template.format(TR.words__account),
eos_name_to_string(msg.account),
),
(f"{TR.words__account}:", eos_name_to_string(msg.account)),
(TR.eos__code, eos_name_to_string(msg.code)),
(TR.eos__type, eos_name_to_string(msg.type)),
),
@ -291,8 +273,8 @@ def authorization_fields(auth: EosAuthorization) -> list[PropertyType]:
_key = public_key_to_wif(bytes(key.key))
_weight = str(key.weight)
header = TR.label_with_colon_template.format(f"Key #{i}")
w_header = TR.label_with_colon_template.format(f"Key #{i} Weight")
header = f"Key #{i}:"
w_header = f"Key #{i} Weight:"
append((header, _key))
append((w_header, _weight))
@ -303,9 +285,9 @@ def authorization_fields(auth: EosAuthorization) -> list[PropertyType]:
i = str(i)
# TODO: handle translation
a_header = TR.label_with_colon_template.format(f"Account #{i}")
p_header = TR.label_with_colon_template.format(f"Acc Permission #{i}")
w_header = TR.label_with_colon_template.format(f"Account #{i} weight")
a_header = f"Account #{i}:"
p_header = f"Acc Permission #{i}:"
w_header = f"Account #{i} weight:"
append((a_header, _account))
append((p_header, _permission))
@ -315,9 +297,9 @@ def authorization_fields(auth: EosAuthorization) -> list[PropertyType]:
_wait = str(wait.wait_sec)
_weight = str(wait.weight)
header = "Delay #" + str(i)
w_header = TR.label_with_colon_template.format(header + " weight")
append((header, _wait + " sec"))
header = f"Delay #{i}"
w_header = f"{header} weight:"
append((f"{header}:", _wait + " sec"))
append((w_header, _weight))
return fields

View File

@ -36,14 +36,8 @@ def _format_path(path: list[int]) -> str:
def _get_address_reference_props(address: AddressReference, display_name: str):
return (
(TR.solana__is_provided_via_lookup_table_template.format(display_name), ""),
(
TR.label_with_colon_template.format(TR.solana__lookup_table_address),
base58.encode(address[0]),
),
(
TR.label_with_colon_template.format(TR.solana__account_index),
f"{address[1]}",
),
(f"{TR.solana__lookup_table_address}:", base58.encode(address[0])),
(f"{TR.solana__account_index}:", f"{address[1]}"),
)
@ -149,9 +143,7 @@ async def confirm_instruction(
signers.append(
(
TR.label_with_colon_template.format(
f"{TR.words__signer} {i}{path_str}"
),
f"{TR.words__signer} {i}{path_str}:",
base58.encode(multisig_signer[0]),
)
)
@ -202,12 +194,7 @@ async def confirm_unsupported_instruction_details(
await confirm_properties(
"instruction_data",
title,
(
(
TR.label_with_colon_template.format(TR.solana__instruction_data),
bytes(instruction.instruction_data),
),
),
((f"{TR.solana__instruction_data}:", bytes(instruction.instruction_data)),),
)
accounts = []
@ -222,9 +209,7 @@ async def confirm_unsupported_instruction_details(
accounts.append(
(
TR.label_with_colon_template.format(
f"{TR.words__account} {i}{path_str} {address_type}"
),
f"{TR.words__account} {i}{path_str} {address_type}:",
base58.encode(account_public_key),
)
)
@ -317,14 +302,7 @@ async def confirm_token_transfer(
br_code=ButtonRequestType.ConfirmOutput,
verb=TR.buttons__continue,
info_items=(
(
(
TR.label_with_colon_template.format(
TR.solana__associated_token_account
),
base58.encode(token_account),
),
)
((f"{TR.solana__associated_token_account}:", base58.encode(token_account)),)
if token_account != destination_account
else None
),
@ -360,16 +338,10 @@ async def confirm_custom_transaction(
await confirm_solana_tx(
amount=f"{format_amount(amount, decimals)} {unit}",
fee=f"{format_amount(fee, 9)} SOL",
fee_title=TR.label_with_colon_template.format(TR.solana__expected_fee),
fee_title=f"{TR.solana__expected_fee}:",
items=(
(
TR.label_with_colon_template.format(TR.words__account),
_format_path(signer_path),
),
(
TR.label_with_colon_template.format(TR.words__blockhash),
base58.encode(blockhash),
),
(f"{TR.words__account}:", _format_path(signer_path)),
(f"{TR.words__blockhash}:", base58.encode(blockhash)),
),
)
@ -381,15 +353,9 @@ async def confirm_transaction(
amount="",
amount_title="",
fee=f"{format_amount(fee, 9)} SOL",
fee_title=TR.label_with_colon_template.format(TR.solana__expected_fee),
fee_title=f"{TR.solana__expected_fee}:",
items=(
(
TR.label_with_colon_template.format(TR.words__account),
_format_path(signer_path),
),
(
TR.label_with_colon_template.format(TR.words__blockhash),
base58.encode(blockhash),
),
(f"{TR.words__account}:", _format_path(signer_path)),
(f"{TR.words__blockhash}:", base58.encode(blockhash)),
),
)

View File

@ -283,7 +283,7 @@ async def confirm_set_options_op(op: StellarSetOptionsOp) -> None:
title = TR.stellar__remove_signer
data: str | bytes = ""
if signer_type == StellarSignerType.ACCOUNT:
description = TR.label_with_colon_template.format(TR.words__account)
description = f"{TR.words__account}:"
data = helpers.address_from_public_key(signer_key)
elif signer_type == StellarSignerType.PRE_AUTH:
description = TR.stellar__preauth_transaction

View File

@ -22,7 +22,7 @@ async def require_confirm_fee(value: int, fee: int) -> None:
await confirm_total(
format_tezos_amount(value),
format_tezos_amount(fee),
total_label=TR.label_with_colon_template.format(TR.words__amount),
total_label=f"{TR.words__amount}:",
)
@ -30,7 +30,7 @@ async def require_confirm_origination(address: str) -> None:
await confirm_address(
TR.tezos__confirm_origination,
address,
TR.label_with_colon_template.format(TR.words__address),
f"{TR.words__address}:",
"confirm_origination",
BR_SIGN_TX,
)
@ -42,10 +42,7 @@ async def require_confirm_origination_fee(balance: int, fee: int) -> None:
TR.tezos__confirm_origination,
(
(TR.tezos__balance, format_tezos_amount(balance)),
(
TR.label_with_colon_template.format(TR.words__fee),
format_tezos_amount(fee),
),
(f"{TR.words__fee}:", format_tezos_amount(fee)),
),
hold=True,
)
@ -65,7 +62,7 @@ async def require_confirm_set_delegate(fee: int) -> None:
await confirm_metadata(
"confirm_delegation_final",
TR.tezos__confirm_delegation,
TR.label_with_colon_template.format(TR.words__fee) + "\n{}",
f"{TR.words__fee}:\n{{}}",
format_tezos_amount(fee),
BR_SIGN_TX,
hold=True,
@ -77,11 +74,8 @@ async def require_confirm_register_delegate(address: str, fee: int) -> None:
"confirm_register_delegate",
TR.tezos__register_delegate,
(
(
TR.label_with_colon_template.format(TR.words__fee),
format_tezos_amount(fee),
),
(TR.label_with_colon_template.format(TR.words__address), address),
(f"{TR.words__fee}:", format_tezos_amount(fee)),
(f"{TR.words__address}:", address),
),
hold=True,
br_code=BR_SIGN_TX,
@ -103,7 +97,7 @@ async def require_confirm_ballot(proposal: str, ballot: str) -> None:
TR.tezos__submit_ballot,
(
(TR.tezos__ballot, ballot),
(TR.label_with_colon_template.format(TR.tezos__proposal), proposal),
(f"{TR.tezos__proposal}:", proposal),
),
hold=True,
br_code=BR_SIGN_TX,
@ -137,7 +131,7 @@ async def require_confirm_manager_remove_delegate(fee: int) -> None:
await confirm_metadata(
"confirm_undelegation_final",
TR.tezos__remove_delegation,
TR.label_with_colon_template.format(TR.words__fee) + "\n{}",
f"{TR.words__fee}:\n{{}}",
format_tezos_amount(fee),
BR_SIGN_TX,
hold=True,

View File

@ -1116,9 +1116,7 @@ if not utils.BITCOIN_ONLY:
br_code: ButtonRequestType = ButtonRequestType.SignTx,
) -> Awaitable[None]:
amount_title = (
amount_title
if amount_title is not None
else TR.label_with_colon_template.format(TR.words__amount)
amount_title if amount_title is not None else f"{TR.words__amount}:"
) # def_arg
fee_title = fee_title or TR.words__fee # def_arg
return _confirm_summary(

View File

@ -1027,9 +1027,7 @@ def confirm_amount(
br_name: str = "confirm_amount",
br_code: ButtonRequestType = BR_CODE_OTHER,
) -> Awaitable[None]:
description = description or TR.label_with_colon_template.format(
TR.words__amount
) # def_arg
description = description or f"{TR.words__amount}:" # def_arg
return confirm_blob(
br_name,
title,
@ -1165,9 +1163,7 @@ def confirm_total(
br_name: str = "confirm_total",
br_code: ButtonRequestType = ButtonRequestType.SignTx,
) -> Awaitable[None]:
total_label = total_label or TR.label_with_colon_template.format(
TR.send__total_amount
) # def_arg
total_label = total_label or f"{TR.send__total_amount}:" # def_arg
fee_label = fee_label or TR.send__including_fee # def_arg
return raise_if_not_confirmed(
interact(
@ -1220,7 +1216,7 @@ if not utils.BITCOIN_ONLY:
amount_title = verb
amount_value = ""
else:
amount_title = TR.label_with_colon_template.format(TR.words__amount)
amount_title = f"{TR.words__amount}:"
amount_value = total_amount
await raise_if_not_confirmed(
interact(
@ -1228,14 +1224,9 @@ if not utils.BITCOIN_ONLY:
trezorui2.altcoin_tx_summary(
amount_title=amount_title,
amount_value=amount_value,
fee_title=TR.label_with_colon_template.format(
TR.send__maximum_fee
),
fee_title=f"{TR.send__maximum_fee}:",
fee_value=maximum_fee,
items=[
(TR.label_with_colon_template.format(k), v)
for (k, v) in info_items
],
items=[(f"{k}:", v) for (k, v) in info_items],
cancel_cross=True,
)
),
@ -1254,9 +1245,7 @@ if not utils.BITCOIN_ONLY:
br_code: ButtonRequestType = ButtonRequestType.SignTx,
) -> Awaitable[None]:
amount_title = (
amount_title
if amount_title is not None
else TR.label_with_colon_template.format(TR.words__amount)
amount_title if amount_title is not None else f"{TR.words__amount}:"
) # def_arg
fee_title = fee_title or TR.words__fee # def_arg
return raise_if_not_confirmed(
@ -1287,14 +1276,11 @@ if not utils.BITCOIN_ONLY:
) -> None:
summary_layout = RustLayout(
trezorui2.altcoin_tx_summary(
amount_title=TR.label_with_colon_template.format(TR.words__amount),
amount_title=f"{TR.words__amount}:",
amount_value=total_amount,
fee_title=TR.label_with_colon_template.format(TR.send__maximum_fee),
fee_title=f"{TR.send__maximum_fee}:",
fee_value=maximum_fee,
items=[
(TR.label_with_colon_template.format(k), v)
for (k, v) in fee_info_items
],
items=[(f"{k}:", v) for (k, v) in fee_info_items],
)
)
@ -1377,7 +1363,7 @@ async def confirm_modify_output(
data=address,
verb=TR.buttons__continue,
verb_cancel=None,
description=TR.label_with_colon_template.format(TR.words__address),
description=f"{TR.words__address}:",
extra=None,
)
)

View File

@ -942,9 +942,7 @@ def confirm_amount(
br_name: str = "confirm_amount",
br_code: ButtonRequestType = BR_CODE_OTHER,
) -> Awaitable[None]:
description = description or TR.label_with_colon_template.format(
TR.words__amount
) # def_arg
description = description or f"{TR.words__amount}:" # def_arg
return confirm_value(
title,
amount,
@ -1043,9 +1041,7 @@ def confirm_total(
br_code: ButtonRequestType = ButtonRequestType.SignTx,
) -> Awaitable[None]:
title = title or TR.words__title_summary # def_arg
total_label = total_label or TR.label_with_colon_template.format(
TR.send__total_amount
) # def_arg
total_label = total_label or f"{TR.send__total_amount}:" # def_arg
fee_label = fee_label or TR.send__including_fee # def_arg
items = [
@ -1056,12 +1052,7 @@ def confirm_total(
if source_account:
info_items.append((TR.confirm_total__sending_from_account, source_account))
if fee_rate_amount:
info_items.append(
(
TR.label_with_colon_template.format(TR.confirm_total__fee_rate),
fee_rate_amount,
)
)
info_items.append((f"{TR.confirm_total__fee_rate}:", fee_rate_amount))
return _confirm_summary(
items,
@ -1116,14 +1107,8 @@ if not utils.BITCOIN_ONLY:
trezorui2.confirm_total(
title=TR.words__title_summary,
items=[
(
TR.label_with_colon_template.format(TR.words__amount),
total_amount,
),
(
TR.label_with_colon_template.format(TR.send__maximum_fee),
maximum_fee,
),
(f"{TR.words__amount}:", total_amount),
(f"{TR.send__maximum_fee}:", maximum_fee),
],
info_button=True,
cancel_arrow=True,
@ -1132,10 +1117,7 @@ if not utils.BITCOIN_ONLY:
info_layout = RustLayout(
trezorui2.show_info_with_cancel(
title=TR.confirm_total__title_fee,
items=[
(TR.label_with_colon_template.format(k), v)
for (k, v) in fee_info_items
],
items=[(f"{k}:", v) for (k, v) in fee_info_items],
)
)
@ -1187,27 +1169,17 @@ if not utils.BITCOIN_ONLY:
# confirmation
if verb == TR.ethereum__staking_claim:
items = (
(
TR.label_with_colon_template.format(TR.send__maximum_fee),
maximum_fee,
),
)
items = ((f"{TR.send__maximum_fee}:", maximum_fee),)
else:
items = (
(TR.label_with_colon_template.format(TR.words__amount), total_amount),
(
TR.label_with_colon_template.format(TR.send__maximum_fee),
maximum_fee,
),
(f"{TR.words__amount}:", total_amount),
(f"{TR.send__maximum_fee}:", maximum_fee),
)
await _confirm_summary(
items, # items
title=title,
info_title=TR.confirm_total__title_fee,
info_items=[
(TR.label_with_colon_template.format(k), v) for (k, v) in info_items
],
info_items=[(f"{k}:", v) for (k, v) in info_items],
br_name=br_name,
br_code=br_code,
)
@ -1222,9 +1194,7 @@ if not utils.BITCOIN_ONLY:
br_code: ButtonRequestType = ButtonRequestType.SignTx,
) -> Awaitable[None]:
amount_title = (
amount_title
if amount_title is not None
else TR.label_with_colon_template.format(TR.words__amount)
amount_title if amount_title is not None else f"{TR.words__amount}:"
) # def_arg
fee_title = fee_title or TR.words__fee # def_arg
return _confirm_summary(
@ -1298,7 +1268,7 @@ async def confirm_modify_output(
data=address,
verb=TR.buttons__continue,
verb_cancel=None,
description=TR.label_with_colon_template.format(TR.words__address),
description=f"{TR.words__address}:",
extra=None,
)
)
@ -1442,16 +1412,9 @@ async def confirm_signverify(
items: list[tuple[str, str]] = []
if account is not None:
items.append((TR.label_with_colon_template.format(TR.words__account), account))
items.append((f"{TR.words__account}:", account))
if path is not None:
items.append(
(
TR.label_with_colon_template.format(
TR.address_details__derivation_path
),
path,
)
)
items.append((f"{TR.address_details__derivation_path}:", path))
items.append(
(
TR.sign_message__message_size,

View File

@ -423,7 +423,6 @@
"joint__title": "Společná transakce",
"joint__to_the_total_amount": "Do celkové částky:",
"joint__you_are_contributing": "Přispíváte:",
"label_with_colon_template": "{0}:",
"language__change_to_template": "Změnit jazyk na {0}?",
"language__changed": "Jazyk byl změněn",
"language__progress": "Změna jazyka",

View File

@ -423,7 +423,6 @@
"joint__title": "Gemeins. transakt.",
"joint__to_the_total_amount": "Gesamtbetrag:",
"joint__you_are_contributing": "Dein Anteil:",
"label_with_colon_template": "{0}:",
"language__change_to_template": "Sprache in {0} ändern?",
"language__changed": "Die Sprache änderte sich erfolgreich",
"language__progress": "Sprache ändern",

View File

@ -400,7 +400,6 @@
"joint__title": "Joint transaction",
"joint__to_the_total_amount": "To the total amount:",
"joint__you_are_contributing": "You are contributing:",
"label_with_colon_template": "{0}:",
"language__change_to_template": "Change language to {0}?",
"language__changed": "Language changed successfully",
"language__progress": "Changing language",

View File

@ -423,7 +423,6 @@
"joint__title": "Transacc. conjunta",
"joint__to_the_total_amount": "Al importe total:",
"joint__you_are_contributing": "Estás aportando:",
"label_with_colon_template": "{0}:",
"language__change_to_template": "Cambiar el idioma a {0}?",
"language__changed": "El lenguaje cambió con éxito",
"language__progress": "Lenguaje cambiante",

View File

@ -423,7 +423,6 @@
"joint__title": "Trans. commune",
"joint__to_the_total_amount": "Au montant total:",
"joint__you_are_contributing": "Votre contribution:",
"label_with_colon_template": "{0}:",
"language__change_to_template": "Changer la langue en {0} ?",
"language__changed": "La langue a changé avec succès",
"language__progress": "Langage changeant",

View File

@ -964,6 +964,5 @@
"962": "fido__title_for_authentication",
"963": "fido__title_select_credential",
"964": "instructions__swipe_down",
"965": "fido__title_credential_details",
"966": "label_with_colon_template"
"965": "fido__title_credential_details"
}

View File

@ -1,8 +1,8 @@
{
"current": {
"merkle_root": "bcfcf3a7596b3c34dff25e340c40c1264b996dce5d2dc082c0a6657bb5383c86",
"datetime": "2024-09-16T08:03:17.940712",
"commit": "e489a1c6dbad936f9011d096fcdc8fab56ed2f6c"
"merkle_root": "3f354ff51c2d3855bf128509cd29b88c442eb7421f40e3788c1999cbbbe852eb",
"datetime": "2024-09-16T08:04:38.685162",
"commit": "1fac12992b035ba9ed86399ba00d52ca44cc9bc5"
},
"history": [
{