Files
purple-electrumwallet/electrum/gui/qml/components/SwapDialog.qml
T

265 lines
8.7 KiB
QML
Raw Normal View History

2022-06-30 15:06:45 +02:00
import QtQuick 2.6
import QtQuick.Controls 2.3
import QtQuick.Layouts 1.0
import QtQuick.Controls.Material 2.0
import org.electrum 1.0
import "controls"
ElDialog {
2022-06-30 15:06:45 +02:00
id: root
2023-02-08 17:12:20 +01:00
required property QtObject swaphelper
2023-04-05 13:13:50 +02:00
implicitHeight: parent.height
implicitWidth: parent.width
2022-06-30 15:06:45 +02:00
title: qsTr('Lightning Swap')
iconSource: Qt.resolvedUrl('../../icons/update.png')
2022-06-30 15:06:45 +02:00
2022-10-21 14:00:35 +02:00
padding: 0
ColumnLayout {
2022-06-30 15:06:45 +02:00
width: parent.width
height: parent.height
spacing: constants.paddingLarge
InfoTextArea {
Layout.leftMargin: constants.paddingXXLarge
Layout.rightMargin: constants.paddingXXLarge
Layout.fillWidth: true
Layout.alignment: Qt.AlignHCenter
visible: swaphelper.userinfo != ''
text: swaphelper.userinfo
}
2022-06-30 15:06:45 +02:00
2022-10-21 14:00:35 +02:00
GridLayout {
id: layout
columns: 2
Layout.preferredWidth: parent.width
Layout.leftMargin: constants.paddingXXLarge
Layout.rightMargin: constants.paddingXXLarge
2022-06-30 15:06:45 +02:00
2022-11-30 14:20:29 +01:00
RowLayout {
Layout.preferredWidth: 1
Layout.fillWidth: true
Label {
Layout.preferredWidth: 1
Layout.fillWidth: true
text: qsTr('You send')
color: Material.accentColor
}
Image {
Layout.preferredWidth: constants.iconSizeSmall
Layout.preferredHeight: constants.iconSizeSmall
2023-02-16 13:24:23 +01:00
source: swaphelper.isReverse
? '../../icons/lightning.png'
: '../../icons/bitcoin.png'
2022-11-30 14:20:29 +01:00
}
2022-06-30 15:06:45 +02:00
}
2022-10-21 14:00:35 +02:00
RowLayout {
2022-11-30 14:20:29 +01:00
Layout.preferredWidth: 1
Layout.fillWidth: true
2022-10-21 14:00:35 +02:00
Label {
id: tosend
text: Config.formatSats(swaphelper.tosend)
font.family: FixedFont
}
Label {
text: Config.baseUnit
color: Material.accentColor
}
2022-11-30 14:20:29 +01:00
}
RowLayout {
Layout.preferredWidth: 1
Layout.fillWidth: true
2022-10-21 14:00:35 +02:00
Label {
2022-11-30 14:20:29 +01:00
Layout.preferredWidth: 1
Layout.fillWidth: true
text: qsTr('You receive')
color: Material.accentColor
}
Image {
Layout.preferredWidth: constants.iconSizeSmall
Layout.preferredHeight: constants.iconSizeSmall
2023-02-16 13:24:23 +01:00
source: swaphelper.isReverse
? '../../icons/bitcoin.png'
: '../../icons/lightning.png'
2022-10-21 14:00:35 +02:00
}
2022-06-30 15:06:45 +02:00
}
2022-10-21 14:00:35 +02:00
RowLayout {
2022-11-30 14:20:29 +01:00
Layout.preferredWidth: 1
2022-10-21 14:00:35 +02:00
Layout.fillWidth: true
Label {
id: toreceive
text: Config.formatSats(swaphelper.toreceive)
font.family: FixedFont
}
Label {
text: Config.baseUnit
color: Material.accentColor
}
2022-06-30 15:06:45 +02:00
}
2022-10-21 14:00:35 +02:00
2022-06-30 15:06:45 +02:00
Label {
2022-11-30 14:20:29 +01:00
Layout.preferredWidth: 1
Layout.fillWidth: true
2022-10-21 14:00:35 +02:00
text: qsTr('Server fee')
2022-06-30 15:06:45 +02:00
color: Material.accentColor
}
2022-10-21 14:00:35 +02:00
RowLayout {
2022-11-30 14:20:29 +01:00
Layout.preferredWidth: 1
Layout.fillWidth: true
2022-10-21 14:00:35 +02:00
Label {
text: Config.formatSats(swaphelper.server_miningfee)
2022-10-21 14:00:35 +02:00
font.family: FixedFont
}
Label {
text: Config.baseUnit
color: Material.accentColor
}
2022-11-15 19:41:08 +01:00
Label {
2023-02-16 13:24:23 +01:00
text: swaphelper.serverfeeperc
? '+ ' + swaphelper.serverfeeperc
2023-02-16 13:24:23 +01:00
: ''
2022-11-15 19:41:08 +01:00
}
2022-06-30 15:06:45 +02:00
}
2022-10-21 14:00:35 +02:00
2022-06-30 15:06:45 +02:00
Label {
2022-11-30 14:20:29 +01:00
Layout.preferredWidth: 1
Layout.fillWidth: true
2022-10-21 14:00:35 +02:00
text: qsTr('Mining fee')
2022-06-30 15:06:45 +02:00
color: Material.accentColor
}
2022-10-21 14:00:35 +02:00
RowLayout {
2022-11-30 14:20:29 +01:00
Layout.preferredWidth: 1
Layout.fillWidth: true
2022-10-21 14:00:35 +02:00
Label {
text: Config.formatSats(swaphelper.miningfee)
font.family: FixedFont
visible: swaphelper.valid
2022-10-21 14:00:35 +02:00
}
Label {
text: Config.baseUnit
color: Material.accentColor
visible: swaphelper.valid
2022-10-21 14:00:35 +02:00
}
}
2022-11-30 14:20:29 +01:00
}
2022-06-30 15:06:45 +02:00
2022-11-30 14:20:29 +01:00
Slider {
id: swapslider
Layout.topMargin: constants.paddingLarge
Layout.bottomMargin: constants.paddingLarge
Layout.leftMargin: constants.paddingXXLarge + (parent.width - 2 * constants.paddingXXLarge) * swaphelper.leftVoid
Layout.rightMargin: constants.paddingXXLarge + (parent.width - 2 * constants.paddingXXLarge) * swaphelper.rightVoid
2022-11-30 14:20:29 +01:00
Layout.fillWidth: true
2022-06-30 15:06:45 +02:00
background: Rectangle {
x: swapslider.leftPadding
y: swapslider.topPadding + swapslider.availableHeight / 2 - height / 2
implicitWidth: 200
implicitHeight: 4
width: swapslider.availableWidth
height: implicitHeight
radius: 2
2023-04-05 13:13:50 +02:00
color: Material.accentColor
// full width somehow misaligns with handle, define rangeWidth
property int rangeWidth: width - swapslider.leftPadding
Rectangle {
x: swapslider.visualPosition > swapslider.scenter
? swapslider.scenter * parent.rangeWidth
: swapslider.visualPosition * parent.rangeWidth
width: swapslider.visualPosition > swapslider.scenter
? (swapslider.visualPosition-swapslider.scenter) * parent.rangeWidth
: (swapslider.scenter-swapslider.visualPosition) * parent.rangeWidth
height: parent.height
color: Material.accentColor
radius: 2
}
2023-03-16 15:03:05 +01:00
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
height: parent.height
color: Material.sliderDisabledColor
}
Rectangle {
x: swapslider.scenter * parent.rangeWidth
y: -4
width: 1
height: parent.height + 2*4
color: parent.color
}
}
property real scenter: -swapslider.from/(swapslider.to-swapslider.from)
2022-11-30 14:20:29 +01:00
from: swaphelper.rangeMin
to: swaphelper.rangeMax
2022-10-21 14:00:35 +02:00
2022-11-30 14:20:29 +01:00
onValueChanged: {
if (activeFocus)
swaphelper.sliderPos = value
}
}
2022-06-30 15:06:45 +02:00
RowLayout {
Layout.fillWidth: true
2023-04-03 14:01:59 +02:00
Layout.topMargin: -constants.paddingXXLarge
Layout.leftMargin: constants.paddingXXLarge + swapslider.leftPadding
Layout.rightMargin: constants.paddingXXLarge + swapslider.rightPadding
Label {
text: '<-- ' + qsTr('Add receiving capacity')
font.pixelSize: constants.fontSizeXSmall
color: Material.accentColor
}
Label {
Layout.fillWidth: true
horizontalAlignment: Text.AlignRight
text: qsTr('Add sending capacity') + ' -->'
font.pixelSize: constants.fontSizeXSmall
color: Material.accentColor
}
2022-06-30 15:06:45 +02:00
}
2022-10-21 14:00:35 +02:00
Item { Layout.fillHeight: true; Layout.preferredWidth: 1 }
2022-06-30 15:06:45 +02:00
2022-10-21 14:00:35 +02:00
FlatButton {
2022-06-30 15:06:45 +02:00
Layout.columnSpan: 2
2022-10-21 14:00:35 +02:00
Layout.fillWidth: true
2023-03-10 12:52:04 +01:00
text: qsTr('Ok')
icon.source: Qt.resolvedUrl('../../icons/confirmed.png')
2022-06-30 15:06:45 +02:00
enabled: swaphelper.valid
onClicked: swaphelper.executeSwap()
}
}
2023-02-08 17:12:20 +01:00
Connections {
target: swaphelper
2023-02-16 13:24:23 +01:00
function onSliderPosChanged() {
swapslider.value = swaphelper.sliderPos
}
function onSwapSuccess() {
2023-02-08 17:12:20 +01:00
root.close()
2022-06-30 15:06:45 +02:00
}
}
2023-02-16 13:24:23 +01:00
Component.onCompleted: {
swapslider.value = swaphelper.sliderPos
}
2022-06-30 15:06:45 +02:00
}