Skip to content

Commit

Permalink
fix(legacy,core): use sat/vB only for segwit and sat/B otherwise
Browse files Browse the repository at this point in the history
[no changelog]
  • Loading branch information
prusnak committed May 25, 2022
1 parent 5671bd0 commit 526a134
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 5 deletions.
2 changes: 1 addition & 1 deletion core/src/apps/bitcoin/sign_tx/layout.py
Original file line number Diff line number Diff line change
Expand Up @@ -190,7 +190,7 @@ async def confirm_total(
fee_rate_str: str | None = None

if fee_rate >= 0:
fee_rate_str = f"({fee_rate:.1f} sat/vB)"
fee_rate_str = f"({fee_rate:.1f} sat/{'v' if coin.segwit else ''}B)"

await layouts.confirm_total(
ctx,
Expand Down
9 changes: 5 additions & 4 deletions legacy/firmware/layout2.c
Original file line number Diff line number Diff line change
Expand Up @@ -504,14 +504,15 @@ static bool formatAmountDifference(const CoinInfo *coin, AmountUnit amount_unit,
}

static bool formatFeeRate(uint64_t fee, uint64_t tx_weight, char *output,
size_t output_length) {
size_t output_length, bool segwit) {
// Compute fee rate and modify it in place for `bn_format_uint64` function -
// multiply by 10, because we only want to display 1 decimal digit
// and then get whole number by leaving it in `uint64_t`.
uint64_t fee_rate_multiplied = (fee * 10) / (tx_weight / 4);

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

void layoutConfirmTx(const CoinInfo *coin, AmountUnit amount_unit,
Expand All @@ -530,7 +531,7 @@ void layoutConfirmTx(const CoinInfo *coin, AmountUnit amount_unit,

if (show_fee_rate) {
formatFeeRate(total_in - total_out, tx_weight, str_fee_rate,
sizeof(str_fee_rate));
sizeof(str_fee_rate), coin->has_segwit);
}

layoutDialogSwipe(&bmp_icon_question, _("Cancel"), _("Confirm"), NULL,
Expand Down

0 comments on commit 526a134

Please sign in to comment.