From 66ddedb97ea2eef37cb9355de35e5ad534013373 Mon Sep 17 00:00:00 2001 From: SomberNight Date: Tue, 19 Nov 2019 19:29:10 +0100 Subject: [PATCH] qt tx dialog: small fee edit fix scenario: enter extremely high feerate (which we cannot satisfy) then click into fee_edit. At that moment, fee_edit is empty and both feerate_edit and fee_edit are considered frozen. As fee_edit has priority, we would construct a tx with default fee. Now, instead, we won't construct this default fee tx ~as if the click to fee_edit did not happen. --- electrum/gui/qt/amountedit.py | 3 ++- electrum/gui/qt/transaction_dialog.py | 4 ++-- electrum/util.py | 2 +- 3 files changed, 5 insertions(+), 4 deletions(-) diff --git a/electrum/gui/qt/amountedit.py b/electrum/gui/qt/amountedit.py index c59730388..ecd3a7484 100644 --- a/electrum/gui/qt/amountedit.py +++ b/electrum/gui/qt/amountedit.py @@ -1,6 +1,7 @@ # -*- coding: utf-8 -*- from decimal import Decimal +from typing import Union from PyQt5.QtCore import pyqtSignal, Qt from PyQt5.QtGui import QPalette, QPainter @@ -71,7 +72,7 @@ class AmountEdit(MyLineEdit): painter.setPen(self.help_palette.brush(QPalette.Disabled, QPalette.Text).color()) painter.drawText(textRect, Qt.AlignRight | Qt.AlignVCenter, self.base_unit()) - def get_amount(self): + def get_amount(self) -> Union[None, Decimal, int]: try: return (int if self.is_int else Decimal)(str(self.text())) except: diff --git a/electrum/gui/qt/transaction_dialog.py b/electrum/gui/qt/transaction_dialog.py index 13680efeb..8c21ec754 100644 --- a/electrum/gui/qt/transaction_dialog.py +++ b/electrum/gui/qt/transaction_dialog.py @@ -693,9 +693,9 @@ class PreviewTxDialog(BaseTxDialog, TxEditor): .format(num_satoshis_added)) def get_fee_estimator(self): - if self.is_send_fee_frozen(): + if self.is_send_fee_frozen() and self.fee_e.get_amount() is not None: fee_estimator = self.fee_e.get_amount() - elif self.is_send_feerate_frozen(): + elif self.is_send_feerate_frozen() and self.feerate_e.get_amount() is not None: amount = self.feerate_e.get_amount() # sat/byte feerate amount = 0 if amount is None else amount * 1000 # sat/kilobyte feerate fee_estimator = partial( diff --git a/electrum/util.py b/electrum/util.py index 9308e3564..90a5e0dfa 100644 --- a/electrum/util.py +++ b/electrum/util.py @@ -642,7 +642,7 @@ def format_fee_satoshis(fee, *, num_zeros=0, precision=None): return format_satoshis(fee, num_zeros=num_zeros, decimal_point=0, precision=precision) -def quantize_feerate(fee): +def quantize_feerate(fee) -> Union[None, Decimal, int]: """Strip sat/byte fee rate of excess precision.""" if fee is None: return None