|
8 | 8 | from electrum.lnworker import hardcoded_trampoline_nodes |
9 | 9 | from electrum.util import NotEnoughFunds, NoDynamicFeeEstimates |
10 | 10 | from electrum.fee_policy import FeePolicy |
| 11 | +from electrum.lntransport import extract_nodeid, ConnStringFormatError |
11 | 12 |
|
12 | 13 | from .util import (WindowModalDialog, Buttons, OkButton, CancelButton, |
13 | 14 | EnterButton, WWLabel, char_width_in_lineedit) |
@@ -43,14 +44,18 @@ def __init__(self, window: 'ElectrumWindow', amount_sat: Optional[int] = None, m |
43 | 44 | vbox.addWidget(QLabel(_('Enter Remote Node ID or connection string or invoice'))) |
44 | 45 | self.remote_nodeid = QLineEdit() |
45 | 46 | self.remote_nodeid.setMinimumWidth(700) |
| 47 | + self.remote_nodeid.textChanged.connect(self.maybe_enable_ok_button) |
46 | 48 | self.suggest_button = QPushButton(self, text=_('Suggest Peer')) |
47 | 49 | self.suggest_button.clicked.connect(self.on_suggest) |
48 | 50 | else: |
49 | 51 | self.trampoline_combo = QComboBox() |
50 | 52 | self.trampoline_combo.addItems(self.trampoline_names) |
| 53 | + # index 1 is "Electrum trampoline" on mainnet, this defaults to -1 if 1 is not available |
51 | 54 | self.trampoline_combo.setCurrentIndex(1) |
| 55 | + self.trampoline_combo.currentIndexChanged.connect(self.maybe_enable_ok_button) |
52 | 56 | self.amount_e = BTCAmountEdit(self.window.get_decimal_point) |
53 | 57 | self.amount_e.setAmount(amount_sat) |
| 58 | + self.amount_e.textChanged.connect(self.maybe_enable_ok_button) |
54 | 59 |
|
55 | 60 | btn_width = 10 * char_width_in_lineedit() |
56 | 61 | self.min_button = EnterButton(_("Min"), self.spend_min) |
@@ -83,9 +88,26 @@ def __init__(self, window: 'ElectrumWindow', amount_sat: Optional[int] = None, m |
83 | 88 |
|
84 | 89 | vbox.addLayout(h) |
85 | 90 | vbox.addStretch() |
86 | | - ok_button = OkButton(self) |
87 | | - ok_button.setDefault(True) |
88 | | - vbox.addLayout(Buttons(CancelButton(self), ok_button)) |
| 91 | + self.ok_button = OkButton(self) |
| 92 | + self.ok_button.setDefault(True) |
| 93 | + self.maybe_enable_ok_button() |
| 94 | + vbox.addLayout(Buttons(CancelButton(self), self.ok_button)) |
| 95 | + |
| 96 | + def maybe_enable_ok_button(self): |
| 97 | + enable = True |
| 98 | + if self.network.channel_db: |
| 99 | + try: |
| 100 | + extract_nodeid(str(self.remote_nodeid.text()).strip()) |
| 101 | + except ConnStringFormatError: |
| 102 | + enable = False |
| 103 | + else: |
| 104 | + try: |
| 105 | + self.trampoline_names[self.trampoline_combo.currentIndex()] |
| 106 | + except IndexError: |
| 107 | + enable = False |
| 108 | + if not self.amount_e.get_amount(): |
| 109 | + enable = False |
| 110 | + self.ok_button.setEnabled(enable) |
89 | 111 |
|
90 | 112 | def on_suggest(self): |
91 | 113 | self.network.start_gossip() |
|
0 commit comments