From 2cf4cc197856ac113ea972fb720a72be082b652c Mon Sep 17 00:00:00 2001 From: Sander van Grieken Date: Thu, 11 May 2023 13:23:23 +0200 Subject: [PATCH] qml: render reserved channel capacity in a darker tone, take frozen into account --- .../gui/qml/components/ChannelDetails.qml | 4 ++ electrum/gui/qml/components/Constants.qml | 4 +- .../qml/components/controls/ChannelBar.qml | 50 +++++++++++++++---- .../components/controls/ChannelDelegate.qml | 4 ++ electrum/gui/qml/qechannellistmodel.py | 10 ++-- 5 files changed, 57 insertions(+), 15 deletions(-) diff --git a/electrum/gui/qml/components/ChannelDetails.qml b/electrum/gui/qml/components/ChannelDetails.qml index a82cbf42f..dbe81e152 100644 --- a/electrum/gui/qml/components/ChannelDetails.qml +++ b/electrum/gui/qml/components/ChannelDetails.qml @@ -170,6 +170,10 @@ Pane { capacity: channeldetails.capacity localCapacity: channeldetails.localCapacity remoteCapacity: channeldetails.remoteCapacity + canSend: channeldetails.canSend + canReceive: channeldetails.canReceive + frozenForSending: channeldetails.frozenForSending + frozenForReceiving: channeldetails.frozenForReceiving } Label { diff --git a/electrum/gui/qml/components/Constants.qml b/electrum/gui/qml/components/Constants.qml index e66f61183..84c935de6 100644 --- a/electrum/gui/qml/components/Constants.qml +++ b/electrum/gui/qml/components/Constants.qml @@ -41,8 +41,10 @@ Item { property color colorProgress: '#ffffff80' property color colorDone: '#ff80ff80' - property color colorLightningLocal: "blue" + property color colorLightningLocal: "#6060ff" + property color colorLightningLocalReserve: "#0000a0" property color colorLightningRemote: "yellow" + property color colorLightningRemoteReserve: Qt.darker(colorLightningRemote, 1.5) property color colorChannelOpen: "#ff80ff80" property color colorPiechartTotal: Material.accentColor diff --git a/electrum/gui/qml/components/controls/ChannelBar.qml b/electrum/gui/qml/components/controls/ChannelBar.qml index 34378158a..0a3d3ee73 100644 --- a/electrum/gui/qml/components/controls/ChannelBar.qml +++ b/electrum/gui/qml/components/controls/ChannelBar.qml @@ -9,6 +9,10 @@ Item { property Amount capacity property Amount localCapacity property Amount remoteCapacity + property Amount canSend + property Amount canReceive + property bool frozenForSending: false + property bool frozenForReceiving: false height: 10 implicitWidth: 100 @@ -16,32 +20,56 @@ Item { onWidthChanged: { var cap = capacity.satsInt * 1000 var twocap = cap * 2 - b1.width = width * (cap - localCapacity.msatsInt) / twocap - b2.width = width * localCapacity.msatsInt / twocap - b3.width = width * remoteCapacity.msatsInt / twocap - b4.width = width * (cap - remoteCapacity.msatsInt) / twocap + l1.width = width * (cap - localCapacity.msatsInt) / twocap + if (frozenForSending) { + l2.width = width * localCapacity.msatsInt / twocap + l3.width = 0 + } else { + l2.width = width * (localCapacity.msatsInt - canSend.msatsInt) / twocap + l3.width = width * canSend.msatsInt / twocap + } + if (frozenForReceiving) { + r3.width = 0 + r2.width = width * remoteCapacity.msatsInt / twocap + } else { + r3.width = width * canReceive.msatsInt / twocap + r2.width = width * (remoteCapacity.msatsInt - canReceive.msatsInt) / twocap + } + r1.width = width * (cap - remoteCapacity.msatsInt) / twocap } Rectangle { - id: b1 + id: l1 x: 0 height: parent.height color: 'gray' } Rectangle { - id: b2 - anchors.left: b1.right + id: l2 + anchors.left: l1.right + height: parent.height + color: constants.colorLightningLocalReserve + } + Rectangle { + id: l3 + anchors.left: l2.right height: parent.height color: constants.colorLightningLocal } Rectangle { - id: b3 - anchors.left: b2.right + id: r3 + anchors.left: l3.right height: parent.height color: constants.colorLightningRemote } Rectangle { - id: b4 - anchors.left: b3.right + id: r2 + anchors.left: r3.right + height: parent.height + color: constants.colorLightningRemoteReserve + } + Rectangle { + id: r1 + anchors.left: r2.right height: parent.height color: 'gray' } diff --git a/electrum/gui/qml/components/controls/ChannelDelegate.qml b/electrum/gui/qml/components/controls/ChannelDelegate.qml index bf54d0a76..299b7433b 100644 --- a/electrum/gui/qml/components/controls/ChannelDelegate.qml +++ b/electrum/gui/qml/components/controls/ChannelDelegate.qml @@ -111,6 +111,10 @@ ItemDelegate { capacity: model.capacity localCapacity: model.local_capacity remoteCapacity: model.remote_capacity + canSend: model.can_send + canReceive: model.can_receive + frozenForSending: model.send_frozen + frozenForReceiving: model.receive_frozen } Item { diff --git a/electrum/gui/qml/qechannellistmodel.py b/electrum/gui/qml/qechannellistmodel.py index a58019f8f..1036a7f31 100644 --- a/electrum/gui/qml/qechannellistmodel.py +++ b/electrum/gui/qml/qechannellistmodel.py @@ -14,9 +14,9 @@ class QEChannelListModel(QAbstractListModel, QtEventListener): _logger = get_logger(__name__) # define listmodel rolemap - _ROLE_NAMES=('cid','state','state_code','initiator','capacity','can_send', - 'can_receive','l_csv_delay','r_csv_delay','send_frozen','receive_frozen', - 'type','node_id','node_alias','short_cid','funding_tx','is_trampoline', + _ROLE_NAMES=('cid', 'state', 'state_code', 'initiator', 'capacity', 'can_send', + 'can_receive', 'l_csv_delay', 'r_csv_delay', 'send_frozen', 'receive_frozen', + 'type', 'node_id', 'node_alias', 'short_cid', 'funding_tx', 'is_trampoline', 'is_backup', 'is_imported', 'local_capacity', 'remote_capacity') _ROLE_KEYS = range(Qt.UserRole, Qt.UserRole + len(_ROLE_NAMES)) _ROLE_MAP = dict(zip(_ROLE_KEYS, [bytearray(x.encode()) for x in _ROLE_NAMES])) @@ -93,12 +93,16 @@ class QEChannelListModel(QAbstractListModel, QtEventListener): item['can_receive'] = QEAmount() item['local_capacity'] = QEAmount() item['remote_capacity'] = QEAmount() + item['send_frozen'] = True + item['receive_frozen'] = True item['is_imported'] = lnc.is_imported else: item['can_send'] = QEAmount(amount_msat=lnc.available_to_spend(LOCAL)) item['can_receive'] = QEAmount(amount_msat=lnc.available_to_spend(REMOTE)) item['local_capacity'] = QEAmount(amount_msat=lnc.balance(LOCAL)) item['remote_capacity'] = QEAmount(amount_msat=lnc.balance(REMOTE)) + item['send_frozen'] = lnc.is_frozen_for_sending() + item['receive_frozen'] = lnc.is_frozen_for_receiving() item['is_imported'] = False return item