channels_list: move swap and rebalance buttons into toolbar
This commit is contained in:
@@ -74,7 +74,6 @@ class ChannelsList(MyTreeView):
|
|||||||
self.network = self.parent.network
|
self.network = self.parent.network
|
||||||
self.wallet = self.parent.wallet
|
self.wallet = self.parent.wallet
|
||||||
self.setSortingEnabled(True)
|
self.setSortingEnabled(True)
|
||||||
self.selectionModel().selectionChanged.connect(self.on_selection_changed)
|
|
||||||
|
|
||||||
@property
|
@property
|
||||||
# property because lnworker might be initialized at runtime
|
# property because lnworker might be initialized at runtime
|
||||||
@@ -208,24 +207,22 @@ class ChannelsList(MyTreeView):
|
|||||||
|
|
||||||
def on_rebalance(self):
|
def on_rebalance(self):
|
||||||
chan1, chan2 = self.get_rebalance_pair()
|
chan1, chan2 = self.get_rebalance_pair()
|
||||||
|
if chan1 is None:
|
||||||
|
self.parent.show_error("Select two active channels to rebalance.")
|
||||||
|
return
|
||||||
self.parent.rebalance_dialog(chan1, chan2)
|
self.parent.rebalance_dialog(chan1, chan2)
|
||||||
|
|
||||||
def on_selection_changed(self):
|
|
||||||
chan1, chan2 = self.get_rebalance_pair()
|
|
||||||
self.rebalance_button.setEnabled(chan1 is not None)
|
|
||||||
|
|
||||||
def create_menu(self, position):
|
def create_menu(self, position):
|
||||||
menu = QMenu()
|
menu = QMenu()
|
||||||
menu.setSeparatorsCollapsible(True) # consecutive separators are merged together
|
menu.setSeparatorsCollapsible(True) # consecutive separators are merged together
|
||||||
selected = self.selected_in_column(self.Columns.NODE_ALIAS)
|
selected = self.selected_in_column(self.Columns.NODE_ALIAS)
|
||||||
if not selected:
|
if not selected:
|
||||||
menu.addAction(_("Import channel backup"), lambda: self.parent.do_process_from_text_channel_backup())
|
|
||||||
menu.exec_(self.viewport().mapToGlobal(position))
|
menu.exec_(self.viewport().mapToGlobal(position))
|
||||||
return
|
return
|
||||||
if len(selected) == 2:
|
if len(selected) == 2:
|
||||||
chan1, chan2 = self.get_rebalance_pair()
|
chan1, chan2 = self.get_rebalance_pair()
|
||||||
if chan1 and chan2:
|
if chan1 and chan2:
|
||||||
menu.addAction(_("Rebalance"), lambda: self.parent.rebalance_dialog(chan1, chan2))
|
menu.addAction(_("Rebalance channels"), lambda: self.parent.rebalance_dialog(chan1, chan2))
|
||||||
menu.exec_(self.viewport().mapToGlobal(position))
|
menu.exec_(self.viewport().mapToGlobal(position))
|
||||||
return
|
return
|
||||||
elif len(selected) > 2:
|
elif len(selected) > 2:
|
||||||
@@ -345,31 +342,18 @@ class ChannelsList(MyTreeView):
|
|||||||
+ _('can receive') + ' ' + self.parent.format_amount(lnworker.num_sats_can_receive())\
|
+ _('can receive') + ' ' + self.parent.format_amount(lnworker.num_sats_can_receive())\
|
||||||
+ ' ' + self.parent.base_unit()
|
+ ' ' + self.parent.base_unit()
|
||||||
self.can_send_label.setText(msg)
|
self.can_send_label.setText(msg)
|
||||||
self.update_swap_button(lnworker)
|
|
||||||
|
|
||||||
def update_swap_button(self, lnworker: LNWallet):
|
|
||||||
if lnworker.num_sats_can_send() or lnworker.num_sats_can_receive():
|
|
||||||
self.swap_button.setEnabled(True)
|
|
||||||
else:
|
|
||||||
self.swap_button.setEnabled(False)
|
|
||||||
|
|
||||||
def create_toolbar(self, config):
|
def create_toolbar(self, config):
|
||||||
h = QHBoxLayout()
|
toolbar, menu = self.create_toolbar_with_menu('')
|
||||||
self.can_send_label = QLabel('')
|
self.can_send_label = toolbar.itemAt(0).widget()
|
||||||
h.addWidget(self.can_send_label)
|
menu.addAction(_('Rebalance channels'), lambda: self.on_rebalance())
|
||||||
h.addStretch()
|
menu.addAction(_('Submarine swap'), lambda: self.parent.run_swap_dialog())
|
||||||
self.rebalance_button = EnterButton(_('Rebalance'), lambda x: self.on_rebalance())
|
menu.addSeparator()
|
||||||
self.rebalance_button.setToolTip("Select two active channels to rebalance.")
|
menu.addAction(_("Import channel backup"), lambda: self.parent.do_process_from_text_channel_backup())
|
||||||
self.rebalance_button.setDisabled(True)
|
self.new_channel_button = EnterButton(_('New Channel'), self.new_channel_with_warning)
|
||||||
self.swap_button = EnterButton(_('Swap'), lambda x: self.parent.run_swap_dialog())
|
|
||||||
self.swap_button.setToolTip("Have at least one channel to do swaps.")
|
|
||||||
self.swap_button.setDisabled(True)
|
|
||||||
self.new_channel_button = EnterButton(_('Open Channel'), self.new_channel_with_warning)
|
|
||||||
self.new_channel_button.setEnabled(self.parent.wallet.has_lightning())
|
self.new_channel_button.setEnabled(self.parent.wallet.has_lightning())
|
||||||
h.addWidget(self.new_channel_button)
|
toolbar.insertWidget(2, self.new_channel_button)
|
||||||
h.addWidget(self.rebalance_button)
|
return toolbar
|
||||||
h.addWidget(self.swap_button)
|
|
||||||
return h
|
|
||||||
|
|
||||||
def new_channel_with_warning(self):
|
def new_channel_with_warning(self):
|
||||||
lnworker = self.parent.wallet.lnworker
|
lnworker = self.parent.wallet.lnworker
|
||||||
|
|||||||
@@ -1111,6 +1111,9 @@ class ElectrumWindow(QMainWindow, MessageBoxMixin, Logger, QtEventListener):
|
|||||||
if not self.network:
|
if not self.network:
|
||||||
self.show_error(_("You are offline."))
|
self.show_error(_("You are offline."))
|
||||||
return
|
return
|
||||||
|
if not self.wallet.lnworker.num_sats_can_send() and not self.wallet.lnworker.num_sats_can_receive():
|
||||||
|
self.show_error(_("You do not have liquidity in your active channels."))
|
||||||
|
return
|
||||||
def get_pairs_thread():
|
def get_pairs_thread():
|
||||||
self.network.run_from_another_thread(self.wallet.lnworker.swap_manager.get_pairs())
|
self.network.run_from_another_thread(self.wallet.lnworker.swap_manager.get_pairs())
|
||||||
try:
|
try:
|
||||||
|
|||||||
Reference in New Issue
Block a user