1
0
mirror of https://github.com/trezor/trezor-firmware.git synced 2024-12-25 07:48:10 +00:00

fix(legacy): Support negative amounts in layoutConfirmTx().

This commit is contained in:
Andrew Kozlik 2020-12-09 16:23:17 +01:00 committed by Andrew Kozlik
parent b90ce7f2fc
commit d252539125
3 changed files with 27 additions and 10 deletions

View File

@ -423,13 +423,30 @@ void layoutConfirmOpReturn(const uint8_t *data, uint32_t size) {
NULL); NULL);
} }
void layoutConfirmTx(const CoinInfo *coin, uint64_t amount_out, static bool formatAmountDifference(const CoinInfo *coin, uint64_t amount1,
uint64_t amount_fee) { uint64_t amount2, char *output,
char str_out[32] = {0}, str_fee[32] = {0}; size_t output_length) {
bn_format_uint64(amount_out, NULL, coin->coin_shortcut, coin->decimals, 0, uint64_t abs_diff = 0;
false, str_out, sizeof(str_out)); const char *sign = NULL;
bn_format_uint64(amount_fee, NULL, coin->coin_shortcut, coin->decimals, 0, if (amount1 >= amount2) {
false, str_fee, sizeof(str_fee)); 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, layoutDialogSwipe(&bmp_icon_question, _("Cancel"), _("Confirm"), NULL,
_("Really send"), str_out, _("from your wallet?"), _("Really send"), str_out, _("from your wallet?"),
_("Fee included:"), str_fee, NULL); _("Fee included:"), str_fee, NULL);

View File

@ -49,8 +49,8 @@ void layoutHome(void);
void layoutConfirmOutput(const CoinInfo *coin, const TxOutputType *out); void layoutConfirmOutput(const CoinInfo *coin, const TxOutputType *out);
void layoutConfirmOmni(const uint8_t *data, uint32_t size); void layoutConfirmOmni(const uint8_t *data, uint32_t size);
void layoutConfirmOpReturn(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, void layoutConfirmTx(const CoinInfo *coin, uint64_t total_in,
uint64_t amount_fee); uint64_t total_out, uint64_t change_out);
void layoutConfirmReplacement(const char *description, uint8_t txid[32]); void layoutConfirmReplacement(const char *description, uint8_t txid[32]);
void layoutConfirmModifyFee(const CoinInfo *coin, uint64_t fee_old, void layoutConfirmModifyFee(const CoinInfo *coin, uint64_t fee_old,
uint64_t fee_new); uint64_t fee_new);

View File

@ -1586,7 +1586,7 @@ static bool signing_confirm_tx(void) {
} }
// last confirmation // last confirmation
layoutConfirmTx(coin, total_in - change_out, fee); layoutConfirmTx(coin, total_in, total_out, change_out);
if (!protectButton(ButtonRequestType_ButtonRequest_SignTx, false)) { if (!protectButton(ButtonRequestType_ButtonRequest_SignTx, false)) {
fsm_sendFailure(FailureType_Failure_ActionCancelled, NULL); fsm_sendFailure(FailureType_Failure_ActionCancelled, NULL);
signing_abort(); signing_abort();