Files
pallectrum/electrum/gui/qml/components/CloseChannelDialog.qml

237 lines
7.5 KiB
QML
Raw Normal View History

import QtQuick
import QtQuick.Layouts
import QtQuick.Controls
import QtQuick.Controls.Material
2022-06-29 00:17:17 +02:00
import org.electrum 1.0
import "controls"
ElDialog {
2022-06-29 00:17:17 +02:00
id: dialog
2023-02-06 13:12:14 +01:00
2022-06-29 00:17:17 +02:00
width: parent.width
height: parent.height
property string channelid
title: qsTr('Close Channel')
2023-01-02 16:58:37 +01:00
iconSource: Qt.resolvedUrl('../../icons/lightning_disconnected.png')
2022-06-29 00:17:17 +02:00
property string _closing_method
2022-06-29 00:17:17 +02:00
2022-10-21 14:11:14 +02:00
padding: 0
ColumnLayout {
anchors.fill: parent
2022-10-21 14:11:14 +02:00
spacing: 0
2022-06-29 00:17:17 +02:00
Flickable {
Layout.preferredWidth: parent.width
Layout.fillHeight: true
2022-06-29 00:17:17 +02:00
leftMargin: constants.paddingLarge
rightMargin: constants.paddingLarge
2022-06-29 00:17:17 +02:00
contentHeight: rootLayout.height
clip:true
interactive: height < contentHeight
GridLayout {
id: rootLayout
width: parent.width
columns: 2
Label {
Layout.fillWidth: true
visible: channeldetails.name
text: qsTr('Channel name')
color: Material.accentColor
}
2022-06-29 00:17:17 +02:00
Label {
Layout.fillWidth: true
visible: channeldetails.name
text: channeldetails.name
}
Label {
text: qsTr('Short channel ID')
color: Material.accentColor
}
Label {
text: channeldetails.shortCid
}
Label {
text: qsTr('Remote node ID')
Layout.columnSpan: 2
color: Material.accentColor
}
2022-10-21 14:11:14 +02:00
TextHighlightPane {
Layout.columnSpan: 2
Layout.fillWidth: true
Label {
width: parent.width
text: channeldetails.pubkey
font.pixelSize: constants.fontSizeLarge
font.family: FixedFont
Layout.fillWidth: true
wrapMode: Text.Wrap
}
2022-10-21 14:11:14 +02:00
}
Item { Layout.preferredHeight: constants.paddingMedium; Layout.preferredWidth: 1; Layout.columnSpan: 2 }
InfoTextArea {
Layout.columnSpan: 2
Layout.fillWidth: true
Layout.bottomMargin: constants.paddingLarge
text: channeldetails.messageForceClose
2022-10-21 14:11:14 +02:00
}
Label {
text: qsTr('Choose closing method')
Layout.columnSpan: 2
color: Material.accentColor
2022-10-21 14:11:14 +02:00
}
ColumnLayout {
Layout.columnSpan: 2
Layout.alignment: Qt.AlignHCenter
ButtonGroup {
id: closetypegroup
}
ElRadioButton {
2023-02-06 13:12:14 +01:00
id: closetypeCoop
ButtonGroup.group: closetypegroup
property string closetype: 'cooperative'
enabled: !channeldetails.isClosing && channeldetails.canCoopClose
text: qsTr('Cooperative close')
}
ElRadioButton {
2023-02-06 13:12:14 +01:00
id: closetypeRemoteForce
ButtonGroup.group: closetypegroup
property string closetype: 'remote_force'
enabled: !channeldetails.isClosing && channeldetails.canRequestForceClose
text: qsTr('Request Force-close')
}
ElRadioButton {
2023-02-06 13:12:14 +01:00
id: closetypeLocalForce
ButtonGroup.group: closetypegroup
property string closetype: 'local_force'
enabled: !channeldetails.isClosing && channeldetails.canLocalForceClose && !channeldetails.isBackup
text: qsTr('Local Force-close')
}
2022-10-21 14:11:14 +02:00
}
ColumnLayout {
Layout.columnSpan: 2
2023-02-06 13:12:14 +01:00
Layout.maximumWidth: parent.width
InfoTextArea {
id: errorText
2023-02-06 13:12:14 +01:00
Layout.alignment: Qt.AlignHCenter
Layout.maximumWidth: parent.width
visible: !channeldetails.isClosing && errorText.text
iconStyle: InfoTextArea.IconStyle.Error
}
Label {
2023-02-06 13:12:14 +01:00
Layout.alignment: Qt.AlignHCenter
text: qsTr('Closing...')
visible: channeldetails.isClosing
}
BusyIndicator {
2023-02-06 13:12:14 +01:00
Layout.alignment: Qt.AlignHCenter
visible: channeldetails.isClosing
}
2022-10-21 14:11:14 +02:00
}
}
2022-06-29 00:17:17 +02:00
}
2022-10-21 14:11:14 +02:00
FlatButton {
2022-06-29 00:17:17 +02:00
Layout.columnSpan: 2
2022-10-21 14:11:14 +02:00
Layout.fillWidth: true
text: qsTr('Close channel')
2022-10-21 14:11:14 +02:00
icon.source: '../../icons/closebutton.png'
enabled: !channeldetails.isClosing
2022-06-29 00:17:17 +02:00
onClicked: {
if (closetypegroup.checkedButton.closetype == 'local_force') {
showBackupThenClose()
} else {
doCloseChannel()
}
2022-06-29 00:17:17 +02:00
}
}
}
2022-06-29 00:17:17 +02:00
function showBackupThenClose() {
var sharedialog = app.genericShareDialog.createObject(app, {
title: qsTr('Save channel backup and force close'),
text_qr: channeldetails.channelBackup(),
text_help: channeldetails.messageForceCloseBackup,
helpTextIconStyle: InfoTextArea.IconStyle.Warn
})
sharedialog.closed.connect(function() {
doCloseChannel()
})
sharedialog.open()
}
function doCloseChannel() {
_closing_method = closetypegroup.checkedButton.closetype
channeldetails.closeChannel(_closing_method)
}
function showCloseMessage(text) {
var msgdialog = app.messageDialog.createObject(app, {
text: text
})
msgdialog.open()
2022-06-29 00:17:17 +02:00
}
ChannelDetails {
id: channeldetails
wallet: Daemon.currentWallet
channelid: dialog.channelid
onAuthRequired: (method, authMessage) => {
app.handleAuthRequired(channeldetails, method, authMessage)
}
onChannelChanged: {
if (!channeldetails.canClose || channeldetails.isClosing)
return
2023-02-06 13:12:14 +01:00
// init default choice
if (channeldetails.canCoopClose)
closetypeCoop.checked = true
else if (channeldetails.canRequestForceClose)
2023-02-06 13:12:14 +01:00
closetypeRemoteForce.checked = true
else
closetypeLocalForce.checked = true
2023-02-06 13:12:14 +01:00
}
2022-06-29 00:17:17 +02:00
onChannelCloseSuccess: {
if (_closing_method == 'local_force') {
showCloseMessage(qsTr('Channel closed. You may need to wait at least %1 blocks, because of CSV delays').arg(channeldetails.toSelfDelay))
} else if (_closing_method == 'remote_force') {
showCloseMessage(qsTr('Request sent'))
} else if (_closing_method == 'cooperative') {
showCloseMessage(qsTr('Channel closed'))
}
2022-06-29 00:17:17 +02:00
dialog.close()
}
onChannelCloseFailed: (message) => {
2022-06-29 00:17:17 +02:00
errorText.text = message
}
}
}