kivy: simplify open_channel dialog
This commit is contained in:
@@ -5,7 +5,7 @@ PYTHON = python3
|
|||||||
.PHONY: theming apk clean
|
.PHONY: theming apk clean
|
||||||
|
|
||||||
theming:
|
theming:
|
||||||
#bash -c 'for i in network lightning; do convert -background none theming/light/$$i.{svg,png}; done'
|
bash -c 'for i in network lightning; do convert -background none theming/light/$$i.{svg,png}; done'
|
||||||
$(PYTHON) -m kivy.atlas theming/light 1024 theming/light/*.png
|
$(PYTHON) -m kivy.atlas theming/light 1024 theming/light/*.png
|
||||||
prepare:
|
prepare:
|
||||||
# running pre build setup
|
# running pre build setup
|
||||||
|
|||||||
@@ -20,8 +20,8 @@ Builder.load_string(r'''
|
|||||||
color: (.5,.5,.5,1) if not card.active else (1,1,1,1)
|
color: (.5,.5,.5,1) if not card.active else (1,1,1,1)
|
||||||
text: root.channelId
|
text: root.channelId
|
||||||
Label:
|
Label:
|
||||||
text: _('State:\n') + (card._chan.get_state() if card._chan else 'n/a')
|
text: (card._chan.get_state() if card._chan else 'n/a')
|
||||||
font_size: '10sp'
|
|
||||||
|
|
||||||
<LightningChannelsDialog@Popup>:
|
<LightningChannelsDialog@Popup>:
|
||||||
name: 'lightning_channels'
|
name: 'lightning_channels'
|
||||||
@@ -31,11 +31,6 @@ Builder.load_string(r'''
|
|||||||
id: box
|
id: box
|
||||||
orientation: 'vertical'
|
orientation: 'vertical'
|
||||||
spacing: '1dp'
|
spacing: '1dp'
|
||||||
Button:
|
|
||||||
size_hint: 1, None
|
|
||||||
height: '48dp'
|
|
||||||
text: _('New channel...')
|
|
||||||
on_press: popup.app.popup_dialog('lightning_open_channel_dialog')
|
|
||||||
ScrollView:
|
ScrollView:
|
||||||
GridLayout:
|
GridLayout:
|
||||||
cols: 1
|
cols: 1
|
||||||
@@ -44,6 +39,11 @@ Builder.load_string(r'''
|
|||||||
height: self.minimum_height
|
height: self.minimum_height
|
||||||
spacing: '2dp'
|
spacing: '2dp'
|
||||||
padding: '12dp'
|
padding: '12dp'
|
||||||
|
Button:
|
||||||
|
size_hint: 1, None
|
||||||
|
height: '48dp'
|
||||||
|
text: _('New channel...')
|
||||||
|
on_press: popup.app.popup_dialog('lightning_open_channel_dialog')
|
||||||
|
|
||||||
<ChannelDetailsItem@BoxLayout>:
|
<ChannelDetailsItem@BoxLayout>:
|
||||||
canvas.before:
|
canvas.before:
|
||||||
|
|||||||
@@ -33,29 +33,21 @@ Builder.load_string('''
|
|||||||
size: '22dp', '22dp'
|
size: '22dp', '22dp'
|
||||||
pos_hint: {'center_y': .5}
|
pos_hint: {'center_y': .5}
|
||||||
BlueButton:
|
BlueButton:
|
||||||
text: s.pubkey if s.pubkey else _('Node ID, [pubkey]@[host]:[port]')
|
text: s.pubkey if s.pubkey else _('Node ID')
|
||||||
shorten: True
|
shorten: True
|
||||||
on_release: s.choose_node()
|
#CardSeparator:
|
||||||
IconButton:
|
# color: blue_bottom.foreground_color
|
||||||
on_release: app.scan_qr(on_complete=s.on_pubkey)
|
#BoxLayout:
|
||||||
icon: 'atlas://electrum/gui/kivy/theming/light/camera'
|
# size_hint: 1, None
|
||||||
color: blue_bottom.foreground_color
|
# height: blue_bottom.item_height
|
||||||
size: '22dp', '22dp'
|
# Image:
|
||||||
pos_hint: {'center_y': .5}
|
# source: 'atlas://electrum/gui/kivy/theming/light/network'
|
||||||
size_hint: None, None
|
# size_hint: None, None
|
||||||
CardSeparator:
|
# size: '22dp', '22dp'
|
||||||
color: blue_bottom.foreground_color
|
# pos_hint: {'center_y': .5}
|
||||||
BoxLayout:
|
# BlueButton:
|
||||||
size_hint: 1, None
|
# text: s.ipport if s.ipport else _('host:port')
|
||||||
height: blue_bottom.item_height
|
# on_release: s.ipport_dialog()
|
||||||
Image:
|
|
||||||
source: 'atlas://electrum/gui/kivy/theming/light/network'
|
|
||||||
size_hint: None, None
|
|
||||||
size: '22dp', '22dp'
|
|
||||||
pos_hint: {'center_y': .5}
|
|
||||||
BlueButton:
|
|
||||||
text: s.ipport if s.ipport else _('Auto-detect IP/port')
|
|
||||||
on_release: s.ipport_dialog()
|
|
||||||
CardSeparator:
|
CardSeparator:
|
||||||
color: blue_bottom.foreground_color
|
color: blue_bottom.foreground_color
|
||||||
BoxLayout:
|
BoxLayout:
|
||||||
@@ -67,18 +59,32 @@ Builder.load_string('''
|
|||||||
size: '22dp', '22dp'
|
size: '22dp', '22dp'
|
||||||
pos_hint: {'center_y': .5}
|
pos_hint: {'center_y': .5}
|
||||||
BlueButton:
|
BlueButton:
|
||||||
text: s.amount if s.amount else _('Channel capacity amount')
|
text: s.amount if s.amount else _('Amount')
|
||||||
on_release: app.amount_dialog(s, True)
|
on_release: app.amount_dialog(s, True)
|
||||||
Button:
|
BoxLayout:
|
||||||
size_hint: 1, None
|
size_hint: 1, None
|
||||||
height: blue_bottom.item_height
|
IconButton:
|
||||||
text: _('Paste')
|
icon: 'atlas://electrum/gui/kivy/theming/light/copy'
|
||||||
on_release: s.do_paste()
|
size_hint: 0.5, None
|
||||||
Button:
|
height: '48dp'
|
||||||
size_hint: 1, None
|
on_release: s.do_paste()
|
||||||
height: blue_bottom.item_height
|
IconButton:
|
||||||
text: _('Open Channel')
|
icon: 'atlas://electrum/gui/kivy/theming/light/camera'
|
||||||
on_release: s.do_open_channel()
|
size_hint: 0.5, None
|
||||||
|
height: '48dp'
|
||||||
|
on_release: app.scan_qr(on_complete=s.on_pubkey)
|
||||||
|
Button:
|
||||||
|
text: _('Suggest')
|
||||||
|
size_hint: 1, None
|
||||||
|
height: '48dp'
|
||||||
|
on_release: s.choose_node()
|
||||||
|
Button:
|
||||||
|
text: _('Open')
|
||||||
|
size_hint: 1, None
|
||||||
|
height: '48dp'
|
||||||
|
on_release: s.open_channel()
|
||||||
|
Widget:
|
||||||
|
size_hint: 1, 1
|
||||||
''')
|
''')
|
||||||
|
|
||||||
class LightningOpenChannelDialog(Factory.Popup):
|
class LightningOpenChannelDialog(Factory.Popup):
|
||||||
@@ -88,18 +94,10 @@ class LightningOpenChannelDialog(Factory.Popup):
|
|||||||
d = LabelDialog(_('IP/port in format:\n[host]:[port]'), self.ipport, callback)
|
d = LabelDialog(_('IP/port in format:\n[host]:[port]'), self.ipport, callback)
|
||||||
d.open()
|
d.open()
|
||||||
|
|
||||||
def on_pubkey(self, data):
|
|
||||||
self.pubkey = data.replace('\n', '') # strip newlines if we choose from ChoiseDialog
|
|
||||||
|
|
||||||
def choose_node(self):
|
def choose_node(self):
|
||||||
lines = []
|
|
||||||
suggested = self.app.wallet.lnworker.suggest_peer()
|
suggested = self.app.wallet.lnworker.suggest_peer()
|
||||||
if suggested:
|
if suggested:
|
||||||
assert len(suggested) == 33
|
self.pubkey = suggested.hex()
|
||||||
for i in range(0, 34, 11):
|
|
||||||
lines += [bh2u(suggested[i:i+11])]
|
|
||||||
servers = ['\n'.join(lines)]
|
|
||||||
ChoiceDialog(_('Choose node to connect to'), sorted(servers), self.pubkey, self.on_pubkey).open()
|
|
||||||
|
|
||||||
def __init__(self, app, lnaddr=None, msg=None):
|
def __init__(self, app, lnaddr=None, msg=None):
|
||||||
super(LightningOpenChannelDialog, self).__init__()
|
super(LightningOpenChannelDialog, self).__init__()
|
||||||
@@ -125,17 +123,21 @@ class LightningOpenChannelDialog(Factory.Popup):
|
|||||||
return
|
return
|
||||||
self.pubkey = contents
|
self.pubkey = contents
|
||||||
|
|
||||||
def do_open_channel(self):
|
def open_channel(self):
|
||||||
if not self.pubkey or not self.amount:
|
if not self.pubkey or not self.amount:
|
||||||
self.app.show_info(_('All fields must be filled out'))
|
self.app.show_info(_('All fields must be filled out'))
|
||||||
return
|
return
|
||||||
conn_str = self.pubkey
|
conn_str = self.pubkey
|
||||||
if self.ipport:
|
if self.ipport:
|
||||||
conn_str += '@' + self.ipport.strip()
|
conn_str += '@' + self.ipport.strip()
|
||||||
|
amount = self.app.get_amount(self.amount)
|
||||||
|
self.app.protected('Enter PIN to create a new channel', self.do_open_channel, (conn_str, amount))
|
||||||
|
self.dismiss()
|
||||||
|
|
||||||
|
def do_open_channel(self, conn_str, amount, password):
|
||||||
try:
|
try:
|
||||||
node_id_hex = self.app.wallet.lnworker.open_channel(conn_str, self.app.get_amount(self.amount), 0)
|
node_id_hex = self.app.wallet.lnworker.open_channel(conn_str, amount, 0, password=password)
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
self.app.show_error(_('Problem opening channel: ') + '\n' + repr(e))
|
self.app.show_error(_('Problem opening channel: ') + '\n' + repr(e))
|
||||||
return
|
return
|
||||||
self.app.show_info(_('Please wait for confirmation, channel is opening with node ') + node_id_hex[:16])
|
self.app.show_info(_('Please wait for confirmation, channel is opening with node ') + node_id_hex[:16])
|
||||||
self.dismiss()
|
|
||||||
|
|||||||
@@ -435,12 +435,14 @@ class LNWallet(LNWorker):
|
|||||||
return ctr
|
return ctr
|
||||||
|
|
||||||
def suggest_peer(self):
|
def suggest_peer(self):
|
||||||
|
r = []
|
||||||
for node_id, peer in self.peers.items():
|
for node_id, peer in self.peers.items():
|
||||||
if not peer.initialized.is_set():
|
if not peer.initialized.is_set():
|
||||||
continue
|
continue
|
||||||
if not all([chan.is_closed() for chan in peer.channels.values()]):
|
if not all([chan.is_closed() for chan in peer.channels.values()]):
|
||||||
continue
|
continue
|
||||||
return node_id
|
r.append(node_id)
|
||||||
|
return random.choice(r) if r else None
|
||||||
|
|
||||||
def channels_for_peer(self, node_id):
|
def channels_for_peer(self, node_id):
|
||||||
assert type(node_id) is bytes
|
assert type(node_id) is bytes
|
||||||
|
|||||||
Reference in New Issue
Block a user