Browse Source

qt PreviewTxDialog: if not enough funds due to fee, fallback to zero fee

fixes #6306

scenario: confirm tx dialog open, not enough funds (but only due to fees),
user clicks advanced, dialog half-empty.

note: the preview dialog is only half-empty if it never managed to create a tx.
if it did but it cannot now due to the current fee settings, then it will just
show that fee is too high (red text, buttons disabled) and show the last tx with the prev fee
master
SomberNight 6 years ago
parent
commit
8f96a92e75
No known key found for this signature in database
GPG Key ID: B33B5F232C6271E9
  1. 10
      electrum/gui/qt/confirm_tx_dialog.py
  2. 15
      electrum/gui/qt/transaction_dialog.py

10
electrum/gui/qt/confirm_tx_dialog.py

@ -80,7 +80,7 @@ class TxEditor:
def get_fee_estimator(self): def get_fee_estimator(self):
return None return None
def update_tx(self): def update_tx(self, *, fallback_to_zero_fee: bool = False):
fee_estimator = self.get_fee_estimator() fee_estimator = self.get_fee_estimator()
try: try:
self.tx = self.make_tx(fee_estimator) self.tx = self.make_tx(fee_estimator)
@ -89,7 +89,13 @@ class TxEditor:
except NotEnoughFunds: except NotEnoughFunds:
self.not_enough_funds = True self.not_enough_funds = True
self.tx = None self.tx = None
return if fallback_to_zero_fee:
try:
self.tx = self.make_tx(0)
except BaseException:
return
else:
return
except NoDynamicFeeEstimates: except NoDynamicFeeEstimates:
self.no_dynfee_estimates = True self.no_dynfee_estimates = True
self.tx = None self.tx = None

15
electrum/gui/qt/transaction_dialog.py

@ -393,7 +393,7 @@ class BaseTxDialog(QDialog, MessageBoxMixin):
def update(self): def update(self):
if not self.finalized: if not self.finalized:
self.update_fee_fields() self.update_fee_fields()
self.finalize_button.setEnabled(self.tx is not None) self.finalize_button.setEnabled(self.can_finalize())
if self.tx is None: if self.tx is None:
return return
self.update_io() self.update_io()
@ -659,6 +659,9 @@ class BaseTxDialog(QDialog, MessageBoxMixin):
def set_title(self): def set_title(self):
self.setWindowTitle(_("Create transaction") if not self.finalized else _("Transaction")) self.setWindowTitle(_("Create transaction") if not self.finalized else _("Transaction"))
def can_finalize(self) -> bool:
return False
def on_finalize(self): def on_finalize(self):
pass # overridden in subclass pass # overridden in subclass
@ -688,7 +691,8 @@ class PreviewTxDialog(BaseTxDialog, TxEditor):
TxEditor.__init__(self, window=window, make_tx=make_tx, is_sweep=bool(external_keypairs)) TxEditor.__init__(self, window=window, make_tx=make_tx, is_sweep=bool(external_keypairs))
BaseTxDialog.__init__(self, parent=window, desc='', prompt_if_unsaved=False, BaseTxDialog.__init__(self, parent=window, desc='', prompt_if_unsaved=False,
finalized=False, external_keypairs=external_keypairs) finalized=False, external_keypairs=external_keypairs)
BlockingWaitingDialog(window, _("Preparing transaction..."), self.update_tx) BlockingWaitingDialog(window, _("Preparing transaction..."),
lambda: self.update_tx(fallback_to_zero_fee=True))
self.update() self.update()
def create_fee_controls(self): def create_fee_controls(self):
@ -861,9 +865,14 @@ class PreviewTxDialog(BaseTxDialog, TxEditor):
self.feerounding_icon.setToolTip(self.feerounding_text) self.feerounding_icon.setToolTip(self.feerounding_text)
self.feerounding_icon.setVisible(abs(feerounding) >= 1) self.feerounding_icon.setVisible(abs(feerounding) >= 1)
def can_finalize(self):
return (self.tx is not None
and not self.not_enough_funds)
def on_finalize(self): def on_finalize(self):
if not self.tx: if not self.can_finalize():
return return
assert self.tx
self.finalized = True self.finalized = True
self.tx.set_rbf(self.rbf_cb.isChecked()) self.tx.set_rbf(self.rbf_cb.isChecked())
self.tx.locktime = self.locktime_e.get_locktime() self.tx.locktime = self.locktime_e.get_locktime()

Loading…
Cancel
Save