From d0ecf634c855f9dbfb5f039597cc7417fe5b3e5f Mon Sep 17 00:00:00 2001 From: Sander van Grieken Date: Mon, 24 Mar 2025 12:10:41 +0100 Subject: [PATCH] qml: auto close invoicedialog after successful onchain tx broadcast --- electrum/gui/qml/components/InvoiceDialog.qml | 15 +++++++++++++++ electrum/gui/qml/components/WalletMainView.qml | 9 ++++++--- electrum/gui/qml/qetxfinalizer.py | 13 +++++++++++++ 3 files changed, 34 insertions(+), 3 deletions(-) diff --git a/electrum/gui/qml/components/InvoiceDialog.qml b/electrum/gui/qml/components/InvoiceDialog.qml index df23a92c2..0a52b73a4 100644 --- a/electrum/gui/qml/components/InvoiceDialog.qml +++ b/electrum/gui/qml/components/InvoiceDialog.qml @@ -12,6 +12,7 @@ ElDialog { property Invoice invoice property bool payImmediately: false + property string broadcastTxid signal doPay signal invoiceAmountChanged @@ -511,6 +512,20 @@ ElDialog { } } + Connections { + target: Daemon.currentWallet + function onBroadcastSucceeded(txid) { + if (dialog.broadcastTxid == txid) { + // our txid was broadcast successfully, close invoicedialog and show success popup + dialog.close() + var successdialog = app.messageDialog.createObject(mainView, { + text: qsTr('Payment sent.') + }) + successdialog.open() + } + } + } + FontMetrics { id: amountFontMetrics font: amountBtc.font diff --git a/electrum/gui/qml/components/WalletMainView.qml b/electrum/gui/qml/components/WalletMainView.qml index 1edc8299b..fe4ca96f1 100644 --- a/electrum/gui/qml/components/WalletMainView.qml +++ b/electrum/gui/qml/components/WalletMainView.qml @@ -103,7 +103,7 @@ Item { dialog.open() } - function payOnchain(invoice) { + function payOnchain(invoicedialog, invoice) { var dialog = confirmPaymentDialog.createObject(mainView, { address: invoice.address, satoshis: invoice.amountOverride.isEmpty @@ -120,6 +120,8 @@ Item { dialog.finalizer.sign() } } else { + // store txid in invoicedialog so the dialog can detect broadcast success + invoicedialog.broadcastTxid = dialog.finalizer.finalizedTxid dialog.finalizer.signAndSend() } }) @@ -519,7 +521,7 @@ Item { } } if (invoice.invoiceType == Invoice.OnchainInvoice) { - payOnchain(invoice) + payOnchain(_invoiceDialog, invoice) } else if (invoice.invoiceType == Invoice.LightningInvoice) { if (lninvoiceButPayOnchain) { var dialog = app.messageDialog.createObject(mainView, { @@ -527,7 +529,7 @@ Item { yesno: true }) dialog.accepted.connect(function() { - payOnchain(invoice) + payOnchain(_invoiceDialog, invoice) }) dialog.open() } else { @@ -653,6 +655,7 @@ Item { dialog.open() } } + // TODO: lingering confirmPaymentDialogs can raise exceptions in // the child finalizer when currentWallet disappears, but we need // it long enough for the finalizer to finish.. diff --git a/electrum/gui/qml/qetxfinalizer.py b/electrum/gui/qml/qetxfinalizer.py index 8a87a5fd3..0919e8b06 100644 --- a/electrum/gui/qml/qetxfinalizer.py +++ b/electrum/gui/qml/qetxfinalizer.py @@ -152,6 +152,7 @@ class TxFeeSlider(FeeSlider): self._tx = None self._inputs = [] self._outputs = [] + self._finalized_txid = '' self._valid = False self._warning = '' @@ -211,6 +212,17 @@ class TxFeeSlider(FeeSlider): self._outputs = outputs self.outputsChanged.emit() + finalizedTxidChanged = pyqtSignal() + @pyqtProperty(str, notify=finalizedTxidChanged) + def finalizedTxid(self): + return self._finalized_txid + + @finalizedTxid.setter + def finalizedTxid(self, finalized_txid): + if self._finalized_txid != finalized_txid: + self._finalized_txid = finalized_txid + self.finalizedTxidChanged.emit() + warningChanged = pyqtSignal() @pyqtProperty(str, notify=warningChanged) def warning(self): @@ -238,6 +250,7 @@ class TxFeeSlider(FeeSlider): self.fee = QEAmount(amount_sat=int(fee)) self.feeRate = f'{feerate:.1f}' + self.finalizedTxid = tx.txid() self.update_inputs_from_tx(tx) self.update_outputs_from_tx(tx)