1
0

add confirm payment dialog/feepicker and qobject backing

This commit is contained in:
Sander van Grieken
2022-04-12 16:48:32 +02:00
parent 3b25f00041
commit 34ef93b2b5
5 changed files with 525 additions and 28 deletions

View File

@@ -0,0 +1,195 @@
import QtQuick 2.6
import QtQuick.Layouts 1.0
import QtQuick.Controls 2.14
import QtQuick.Controls.Material 2.0
import org.electrum 1.0
import "controls"
Dialog {
id: dialog
property alias address: finalizer.address
property alias satoshis: finalizer.amount
property string message
width: parent.width
height: parent.height
title: qsTr('Confirm Payment')
modal: true
parent: Overlay.overlay
Overlay.modal: Rectangle {
color: "#aa000000"
}
GridLayout {
id: layout
width: parent.width
height: parent.height
columns: 2
Rectangle {
height: 1
Layout.fillWidth: true
Layout.columnSpan: 2
color: Material.accentColor
}
Label {
text: qsTr('Amount to send')
}
RowLayout {
Layout.fillWidth: true
Label {
font.bold: true
text: Config.formatSats(satoshis, false)
}
Label {
text: Config.baseUnit
color: Material.accentColor
}
Label {
id: fiatValue
Layout.fillWidth: true
text: Daemon.fx.enabled
? '(' + Daemon.fx.fiatValue(satoshis, false) + ' ' + Daemon.fx.fiatCurrency + ')'
: ''
font.pixelSize: constants.fontSizeMedium
}
}
Label {
text: qsTr('Mining fee')
}
RowLayout {
Label {
id: fee
text: Config.formatSats(finalizer.fee)
}
Label {
text: Config.baseUnit
color: Material.accentColor
}
}
Label {
text: qsTr('Fee rate')
}
RowLayout {
Label {
id: feeRate
text: finalizer.feeRate
}
Label {
text: 'sat/vB'
color: Material.accentColor
}
}
Label {
text: qsTr('Target')
}
Label {
id: targetdesc
text: finalizer.target
}
Slider {
id: feeslider
snapMode: Slider.SnapOnRelease
stepSize: 1
from: 0
to: finalizer.sliderSteps
onValueChanged: {
if (activeFocus)
finalizer.sliderPos = value
}
Component.onCompleted: {
value = finalizer.sliderPos
}
Connections {
target: finalizer
function onSliderPosChanged() {
feeslider.value = finalizer.sliderPos
}
}
}
ComboBox {
id: target
textRole: 'text'
valueRole: 'value'
model: [
{ text: qsTr('ETA'), value: 1 },
{ text: qsTr('Mempool'), value: 2 },
{ text: qsTr('Static'), value: 0 }
]
onCurrentValueChanged: {
if (activeFocus)
finalizer.method = currentValue
}
Component.onCompleted: {
currentIndex = indexOfValue(finalizer.method)
}
}
InfoTextArea {
Layout.columnSpan: 2
visible: finalizer.warning != ''
text: finalizer.warning
iconStyle: InfoTextArea.IconStyle.Warn
}
CheckBox {
id: final_cb
text: qsTr('Final')
Layout.columnSpan: 2
}
Rectangle {
height: 1
Layout.fillWidth: true
Layout.columnSpan: 2
color: Material.accentColor
}
RowLayout {
Layout.columnSpan: 2
Layout.alignment: Qt.AlignHCenter
Button {
text: qsTr('Cancel')
onClicked: dialog.close()
}
Button {
text: qsTr('Pay')
enabled: finalizer.valid
onClicked: {
var f_amount = parseFloat(dialog.satoshis)
if (isNaN(f_amount))
return
var result = Daemon.currentWallet.send_onchain(dialog.address, dialog.satoshis, undefined, false)
}
}
}
Item { Layout.fillHeight: true; Layout.preferredWidth: 1 }
}
TxFinalizer {
id: finalizer
wallet: Daemon.currentWallet
onAmountChanged: console.log(amount)
}
}

View File

