From 32807462b08d420d666dfa8119953eabc1d57861 Mon Sep 17 00:00:00 2001 From: ThomasV Date: Fri, 21 Mar 2025 11:15:43 +0100 Subject: [PATCH] qt: add warning about low utxo reserve --- electrum/gui/messages.py | 5 +++++ electrum/gui/qt/balance_dialog.py | 36 ++++++++++++++++++++++++++----- electrum/gui/qt/main_window.py | 19 +++++++++------- 3 files changed, 47 insertions(+), 13 deletions(-) diff --git a/electrum/gui/messages.py b/electrum/gui/messages.py index e10cae158..2b3c573ae 100644 --- a/electrum/gui/messages.py +++ b/electrum/gui/messages.py @@ -73,3 +73,8 @@ MSG_REVERSE_SWAP_FUNDING_MEMPOOL = ( _("If you go offline before broadcasting the claiming transaction and let the swap time out, " "you will not get back the already pre-paid mining fees.") ) + +MSG_LN_UTXO_RESERVE = ( + _("You do not have enough on-chain funds to protect your Lightning channels.") + ' ' + + _("You should have at least {} on-chain in order to be able to sweep channel outputs.") +) diff --git a/electrum/gui/qt/balance_dialog.py b/electrum/gui/qt/balance_dialog.py index b5f036796..b7d2a54ff 100644 --- a/electrum/gui/qt/balance_dialog.py +++ b/electrum/gui/qt/balance_dialog.py @@ -25,13 +25,14 @@ from typing import TYPE_CHECKING -from PyQt6.QtWidgets import QVBoxLayout, QLabel, QWidget, QGridLayout, QToolButton, QPushButton +from PyQt6.QtWidgets import QVBoxLayout, QHBoxLayout, QLabel, QWidget, QGridLayout, QToolButton, QPushButton from PyQt6.QtCore import QRect, Qt -from PyQt6.QtGui import QPen, QPainter +from PyQt6.QtGui import QPen, QPainter, QPixmap from electrum.i18n import _ +from electrum.gui.messages import MSG_LN_UTXO_RESERVE -from .util import Buttons, CloseButton, WindowModalDialog, ColorScheme, font_height, AmountLabel +from .util import Buttons, CloseButton, WindowModalDialog, ColorScheme, font_height, AmountLabel, icon_path if TYPE_CHECKING: from .main_window import ElectrumWindow @@ -102,8 +103,10 @@ class BalanceToolButton(QToolButton, PieChartObject): QToolButton.__init__(self) self._list = [] self._update_size() + self._warning = False - def update_list(self, l): + def update_list(self, l, warning: bool): + self._warning = warning self._list = l self.update() @@ -113,7 +116,14 @@ class BalanceToolButton(QToolButton, PieChartObject): def paintEvent(self, event): QToolButton.paintEvent(self, event) - PieChartObject.paintEvent(self, event) + if not self._warning: + PieChartObject.paintEvent(self, event) + else: + pixmap = QPixmap(icon_path("warning.png")) + qp = QPainter() + qp.begin(self) + qp.drawPixmap(self.R, pixmap) + qp.end() def resizeEvent(self, e): super().resizeEvent(e) @@ -187,6 +197,22 @@ class BalanceDialog(WindowModalDialog): ) vbox = QVBoxLayout() + if self.wallet.is_low_reserve(): + reserve_str = self.config.format_amount_and_units(self.config.LN_UTXO_RESERVE) + hbox = QHBoxLayout() + msg = _('Warning') + ': ' + MSG_LN_UTXO_RESERVE.format(reserve_str) + label = QLabel(msg) + label.setWordWrap(True) + logo = QLabel('') + logo.setPixmap( + QPixmap(icon_path("warning.png")).scaledToWidth( + 25, mode=Qt.TransformationMode.SmoothTransformation) + ) + logo.setMaximumWidth(28) + hbox.addWidget(logo) + hbox.addWidget(label) + vbox.addLayout(hbox) + vbox.addWidget(piechart) grid = QGridLayout() #grid.addWidget(QLabel(_("Onchain") + ':'), 0, 1) diff --git a/electrum/gui/qt/main_window.py b/electrum/gui/qt/main_window.py index 181363e49..a73f4b4cc 100644 --- a/electrum/gui/qt/main_window.py +++ b/electrum/gui/qt/main_window.py @@ -1002,14 +1002,17 @@ class ElectrumWindow(QMainWindow, MessageBoxMixin, Logger, QtEventListener): else: network_text = _("Connected") confirmed, unconfirmed, unmatured, frozen, lightning, f_lightning = self.wallet.get_balances_for_piechart() - self.balance_label.update_list([ - (_('Frozen'), COLOR_FROZEN, frozen), - (_('Unmatured'), COLOR_UNMATURED, unmatured), - (_('Unconfirmed'), COLOR_UNCONFIRMED, unconfirmed), - (_('On-chain'), COLOR_CONFIRMED, confirmed), - (_('Lightning'), COLOR_LIGHTNING, lightning), - (_('Lightning frozen'), COLOR_FROZEN_LIGHTNING, f_lightning), - ]) + self.balance_label.update_list( + [ + (_('Frozen'), COLOR_FROZEN, frozen), + (_('Unmatured'), COLOR_UNMATURED, unmatured), + (_('Unconfirmed'), COLOR_UNCONFIRMED, unconfirmed), + (_('On-chain'), COLOR_CONFIRMED, confirmed), + (_('Lightning'), COLOR_LIGHTNING, lightning), + (_('Lightning frozen'), COLOR_FROZEN_LIGHTNING, f_lightning), + ], + warning = self.wallet.is_low_reserve(), + ) balance = confirmed + unconfirmed + unmatured + frozen + lightning + f_lightning balance_text = _("Balance") + ": %s "%(self.format_amount_and_units(balance)) # append fiat balance and price