Browse Source

qml: fix issues with close channel

master
Sander van Grieken 3 years ago
parent
commit
7adc8b1fbb
  1. 47
      electrum/gui/qml/components/CloseChannelDialog.qml
  2. 17
      electrum/gui/qml/qechanneldetails.py

47
electrum/gui/qml/components/CloseChannelDialog.qml

@ -9,6 +9,7 @@ import "controls"
ElDialog { ElDialog {
id: dialog id: dialog
width: parent.width width: parent.width
height: parent.height height: parent.height
@ -22,7 +23,7 @@ ElDialog {
Overlay.modal: Rectangle { Overlay.modal: Rectangle {
color: "#aa000000" color: "#aa000000"
} }
property bool closing: false property bool _closing: false
closePolicy: Popup.NoAutoClose closePolicy: Popup.NoAutoClose
@ -97,7 +98,7 @@ ElDialog {
InfoTextArea { InfoTextArea {
Layout.columnSpan: 2 Layout.columnSpan: 2
Layout.fillWidth: true Layout.fillWidth: true
text: qsTr(channeldetails.message_force_close) text: channeldetails.message_force_close
} }
Label { Label {
@ -115,41 +116,47 @@ ElDialog {
} }
RadioButton { RadioButton {
id: closetypeCoop
ButtonGroup.group: closetypegroup ButtonGroup.group: closetypegroup
property string closetype: 'cooperative' property string closetype: 'cooperative'
checked: true enabled: !_closing && channeldetails.canCoopClose
enabled: !closing && channeldetails.canCoopClose
text: qsTr('Cooperative close') text: qsTr('Cooperative close')
} }
RadioButton { RadioButton {
id: closetypeRemoteForce
ButtonGroup.group: closetypegroup ButtonGroup.group: closetypegroup
property string closetype: 'remote_force' property string closetype: 'remote_force'
enabled: !closing && channeldetails.canForceClose enabled: !_closing && channeldetails.canForceClose
text: qsTr('Request Force-close') text: qsTr('Request Force-close')
} }
RadioButton { RadioButton {
id: closetypeLocalForce
ButtonGroup.group: closetypegroup ButtonGroup.group: closetypegroup
property string closetype: 'local_force' property string closetype: 'local_force'
enabled: !closing && channeldetails.canForceClose && !channeldetails.isBackup enabled: !_closing && channeldetails.canForceClose && !channeldetails.isBackup
text: qsTr('Local Force-close') text: qsTr('Local Force-close')
} }
} }
ColumnLayout { ColumnLayout {
Layout.columnSpan: 2 Layout.columnSpan: 2
Layout.alignment: Qt.AlignHCenter Layout.maximumWidth: parent.width
Label { Label {
id: errorText id: errorText
visible: !closing && errorText Layout.alignment: Qt.AlignHCenter
Layout.maximumWidth: parent.width
visible: !_closing && errorText
wrapMode: Text.Wrap wrapMode: Text.Wrap
Layout.preferredWidth: layout.width
} }
Label { Label {
Layout.alignment: Qt.AlignHCenter
text: qsTr('Closing...') text: qsTr('Closing...')
visible: closing visible: _closing
} }
BusyIndicator { BusyIndicator {
visible: closing Layout.alignment: Qt.AlignHCenter
visible: _closing
} }
} }
} }
@ -160,10 +167,10 @@ ElDialog {
Layout.fillWidth: true Layout.fillWidth: true
text: qsTr('Close channel') text: qsTr('Close channel')
icon.source: '../../icons/closebutton.png' icon.source: '../../icons/closebutton.png'
enabled: !closing enabled: !_closing
onClicked: { onClicked: {
closing = true _closing = true
channeldetails.close_channel(closetypegroup.checkedButton.closetype) channeldetails.closeChannel(closetypegroup.checkedButton.closetype)
} }
} }
@ -175,13 +182,21 @@ ElDialog {
wallet: Daemon.currentWallet wallet: Daemon.currentWallet
channelid: dialog.channelid channelid: dialog.channelid
onChannelChanged : {
// init default choice
if (channeldetails.canCoopClose)
closetypeCoop.checked = true
else
closetypeRemoteForce.checked = true
}
onChannelCloseSuccess: { onChannelCloseSuccess: {
closing = false _closing = false
dialog.close() dialog.close()
} }
onChannelCloseFailed: { onChannelCloseFailed: {
closing = false _closing = false
errorText.text = message errorText.text = message
} }
} }

17
electrum/gui/qml/qechanneldetails.py

@ -1,4 +1,5 @@
import asyncio import asyncio
import threading
from PyQt5.QtCore import pyqtProperty, pyqtSignal, pyqtSlot, QObject, Q_ENUMS from PyQt5.QtCore import pyqtProperty, pyqtSignal, pyqtSlot, QObject, Q_ENUMS
@ -177,25 +178,23 @@ class QEChannelDetails(QObject, QtEventListener):
else: else:
self._logger.debug(messages.MSG_NON_TRAMPOLINE_CHANNEL_FROZEN_WITHOUT_GOSSIP) self._logger.debug(messages.MSG_NON_TRAMPOLINE_CHANNEL_FROZEN_WITHOUT_GOSSIP)
# this method assumes the qobject is not destroyed before the close either fails or succeeds
@pyqtSlot(str) @pyqtSlot(str)
def close_channel(self, closetype): def closeChannel(self, closetype):
async def do_close(closetype, channel_id): channel_id = self._channel.channel_id
def do_close():
try: try:
if closetype == 'remote_force': if closetype == 'remote_force':
await self._wallet.wallet.lnworker.request_force_close(channel_id) self._wallet.wallet.network.run_from_another_thread(self._wallet.wallet.lnworker.request_force_close(channel_id))
elif closetype == 'local_force': elif closetype == 'local_force':
await self._wallet.wallet.lnworker.force_close_channel(channel_id) self._wallet.wallet.network.run_from_another_thread(self._wallet.wallet.lnworker.force_close_channel(channel_id))
else: else:
await self._wallet.wallet.lnworker.close_channel(channel_id) self._wallet.wallet.network.run_from_another_thread(self._wallet.wallet.lnworker.close_channel(channel_id))
self.channelCloseSuccess.emit() self.channelCloseSuccess.emit()
except Exception as e: except Exception as e:
self._logger.exception("Could not close channel: " + repr(e)) self._logger.exception("Could not close channel: " + repr(e))
self.channelCloseFailed.emit(_('Could not close channel: ') + repr(e)) self.channelCloseFailed.emit(_('Could not close channel: ') + repr(e))
loop = self._wallet.wallet.network.asyncio_loop threading.Thread(target=do_close).start()
coro = do_close(closetype, self._channel.channel_id)
asyncio.run_coroutine_threadsafe(coro, loop)
@pyqtSlot() @pyqtSlot()
def deleteChannel(self): def deleteChannel(self):

Loading…
Cancel
Save