Files
pay/desktop/SendTransactionPane.qml
T

320 lines
11 KiB
QML
Raw Permalink Normal View History

2020-10-15 19:18:54 +02:00
/*
* This file is part of the Flowee project
2021-01-05 14:03:30 +01:00
* Copyright (C) 2020 Tom Zander <tom@flowee.org>
2020-10-15 19:18:54 +02:00
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
import QtQuick 2.14
import QtQuick.Controls 2.14
import QtQuick.Layouts 1.14
2020-10-15 19:18:54 +02:00
import QtQuick.Window 2.14
import Flowee.org.pay 1.0
2020-10-15 19:18:54 +02:00
import "./ControlColors.js" as ControlColors
2020-10-15 19:18:54 +02:00
Pane {
id: root
2020-10-15 19:18:54 +02:00
function reset() {
// reset fields
2020-10-24 14:50:04 +02:00
bitcoinValueField.reset();
bitcoinValueField.maxSelected = false;
destination.text = "";
}
2020-10-15 19:18:54 +02:00
opacity: visible ? 1 : 0
2021-01-16 17:01:42 +01:00
padding: 0
GridLayout {
2020-10-15 19:18:54 +02:00
id: grid
2021-01-16 17:01:42 +01:00
width: parent.width
2020-06-12 23:37:32 +02:00
columns: 3
2020-10-15 19:18:54 +02:00
Label {
2021-01-29 10:27:24 +01:00
text: qsTr("Destination") + ":"
2021-01-31 20:59:53 +01:00
Layout.alignment: Qt.AlignRight | Qt.AlignBaseline
2020-06-11 19:30:33 +02:00
}
TextField {
id: destination
2020-10-15 19:18:54 +02:00
focus: true
2020-06-12 23:37:32 +02:00
property bool addressOk: {
let res = Flowee.identifyString(text);
return res === Pay.CashPKH || res === Pay.LegacyPKH;
}
2020-10-24 12:50:18 +02:00
placeholderText: qsTr("Enter Bitcoin Address")
Layout.fillWidth: true
2020-06-12 23:37:32 +02:00
onFocusChanged: {
2020-10-15 19:18:54 +02:00
if (activeFocus || text === "")
color = mainWindow.palette.text
2020-06-12 23:37:32 +02:00
else if (!addressOk)
2020-10-15 19:18:54 +02:00
color = Flowee.useDarkSkin ? "#ff6568" : "red"
2020-06-12 23:37:32 +02:00
}
}
2020-10-15 19:18:54 +02:00
Label {
2020-06-12 23:37:32 +02:00
id: checked
color: "green"
font.pixelSize: 24
text: destination.addressOk ? "✔" : " "
}
2020-06-12 23:37:32 +02:00
// next row
2020-10-15 19:18:54 +02:00
Label {
2020-06-12 20:53:01 +02:00
id: payAmount
2021-01-29 10:27:24 +01:00
text: qsTr("Amount") + ":"
2020-06-12 20:53:01 +02:00
}
BitcoinValueField {
id: bitcoinValueField
2020-10-24 14:50:04 +02:00
property bool maxSelected: false
fontPtSize: payAmount.font.pointSize
2020-06-12 23:37:32 +02:00
Layout.columnSpan: 2
2020-10-23 22:34:34 +02:00
onValueChanged: maxSelected = false
2020-06-12 20:53:01 +02:00
}
2020-10-15 19:18:54 +02:00
RowLayout {
2020-06-12 23:37:32 +02:00
Layout.columnSpan: 3
2020-10-23 22:34:34 +02:00
Button2 {
id: sendAll
2020-10-24 14:50:04 +02:00
text: qsTr("Max")
checkable: true
checked: bitcoinValueField.maxSelected
property string previousAmountString: ""
onClicked: {
var isChecked = !bitcoinValueField.maxSelected // simply invert
if (isChecked) {
// backup what the user typed there, to be used if she no longer wants 'max'
previousAmountString = bitcoinValueField.valueObject.enteredString;
// the usage of 'account' here assumes we are under the hierarchy of the AccountPage
2020-11-06 22:15:03 +01:00
bitcoinValueField.value = account.balanceConfirmed + account.balanceUnconfirmed
2020-10-24 14:50:04 +02:00
} else {
bitcoinValueField.valueObject.strValue = previousAmountString
}
bitcoinValueField.maxSelected = isChecked
}
2020-10-23 22:34:34 +02:00
}
Item {
width: 1; height: 1
Layout.fillWidth: true
}
2020-10-15 20:49:50 +02:00
Button2 {
2020-06-12 23:37:32 +02:00
id: nextButton
text: qsTr("Next")
2020-10-23 22:34:34 +02:00
enabled: (bitcoinValueField.value > 0
|| bitcoinValueField.maxSelected) && destination.addressOk;
2020-06-12 23:37:32 +02:00
onClicked: {
2020-10-23 22:34:34 +02:00
if (bitcoinValueField.maxSelected)
var payment = portfolio.startPayAllToAddress(destination.text);
else
payment = portfolio.startPayToAddress(destination.text, bitcoinValueField.valueObject);
checkAndSendTx.payment = payment;
2020-10-15 19:18:54 +02:00
ControlColors.applySkin(checkAndSendTx);
2020-10-23 22:34:34 +02:00
payment.approveAndSign();
2020-10-15 19:18:54 +02:00
}
}
2020-10-15 20:49:50 +02:00
Button2 {
2020-10-15 19:18:54 +02:00
id: cancelbutton
text: qsTr("Cancel")
2020-06-13 19:22:08 +02:00
2020-10-15 19:18:54 +02:00
onClicked: {
root.visible = false;
root.reset();
2020-06-12 23:37:32 +02:00
}
}
}
2020-06-12 20:53:01 +02:00
/*
2020-06-12 23:37:32 +02:00
TODO;
- have a fiat value input.
*/
2020-06-12 23:37:32 +02:00
}
2020-06-12 20:53:01 +02:00
2020-10-15 19:18:54 +02:00
ApplicationWindow {
2020-06-12 23:37:32 +02:00
id: checkAndSendTx
2020-10-15 19:18:54 +02:00
visible: false
title: qsTr("Validate and Send Transaction")
modality: Qt.NonModal
flags: Qt.Dialog
width: header.implicitWidth + 20
2020-10-16 18:17:56 +02:00
height: 20 + minimumHeight
minimumHeight: {
var h = header.implicitHeight + table.implicitHeight + button.height + 60;
2020-10-23 22:34:34 +02:00
if (checkAndSendTx.payment !== null && checkAndSendTx.payment.paymentOk)
h += table2.implicitHeight
return h;
}
2020-06-12 23:37:32 +02:00
property QtObject payment: null
2020-10-15 19:18:54 +02:00
onPaymentChanged: visible = payment !== null
2020-06-12 23:37:32 +02:00
onVisibleChanged: {
if (!visible) {
2020-10-15 19:18:54 +02:00
if (payment !== null) {
console.log("user closed the window")
payment = null
}
else {
console.log("user accepted the payment")
root.visible = false;
root.reset();
}
2020-06-12 23:37:32 +02:00
}
}
2020-10-15 19:18:54 +02:00
Label {
id: header
anchors.top: parent.top
anchors.left: parent.left
anchors.right: parent.right
anchors.margins: 10
2020-10-23 19:45:21 +02:00
horizontalAlignment: Text.AlignHCenter
2020-10-23 22:34:34 +02:00
text: checkAndSendTx.payment !== null && checkAndSendTx.payment.paymentOk ?
qsTr("Check your values and press approve to send payment.")
: qsTr("Not enough funds in account to make payment!");
2020-06-12 23:37:32 +02:00
font.bold: true
wrapMode: Text.WrapAtWordBoundaryOrAnywhere
2020-10-15 19:18:54 +02:00
}
GridLayout {
id: table
anchors.left: parent.left
anchors.right: parent.right
anchors.margins: 10
anchors.top: header.bottom
columns: 2
Label {
2021-01-29 10:27:24 +01:00
text: qsTr("Destination") + ":"
2020-10-15 19:18:54 +02:00
Layout.alignment: Qt.AlignRight
}
Label {
text: checkAndSendTx.payment === null ? "waiting" : checkAndSendTx.payment.formattedTargetAddress
wrapMode: Text.WrapAnywhere
Layout.fillWidth: true
}
Label {
id: origText
2021-01-29 10:27:24 +01:00
text: qsTr("Was", "user-entered-format") + ":"
2020-10-15 19:18:54 +02:00
Layout.alignment: Qt.AlignRight
visible: checkAndSendTx.payment !== null
&& checkAndSendTx.payment.targetAddress !== checkAndSendTx.payment.formattedTargetAddress
}
Label {
visible: origText.visible
text: checkAndSendTx.payment === null ? "" : checkAndSendTx.payment.targetAddress
wrapMode: Text.WrapAnywhere
}
2020-06-22 12:52:49 +02:00
2020-10-15 19:18:54 +02:00
Label {
Layout.alignment: Qt.AlignRight
2021-01-29 10:27:24 +01:00
text: qsTr("Amount") + ":"
2020-10-15 19:18:54 +02:00
}
BitcoinAmountLabel {
2020-12-26 19:31:59 +01:00
value: {
if (checkAndSendTx.payment === null)
return 0;
var val = checkAndSendTx.payment.paymentAmount;
if (val === -1)
return account.balanceConfirmed + account.balanceUnconfirmed;
return val;
}
2020-10-15 19:18:54 +02:00
fontPtSize: origText.font.pointSize
colorize: false
textColor: mainWindow.palette.text
}
}
GridLayout {
id: table2
2020-10-23 22:34:34 +02:00
visible: checkAndSendTx.payment !== null && checkAndSendTx.payment.paymentOk
2020-10-15 19:18:54 +02:00
anchors.left: parent.left
anchors.right: parent.right
2020-10-23 19:45:21 +02:00
anchors.margins: 20
2020-10-15 19:18:54 +02:00
anchors.top: table.bottom
columns: 2
Label {
2021-01-29 10:27:24 +01:00
text: qsTr("More Details") + ":"
2020-10-23 19:45:21 +02:00
font.italic: true
2020-10-15 19:18:54 +02:00
Layout.columnSpan: 2
}
Label {
2021-01-29 10:27:24 +01:00
// no need translating this one.
text: "TxId:"
2020-10-15 19:18:54 +02:00
Layout.alignment: Qt.AlignRight | Qt.AlignTop
}
2020-06-12 23:37:32 +02:00
2020-10-15 19:18:54 +02:00
Label {
text: checkAndSendTx.payment === null ? "" : checkAndSendTx.payment.txid
wrapMode: Text.WrapAnywhere
Layout.fillWidth: true
}
2020-06-13 19:22:08 +02:00
2020-10-15 19:18:54 +02:00
Label {
2021-01-29 10:27:24 +01:00
text: qsTr("Fee") + ":"
2020-10-15 19:18:54 +02:00
Layout.alignment: Qt.AlignRight
}
2020-06-13 19:22:08 +02:00
2020-10-15 19:18:54 +02:00
Label {
2020-10-23 19:45:21 +02:00
text: checkAndSendTx.payment === null ? "" : qsTr("%1 sats").arg(checkAndSendTx.payment.assignedFee)
2020-10-15 19:18:54 +02:00
}
Label {
2021-01-29 10:27:24 +01:00
text: qsTr("Transaction size") + ":"
2020-10-15 19:18:54 +02:00
Layout.alignment: Qt.AlignRight
}
Label {
2021-01-29 10:27:24 +01:00
text: {
if (checkAndSendTx.payment === null)
return "";
var rc = checkAndSendTx.payment.txSize;
return qsTr("%1 bytes", "", rc).arg(rc)
}
2020-10-15 19:18:54 +02:00
}
Label {
2021-01-29 10:27:24 +01:00
text: qsTr("Fee per byte") + ":"
2020-10-15 19:18:54 +02:00
Layout.alignment: Qt.AlignRight
}
Label {
2021-01-29 10:27:24 +01:00
text: {
if (checkAndSendTx.payment === null)
return "";
var rc = checkAndSendTx.payment.assignedFee / checkAndSendTx.payment.txSize;
return qsTr("%1 sat/byte", "fee", rc).arg((rc).toFixed(3))
}
2020-10-15 19:18:54 +02:00
}
}
2020-06-13 19:22:08 +02:00
2020-10-15 19:18:54 +02:00
Button {
id: button
anchors.right: parent.right
anchors.bottom: parent.bottom
anchors.margins: 10
2020-10-23 22:34:34 +02:00
text: checkAndSendTx.payment !== null && checkAndSendTx.payment.paymentOk
2021-01-29 10:27:24 +01:00
? qsTr("Approve and Send", "button") : qsTr("Close", "button")
onClicked: {
if (checkAndSendTx.payment.paymentOk) {
checkAndSendTx.payment.sendTx();
checkAndSendTx.payment = null
} else {
checkAndSendTx.close();
}
2020-06-12 23:37:32 +02:00
}
2020-06-12 20:53:01 +02:00
}
}
2020-10-15 19:18:54 +02:00
Behavior on opacity { NumberAnimation { duration: 350 } }
}