1
0

qt: add warning about low utxo reserve

This commit is contained in:
ThomasV
2025-03-21 11:15:43 +01:00
parent b339b1e7e3
commit 32807462b0
3 changed files with 47 additions and 13 deletions

View File

@@ -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.")
)

View File

@@ -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)

View File

@@ -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