mirror of
https://github.com/trezor/trezor-firmware.git
synced 2024-12-24 07:18:09 +00:00
fix(legacy): Support negative amounts in layoutConfirmTx().
This commit is contained in:
parent
b90ce7f2fc
commit
d252539125
@ -423,13 +423,30 @@ void layoutConfirmOpReturn(const uint8_t *data, uint32_t size) {
|
||||
NULL);
|
||||
}
|
||||
|
||||
void layoutConfirmTx(const CoinInfo *coin, uint64_t amount_out,
|
||||
uint64_t amount_fee) {
|
||||
char str_out[32] = {0}, str_fee[32] = {0};
|
||||
bn_format_uint64(amount_out, NULL, coin->coin_shortcut, coin->decimals, 0,
|
||||
false, str_out, sizeof(str_out));
|
||||
bn_format_uint64(amount_fee, NULL, coin->coin_shortcut, coin->decimals, 0,
|
||||
false, str_fee, sizeof(str_fee));
|
||||
static bool formatAmountDifference(const CoinInfo *coin, uint64_t amount1,
|
||||
uint64_t amount2, char *output,
|
||||
size_t output_length) {
|
||||
uint64_t abs_diff = 0;
|
||||
const char *sign = NULL;
|
||||
if (amount1 >= amount2) {
|
||||
abs_diff = amount1 - amount2;
|
||||
} else {
|
||||
abs_diff = amount2 - amount1;
|
||||
sign = "-";
|
||||
}
|
||||
|
||||
return bn_format_uint64(abs_diff, sign, coin->coin_shortcut, coin->decimals,
|
||||
0, false, output, output_length) != 0;
|
||||
}
|
||||
|
||||
void layoutConfirmTx(const CoinInfo *coin, uint64_t total_in,
|
||||
uint64_t total_out, uint64_t change_out) {
|
||||
char str_out[32] = {0};
|
||||
formatAmountDifference(coin, total_in, change_out, str_out, sizeof(str_out));
|
||||
|
||||
char str_fee[32] = {0};
|
||||
formatAmountDifference(coin, total_in, total_out, str_fee, sizeof(str_fee));
|
||||
|
||||
layoutDialogSwipe(&bmp_icon_question, _("Cancel"), _("Confirm"), NULL,
|
||||
_("Really send"), str_out, _("from your wallet?"),
|
||||
_("Fee included:"), str_fee, NULL);
|
||||
|
@ -49,8 +49,8 @@ void layoutHome(void);
|
||||
void layoutConfirmOutput(const CoinInfo *coin, const TxOutputType *out);
|
||||
void layoutConfirmOmni(const uint8_t *data, uint32_t size);
|
||||
void layoutConfirmOpReturn(const uint8_t *data, uint32_t size);
|
||||
void layoutConfirmTx(const CoinInfo *coin, uint64_t amount_out,
|
||||
uint64_t amount_fee);
|
||||
void layoutConfirmTx(const CoinInfo *coin, uint64_t total_in,
|
||||
uint64_t total_out, uint64_t change_out);
|
||||
void layoutConfirmReplacement(const char *description, uint8_t txid[32]);
|
||||
void layoutConfirmModifyFee(const CoinInfo *coin, uint64_t fee_old,
|
||||
uint64_t fee_new);
|
||||
|
@ -1586,7 +1586,7 @@ static bool signing_confirm_tx(void) {
|
||||
}
|
||||
|
||||
// last confirmation
|
||||
layoutConfirmTx(coin, total_in - change_out, fee);
|
||||
layoutConfirmTx(coin, total_in, total_out, change_out);
|
||||
if (!protectButton(ButtonRequestType_ButtonRequest_SignTx, false)) {
|
||||
fsm_sendFailure(FailureType_Failure_ActionCancelled, NULL);
|
||||
signing_abort();
|
||||
|
Loading…
Reference in New Issue
Block a user