diff --git a/electrum/gui/qml/components/WalletMainView.qml b/electrum/gui/qml/components/WalletMainView.qml index 0940365b9..0a7d3de38 100644 --- a/electrum/gui/qml/components/WalletMainView.qml +++ b/electrum/gui/qml/components/WalletMainView.qml @@ -51,10 +51,6 @@ Item { } } - function showExportByTxid(txid, helptext) { - showExport(Daemon.currentWallet.getSerializedTx(txid), helptext) - } - function showExport(data, helptext) { var dialog = exportTxDialog.createObject(app, { text: data[0], @@ -334,7 +330,7 @@ Item { if (Daemon.currentWallet.isWatchOnly) { dialog.finalizer.save() } else { - dialog.finalizer.signAndSave() + dialog.finalizer.sign() } } else { dialog.finalizer.signAndSend() @@ -430,13 +426,24 @@ Item { finalizer: TxFinalizer { wallet: Daemon.currentWallet canRbf: true - onFinishedSave: { - if (wallet.isWatchOnly) { - // tx was saved. Show QR for signer(s) - showExportByTxid(txid, qsTr('Transaction created. Present this QR code to the signing device')) - } else { - // tx was (partially) signed and saved. Show QR for co-signers or online wallet - showExportByTxid(txid, qsTr('Transaction created and partially signed by this wallet. Present this QR code to the next co-signer')) + onFinished: { + if (!complete) { + var msg + if (wallet.isWatchOnly) { + // tx created in watchonly wallet. Show QR for signer(s) + if (wallet.isMultisig) { + msg = qsTr('Transaction created. Present this QR code to one of the co-cigners or signing devices') + } else { + msg = qsTr('Transaction created. Present this QR code to the signing device') + } + } else { + if (signed) { + msg = qsTr('Transaction created and partially signed by this wallet. Present this QR code to the next co-signer') + } else { + msg = qsTr('Transaction created but not signed by this wallet yet. Sign the transaction and present this QR code to the next co-signer') + } + } + showExport(getSerializedTx(), msg) } _confirmPaymentDialog.destroy() } diff --git a/electrum/gui/qml/qetxfinalizer.py b/electrum/gui/qml/qetxfinalizer.py index 17b952d0e..cbab6f75e 100644 --- a/electrum/gui/qml/qetxfinalizer.py +++ b/electrum/gui/qml/qetxfinalizer.py @@ -1,5 +1,6 @@ from decimal import Decimal from typing import Optional +from functools import partial from PyQt5.QtCore import pyqtProperty, pyqtSignal, pyqtSlot, QObject @@ -220,7 +221,7 @@ class TxFeeSlider(FeeSlider): class QETxFinalizer(TxFeeSlider): _logger = get_logger(__name__) - finishedSave = pyqtSignal([str], arguments=['txid']) + finished = pyqtSignal([bool, bool, bool], arguments=['signed', 'saved', 'complete']) def __init__(self, parent=None, *, make_tx=None, accept=None): super().__init__(parent) @@ -343,12 +344,16 @@ class QETxFinalizer(TxFeeSlider): @pyqtSlot() def save(self): - if not self._valid or not self._tx: - self._logger.debug('no valid tx') + if not self._valid or not self._tx or not self._tx.txid(): + self._logger.debug('no valid tx or no txid') return + saved = False if self._wallet.save_tx(self._tx): - self.finishedSave.emit(self._tx.txid()) + saved = True + # self.finishedSave.emit(self._tx.txid()) + + self.finished.emit(False, saved) @pyqtSlot() def signAndSend(self): @@ -360,25 +365,36 @@ class QETxFinalizer(TxFeeSlider): self.f_accept(self._tx) return - self._wallet.sign(self._tx, broadcast=True) + self._wallet.sign(self._tx, + broadcast=True, + on_success=partial(self.on_signed_tx, False) + ) @pyqtSlot() - def signAndSave(self): + def sign(self): if not self._valid or not self._tx: self._logger.error('no valid tx') return - self._wallet.sign(self._tx, broadcast=False, on_success=self.on_signed_tx) + self._wallet.sign(self._tx, + broadcast=False, + on_success=partial(self.on_signed_tx, True) + ) - def on_signed_tx(self, tx: Transaction): + def on_signed_tx(self, save: bool, tx: Transaction): self._logger.debug('on_signed_tx') - if not self._wallet.save_tx(self._tx): - self._logger.error('Could not save tx') - else: - # FIXME: don't rely on txid. (non-segwit tx don't have a txid - # until tx is complete, and can't save to backend without it). - self.finishedSave.emit(self._tx.txid()) + saved = False + if save and self._tx.txid(): + if self._wallet.save_tx(self._tx): + saved = True + else: + self._logger.error('Could not save tx') + self.finished.emit(True, saved, tx.is_complete()) + @pyqtSlot(result='QVariantList') + def getSerializedTx(self): + txqr = self._tx.to_qr_data() + return [str(self._tx), txqr[0], txqr[1]] # mixin for watching an existing TX based on its txid for verified event # requires self._wallet to contain a QEWallet instance