From 03e95accdc4a6171bdcf47362e6eba35f39a210b Mon Sep 17 00:00:00 2001 From: Sander van Grieken Date: Wed, 4 Mar 2026 15:11:23 +0100 Subject: [PATCH 1/2] qt, qml: for new transaction notifications, instead of using sign, explicitly say sent/received. For multiple transactions, split summary in total sent/received and a balance change. move duplicated code to wallet.get_user_notifications_for_new_txns() --- electrum/gui/qml/qewallet.py | 23 ++++----------------- electrum/gui/qt/main_window.py | 21 ++++--------------- electrum/wallet.py | 37 ++++++++++++++++++++++++++++++++++ 3 files changed, 45 insertions(+), 36 deletions(-) diff --git a/electrum/gui/qml/qewallet.py b/electrum/gui/qml/qewallet.py index 314368a1b..443fca44a 100644 --- a/electrum/gui/qml/qewallet.py +++ b/electrum/gui/qml/qewallet.py @@ -198,7 +198,7 @@ class QEWallet(AuthMixin, QObject, QtEventListener): self.invoiceStatusChanged.emit(key, status) @qt_event_listener - def on_event_new_transaction(self, wallet, tx): + def on_event_new_transaction(self, wallet: Abstract_Wallet, tx: Transaction): if wallet == self.wallet: self._logger.info(f'new transaction {tx.txid()}') self.add_tx_notification(tx) @@ -258,7 +258,7 @@ class QEWallet(AuthMixin, QObject, QtEventListener): def on_destroy(self): self.unregister_callbacks() - def add_tx_notification(self, tx): + def add_tx_notification(self, tx: Transaction): self._logger.debug('new transaction event') self.tx_notification_queue.put(tx) if not self.notification_timer.isActive(): @@ -285,23 +285,8 @@ class QEWallet(AuthMixin, QObject, QtEventListener): except queue.Empty: break - config = self.wallet.config - # Combine the transactions if there are at least three - if len(txns) >= 3: - total_amount = 0 - for tx in txns: - tx_wallet_delta = self.wallet.get_wallet_delta(tx) - if not tx_wallet_delta.is_relevant: - continue - total_amount += tx_wallet_delta.delta - self.userNotify.emit(self.wallet, _("{} new transactions: Total amount received in the new transactions {}").format(len(txns), config.format_amount_and_units(total_amount))) - else: - for tx in txns: - tx_wallet_delta = self.wallet.get_wallet_delta(tx) - if not tx_wallet_delta.is_relevant: - continue - self.userNotify.emit(self.wallet, - _("New transaction: {}").format(config.format_amount_and_units(tx_wallet_delta.delta))) + for notification in self.wallet.get_user_notifications_for_new_txns(txns): + self.userNotify.emit(self.wallet, notification) def update_sync_progress(self): if self.wallet.network and self.wallet.network.is_connected(): diff --git a/electrum/gui/qt/main_window.py b/electrum/gui/qt/main_window.py index 6b8542214..993a216ff 100644 --- a/electrum/gui/qt/main_window.py +++ b/electrum/gui/qt/main_window.py @@ -474,7 +474,7 @@ class ElectrumWindow(QMainWindow, MessageBoxMixin, Logger, QtEventListener): self.need_update.set() @event_listener - def on_event_new_transaction(self, wallet, tx): + def on_event_new_transaction(self, wallet: Abstract_Wallet, tx: Transaction): if wallet == self.wallet: self.tx_notification_queue.put(tx) self.need_update.set() @@ -930,22 +930,9 @@ class ElectrumWindow(QMainWindow, MessageBoxMixin, Logger, QtEventListener): txns.append(self.tx_notification_queue.get_nowait()) except queue.Empty: break - # Combine the transactions if there are at least three - if len(txns) >= 3: - total_amount = 0 - for tx in txns: - tx_wallet_delta = self.wallet.get_wallet_delta(tx) - if not tx_wallet_delta.is_relevant: - continue - total_amount += tx_wallet_delta.delta - self.notify(_("{} new transactions: Total amount received in the new transactions {}") - .format(len(txns), self.format_amount_and_units(total_amount))) - else: - for tx in txns: - tx_wallet_delta = self.wallet.get_wallet_delta(tx) - if not tx_wallet_delta.is_relevant: - continue - self.notify(_("New transaction: {}").format(self.format_amount_and_units(tx_wallet_delta.delta))) + + for notification in self.wallet.get_user_notifications_for_new_txns(txns): + self.notify(notification) def notify(self, message): if self.tray: diff --git a/electrum/wallet.py b/electrum/wallet.py index ae116e926..de3410513 100644 --- a/electrum/wallet.py +++ b/electrum/wallet.py @@ -3691,6 +3691,43 @@ class Abstract_Wallet(ABC, Logger, EventListener): else: f.write(util.json_encode(txns)) + def get_user_notifications_for_new_txns(self, txns: Sequence[Transaction]) -> Sequence[str]: + notifications = [] + # Combine the transactions if there are at least three + if len(txns) >= 3: + total_amount = 0 + total_debit = 0 + total_credit = 0 + for tx in txns: + tx_wallet_delta = self.get_wallet_delta(tx) + if not tx_wallet_delta.is_relevant: + continue + if tx_wallet_delta.delta < 0: + total_debit += -tx_wallet_delta.delta + else: + total_credit += tx_wallet_delta.delta + total_amount += tx_wallet_delta.delta + message = _('{} new transactions:').format(len(txns)) + if total_debit: + message += '\n' + _('Total amount sent {}').format(self.config.format_amount_and_units(total_debit)) + if total_credit: + message += '\n' + _('Total amount received {}').format(self.config.format_amount_and_units(total_credit)) + if total_debit and total_credit: + message += '\n' + _('Total balance change: {}').format(self.config.format_amount_and_units(total_amount)) + notifications.append(message) + else: + for tx in txns: + tx_wallet_delta = self.get_wallet_delta(tx) + if not tx_wallet_delta.is_relevant: + continue + if tx_wallet_delta.delta < 0: + message = _('sent {}').format(self.config.format_amount_and_units(-tx_wallet_delta.delta)) + else: + message = _('received {}').format(self.config.format_amount_and_units(tx_wallet_delta.delta)) + message = _("New transaction: {}").format(message) + notifications.append(message) + return notifications + class Simple_Wallet(Abstract_Wallet): # wallet with a single keystore From 2ea8d11524a9a9d48658bf70affb8ee5513a3dc9 Mon Sep 17 00:00:00 2001 From: SomberNight Date: Fri, 20 Mar 2026 13:49:16 +0000 Subject: [PATCH 2/2] fixup prev --- electrum/gui/qml/qewallet.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/electrum/gui/qml/qewallet.py b/electrum/gui/qml/qewallet.py index 443fca44a..2b7b30348 100644 --- a/electrum/gui/qml/qewallet.py +++ b/electrum/gui/qml/qewallet.py @@ -198,7 +198,7 @@ class QEWallet(AuthMixin, QObject, QtEventListener): self.invoiceStatusChanged.emit(key, status) @qt_event_listener - def on_event_new_transaction(self, wallet: Abstract_Wallet, tx: Transaction): + def on_event_new_transaction(self, wallet: 'Abstract_Wallet', tx: Transaction): if wallet == self.wallet: self._logger.info(f'new transaction {tx.txid()}') self.add_tx_notification(tx)