From 27cd7fe8a886836681ab8077722a9260b5364ee5 Mon Sep 17 00:00:00 2001 From: Sander van Grieken Date: Wed, 12 Apr 2023 12:31:47 +0200 Subject: [PATCH] qml: deduplicate swap initiation, move to main.qml --- .../gui/qml/components/BalanceDetails.qml | 24 +---------------- electrum/gui/qml/components/Channels.qml | 27 +------------------ electrum/gui/qml/components/main.qml | 26 ++++++++++++++++++ 3 files changed, 28 insertions(+), 49 deletions(-) diff --git a/electrum/gui/qml/components/BalanceDetails.qml b/electrum/gui/qml/components/BalanceDetails.qml index 0a558fdcf..138c79d19 100644 --- a/electrum/gui/qml/components/BalanceDetails.qml +++ b/electrum/gui/qml/components/BalanceDetails.qml @@ -171,15 +171,7 @@ Pane { visible: Daemon.currentWallet.isLightning enabled: Daemon.currentWallet.lightningCanSend.satsInt > 0 || Daemon.currentWallet.lightningCanReceive.satInt > 0 icon.source: Qt.resolvedUrl('../../icons/update.png') - onClicked: { - var swaphelper = app.swaphelper.createObject(app) - swaphelper.swapStarted.connect(function() { - var dialog = swapProgressDialog.createObject(app, { swaphelper: swaphelper }) - dialog.open() - }) - var dialog = swapDialog.createObject(rootItem, { swaphelper: swaphelper }) - dialog.open() - } + onClicked: app.startSwap() } FlatButton { @@ -199,20 +191,6 @@ Pane { } - Component { - id: swapDialog - SwapDialog { - onClosed: destroy() - } - } - - Component { - id: swapProgressDialog - SwapProgressDialog { - onClosed: destroy() - } - } - Component { id: openChannelDialog OpenChannelDialog { diff --git a/electrum/gui/qml/components/Channels.qml b/electrum/gui/qml/components/Channels.qml index f1f1370dc..19a9ed915 100644 --- a/electrum/gui/qml/components/Channels.qml +++ b/electrum/gui/qml/components/Channels.qml @@ -125,15 +125,7 @@ Pane { text: qsTr('Swap'); enabled: Daemon.currentWallet.lightningCanSend.satsInt > 0 || Daemon.currentWallet.lightningCanReceive.satInt > 0 icon.source: Qt.resolvedUrl('../../icons/update.png') - onClicked: { - var swaphelper = app.swaphelper.createObject(app) - swaphelper.swapStarted.connect(function() { - var dialog = swapProgressDialog.createObject(app, { swaphelper: swaphelper }) - dialog.open() - }) - var dialog = swapDialog.createObject(root, { swaphelper: swaphelper }) - dialog.open() - } + onClicked: app.startSwap() } FlatButton { @@ -152,23 +144,6 @@ Pane { } - Component { - id: swapDialog - SwapDialog { - onClosed: { - console.log('Destroying SwapDialog ' + this) - destroy() - } - } - } - - Component { - id: swapProgressDialog - SwapProgressDialog { - onClosed: destroy() - } - } - Component { id: openChannelDialog OpenChannelDialog { diff --git a/electrum/gui/qml/components/main.qml b/electrum/gui/qml/components/main.qml index 2a83729a0..f7435574c 100644 --- a/electrum/gui/qml/components/main.qml +++ b/electrum/gui/qml/components/main.qml @@ -362,6 +362,21 @@ ApplicationWindow id: _channelOpenProgressDialog } + Component { + id: swapDialog + SwapDialog { + onClosed: destroy() + } + } + + Component { + id: swapProgressDialog + SwapProgressDialog { + onClosed: destroy() + } + } + + NotificationPopup { id: notificationPopup width: parent.width @@ -572,6 +587,17 @@ ApplicationWindow } } + function startSwap() { + var swaphelper = app.swaphelper.createObject(app) + var swapdialog = swapDialog.createObject(app, { swaphelper: swaphelper }) + swaphelper.swapStarted.connect(function() { + swapdialog.close() + var progressdialog = swapProgressDialog.createObject(app, { swaphelper: swaphelper }) + progressdialog.open() + }) + swapdialog.open() + } + property var _lastActive: 0 // record time of last activity property bool _lockDialogShown: false