@@ -3,10 +3,13 @@ import QtQuick.Controls 2.0
import QtQuick.Layouts 1.0
import QtQuick.Controls.Material 2.0
import "controls"
Pane {
id: rootItem
GridLayout {
id: form
width: parent.width
rowSpacing: constants.paddingSmall
columnSpacing: constants.paddingSmall
@@ -30,11 +33,29 @@ Pane {
placeholderText: qsTr('Paste address or invoice')
}
ToolButton {
icon.source: '../../icons/copy.png'
icon.color: 'transparent'
icon.height: constants.iconSizeSmall
icon.width: constants.iconSizeSmall
RowLayout {
spacing: 0
ToolButton {
icon.source: '../../icons/paste.png'
icon.height: constants.iconSizeMedium
icon.width: constants.iconSizeMedium
onClicked: address.text = AppController.clipboardToText()
}
ToolButton {
icon.source: '../../icons/qrcode.png'
icon.height: constants.iconSizeMedium
icon.width: constants.iconSizeMedium
scale: 1.2
onClicked: {
var page = app.stack.push(Qt.resolvedUrl('Scan.qml'))
page.onFound.connect(function() {
console.log('got ' + page.invoiceData)
address.text = page.invoiceData['address']
amount.text = Config.satsToUnits(page.invoiceData['amount'])
description.text = page.invoiceData['message']
})
}
}
}
Label {
@@ -71,7 +92,6 @@ Pane {
Item { width: 1; height: 1 }
Item { width: 1; height: 1; visible: Daemon.fx.enabled }
TextField {
@@ -97,54 +117,102 @@ Pane {
Item { visible: Daemon.fx.enabled ; height: 1; width: 1 }
Label {
text: qsTr('Fee')
text: qsTr('Description')
}
TextField {
id: fee
id: description
font.family: FixedFont
placeholderText: qsTr('sat/vB')
Layout.columnSpan: 2
placeholderText: qsTr('Description')
Layout.columnSpan: 3
Layout.fillWidth: true
}
Item { width: 1; height: 1 }
RowLayout {
Layout.columnSpan: 4
Layout.alignment: Qt.AlignHCenter
spacing: constants.paddingMedium
Button {
text: qsTr('Pay')
text: qsTr('Save')
enabled: false
onClicked: {
console.log('TODO: save')
}
}
Button {
text: qsTr('Pay now')
enabled: amount.text != '' && address.text != ''// TODO proper validation
onClicked: {
var f_amount = parseFloat(amount.text)
if (isNaN(f_amount))
return
var sats = Config.unitsToSats(f_amount)
var result = Daemon.currentWallet.send_onchain(address.text, sats, undefined, false)
}
}
Button {
text: qsTr('Scan QR Code')
onClicked: {
var page = app.stack.push(Qt.resolvedUrl('Scan.qml'))
page.onFound.connect(function() {
console.log('got ' + page.invoiceData)
address.text = page.invoiceData['address']
amount.text = Config.formatSats(page.invoiceData['amount'])
var sats = Config.unitsToSats(amount.text).toString()
var dialog = confirmPaymentDialog.createObject(app, {
'address': address.text,
'satoshis': sats,
'message': description.text
})
dialog.open()
}
}
}
}
Frame {
verticalPadding: 0
horizontalPadding: 0
anchors {
top: form.bottom
topMargin: constants.paddingXLarge
left: parent.left
right: parent.right
bottom: parent.bottom
}
background: PaneInsetBackground {}
ColumnLayout {
spacing: 0
anchors.fill: parent
Item {
Layout.preferredHeight: hitem.height
Layout.preferredWidth: parent.width
Rectangle {
anchors.fill: parent
color: Qt.lighter(Material.background, 1.25)
}
RowLayout {
id: hitem
width: parent.width
Label {
text: qsTr('Send queue')
font.pixelSize: constants.fontSizeXLarge
}
}
}
ListView {
id: listview
Layout.fillHeight: true
Layout.fillWidth: true
clip: true
}
}
}
Component {
id: confirmPaymentDialog
ConfirmPaymentDialog {}
}
Connections {
target: Daemon.fx
function onQuotesUpdated() {
var a = Config.unitsToSats(amount.text)
amountFiat.text = Daemon.fx.fiatValue(a)
amountFiat.text = Daemon.fx.fiatValue(Config.unitsToSats(amount.text))
}
}