Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

submarine_swaps: implement swaps-over-nostr for qml #9304

Draft
wants to merge 1 commit into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion contrib/requirements/requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ certifi
attrs>=20.1.0
jsonpatch
electrum_ecc
electrum_aionostr>=0.0.6
electrum_aionostr>=0.0.7

# Note that we also need the dnspython[DNSSEC] extra which pulls in cryptography,
# but as that is not pure-python it cannot be listed in this file!
Expand Down
1 change: 1 addition & 0 deletions electrum/gui/qml/components/Constants.qml
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ Item {
property color colorValidBackground: '#ff008000'
property color colorInvalidBackground: '#ff800000'
property color colorAcceptable: '#ff8080ff'
property color colorOk: colorDone

property color colorLightningLocal: "#6060ff"
property color colorLightningLocalReserve: "#0000a0"
Expand Down
140 changes: 140 additions & 0 deletions electrum/gui/qml/components/NostrSwapServersDialog.qml
Original file line number Diff line number Diff line change
@@ -0,0 +1,140 @@
import QtQuick
import QtQuick.Layouts
import QtQuick.Controls
import QtQuick.Controls.Material

import org.electrum 1.0

import "controls"

ElDialog {
id: dialog
title: qsTr("Select Swap Server")

property QtObject swaphelper

property string selectedPubkey

anchors.centerIn: parent

padding: 0

width: parent.width * 4/5
height: parent.height * 4/5

ColumnLayout {
id: rootLayout
width: parent.width
height: parent.height

Frame {
id: accountsFrame
Layout.fillWidth: true
Layout.fillHeight: true
Layout.topMargin: constants.paddingLarge
Layout.bottomMargin: constants.paddingLarge
Layout.leftMargin: constants.paddingMedium
Layout.rightMargin: constants.paddingMedium

verticalPadding: 0
horizontalPadding: 0
background: PaneInsetBackground {}

ColumnLayout {
spacing: 0
anchors.fill: parent

ListView {
id: listview
Layout.preferredWidth: parent.width
Layout.fillHeight: true
clip: true
model: swaphelper.availableSwapServers

delegate: ItemDelegate {
width: ListView.view.width
height: itemLayout.height

onClicked: {
dialog.selectedPubkey = model.npub
dialog.doAccept()
}

GridLayout {
id: itemLayout
columns: 3
rowSpacing: 0

anchors {
left: parent.left
right: parent.right
leftMargin: constants.paddingMedium
rightMargin: constants.paddingMedium
}

Item {
Layout.columnSpan: 3
Layout.preferredHeight: constants.paddingLarge
Layout.preferredWidth: 1
}
Image {
Layout.rowSpan: 3
source: Qt.resolvedUrl('../../icons/network.png')
}
Label {
text: qsTr('npub')
color: Material.accentColor
}
Label {
Layout.fillWidth: true
text: model.npub.substring(0,10)
wrapMode: Text.Wrap
}
Label {
text: qsTr('fee')
color: Material.accentColor
}
Label {
Layout.fillWidth: true
text: model.percentage_fee + '%'
}
Label {
text: qsTr('last seen')
color: Material.accentColor
}
Label {
Layout.fillWidth: true
text: model.timestamp
}
Item {
Layout.columnSpan: 3
Layout.preferredHeight: constants.paddingLarge
Layout.preferredWidth: 1
}
}
}

ScrollIndicator.vertical: ScrollIndicator { }

Label {
visible: swaphelper.availableSwapServers.count == 0
anchors.centerIn: parent
width: listview.width * 4/5
font.pixelSize: constants.fontSizeXXLarge
color: constants.mutedForeground
text: qsTr('No swap servers found')
wrapMode: Text.Wrap
horizontalAlignment: Text.AlignHCenter
}

}
}
}
}

Component.onCompleted: {
if (dialog.selectedPubkey) {
listview.currentIndex = swaphelper.availableSwapServers.indexFor(dialog.selectedPubkey)
}
}
}
44 changes: 37 additions & 7 deletions electrum/gui/qml/components/SwapDialog.qml
Original file line number Diff line number Diff line change
Expand Up @@ -33,13 +33,15 @@ ElDialog {
Layout.alignment: Qt.AlignHCenter
visible: swaphelper.userinfo != ''
text: swaphelper.userinfo
iconStyle: swaphelper.state == SwapHelper.Started
iconStyle: swaphelper.state == SwapHelper.Started || swaphelper.state == SwapHelper.Initializing
? InfoTextArea.IconStyle.Spinner
: swaphelper.state == SwapHelper.Failed || swaphelper.state == SwapHelper.Cancelled
? InfoTextArea.IconStyle.Error
: swaphelper.state == SwapHelper.Success
? InfoTextArea.IconStyle.Done
: InfoTextArea.IconStyle.Info
: swaphelper.state == SwapHelper.NoService
? InfoTextArea.IconStyle.Warn
: InfoTextArea.IconStyle.Info
}

GridLayout {
Expand Down Expand Up @@ -170,7 +172,7 @@ ElDialog {
Layout.leftMargin: constants.paddingXXLarge + (parent.width - 2 * constants.paddingXXLarge) * swaphelper.leftVoid
Layout.rightMargin: constants.paddingXXLarge + (parent.width - 2 * constants.paddingXXLarge) * swaphelper.rightVoid

property real scenter: -swapslider.from/(swapslider.to-swapslider.from)
property real scenter: -swapslider.from / (swapslider.to - swapslider.from)

enabled: swaphelper.state == SwapHelper.ServiceReady || swaphelper.state == SwapHelper.Failed

Expand All @@ -193,21 +195,21 @@ ElDialog {
x: swapslider.visualPosition > swapslider.scenter
? swapslider.scenter * parent.rangeWidth
: swapslider.visualPosition * parent.rangeWidth
y: enabled ? -1 : 0
width: swapslider.visualPosition > swapslider.scenter
? (swapslider.visualPosition-swapslider.scenter) * parent.rangeWidth
: (swapslider.scenter-swapslider.visualPosition) * parent.rangeWidth
height: parent.height
height: enabled ? parent.height + 2 : parent.height
color: enabled
? Material.accentColor
? constants.colorOk
: Material.sliderDisabledColor
radius: 2
}

Rectangle {
x: - (swapslider.parent.width - 2 * constants.paddingXXLarge) * swaphelper.leftVoid
z: -1
// width makes rectangle go outside the control, into the Layout margins
width: parent.width + (swapslider.parent.width - 2 * constants.paddingXXLarge) * swaphelper.rightVoid
width: swapslider.parent.width - 2 * constants.paddingXXLarge - swapslider.leftPadding - swapslider.rightPadding
height: parent.height
color: Material.sliderDisabledColor
}
Expand Down Expand Up @@ -249,6 +251,34 @@ ElDialog {
}
}


Pane {
Layout.alignment: Qt.AlignHCenter
visible: _swaphelper.isNostr()
background: Rectangle { color: constants.darkerDialogBackground }
padding: 0

FlatButton {
text: qsTr('Choose swap provider')
enabled: _swaphelper.state != SwapHelper.Initializing
&& _swaphelper.state != SwapHelper.Success
&& _swaphelper.availableSwapServers.count
onClicked: {
var dialog = app.nostrSwapServersDialog.createObject(app, {
swaphelper: _swaphelper,
selectedPubkey: Config.swapServerNPub
})
dialog.accepted.connect(function() {
if (Config.swapServerNPub != dialog.selectedPubkey) {
Config.swapServerNPub = dialog.selectedPubkey
_swaphelper.init_swap_manager()
}
})
dialog.open()
}
}
}

Item { Layout.fillHeight: true; Layout.preferredWidth: 1 }

ButtonContainer {
Expand Down
23 changes: 23 additions & 0 deletions electrum/gui/qml/components/main.qml
Original file line number Diff line number Diff line change
Expand Up @@ -436,9 +436,18 @@ ApplicationWindow
}
}

property alias nostrSwapServersDialog: _nostrSwapServersDialog
Component {
id: _nostrSwapServersDialog
NostrSwapServersDialog {
onClosed: destroy()
}
}

Component {
id: swapDialog
SwapDialog {
id: _swapdialog
onClosed: destroy()
swaphelper: SwapHelper {
id: _swaphelper
Expand All @@ -454,6 +463,20 @@ ApplicationWindow
})
dialog.open()
}
onUndefinedNPub: {
var dialog = app.nostrSwapServersDialog.createObject(app, {
swaphelper: _swaphelper,
selectedPubkey: Config.swapServerNPub
})
dialog.accepted.connect(function() {
Config.swapServerNPub = dialog.selectedPubkey
_swaphelper.init_swap_manager()
})
dialog.rejected.connect(function() {
_swaphelper.npubSelectionCancelled()
})
dialog.open()
}
}
}
}
Expand Down
11 changes: 11 additions & 0 deletions electrum/gui/qml/qeconfig.py
Original file line number Diff line number Diff line change
Expand Up @@ -276,6 +276,17 @@ def lightningPaymentFeeMaxMillionths(self, lightningPaymentFeeMaxMillionths):
self.config.LIGHTNING_PAYMENT_FEE_MAX_MILLIONTHS = lightningPaymentFeeMaxMillionths
self.lightningPaymentFeeMaxMillionthsChanged.emit()

swapServerNPubChanged = pyqtSignal()
@pyqtProperty(str, notify=swapServerNPubChanged)
def swapServerNPub(self):
return self.config.SWAPSERVER_NPUB

@swapServerNPub.setter
def swapServerNPub(self, swapserver_npub):
if swapserver_npub != self.config.SWAPSERVER_NPUB:
self.config.SWAPSERVER_NPUB = swapserver_npub
self.swapServerNPubChanged.emit()

@pyqtSlot('qint64', result=str)
@pyqtSlot(QEAmount, result=str)
def formatSatsForEditing(self, satoshis):
Expand Down
Loading