qt/kivy: show warning when sending tx with high fee/amount ratio
related: #6162
This commit is contained in:
@@ -33,6 +33,7 @@ from electrum.util import (parse_URI, InvalidBitcoinURI, PR_PAID, PR_UNKNOWN, PR
|
|||||||
from electrum.plugin import run_hook
|
from electrum.plugin import run_hook
|
||||||
from electrum.wallet import InternalAddressCorruption
|
from electrum.wallet import InternalAddressCorruption
|
||||||
from electrum import simple_config
|
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.lnaddr import lndecode, parse_lightning_invoice
|
||||||
from electrum.lnutil import RECEIVED, SENT, PaymentFailure
|
from electrum.lnutil import RECEIVED, SENT, PaymentFailure
|
||||||
|
|
||||||
@@ -371,9 +372,14 @@ class SendScreen(CScreen):
|
|||||||
x_fee_address, x_fee_amount = x_fee
|
x_fee_address, x_fee_amount = x_fee
|
||||||
msg.append(_("Additional fees") + ": " + self.app.format_amount_and_units(x_fee_amount))
|
msg.append(_("Additional fees") + ": " + self.app.format_amount_and_units(x_fee_amount))
|
||||||
|
|
||||||
feerate_warning = simple_config.FEERATE_WARNING_HIGH_FEE
|
feerate = Decimal(fee) / tx.estimated_size() # sat/byte
|
||||||
if fee > feerate_warning * tx.estimated_size() / 1000:
|
fee_ratio = Decimal(fee) / amount if amount else 1
|
||||||
msg.append(_('Warning') + ': ' + _("The fee for this transaction seems unusually high."))
|
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,))
|
self.app.protected('\n'.join(msg), self.send_tx, (tx,))
|
||||||
|
|
||||||
def send_tx(self, tx, password):
|
def send_tx(self, tx, password):
|
||||||
|
|||||||
@@ -23,6 +23,7 @@
|
|||||||
# CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
# CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||||
# SOFTWARE.
|
# SOFTWARE.
|
||||||
|
|
||||||
|
from decimal import Decimal
|
||||||
from typing import TYPE_CHECKING, Optional, Union
|
from typing import TYPE_CHECKING, Optional, Union
|
||||||
|
|
||||||
from PyQt5.QtWidgets import QVBoxLayout, QLabel, QGridLayout, QPushButton, QLineEdit
|
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.util import NotEnoughFunds, NoDynamicFeeEstimates
|
||||||
from electrum.plugin import run_hook
|
from electrum.plugin import run_hook
|
||||||
from electrum.transaction import Transaction, PartialTransaction
|
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 electrum.wallet import InternalAddressCorruption
|
||||||
|
|
||||||
from .util import (WindowModalDialog, ColorScheme, HelpLabel, Buttons, CancelButton,
|
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.setVisible(True)
|
||||||
self.extra_fee_value.setText(self.main_window.format_amount_and_units(x_fee_amount))
|
self.extra_fee_value.setText(self.main_window.format_amount_and_units(x_fee_amount))
|
||||||
|
|
||||||
feerate_warning = FEERATE_WARNING_HIGH_FEE
|
amount = tx.output_value() if self.output_value == '!' else self.output_value
|
||||||
low_fee = fee < self.wallet.relayfee() * tx.estimated_size() / 1000
|
feerate = Decimal(fee) / tx.estimated_size() # sat/byte
|
||||||
high_fee = fee > feerate_warning * tx.estimated_size() / 1000
|
fee_ratio = Decimal(fee) / amount if amount else 1
|
||||||
if low_fee:
|
if feerate < self.wallet.relayfee() / 1000:
|
||||||
msg = '\n'.join([
|
msg = '\n'.join([
|
||||||
_("This transaction requires a higher fee, or it will not be propagated by your current server"),
|
_("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.")
|
_("Try to raise your transaction fee, or use a server with a lower relay fee.")
|
||||||
])
|
])
|
||||||
self.toggle_send_button(False, message=msg)
|
self.toggle_send_button(False, message=msg)
|
||||||
elif high_fee:
|
elif fee_ratio >= FEE_RATIO_HIGH_WARNING:
|
||||||
self.toggle_send_button(True,
|
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:
|
else:
|
||||||
self.toggle_send_button(True)
|
self.toggle_send_button(True)
|
||||||
|
|||||||
@@ -33,6 +33,8 @@ FEERATE_STATIC_VALUES = [1000, 2000, 5000, 10000, 20000, 30000,
|
|||||||
50000, 70000, 100000, 150000, 200000, 300000]
|
50000, 70000, 100000, 150000, 200000, 300000]
|
||||||
FEERATE_REGTEST_HARDCODED = 180000 # for eclair compat
|
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__)
|
_logger = get_logger(__name__)
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user