Browse Source

qt/kivy: show warning when sending tx with high fee/amount ratio

related: #6162
master
SomberNight 5 years ago
parent
commit
7da8c2dfe5
No known key found for this signature in database GPG Key ID: B33B5F232C6271E9
  1. 12
      electrum/gui/kivy/uix/screens.py
  2. 20
      electrum/gui/qt/confirm_tx_dialog.py
  3. 2
      electrum/simple_config.py

12
electrum/gui/kivy/uix/screens.py

@ -33,6 +33,7 @@ from electrum.util import (parse_URI, InvalidBitcoinURI, PR_PAID, PR_UNKNOWN, PR
from electrum.plugin import run_hook
from electrum.wallet import InternalAddressCorruption
from electrum import simple_config
from electrum.simple_config import FEERATE_WARNING_HIGH_FEE, FEE_RATIO_HIGH_WARNING
from electrum.lnaddr import lndecode, parse_lightning_invoice
from electrum.lnutil import RECEIVED, SENT, PaymentFailure
@ -371,9 +372,14 @@ class SendScreen(CScreen):
x_fee_address, x_fee_amount = x_fee
msg.append(_("Additional fees") + ": " + self.app.format_amount_and_units(x_fee_amount))
feerate_warning = simple_config.FEERATE_WARNING_HIGH_FEE
if fee > feerate_warning * tx.estimated_size() / 1000:
msg.append(_('Warning') + ': ' + _("The fee for this transaction seems unusually high."))
feerate = Decimal(fee) / tx.estimated_size() # sat/byte
fee_ratio = Decimal(fee) / amount if amount else 1
if fee_ratio >= FEE_RATIO_HIGH_WARNING:
msg.append(_('Warning') + ': ' + _("The fee for this transaction seems unusually high.")
+ f' ({fee_ratio*100:.2f}% of amount)')
elif feerate > FEERATE_WARNING_HIGH_FEE / 1000:
msg.append(_('Warning') + ': ' + _("The fee for this transaction seems unusually high.")
+ f' (feerate: {feerate:.2f} sat/byte)')
self.app.protected('\n'.join(msg), self.send_tx, (tx,))
def send_tx(self, tx, password):

20
electrum/gui/qt/confirm_tx_dialog.py

@ -23,6 +23,7 @@
# CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
# SOFTWARE.
from decimal import Decimal
from typing import TYPE_CHECKING, Optional, Union
from PyQt5.QtWidgets import QVBoxLayout, QLabel, QGridLayout, QPushButton, QLineEdit
@ -31,7 +32,7 @@ from electrum.i18n import _
from electrum.util import NotEnoughFunds, NoDynamicFeeEstimates
from electrum.plugin import run_hook
from electrum.transaction import Transaction, PartialTransaction
from electrum.simple_config import FEERATE_WARNING_HIGH_FEE
from electrum.simple_config import FEERATE_WARNING_HIGH_FEE, FEE_RATIO_HIGH_WARNING
from electrum.wallet import InternalAddressCorruption
from .util import (WindowModalDialog, ColorScheme, HelpLabel, Buttons, CancelButton,
@ -240,17 +241,22 @@ class ConfirmTxDialog(TxEditor, WindowModalDialog):
self.extra_fee_value.setVisible(True)
self.extra_fee_value.setText(self.main_window.format_amount_and_units(x_fee_amount))
feerate_warning = FEERATE_WARNING_HIGH_FEE
low_fee = fee < self.wallet.relayfee() * tx.estimated_size() / 1000
high_fee = fee > feerate_warning * tx.estimated_size() / 1000
if low_fee:
amount = tx.output_value() if self.output_value == '!' else self.output_value
feerate = Decimal(fee) / tx.estimated_size() # sat/byte
fee_ratio = Decimal(fee) / amount if amount else 1
if feerate < self.wallet.relayfee() / 1000:
msg = '\n'.join([
_("This transaction requires a higher fee, or it will not be propagated by your current server"),
_("Try to raise your transaction fee, or use a server with a lower relay fee.")
])
self.toggle_send_button(False, message=msg)
elif high_fee:
elif fee_ratio >= FEE_RATIO_HIGH_WARNING:
self.toggle_send_button(True,
message=_('Warning') + ': ' + _("The fee for this transaction seems unusually high."))
message=_('Warning') + ': ' + _("The fee for this transaction seems unusually high.")
+ f'\n({fee_ratio*100:.2f}% of amount)')
elif feerate > FEERATE_WARNING_HIGH_FEE / 1000:
self.toggle_send_button(True,
message=_('Warning') + ': ' + _("The fee for this transaction seems unusually high.")
+ f'\n(feerate: {feerate:.2f} sat/byte)')
else:
self.toggle_send_button(True)

2
electrum/simple_config.py

@ -33,6 +33,8 @@ FEERATE_STATIC_VALUES = [1000, 2000, 5000, 10000, 20000, 30000,
50000, 70000, 100000, 150000, 200000, 300000]
FEERATE_REGTEST_HARDCODED = 180000 # for eclair compat
FEE_RATIO_HIGH_WARNING = 0.05 # warn user if fee/amount for on-chain tx is higher than this
_logger = get_logger(__name__)

Loading…
Cancel
Save