Browse Source

qt: handle exceptions when pressing "Max" button

fixes #5783
hard-fail-on-bad-server-string
SomberNight 5 years ago
parent
commit
369d972aed
No known key found for this signature in database GPG Key ID: B33B5F232C6271E9
  1. 10
      electrum/gui/qt/channels_list.py
  2. 13
      electrum/gui/qt/main_window.py

10
electrum/gui/qt/channels_list.py

@ -6,7 +6,7 @@ from PyQt5 import QtCore, QtGui
from PyQt5.QtCore import Qt
from PyQt5.QtWidgets import QMenu, QHBoxLayout, QLabel, QVBoxLayout, QGridLayout, QLineEdit
from electrum.util import bh2u
from electrum.util import bh2u, NotEnoughFunds, NoDynamicFeeEstimates
from electrum.i18n import _
from electrum.lnchannel import Channel
from electrum.wallet import Abstract_Wallet
@ -178,7 +178,13 @@ class ChannelsList(MyTreeView):
if not max_button.isChecked():
return
make_tx = self.parent.mktx_for_open_channel('!')
tx = make_tx(None)
try:
tx = make_tx(None)
except (NotEnoughFunds, NoDynamicFeeEstimates) as e:
max_button.setChecked(False)
amount_e.setFrozen(False)
self.main_window.show_error(str(e))
return
amount = tx.output_value()
amount = min(amount, LN_MAX_FUNDING_SAT)
amount_e.setAmount(amount)

13
electrum/gui/qt/main_window.py

@ -60,7 +60,8 @@ from electrum.util import (format_time, format_satoshis, format_fee_satoshis,
decimal_point_to_base_unit_name,
UnknownBaseUnit, DECIMAL_POINT_DEFAULT, UserFacingException,
get_new_wallet_name, send_exception_to_crash_reporter,
InvalidBitcoinURI, maybe_extract_bolt11_invoice)
InvalidBitcoinURI, maybe_extract_bolt11_invoice, NotEnoughFunds,
NoDynamicFeeEstimates)
from electrum.util import PR_TYPE_ONCHAIN, PR_TYPE_LN
from electrum.transaction import (Transaction, PartialTxInput,
PartialTransaction, PartialTxOutput)
@ -1293,14 +1294,20 @@ class ElectrumWindow(QMainWindow, MessageBoxMixin, Logger):
outputs = self.payto_e.get_outputs(True)
if not outputs:
return
self.max_button.setChecked(True)
make_tx = lambda fee_est: self.wallet.make_unsigned_transaction(
coins=self.get_coins(),
outputs=outputs,
fee=fee_est,
is_sweep=False)
tx = make_tx(None)
try:
tx = make_tx(None)
except (NotEnoughFunds, NoDynamicFeeEstimates) as e:
self.max_button.setChecked(False)
self.show_error(str(e))
return
self.max_button.setChecked(True)
amount = tx.output_value()
__, x_fee_amount = run_hook('get_tx_extra_fee', self.wallet, tx) or (None, 0)
amount_after_all_fees = amount - x_fee_amount

Loading…
Cancel
Save