Skip to content

Commit

Permalink
feat(legacy): use thousands separator (fixes #2394)
Browse files Browse the repository at this point in the history
  • Loading branch information
matejcik committed Aug 2, 2022
1 parent f0976fe commit 31f608e
Show file tree
Hide file tree
Showing 6 changed files with 29 additions and 30 deletions.
1 change: 1 addition & 0 deletions legacy/firmware/.changelog.d/2394.added
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Show thousands separator when displaying large amounts.
2 changes: 1 addition & 1 deletion legacy/firmware/ethereum.c
Original file line number Diff line number Diff line change
Expand Up @@ -331,7 +331,7 @@ static void ethereumFormatAmount(const bignum256 *amnt, const TokenType *token,
} else {
ASSIGN_ETHEREUM_SUFFIX(suffix, chain_id);
}
bn_format(amnt, NULL, suffix, decimals, 0, false, buf, buflen);
bn_format(amnt, NULL, suffix, decimals, 0, false, ',', buf, buflen);
}

static void layoutEthereumConfirmTx(const uint8_t *to, uint32_t to_len,
Expand Down
14 changes: 6 additions & 8 deletions legacy/firmware/layout2.c
Original file line number Diff line number Diff line change
Expand Up @@ -405,8 +405,7 @@ static size_t format_coin_amount(uint64_t amount, const char *prefix,
strlcpy(suffix + 1, coin->coin_shortcut, sizeof(suffix) - 1);
break;
}
return bn_format_uint64(amount, prefix, suffix, decimals, 0, false, output,
output_len);
return bn_format_amount(amount, prefix, suffix, decimals, output, output_len);
}

