diff --git a/electrum/gui/qt/main_window.py b/electrum/gui/qt/main_window.py index 67fd252fd..c8d888495 100644 --- a/electrum/gui/qt/main_window.py +++ b/electrum/gui/qt/main_window.py @@ -1050,8 +1050,8 @@ class ElectrumWindow(QMainWindow, MessageBoxMixin, Logger, QtEventListener): from .channel_details import ChannelDetailsDialog ChannelDetailsDialog(self, chan).show() - def show_transaction(self, tx: Transaction): - show_transaction(tx, parent=self) + def show_transaction(self, tx: Transaction, *, external_keypairs=None): + show_transaction(tx, parent=self, external_keypairs=external_keypairs) def show_lightning_transaction(self, tx_item): from .lightning_tx_dialog import LightningTxDialog @@ -1174,7 +1174,7 @@ class ElectrumWindow(QMainWindow, MessageBoxMixin, Logger, QtEventListener): invoice = self.wallet.get_invoice(key) if invoice and invoice.is_lightning() and invoice.get_address(): if self.question(_('Payment failed') + '\n\n' + reason + '\n\n'+ 'Fallback to onchain payment?'): - self.send_tab.pay_onchain_dialog(self.get_coins(), invoice.get_outputs()) + self.send_tab.pay_onchain_dialog(invoice.get_outputs()) else: self.show_error(_('Payment failed') + '\n\n' + reason) @@ -2387,6 +2387,9 @@ class ElectrumWindow(QMainWindow, MessageBoxMixin, Logger, QtEventListener): def sweep_key_dialog(self): + if not self.network: + self.show_error(_("You are offline.")) + return d = WindowModalDialog(self, title=_('Sweep private keys')) d.setMinimumSize(600, 300) vbox = QVBoxLayout(d) @@ -2450,7 +2453,8 @@ class ElectrumWindow(QMainWindow, MessageBoxMixin, Logger, QtEventListener): coins, keypairs = result outputs = [PartialTxOutput.from_address_and_value(addr, value='!')] self.warn_if_watching_only() - self.send_tab.pay_onchain_dialog(coins, outputs, external_keypairs=keypairs) + self.send_tab.pay_onchain_dialog( + outputs, external_keypairs=keypairs, get_coins=lambda *args, **kwargs: coins) def on_failure(exc_info): self.on_error(exc_info) msg = _('Preparing sweep transaction...') diff --git a/electrum/gui/qt/send_tab.py b/electrum/gui/qt/send_tab.py index c8276c82d..dffa15d31 100644 --- a/electrum/gui/qt/send_tab.py +++ b/electrum/gui/qt/send_tab.py @@ -4,7 +4,7 @@ import asyncio from decimal import Decimal -from typing import Optional, TYPE_CHECKING, Sequence, List +from typing import Optional, TYPE_CHECKING, Sequence, List, Callable, Any from urllib.parse import urlparse from PyQt5.QtCore import pyqtSignal, QPoint @@ -238,14 +238,18 @@ class SendTab(QWidget, MessageBoxMixin, Logger): self, outputs: List[PartialTxOutput], *, nonlocal_only=False, - external_keypairs=None) -> None: + external_keypairs=None, + get_coins: Callable[..., Sequence[PartialTxInput]] = None, + ) -> None: # trustedcoin requires this if run_hook('abort_send', self): return is_sweep = bool(external_keypairs) # we call get_coins inside make_tx, so that inputs can be changed dynamically + if get_coins is None: + get_coins = self.window.get_coins make_tx = lambda fee_est, *, confirmed_only=False: self.wallet.make_unsigned_transaction( - coins=self.window.get_coins(nonlocal_only=nonlocal_only, confirmed_only=confirmed_only), + coins=get_coins(nonlocal_only=nonlocal_only, confirmed_only=confirmed_only), outputs=outputs, fee=fee_est, is_sweep=is_sweep) @@ -266,7 +270,7 @@ class SendTab(QWidget, MessageBoxMixin, Logger): return is_preview = conf_dlg.is_preview if is_preview: - self.window.show_transaction(tx) + self.window.show_transaction(tx, external_keypairs=external_keypairs) return self.save_pending_invoice() def sign_done(success): diff --git a/electrum/gui/qt/transaction_dialog.py b/electrum/gui/qt/transaction_dialog.py index 5fb1f2060..c29de2cbb 100644 --- a/electrum/gui/qt/transaction_dialog.py +++ b/electrum/gui/qt/transaction_dialog.py @@ -372,10 +372,15 @@ class TxInOutWidget(QWidget): menu.exec_(global_pos) - -def show_transaction(tx: Transaction, *, parent: 'ElectrumWindow', prompt_if_unsaved=False): +def show_transaction( + tx: Transaction, + *, + parent: 'ElectrumWindow', + prompt_if_unsaved: bool = False, + external_keypairs=None, +): try: - d = TxDialog(tx, parent=parent, prompt_if_unsaved=prompt_if_unsaved) + d = TxDialog(tx, parent=parent, prompt_if_unsaved=prompt_if_unsaved, external_keypairs=external_keypairs) except SerializationError as e: _logger.exception('unable to deserialize the transaction') parent.show_critical(_("Electrum was unable to deserialize the transaction:") + "\n" + str(e)) @@ -383,13 +388,11 @@ def show_transaction(tx: Transaction, *, parent: 'ElectrumWindow', prompt_if_uns d.show() - - class TxDialog(QDialog, MessageBoxMixin): throttled_update_sig = pyqtSignal() # emit from thread to do update in main thread - def __init__(self, tx: Transaction, *, parent: 'ElectrumWindow', prompt_if_unsaved, external_keypairs=None): + def __init__(self, tx: Transaction, *, parent: 'ElectrumWindow', prompt_if_unsaved: bool, external_keypairs=None): '''Transactions in the wallet will show their description. Pass desc to give a description for txs not yet in the wallet. '''