Browse Source

Qt: display number of tasks (window._coroutines_scheduled) in toolbar.

Disable rebalance/swap suggestions attached to requests/invoices if there is an ongoing task.
Note: This assumes that all tasks are lightning payments, which is true for the moment.
patch-4
ThomasV 3 years ago
parent
commit
f14c420c30
  1. 32
      electrum/gui/qt/main_window.py

32
electrum/gui/qt/main_window.py

@ -343,9 +343,11 @@ class ElectrumWindow(QMainWindow, MessageBoxMixin, Logger):
on_result(res)
finally:
self._coroutines_scheduled.discard(fut)
self.need_update.set()
fut = asyncio.run_coroutine_threadsafe(wrapper(), self.network.asyncio_loop)
self._coroutines_scheduled.add(fut)
self.need_update.set()
def on_fx_history(self):
self.history_model.refresh('fx_history')
@ -1028,6 +1030,15 @@ class ElectrumWindow(QMainWindow, MessageBoxMixin, Logger):
if self.status_button:
self.status_button.setIcon(icon)
num_tasks = self.num_tasks()
self.tasks_label.setText("(%d %s)"%(num_tasks, _("tasks")))
self.tasks_label.setVisible(num_tasks > 0)
def num_tasks(self):
# For the moment, all the coroutines in this set are outgoing LN payments,
# so we can use this to disable buttons for rebalance/swap suggestions
return len(self._coroutines_scheduled)
def update_wallet(self):
self.update_status()
if self.wallet.is_up_to_date() or not self.network or not self.network.is_connected():
@ -1330,22 +1341,22 @@ class ElectrumWindow(QMainWindow, MessageBoxMixin, Logger):
elif not can_receive_lightning:
self.receive_rebalance_button.suggestion = self.wallet.lnworker.suggest_rebalance_to_receive(amount_sat)
self.receive_swap_button.suggestion = self.wallet.lnworker.suggest_swap_to_receive(amount_sat)
ln_help = _('Your Lightning channels do not have the capacity to receive this amount.')
can_rebalance = bool(self.receive_rebalance_button.suggestion)
can_swap = bool(self.receive_swap_button.suggestion)
lnaddr = ''
ln_help = _('You do not have the capacity to receive that amount with Lightning.')
if can_rebalance:
ln_help += '\n\n' + _('You may have that capacity after rebalancing your channels.')
ln_help += '\n\n' + _('You may have that capacity if you rebalance your channels.')
elif can_swap:
ln_help += '\n\n' + _('You may have that capacity after swapping some of your funds.')
lnaddr = ''
ln_help += '\n\n' + _('You may have that capacity if you swap some of your funds.')
else:
ln_help = ''
can_rebalance = False
can_swap = False
self.receive_rebalance_button.setEnabled(can_rebalance)
self.receive_rebalance_button.setVisible(can_rebalance)
self.receive_swap_button.setEnabled(can_swap)
self.receive_swap_button.setVisible(can_swap)
self.receive_rebalance_button.setEnabled(can_rebalance and self.num_tasks() == 0)
self.receive_swap_button.setEnabled(can_swap and self.num_tasks() == 0)
icon_name = "lightning.png" if lnaddr else "lightning_disconnected.png"
self.receive_tabs.setTabIcon(2, read_QIcon(icon_name))
# encode lightning invoices as uppercase so QR encoding can use
@ -1747,7 +1758,8 @@ class ElectrumWindow(QMainWindow, MessageBoxMixin, Logger):
can_pay_onchain = invoice.get_address() and self.wallet.can_pay_onchain(invoice.get_outputs(), coins=coins)
can_pay_with_new_channel = self.wallet.lnworker.suggest_funding_amount(amount_sat, coins=coins)
can_pay_with_swap = self.wallet.lnworker.suggest_swap_to_send(amount_sat, coins=coins)
can_rebalance = self.wallet.lnworker.suggest_rebalance_to_send(amount_sat)
rebalance_suggestion = self.wallet.lnworker.suggest_rebalance_to_send(amount_sat)
can_rebalance = bool(rebalance_suggestion) and self.num_tasks() == 0
choices = {}
if can_rebalance:
msg = ''.join([
@ -1782,7 +1794,7 @@ class ElectrumWindow(QMainWindow, MessageBoxMixin, Logger):
if r is not None:
self.save_pending_invoice()
if r == 0:
chan1, chan2, delta = can_rebalance
chan1, chan2, delta = rebalance_suggestion
self.rebalance_dialog(chan1, chan2, amount_sat=delta)
elif r == 1:
amount_sat, min_amount_sat = can_pay_with_new_channel
@ -2540,6 +2552,9 @@ class ElectrumWindow(QMainWindow, MessageBoxMixin, Logger):
self.update_check_button.hide()
sb.addPermanentWidget(self.update_check_button)
self.tasks_label = QLabel('')
sb.addPermanentWidget(self.tasks_label)
self.password_button = StatusBarButton(QIcon(), _("Password"), self.change_password_dialog)
sb.addPermanentWidget(self.password_button)
@ -3754,3 +3769,4 @@ class ElectrumWindow(QMainWindow, MessageBoxMixin, Logger):
amount_msat = amount_e.get_amount() * 1000
coro = self.wallet.lnworker.rebalance_channels(d.chan_from, d.chan_to, amount_msat=amount_msat)
self.run_coroutine_from_thread(coro)
self.update_current_request()

Loading…
Cancel
Save