electrum

Electrum Bitcoin wallet
git clone https://git.parazyd.org/electrum
Log | Files | Refs | Submodules

commit 369d972aed376a59bb21952afa16b43105724a32
parent 20bbe85bcecb454a4647b675066d6accea37bc78
Author: SomberNight <somber.night@protonmail.com>
Date:   Sun,  8 Dec 2019 03:21:02 +0100

qt: handle exceptions when pressing "Max" button

fixes #5783

Diffstat:
Melectrum/gui/qt/channels_list.py | 10++++++++--
Melectrum/gui/qt/main_window.py | 13++++++++++---
2 files changed, 18 insertions(+), 5 deletions(-)

diff --git a/electrum/gui/qt/channels_list.py b/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) diff --git a/electrum/gui/qt/main_window.py b/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