URI: 
       tqt/kivy: show warning when sending tx with high fee/amount ratio - electrum - Electrum Bitcoin wallet
  HTML git clone https://git.parazyd.org/electrum
   DIR Log
   DIR Files
   DIR Refs
   DIR Submodules
       ---
   DIR commit 7da8c2dfe5ec887fa41064258117bc2f5e4ed057
   DIR parent 937c0f36ae1e47fdd054eb6b2ea931d3c5d68eec
  HTML Author: SomberNight <somber.night@protonmail.com>
       Date:   Fri, 15 May 2020 19:21:28 +0200
       
       qt/kivy: show warning when sending tx with high fee/amount ratio
       
       related: #6162
       
       Diffstat:
         M electrum/gui/kivy/uix/screens.py    |      12 +++++++++---
         M electrum/gui/qt/confirm_tx_dialog.… |      20 +++++++++++++-------
         M electrum/simple_config.py           |       2 ++
       
       3 files changed, 24 insertions(+), 10 deletions(-)
       ---
   DIR diff --git a/electrum/gui/kivy/uix/screens.py b/electrum/gui/kivy/uix/screens.py
       t@@ -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
        
       t@@ -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):
   DIR diff --git a/electrum/gui/qt/confirm_tx_dialog.py b/electrum/gui/qt/confirm_tx_dialog.py
       t@@ -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
       t@@ -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,
       t@@ -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)
   DIR diff --git a/electrum/simple_config.py b/electrum/simple_config.py
       t@@ -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__)