Browse Source

Qt balance piechart: show lightning funds that are frozen

patch-4
ThomasV 3 years ago
parent
commit
1274ec7655
  1. 11
      electrum/gui/qt/balance_dialog.py
  2. 7
      electrum/gui/qt/main_window.py
  3. 4
      electrum/lnworker.py
  4. 3
      electrum/wallet.py

11
electrum/gui/qt/balance_dialog.py

@ -49,6 +49,7 @@ COLOR_UNCONFIRMED = Qt.red
COLOR_UNMATURED = Qt.magenta
COLOR_FROZEN = ColorScheme.BLUE.as_color(True)
COLOR_LIGHTNING = Qt.yellow
COLOR_FROZEN_LIGHTNING = Qt.cyan
class PieChartObject:
@ -146,19 +147,21 @@ class BalanceDialog(WindowModalDialog):
self.config = parent.config
self.fx = parent.fx
confirmed, unconfirmed, unmatured, frozen, lightning = self.wallet.get_balances_for_piechart()
confirmed, unconfirmed, unmatured, frozen, lightning, f_lightning = self.wallet.get_balances_for_piechart()
frozen_str = self.config.format_amount_and_units(frozen)
confirmed_str = self.config.format_amount_and_units(confirmed)
unconfirmed_str = self.config.format_amount_and_units(unconfirmed)
unmatured_str = self.config.format_amount_and_units(unmatured)
lightning_str = self.config.format_amount_and_units(lightning)
f_lightning_str = self.config.format_amount_and_units(f_lightning)
frozen_fiat_str = self.fx.format_amount_and_units(frozen) if self.fx else ''
confirmed_fiat_str = self.fx.format_amount_and_units(confirmed) if self.fx else ''
unconfirmed_fiat_str = self.fx.format_amount_and_units(unconfirmed) if self.fx else ''
unmatured_fiat_str = self.fx.format_amount_and_units(unmatured) if self.fx else ''
lightning_fiat_str = self.fx.format_amount_and_units(lightning) if self.fx else ''
f_lightning_fiat_str = self.fx.format_amount_and_units(f_lightning) if self.fx else ''
piechart = PieChartWidget(120, [
(_('Frozen'), COLOR_FROZEN, frozen),
@ -166,6 +169,7 @@ class BalanceDialog(WindowModalDialog):
(_('Unconfirmed'), COLOR_UNCONFIRMED, unconfirmed),
(_('Confirmed'), COLOR_CONFIRMED, confirmed),
(_('Lightning'), COLOR_LIGHTNING, lightning),
(_('Lightning frozen'), COLOR_FROZEN_LIGHTNING, f_lightning),
])
vbox = QVBoxLayout()
@ -200,6 +204,11 @@ class BalanceDialog(WindowModalDialog):
grid.addWidget(QLabel(_("Lightning") + ':'), 4, 1)
grid.addWidget(QLabel(lightning_str), 4, 2, alignment=Qt.AlignRight)
grid.addWidget(QLabel(lightning_fiat_str), 4, 3, alignment=Qt.AlignRight)
if f_lightning:
grid.addWidget(LegendWidget(COLOR_FROZEN_LIGHTNING), 5, 0)
grid.addWidget(QLabel(_("Lightning (frozen)") + ':'), 5, 1)
grid.addWidget(QLabel(f_lightning_str), 5, 2, alignment=Qt.AlignRight)
grid.addWidget(QLabel(f_lightning_fiat_str), 5, 3, alignment=Qt.AlignRight)
vbox.addLayout(grid)
vbox.addStretch(1)

7
electrum/gui/qt/main_window.py

@ -106,7 +106,7 @@ from .transaction_dialog import PreviewTxDialog
from .rbf_dialog import BumpFeeDialog, DSCancelDialog
from .qrreader import scan_qrcode
from .swap_dialog import SwapDialog
from .balance_dialog import BalanceToolButton, COLOR_FROZEN, COLOR_UNMATURED, COLOR_UNCONFIRMED, COLOR_CONFIRMED, COLOR_LIGHTNING
from .balance_dialog import BalanceToolButton, COLOR_FROZEN, COLOR_UNMATURED, COLOR_UNCONFIRMED, COLOR_CONFIRMED, COLOR_LIGHTNING, COLOR_FROZEN_LIGHTNING
if TYPE_CHECKING:
from . import ElectrumGui
@ -992,15 +992,16 @@ class ElectrumWindow(QMainWindow, MessageBoxMixin, Logger):
icon = read_QIcon("status_lagging%s.png"%fork_str)
else:
network_text = _("Connected")
confirmed, unconfirmed, unmatured, frozen, lightning = self.wallet.get_balances_for_piechart()
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),
(_('Confirmed'), COLOR_CONFIRMED, confirmed),
(_('Lightning'), COLOR_LIGHTNING, lightning),
(_('Lightning (frozen)'), COLOR_FROZEN_LIGHTNING, f_lightning),
])
balance = confirmed + unconfirmed + unmatured + frozen + lightning
balance = confirmed + unconfirmed + unmatured + frozen + lightning + f_lightning
balance_text = _("Balance") + ": %s "%(self.format_amount_and_units(balance))
# append fiat balance and price
if self.fx.is_enabled():

4
electrum/lnworker.py

@ -2087,10 +2087,10 @@ class LNWallet(LNWorker):
return
self.wallet.save_db()
def get_balance(self):
def get_balance(self, frozen=False):
with self.lock:
return Decimal(sum(
chan.balance(LOCAL) if not chan.is_closed() else 0
chan.balance(LOCAL) if not chan.is_closed() and (chan.is_frozen_for_sending() if frozen else True) else 0
for chan in self.channels.values())) / 1000
def num_sats_can_send(self) -> Decimal:

3
electrum/wallet.py

@ -729,6 +729,7 @@ class Abstract_Wallet(AddressSynchronizer, ABC):
c, u, x = self.get_balance()
fc, fu, fx = self.get_frozen_balance()
lightning = self.lnworker.get_balance() if self.has_lightning() else 0
f_lightning = self.lnworker.get_balance(frozen=True) if self.has_lightning() else 0
# subtract frozen funds
cc = c - fc
uu = u - fu
@ -739,7 +740,7 @@ class Abstract_Wallet(AddressSynchronizer, ABC):
if uu < 0:
cc = cc + uu
uu = 0
return cc, uu, xx, frozen, lightning
return cc, uu, xx, frozen, lightning - f_lightning, f_lightning
def balance_at_timestamp(self, domain, target_timestamp):
# we assume that get_history returns items ordered by block height

Loading…
Cancel
Save