Qt: move new_channel_dialog to main_window and test available amount beforehand
This commit is contained in:
@@ -363,22 +363,11 @@ class ChannelsList(MyTreeView):
|
|||||||
menu.addAction(_('Submarine swap'), lambda: self.main_window.run_swap_dialog())
|
menu.addAction(_('Submarine swap'), lambda: self.main_window.run_swap_dialog())
|
||||||
menu.addSeparator()
|
menu.addSeparator()
|
||||||
menu.addAction(_("Import channel backup"), lambda: self.main_window.do_process_from_text_channel_backup())
|
menu.addAction(_("Import channel backup"), lambda: self.main_window.do_process_from_text_channel_backup())
|
||||||
self.new_channel_button = EnterButton(_('New Channel'), self.new_channel_with_warning)
|
self.new_channel_button = EnterButton(_('New Channel'), self.main_window.new_channel_dialog)
|
||||||
self.new_channel_button.setEnabled(self.wallet.has_lightning())
|
self.new_channel_button.setEnabled(self.wallet.has_lightning())
|
||||||
toolbar.insertWidget(2, self.new_channel_button)
|
toolbar.insertWidget(2, self.new_channel_button)
|
||||||
return toolbar
|
return toolbar
|
||||||
|
|
||||||
def new_channel_with_warning(self):
|
|
||||||
lnworker = self.wallet.lnworker
|
|
||||||
if not lnworker.channels and not lnworker.channel_backups:
|
|
||||||
warning = _(messages.MSG_LIGHTNING_WARNING)
|
|
||||||
answer = self.main_window.question(
|
|
||||||
_('Do you want to create your first channel?') + '\n\n' + warning)
|
|
||||||
if answer:
|
|
||||||
self.new_channel_dialog()
|
|
||||||
else:
|
|
||||||
self.new_channel_dialog()
|
|
||||||
|
|
||||||
def statistics_dialog(self):
|
def statistics_dialog(self):
|
||||||
channel_db = self.network.channel_db
|
channel_db = self.network.channel_db
|
||||||
capacity = self.main_window.format_amount(channel_db.capacity()) + ' '+ self.main_window.base_unit()
|
capacity = self.main_window.format_amount(channel_db.capacity()) + ' '+ self.main_window.base_unit()
|
||||||
@@ -396,11 +385,6 @@ class ChannelsList(MyTreeView):
|
|||||||
vbox.addLayout(Buttons(OkButton(d)))
|
vbox.addLayout(Buttons(OkButton(d)))
|
||||||
d.exec_()
|
d.exec_()
|
||||||
|
|
||||||
def new_channel_dialog(self, *, amount_sat=None, min_amount_sat=None):
|
|
||||||
from .new_channel_dialog import NewChannelDialog
|
|
||||||
d = NewChannelDialog(self.main_window, amount_sat, min_amount_sat)
|
|
||||||
return d.run()
|
|
||||||
|
|
||||||
def set_visibility_of_columns(self):
|
def set_visibility_of_columns(self):
|
||||||
def set_visible(col: int, b: bool):
|
def set_visible(col: int, b: bool):
|
||||||
self.showColumn(col) if b else self.hideColumn(col)
|
self.showColumn(col) if b else self.hideColumn(col)
|
||||||
|
|||||||
@@ -1681,6 +1681,23 @@ class ElectrumWindow(QMainWindow, MessageBoxMixin, Logger, QtEventListener):
|
|||||||
if hasattr(tab, 'searchable_list'):
|
if hasattr(tab, 'searchable_list'):
|
||||||
tab.searchable_list.filter(t)
|
tab.searchable_list.filter(t)
|
||||||
|
|
||||||
|
def new_channel_dialog(self, *, amount_sat=None, min_amount_sat=None):
|
||||||
|
from electrum.lnutil import MIN_FUNDING_SAT
|
||||||
|
from .new_channel_dialog import NewChannelDialog
|
||||||
|
confirmed, unconfirmed, unmatured, frozen, lightning, f_lightning = self.wallet.get_balances_for_piechart()
|
||||||
|
min_amount_sat = min_amount_sat or MIN_FUNDING_SAT
|
||||||
|
if confirmed < min_amount_sat:
|
||||||
|
msg = _('Not enough funds') + '\n\n' + _('You need at least {} to open a channel.').format(self.format_amount_and_units(min_amount_sat))
|
||||||
|
self.show_error(msg)
|
||||||
|
return
|
||||||
|
lnworker = self.wallet.lnworker
|
||||||
|
if not lnworker.channels and not lnworker.channel_backups:
|
||||||
|
msg = _('Do you want to create your first channel?') + '\n\n' + _(messages.MSG_LIGHTNING_WARNING)
|
||||||
|
if not self.question(msg):
|
||||||
|
return
|
||||||
|
d = NewChannelDialog(self, amount_sat, min_amount_sat)
|
||||||
|
return d.run()
|
||||||
|
|
||||||
def new_contact_dialog(self):
|
def new_contact_dialog(self):
|
||||||
d = WindowModalDialog(self, _("New Contact"))
|
d = WindowModalDialog(self, _("New Contact"))
|
||||||
vbox = QVBoxLayout(d)
|
vbox = QVBoxLayout(d)
|
||||||
|
|||||||
@@ -42,9 +42,7 @@ class NewChannelDialog(WindowModalDialog):
|
|||||||
).setEnabled(self.lnworker.can_have_recoverable_channels())
|
).setEnabled(self.lnworker.can_have_recoverable_channels())
|
||||||
vbox.addLayout(toolbar)
|
vbox.addLayout(toolbar)
|
||||||
msg = _('Choose a remote node and an amount to fund the channel.')
|
msg = _('Choose a remote node and an amount to fund the channel.')
|
||||||
if min_amount_sat:
|
msg += '\n' + _('You need to put at least') + ': ' + self.window.format_amount_and_units(self.min_amount_sat)
|
||||||
# only displayed if min_amount_sat is passed as parameter
|
|
||||||
msg += '\n' + _('You need to put at least') + ': ' + self.window.format_amount_and_units(self.min_amount_sat)
|
|
||||||
vbox.addWidget(WWLabel(msg))
|
vbox.addWidget(WWLabel(msg))
|
||||||
if self.network.channel_db:
|
if self.network.channel_db:
|
||||||
vbox.addWidget(QLabel(_('Enter Remote Node ID or connection string or invoice')))
|
vbox.addWidget(QLabel(_('Enter Remote Node ID or connection string or invoice')))
|
||||||
|
|||||||
@@ -713,7 +713,7 @@ class SendTab(QWidget, MessageBoxMixin, Logger):
|
|||||||
self.window.rebalance_dialog(chan1, chan2, amount_sat=delta)
|
self.window.rebalance_dialog(chan1, chan2, amount_sat=delta)
|
||||||
elif r == 1:
|
elif r == 1:
|
||||||
amount_sat, min_amount_sat = can_pay_with_new_channel
|
amount_sat, min_amount_sat = can_pay_with_new_channel
|
||||||
self.window.channels_list.new_channel_dialog(amount_sat=amount_sat, min_amount_sat=min_amount_sat)
|
self.window.new_channel_dialog(amount_sat=amount_sat, min_amount_sat=min_amount_sat)
|
||||||
elif r == 2:
|
elif r == 2:
|
||||||
chan, swap_recv_amount_sat = can_pay_with_swap
|
chan, swap_recv_amount_sat = can_pay_with_swap
|
||||||
self.window.run_swap_dialog(is_reverse=False, recv_amount_sat=swap_recv_amount_sat, channels=[chan])
|
self.window.run_swap_dialog(is_reverse=False, recv_amount_sat=swap_recv_amount_sat, channels=[chan])
|
||||||
|
|||||||
Reference in New Issue
Block a user