Lightning: Show sending and receiving capacity. Fixes #5967
This commit is contained in:
@@ -52,11 +52,20 @@ Builder.load_string(r'''
|
|||||||
<LightningChannelsDialog@Popup>:
|
<LightningChannelsDialog@Popup>:
|
||||||
name: 'lightning_channels'
|
name: 'lightning_channels'
|
||||||
title: _('Lightning channels.')
|
title: _('Lightning channels.')
|
||||||
|
can_send: ''
|
||||||
|
can_receive: ''
|
||||||
id: popup
|
id: popup
|
||||||
BoxLayout:
|
BoxLayout:
|
||||||
id: box
|
id: box
|
||||||
orientation: 'vertical'
|
orientation: 'vertical'
|
||||||
spacing: '1dp'
|
spacing: '2dp'
|
||||||
|
padding: '12dp'
|
||||||
|
BoxLabel:
|
||||||
|
text: _('Can send') + ':'
|
||||||
|
value: root.can_send
|
||||||
|
BoxLabel:
|
||||||
|
text: _('Can receive') + ':'
|
||||||
|
value: root.can_receive
|
||||||
ScrollView:
|
ScrollView:
|
||||||
GridLayout:
|
GridLayout:
|
||||||
cols: 1
|
cols: 1
|
||||||
@@ -64,12 +73,17 @@ Builder.load_string(r'''
|
|||||||
size_hint: 1, None
|
size_hint: 1, None
|
||||||
height: self.minimum_height
|
height: self.minimum_height
|
||||||
spacing: '2dp'
|
spacing: '2dp'
|
||||||
padding: '12dp'
|
BoxLayout:
|
||||||
Button:
|
|
||||||
size_hint: 1, None
|
size_hint: 1, None
|
||||||
height: '48dp'
|
height: '48dp'
|
||||||
text: _('New channel...')
|
Widget:
|
||||||
on_press: popup.app.popup_dialog('lightning_open_channel_dialog')
|
size_hint: 0.7, None
|
||||||
|
height: '48dp'
|
||||||
|
Button:
|
||||||
|
size_hint: 0.3, None
|
||||||
|
height: '48dp'
|
||||||
|
text: _('New...')
|
||||||
|
on_press: popup.app.popup_dialog('lightning_open_channel_dialog')
|
||||||
|
|
||||||
<ChannelDetailsList@RecycleView>:
|
<ChannelDetailsList@RecycleView>:
|
||||||
scroll_type: ['bars', 'content']
|
scroll_type: ['bars', 'content']
|
||||||
@@ -147,6 +161,7 @@ class ChannelDetailsPopup(Popup):
|
|||||||
_('Remote CTN'): chan.get_latest_ctn(REMOTE),
|
_('Remote CTN'): chan.get_latest_ctn(REMOTE),
|
||||||
_('Capacity'): self.app.format_amount_and_units(chan.constraints.capacity),
|
_('Capacity'): self.app.format_amount_and_units(chan.constraints.capacity),
|
||||||
_('Can send'): self.app.format_amount_and_units(chan.available_to_spend(LOCAL) // 1000),
|
_('Can send'): self.app.format_amount_and_units(chan.available_to_spend(LOCAL) // 1000),
|
||||||
|
_('Can receive'): self.app.format_amount_and_units(chan.available_to_spend(REMOTE) // 1000),
|
||||||
_('Current feerate'): str(chan.get_latest_feerate(LOCAL)),
|
_('Current feerate'): str(chan.get_latest_feerate(LOCAL)),
|
||||||
_('Node ID'): bh2u(chan.node_id),
|
_('Node ID'): bh2u(chan.node_id),
|
||||||
_('Channel ID'): bh2u(chan.channel_id),
|
_('Channel ID'): bh2u(chan.channel_id),
|
||||||
@@ -202,6 +217,7 @@ class LightningChannelsDialog(Factory.Popup):
|
|||||||
super(LightningChannelsDialog, self).__init__()
|
super(LightningChannelsDialog, self).__init__()
|
||||||
self.clocks = []
|
self.clocks = []
|
||||||
self.app = app
|
self.app = app
|
||||||
|
self.can_send = ''
|
||||||
self.update()
|
self.update()
|
||||||
|
|
||||||
def show_item(self, obj):
|
def show_item(self, obj):
|
||||||
@@ -231,6 +247,7 @@ class LightningChannelsDialog(Factory.Popup):
|
|||||||
l, r = self.format_fields(chan)
|
l, r = self.format_fields(chan)
|
||||||
item.local_balance = _('Local') + ':' + l
|
item.local_balance = _('Local') + ':' + l
|
||||||
item.remote_balance = _('Remote') + ': ' + r
|
item.remote_balance = _('Remote') + ': ' + r
|
||||||
|
self.update_can_send()
|
||||||
|
|
||||||
def update(self):
|
def update(self):
|
||||||
channel_cards = self.ids.lightning_channels_container
|
channel_cards = self.ids.lightning_channels_container
|
||||||
@@ -245,3 +262,9 @@ class LightningChannelsDialog(Factory.Popup):
|
|||||||
item._chan = i
|
item._chan = i
|
||||||
self.update_item(item)
|
self.update_item(item)
|
||||||
channel_cards.add_widget(item)
|
channel_cards.add_widget(item)
|
||||||
|
self.update_can_send()
|
||||||
|
|
||||||
|
def update_can_send(self):
|
||||||
|
lnworker = self.app.wallet.lnworker
|
||||||
|
self.can_send = self.app.format_amount_and_units(lnworker.can_send())
|
||||||
|
self.can_receive = self.app.format_amount_and_units(lnworker.can_receive())
|
||||||
|
|||||||
@@ -130,6 +130,7 @@ class ChannelsList(MyTreeView):
|
|||||||
if item.data(ROLE_CHANNEL_ID) == chan.channel_id:
|
if item.data(ROLE_CHANNEL_ID) == chan.channel_id:
|
||||||
for column, v in enumerate(self.format_fields(chan)):
|
for column, v in enumerate(self.format_fields(chan)):
|
||||||
self.model().item(row, column).setData(v, QtCore.Qt.DisplayRole)
|
self.model().item(row, column).setData(v, QtCore.Qt.DisplayRole)
|
||||||
|
self.update_can_send(self.parent.wallet.lnworker)
|
||||||
|
|
||||||
@QtCore.pyqtSlot(Abstract_Wallet)
|
@QtCore.pyqtSlot(Abstract_Wallet)
|
||||||
def do_update_rows(self, wallet):
|
def do_update_rows(self, wallet):
|
||||||
@@ -138,6 +139,7 @@ class ChannelsList(MyTreeView):
|
|||||||
lnworker = self.parent.wallet.lnworker
|
lnworker = self.parent.wallet.lnworker
|
||||||
if not lnworker:
|
if not lnworker:
|
||||||
return
|
return
|
||||||
|
self.update_can_send(lnworker)
|
||||||
self.model().clear()
|
self.model().clear()
|
||||||
self.update_headers(self.headers)
|
self.update_headers(self.headers)
|
||||||
for chan in lnworker.channels.values():
|
for chan in lnworker.channels.values():
|
||||||
@@ -149,8 +151,17 @@ class ChannelsList(MyTreeView):
|
|||||||
items[self.Columns.REMOTE_BALANCE].setFont(QFont(MONOSPACE_FONT))
|
items[self.Columns.REMOTE_BALANCE].setFont(QFont(MONOSPACE_FONT))
|
||||||
self.model().insertRow(0, items)
|
self.model().insertRow(0, items)
|
||||||
|
|
||||||
|
def update_can_send(self, lnworker):
|
||||||
|
msg = _('Can send') + ' ' + self.parent.format_amount(lnworker.can_send())\
|
||||||
|
+ ' ' + self.parent.base_unit() + '; '\
|
||||||
|
+ _('can receive') + ' ' + self.parent.format_amount(lnworker.can_receive())\
|
||||||
|
+ ' ' + self.parent.base_unit()
|
||||||
|
self.can_send_label.setText(msg)
|
||||||
|
|
||||||
def get_toolbar(self):
|
def get_toolbar(self):
|
||||||
h = QHBoxLayout()
|
h = QHBoxLayout()
|
||||||
|
self.can_send_label = QLabel('')
|
||||||
|
h.addWidget(self.can_send_label)
|
||||||
h.addStretch()
|
h.addStretch()
|
||||||
h.addWidget(EnterButton(_('Open Channel'), self.new_channel_dialog))
|
h.addWidget(EnterButton(_('Open Channel'), self.new_channel_dialog))
|
||||||
return h
|
return h
|
||||||
|
|||||||
@@ -298,6 +298,9 @@ class Channel(Logger):
|
|||||||
def get_state(self):
|
def get_state(self):
|
||||||
return self._state
|
return self._state
|
||||||
|
|
||||||
|
def is_open(self):
|
||||||
|
return self.get_state() == channel_states.OPEN
|
||||||
|
|
||||||
def is_closing(self):
|
def is_closing(self):
|
||||||
return self.get_state() in [channel_states.CLOSING, channel_states.FORCE_CLOSING]
|
return self.get_state() in [channel_states.CLOSING, channel_states.FORCE_CLOSING]
|
||||||
|
|
||||||
|
|||||||
@@ -1163,6 +1163,14 @@ class LNWallet(LNWorker):
|
|||||||
with self.lock:
|
with self.lock:
|
||||||
return Decimal(sum(chan.balance(LOCAL) if not chan.is_closed() else 0 for chan in self.channels.values()))/1000
|
return Decimal(sum(chan.balance(LOCAL) if not chan.is_closed() else 0 for chan in self.channels.values()))/1000
|
||||||
|
|
||||||
|
def can_send(self):
|
||||||
|
with self.lock:
|
||||||
|
return Decimal(max(chan.available_to_spend(LOCAL) if chan.is_open() else 0 for chan in self.channels.values()))/1000
|
||||||
|
|
||||||
|
def can_receive(self):
|
||||||
|
with self.lock:
|
||||||
|
return Decimal(max(chan.available_to_spend(REMOTE) if chan.is_open() else 0 for chan in self.channels.values()))/1000
|
||||||
|
|
||||||
def list_channels(self):
|
def list_channels(self):
|
||||||
encoder = MyEncoder()
|
encoder = MyEncoder()
|
||||||
with self.lock:
|
with self.lock:
|
||||||
|
|||||||
Reference in New Issue
Block a user