void layoutConfirmOutput(const CoinInfo *coin, AmountUnit amount_unit,
Expand Down Expand Up @@ -455,7 +454,7 @@ void layoutConfirmOmni(const uint8_t *data, uint32_t size) {
uint64_t amount_be = 0, amount = 0;
memcpy(&amount_be, data + 12, sizeof(uint64_t));
REVERSE64(amount_be, amount);
bn_format_uint64(amount, NULL, suffix, divisible ? 8 : 0, 0, false, str_out,
bn_format_amount(amount, NULL, suffix, divisible ? 8 : 0, str_out,
sizeof(str_out));
} else {
desc = _("Unknown transaction");
Expand Down Expand Up @@ -520,8 +519,8 @@ static bool formatFeeRate(uint64_t fee, uint64_t tx_weight, char *output,
// one decimal digit.
uint64_t fee_rate_multiplied = div_round(10 * fee, tx_size);

return bn_format_uint64(fee_rate_multiplied, "(",
segwit ? " sat/vB)" : " sat/B)", 1, 0, false, output,
return bn_format_amount(fee_rate_multiplied, "(",
segwit ? " sat/vB)" : " sat/B)", 1, output,
output_length) != 0;
}

Expand Down Expand Up @@ -1186,7 +1185,7 @@ void layoutNEMLevy(const NEMMosaicDefinition *definition, uint8_t network) {

switch (definition->levy) {
case NEMMosaicLevy_MosaicLevy_Percentile:
bn_format_uint64(definition->fee, NULL, NULL, 0, 0, false, str_out,
bn_format_amount(definition->fee, NULL, NULL, 0, str_out,
sizeof(str_out));

layoutDialogSwipe(
Expand Down Expand Up @@ -1267,8 +1266,7 @@ void layoutConfirmAutoLockDelay(uint32_t delay_ms) {

strlcpy(line, _("after "), sizeof(line));
size_t off = strlen(line);
bn_format_uint64(num, NULL, NULL, 0, 0, false, &line[off],
sizeof(line) - off);
bn_format_amount(num, NULL, NULL, 0, &line[off], sizeof(line) - off);
strlcat(line, " ", sizeof(line));
strlcat(line, unit, sizeof(line));
if (num > 1) {
Expand Down
8 changes: 4 additions & 4 deletions legacy/firmware/nem2.c
Original file line number Diff line number Diff line change
Expand Up @@ -353,7 +353,7 @@ bool nem_askMosaicCreation(const NEMTransactionCommon *common,

bn_format_uint64(mosaic_creation->definition.supply, NULL, NULL,
mosaic_creation->definition.divisibility,
mosaic_creation->definition.divisibility, true, str_out,
mosaic_creation->definition.divisibility, true, ',', str_out,
sizeof(str_out));

layoutDialogSwipe(
Expand Down Expand Up @@ -430,7 +430,7 @@ bool nem_askSupplyChange(const NEMTransactionCommon *common,
}

char str_out[32] = {0};
bn_format_uint64(supply_change->delta, NULL, NULL, 0, 0, false, str_out,
bn_format_uint64(supply_change->delta, NULL, NULL, 0, 0, false, ',', str_out,
sizeof(str_out));

layoutDialogSwipe(
Expand Down Expand Up @@ -496,7 +496,7 @@ bool nem_askAggregateModification(
if (relative_change) {
char str_out[32] = {0};
bn_format_uint64(relative_change < 0 ? -relative_change : relative_change,
NULL, NULL, 0, 0, false, str_out, sizeof(str_out));
NULL, NULL, 0, 0, false, ',', str_out, sizeof(str_out));

layoutDialogSwipe(&bmp_icon_question, _("Cancel"), _("Next"), desc,
creation ? _("Set minimum")
Expand Down Expand Up @@ -648,7 +648,7 @@ static inline size_t format_amount(const NEMMosaicDefinition *definition,
&val, NULL,
definition && definition->has_ticker ? definition->ticker : NULL,
definition && definition->has_divisibility ? definition->divisibility : 0,
-divisor, false, str_out, size);
-divisor, false, ',', str_out, size);
}

void nem_canonicalizeMosaics(NEMTransfer *transfer) {
Expand Down
8 changes: 4 additions & 4 deletions legacy/firmware/stellar.c
Original file line number Diff line number Diff line change
Expand Up @@ -1379,7 +1379,7 @@ void stellar_getSignatureForActiveTx(uint8_t *out_signature) {
* "100.0"
*/
void stellar_format_stroops(uint64_t number, char *out, size_t outlen) {
bn_format_uint64(number, NULL, NULL, 7, 0, false, out, outlen);
bn_format_amount(number, NULL, NULL, 7, out, outlen);
}

/*
Expand Down Expand Up @@ -1423,7 +1423,7 @@ void stellar_format_price(uint32_t numerator, uint32_t denominator, char *out,
}

// Format with bn_format_uint64
bn_format_uint64(value, NULL, NULL, 6, 6 - scale, true, out, outlen);
bn_format_uint64(value, NULL, NULL, 6, 6 - scale, true, ',', out, outlen);
}

/*
Expand All @@ -1432,14 +1432,14 @@ void stellar_format_price(uint32_t numerator, uint32_t denominator, char *out,
void stellar_format_uint32(uint32_t number, char *out, size_t outlen) {
bignum256 bn_number = {0};
bn_read_uint32(number, &bn_number);
bn_format(&bn_number, NULL, NULL, 0, 0, false, out, outlen);
bn_format(&bn_number, NULL, NULL, 0, 0, false, ',', out, outlen);
}

/*
* Returns a uint64 formatted as a string
*/
void stellar_format_uint64(uint64_t number, char *out, size_t outlen) {
bn_format_uint64(number, NULL, NULL, 0, 0, false, out, outlen);
bn_format_uint64(number, NULL, NULL, 0, 0, false, ',', out, outlen);
}

/*
Expand Down
26 changes: 13 additions & 13 deletions tests/ui_tests/fixtures.json
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@
"T1_bitcoin-test_descriptors.py::test_descriptors[Testnet-1-InputScriptType.SPENDTAPROOT-tr([5c-ddc924d3": "f24b6c201efc2efbb174a48766df03f5964ea95908abca791714e22bcf9b635d",
"T1_bitcoin-test_descriptors.py::test_descriptors[Testnet-1-InputScriptType.SPENDWITNESS-wpkh([-996ae319": "cd384fcf3379759dd5fc3f2737ddfb9185a55e506d9d0869f8a85ba31ed1d973",
"T1_bitcoin-test_firo.py::test_spend_lelantus": "4597a8d1b5311af382c9d495bbbd08ef4fb8bc61b5645d78f1411397b4d1a0a5",
"T1_bitcoin-test_fujicoin.py::test_send_p2tr": "ac7a973fbca83d8af8276be75f18ff71659d82f0527256a19f75ebc8dfc57ee3",
"T1_bitcoin-test_fujicoin.py::test_send_p2tr": "bfa5dc1a494ea17fd43d52a315a7f1abe9ad80d7fdaa8b3ec5f92c4118638d1e",
"T1_bitcoin-test_getaddress.py::test_bch": "e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855",
"T1_bitcoin-test_getaddress.py::test_bch_multisig": "730fd13c57131201223dd2f5a14f287ca3b43f5d3a526ac71a9f436b123de388",
"T1_bitcoin-test_getaddress.py::test_btc": "e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855",
Expand Down Expand Up @@ -240,7 +240,7 @@
"T1_bitcoin-test_signtx.py::test_signtx_forbidden_fields[version_group_id-69]": "e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855",
"T1_bitcoin-test_signtx.py::test_spend_coinbase": "9f908b31e01ba580b127284c241c9730f517a1d0df1f9398375f80b86068729f",
"T1_bitcoin-test_signtx.py::test_testnet_big_amount": "f719fdaecbbf3abda98e3429c912bfb59079ad3df92b0d0fc8cc603d189b87cf",
"T1_bitcoin-test_signtx.py::test_testnet_fee_high_warning": "780476b5a22bb4901ed4e9a67f7a631c5ade4b50d2813d64cc227188305a7ced",
"T1_bitcoin-test_signtx.py::test_testnet_fee_high_warning": "169851ff1163295e6a411685c9e3c50722a332288e8e12b84e6c71ac10c4c4d4",
"T1_bitcoin-test_signtx.py::test_testnet_one_two_fee": "d415fc90494448dd952871a3ef2d77100c4b9f7f852513137ae34a9e2126449b",
"T1_bitcoin-test_signtx.py::test_two_changes": "61e8de6771877b747d58272920e47671d4cc6f0de0643c0932dba2d7a64aee31",
"T1_bitcoin-test_signtx.py::test_two_two": "dbe1e1fea61ba401b84a89253cc6d86c80ecb80d58ec50f6b984d9c043d66686",
Expand Down Expand Up @@ -362,7 +362,7 @@
"T1_ethereum-test_sign_verify_message.py::test_verify[parameters6-result6]": "0f79aea15b09e207f7e2bb226421549a0446a4722dde3000c31c3c66ec2059d1",
"T1_ethereum-test_sign_verify_message.py::test_verify[parameters7-result7]": "22daa96dbdd3aeeec11f1134baa29c0ccecbadf032a47aaa355f30c994897907",
"T1_ethereum-test_sign_verify_message.py::test_verify_invalid": "cdec0f79f2abbd90f4346494037f7bb4dd4dccc7c6739b497873d0c5603f2a26",
"T1_ethereum-test_signtx.py::test_data_streaming": "3856c34f789b98c94462607e431899490800681a09a5e54f366a77026f87a2b3",
"T1_ethereum-test_signtx.py::test_data_streaming": "058a66e82bb733d5c5c687b5537887022acfd7401bb0b5aa4a12f6f35b209239",
"T1_ethereum-test_signtx.py::test_sanity_checks": "e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855",
"T1_ethereum-test_signtx.py::test_sanity_checks_eip1559": "e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855",
"T1_ethereum-test_signtx.py::test_signtx[Auxilium]": "05d5ac917c9d3032fb4658b7f502748b412ffe435fc788c62733e00b948da5f7",
Expand All @@ -375,18 +375,18 @@
"T1_ethereum-test_signtx.py::test_signtx[Unknown_chain_id_eth_path]": "a6e6d63cba839c897e80dc0b7cf5c2263be8ff64a5281a43fca992380cca872b",
"T1_ethereum-test_signtx.py::test_signtx[Unknown_chain_id_testnet_path]": "a6e6d63cba839c897e80dc0b7cf5c2263be8ff64a5281a43fca992380cca872b",
"T1_ethereum-test_signtx.py::test_signtx[data_1]": "8b432aba21bc4344814cceaf693e114b9d3e3d6ceb83c3a6af7c3ed0f9b37449",
"T1_ethereum-test_signtx.py::test_signtx[data_2_bigdata]": "8f19f49cb3ef2532ba73ebeee12e779cb06a81677248e45e0fd76b042ee107c9",
"T1_ethereum-test_signtx.py::test_signtx[data_2_bigdata]": "445286b7501ca67dd16dafd7ea09c57cc4a37a642ae50f0c812d74353c37c017",
"T1_ethereum-test_signtx.py::test_signtx[known_erc20_token]": "7ef8d3bbf6e299b41522769a893f72b04571fc7176bc93e5c1701a2b5721fb20",
"T1_ethereum-test_signtx.py::test_signtx[max_chain_id]": "a6e6d63cba839c897e80dc0b7cf5c2263be8ff64a5281a43fca992380cca872b",
"T1_ethereum-test_signtx.py::test_signtx[max_chain_plus_one]": "a6e6d63cba839c897e80dc0b7cf5c2263be8ff64a5281a43fca992380cca872b",
"T1_ethereum-test_signtx.py::test_signtx[max_uint64]": "a6e6d63cba839c897e80dc0b7cf5c2263be8ff64a5281a43fca992380cca872b",
"T1_ethereum-test_signtx.py::test_signtx[newcontract]": "4ac80878058533d886276f66d2aeceff9d8a1b8083345458788ce85d9ce9e44d",
"T1_ethereum-test_signtx.py::test_signtx[newcontract]": "a7efa7f690d1448dc48f642f69688e8b266417901cc014e5930c94c9087b3e08",
"T1_ethereum-test_signtx.py::test_signtx[nodata_1]": "6bd90f2c98122de19159e60fd4dcf9f4b16a600407ac84ea1e447d561ea9decb",
"T1_ethereum-test_signtx.py::test_signtx[nodata_2_bigvalue]": "2a7108865158f53183b8eed55fa364ab9db508b4f62b875ba760acb520b66a8b",
"T1_ethereum-test_signtx.py::test_signtx[nodata_2_bigvalue]": "538f7be885ce6ea3a6dc842ef10797fa45184d7737f6f179c42d36fe92fadd45",
"T1_ethereum-test_signtx.py::test_signtx[unknown_erc20_token]": "df41efe4c5336fc188d3f754d2fe0b830588e57eaa32c98607b0bc4057851fcc",
"T1_ethereum-test_signtx.py::test_signtx[wanchain]": "37aa64fbab44b89757833df6ee78e302c97fe24c4cb74175f1843f635cb2dbec",
"T1_ethereum-test_signtx.py::test_signtx_eip1559[data_1]": "171ffadf61a2520274bedf6a8543127f23a8948c2689e034f996e170289b1822",
"T1_ethereum-test_signtx.py::test_signtx_eip1559[data_2_bigdata]": "6026efba08ebb6ff161eaa83a215e337f62242d6879f536578d0c2108e78817a",
"T1_ethereum-test_signtx.py::test_signtx_eip1559[data_2_bigdata]": "28d2a0d397b4e9865ca8286cc1a3669c3a7d34bb31b430662354bf3ec69d1cc5",
"T1_ethereum-test_signtx.py::test_signtx_eip1559[known_erc20]": "b8e205a40711e377f2185cec6e085fa2f6a4d5bbc6a03d9cf2758058b6c1e17b",
"T1_ethereum-test_signtx.py::test_signtx_eip1559[large_chainid]": "5b008a081b4ef9e7b47c9d0c1fc4bb24d729d77841193694232bd2da4a386515",
"T1_ethereum-test_signtx.py::test_signtx_eip1559[nodata]": "5b008a081b4ef9e7b47c9d0c1fc4bb24d729d77841193694232bd2da4a386515",
Expand Down Expand Up @@ -435,9 +435,9 @@
"T1_nem-test_signtx_transfers.py::test_nem_signtx_encrypted_payload": "b1fd9c5250032b2decce6ef18cb1c6e06e9daea279039b58e01cc28a3f4dc765",
"T1_nem-test_signtx_transfers.py::test_nem_signtx_known_mosaic": "4de1af57a9f25b81ab5d29a6c96e2cd117145aae6cba3fedd083cac7f8cff1d7",
"T1_nem-test_signtx_transfers.py::test_nem_signtx_known_mosaic_with_levy": "ebc2635064a4469a98c2a4db2608ec3d006a69386d47e78bbbb8800bb0e7dc2a",
"T1_nem-test_signtx_transfers.py::test_nem_signtx_multiple_mosaics": "483194e161e010b5860086054fd1527ab79bbdfbf6fcbf556047a3e7f9d66d6d",
"T1_nem-test_signtx_transfers.py::test_nem_signtx_multiple_mosaics": "ac772c16bacef88ec59bc4e1561520ed57e8d0ac74045136f5849a665b92978f",
"T1_nem-test_signtx_transfers.py::test_nem_signtx_simple": "3dac9a2abaab139be3b670d6f8e22d34db0171d09101b447c9de7011ad59b465",
"T1_nem-test_signtx_transfers.py::test_nem_signtx_unknown_mosaic": "0fd4bec396dc0850d42a43fb6bd23a751565ef143870ae21e1c1ff5faaeb1bef",
"T1_nem-test_signtx_transfers.py::test_nem_signtx_unknown_mosaic": "df352a677aa8f591effe241d0a384cea282934d5735c4bf34734616237fb96ca",
"T1_nem-test_signtx_transfers.py::test_nem_signtx_xem_as_mosaic": "9cc4d7978b6296e0d107a20912e4dedcc9ed6eb3229749a7fb515827c85f18ee",
"T1_reset_recovery-test_recovery_bip39_dryrun.py::test_bad_parameters[label-test]": "e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855",
"T1_reset_recovery-test_recovery_bip39_dryrun.py::test_bad_parameters[language-test]": "e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855",
Expand Down Expand Up @@ -475,14 +475,14 @@
"T1_stellar-test_stellar.py::test_sign_tx[StellarAccountMergeOp]": "3f55b35c47b3f0cf896793263006d9bc4089227f21e46e4e68f67386c1c85040",
"T1_stellar-test_stellar.py::test_sign_tx[StellarAllowTrustOp-allow]": "8fd4d210bda197e57ee660e71158b295dd3f51f8df9a235e245d5a72f54c68e8",
"T1_stellar-test_stellar.py::test_sign_tx[StellarAllowTrustOp-revoke]": "0834c3ffb6c8a792cfa8146de3641e3a4b95276b9583cd729350aca372528ed8",
"T1_stellar-test_stellar.py::test_sign_tx[StellarBumpSequenceOp]": "55eecce2fadcf7010dd9447cc359d6b125edfb910d2cf5c734c9987e3f667bb9",
"T1_stellar-test_stellar.py::test_sign_tx[StellarBumpSequenceOp]": "9504677a06c0da6f339a5313bdff39f7fd90c037a944cf9c3c0a4f4b40e787cf",
"T1_stellar-test_stellar.py::test_sign_tx[StellarChangeTrustOp-add]": "c0dd9ef3c1635dcceca33d68af85aeb2b544c2141e021b2296b17511fb111dec",
"T1_stellar-test_stellar.py::test_sign_tx[StellarChangeTrustOp-delete]": "52c9140b474f32678d2e0e3e6bffa255c14a82b7949f382da4e540f07d47383d",
"T1_stellar-test_stellar.py::test_sign_tx[StellarCreateAccountOp]": "8b65a55dddbdab0724f551b95b8243467fa8aa1e24b70f11c11c948fdbc1ade8",
"T1_stellar-test_stellar.py::test_sign_tx[StellarCreatePassiveSellOfferOp]": "f7663936ab2dbc3c11874a9f6e9e380c263041d38a147321da5570c3ecc3a214",
"T1_stellar-test_stellar.py::test_sign_tx[StellarManageBuyOfferOp]": "e91efb6b4802af84c881c45a6b87f104e9f3059c8eece9249d848395b644d976",
"T1_stellar-test_stellar.py::test_sign_tx[StellarManageBuyOfferOp]": "1ec10003113ac613a28c37ae8ec3ee67f793ad5edd61b2c17e1c8282e2839273",
"T1_stellar-test_stellar.py::test_sign_tx[StellarManageDataOp]": "a19740a14fdb9e8f8fb2d48fbf695015d575212e5fb5feb58ce5866f56fb5e0f",
"T1_stellar-test_stellar.py::test_sign_tx[StellarManageSellOfferOp]": "6c07a09a3fb110f02bc660ae91cfd1af2a9728c3ad9e4b2b7e68737f548d48f0",
"T1_stellar-test_stellar.py::test_sign_tx[StellarManageSellOfferOp]": "cb39bbb78f12de2bdf95bc053897b3bfa41adcf3aacab61522852d358f112656",
"T1_stellar-test_stellar.py::test_sign_tx[StellarPathPaymentStrictReceiveOp]": "713fcd90a54a10399390e649b799b33167bae37b62ab7fa1437b960c69b40cd5",
"T1_stellar-test_stellar.py::test_sign_tx[StellarPathPaymentStrictSendOp]": "b4683e95a636be05965b43705f953a1c02d475c8b2ca516c51b840e7aa737680",
"T1_stellar-test_stellar.py::test_sign_tx[StellarPaymentOp-asset12]": "d16f43f49d8bd5c07b21a1ee7684d831b7a15800bf9770973399c8cd89f6dfc3",
Expand All @@ -492,7 +492,7 @@
"T1_stellar-test_stellar.py::test_sign_tx[StellarSetOptionsOp-one]": "9dd8f325286fb29d558541586781818079b09d75d8d2cc734ccea4b80b95c876",
"T1_stellar-test_stellar.py::test_sign_tx[StellarSetOptionsOp-some]": "2467d2ac824a5b01e1d0be8a8ddec5cc554479a66916511eec67fdcbbd18b82d",
"T1_stellar-test_stellar.py::test_sign_tx[memo_hash]": "04d407ec2ac218be58e850de413cf2dbd1e6006f1fbc84792108484c4e8e9e7f",
"T1_stellar-test_stellar.py::test_sign_tx[memo_id]": "7695c2c837437767763cb2c81ad800bc28cb2582a4a1d7f513a35c8e2b1b20a5",
"T1_stellar-test_stellar.py::test_sign_tx[memo_id]": "288fd25b505a374900b0de9caed38a01bacee862a83bb043f350348e4949f1ad",
"T1_stellar-test_stellar.py::test_sign_tx[memo_return]": "542f7eb47c0007810de6c43b20c9a9e3f3c64bb695e375137154e5bdda3b2f50",
"T1_stellar-test_stellar.py::test_sign_tx[memo_text]": "43ec6d06d403c3d0a7f6ce3c3df48b3611094db491a8b382165d1412e4704331",
"T1_stellar-test_stellar.py::test_sign_tx[multiple_operations]": "1bd531cd757b8ca295201f9dcfa9e19e56f0ba697b6200819ab06d041563247d",
Expand Down

0 comments on commit 31f608e

Please sign in to comment.