Browse Source

qml: render reserved channel capacity in a darker tone, take frozen into account

master
Sander van Grieken 3 years ago committed by accumulator
parent
commit
2cf4cc1978
  1. 4
      electrum/gui/qml/components/ChannelDetails.qml
  2. 4
      electrum/gui/qml/components/Constants.qml
  3. 50
      electrum/gui/qml/components/controls/ChannelBar.qml
  4. 4
      electrum/gui/qml/components/controls/ChannelDelegate.qml
  5. 10
      electrum/gui/qml/qechannellistmodel.py

4
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 {

4
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

50
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'
}

4
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 {

10
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

Loading…
Cancel
Save