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 fcd43b9 commit 70c1b12
Show file tree
Hide file tree
Showing 6 changed files with 38 additions and 39 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
Loading

0 comments on commit 70c1b12

Please sign in to comment.