2022-12-08 13:00:19 +01:00
|
|
|
/*
|
|
|
|
|
* This file is part of the Flowee project
|
2025-03-03 15:32:45 +01:00
|
|
|
* Copyright (C) 2022-2025 Tom Zander <tom@flowee.org>
|
2022-12-08 13:00:19 +01: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
|
2025-06-18 17:48:29 +02:00
|
|
|
import QtQuick.Controls.Basic as QQC2
|
2025-03-03 15:32:45 +01:00
|
|
|
import QtQuick.Particles
|
2022-12-08 13:00:19 +01:00
|
|
|
import "../Flowee" as Flowee
|
|
|
|
|
import Flowee.org.pay
|
|
|
|
|
|
|
|
|
|
FocusScope {
|
2025-02-09 22:57:14 +01:00
|
|
|
id: root
|
2022-12-08 13:00:19 +01:00
|
|
|
property string icon: "qrc:/receive.svg"
|
2025-02-09 22:57:14 +01:00
|
|
|
property string title: qsTr("Receive")
|
|
|
|
|
property bool showInstructions: true
|
2022-12-08 13:00:19 +01:00
|
|
|
property QtObject account: portfolio.current
|
2023-05-24 11:35:25 +02:00
|
|
|
property bool qrViewActive: true;
|
|
|
|
|
property bool editViewActive: false
|
2025-03-03 14:10:34 +01:00
|
|
|
property alias verticalTab: swipeView.currentIndex
|
2025-02-10 16:04:45 +01:00
|
|
|
focus: true
|
2022-12-08 13:00:19 +01:00
|
|
|
|
2023-04-27 17:29:35 +02:00
|
|
|
PaymentRequest {
|
|
|
|
|
id: request
|
2023-05-24 11:35:25 +02:00
|
|
|
amount: priceInput.paymentBackend.paymentAmount
|
2025-02-10 16:04:45 +01:00
|
|
|
onAmountSeenChanged: feedback.hide = false;
|
2022-12-08 13:00:19 +01:00
|
|
|
}
|
|
|
|
|
|
2023-04-28 12:07:26 +02:00
|
|
|
onAccountChanged: {
|
2023-05-01 21:11:11 +02:00
|
|
|
var state = request.state;
|
|
|
|
|
if (request.state === PaymentRequest.Unpaid) {
|
|
|
|
|
// I can only change the wallet without cost
|
|
|
|
|
// if no payment has been seen.
|
2023-04-28 12:07:26 +02:00
|
|
|
request.account = account;
|
|
|
|
|
}
|
|
|
|
|
}
|
2023-05-01 19:44:40 +02:00
|
|
|
|
2023-04-28 12:07:26 +02:00
|
|
|
onActiveFocusChanged: {
|
2023-05-24 11:35:25 +02:00
|
|
|
// starting reserves an adderess, don't do that until
|
|
|
|
|
// this tab is actually viewed.
|
2023-05-01 19:44:40 +02:00
|
|
|
if (activeFocus)
|
2023-04-28 12:07:26 +02:00
|
|
|
request.start();
|
|
|
|
|
}
|
2025-02-09 22:57:14 +01:00
|
|
|
Column {
|
|
|
|
|
id: verticalTabs
|
|
|
|
|
y: 50
|
|
|
|
|
x: -10
|
2025-02-10 16:04:45 +01:00
|
|
|
enabled: feedback.opacity < 0.1
|
2025-02-09 22:57:14 +01:00
|
|
|
Repeater {
|
|
|
|
|
model: ["qr-code", "edit-money", "edit-pen"]
|
|
|
|
|
MouseArea {
|
|
|
|
|
property bool active: index === swipeView.currentIndex
|
|
|
|
|
width: 50
|
|
|
|
|
height: 50
|
2025-02-10 20:41:03 +01:00
|
|
|
onClicked: swipeView.moveTo(index);
|
2023-04-28 12:07:26 +02:00
|
|
|
|
2025-02-09 22:57:14 +01:00
|
|
|
Rectangle {
|
|
|
|
|
x: 46
|
|
|
|
|
y: 5
|
|
|
|
|
width: 4
|
|
|
|
|
height: 40
|
|
|
|
|
color: palette.highlight
|
|
|
|
|
visible: parent.active
|
|
|
|
|
}
|
|
|
|
|
Rectangle {
|
|
|
|
|
anchors.fill: parent
|
2025-02-24 22:56:13 +01:00
|
|
|
color: parent.active ? palette.highlight : palette.light
|
|
|
|
|
opacity: parent.active ? 0.15 : 1
|
2025-02-09 22:57:14 +01:00
|
|
|
}
|
|
|
|
|
Image {
|
|
|
|
|
anchors.fill: parent
|
|
|
|
|
anchors.margins: 10
|
|
|
|
|
source: "qrc:/" + modelData + (Pay.useDarkSkin ? "-light" : "") + ".svg"
|
|
|
|
|
smooth: true
|
2025-02-10 16:04:45 +01:00
|
|
|
opacity: enabled ? 1 : 0.4
|
2025-02-09 22:57:14 +01:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
Flowee.Label {
|
|
|
|
|
id: instructions
|
|
|
|
|
anchors.horizontalCenter: parent.horizontalCenter
|
|
|
|
|
text: qsTr("Share this QR to receive")
|
2025-03-16 22:59:21 +01:00
|
|
|
y: 10
|
2025-02-09 22:57:14 +01:00
|
|
|
opacity: editViewActive ? 0 : 0.5
|
|
|
|
|
Behavior on opacity { OpacityAnimator { } }
|
|
|
|
|
visible: root.showInstructions
|
|
|
|
|
}
|
|
|
|
|
Flowee.QRWidget {
|
|
|
|
|
id: qr
|
|
|
|
|
width: parent.width
|
2025-03-16 22:59:21 +01:00
|
|
|
y: root.showInstructions ? instructions.y + instructions.height + 15 : 0
|
2025-02-09 22:57:14 +01:00
|
|
|
qrSize: {
|
|
|
|
|
var avail = root.height - y - swipeView.height;
|
|
|
|
|
return Math.min(256, avail);
|
|
|
|
|
}
|
|
|
|
|
textVisible: false
|
|
|
|
|
qrText: request.qr
|
|
|
|
|
|
|
|
|
|
Flowee.Label {
|
|
|
|
|
visible: request.failReason !== PaymentRequest.NoFailure
|
|
|
|
|
text: {
|
|
|
|
|
var f = request.failReason;
|
|
|
|
|
if (f === PaymentRequest.AccountEncrypted)
|
|
|
|
|
return qsTr("Encrypted Wallet");
|
|
|
|
|
if (f === PaymentRequest.AccountImporting)
|
|
|
|
|
return qsTr("Import Running...");
|
|
|
|
|
if (f === PaymentRequest.NoAccountSet)
|
|
|
|
|
return "No Account Set"; // not translated b/c cause is bug in QML
|
|
|
|
|
return "";
|
|
|
|
|
}
|
|
|
|
|
anchors.centerIn: parent
|
|
|
|
|
width: parent.width - 40
|
|
|
|
|
wrapMode: Text.WrapAtWordBoundaryOrAnywhere
|
|
|
|
|
font.pointSize: 18
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
QQC2.SwipeView {
|
|
|
|
|
id: swipeView
|
|
|
|
|
width: parent.width + 20 // to ensure swiped pages are wide enough
|
|
|
|
|
x: -10
|
|
|
|
|
height: {
|
|
|
|
|
var have = parent.height - (showInstructions ? instructions.height : 0) - 256; // qr is ideally 256
|
|
|
|
|
if (currentIndex === 1)
|
|
|
|
|
return Math.max(have, priceInput.implicitHeight + 215);
|
|
|
|
|
return have - 6; // spacing of 6
|
|
|
|
|
}
|
|
|
|
|
anchors.bottom: parent.bottom
|
|
|
|
|
|
2025-02-10 20:41:03 +01:00
|
|
|
onCurrentIndexChanged: currentItem.doFocus();
|
|
|
|
|
function moveTo(index) {
|
|
|
|
|
forceActiveFocus();
|
|
|
|
|
currentIndex = index;
|
|
|
|
|
currentItem.doFocus();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2025-02-09 22:57:14 +01:00
|
|
|
Item {
|
2025-02-10 20:41:03 +01:00
|
|
|
function doFocus() { }
|
2025-02-17 15:05:41 +01:00
|
|
|
clip: true
|
2025-02-09 22:57:14 +01:00
|
|
|
Column {
|
|
|
|
|
width: parent.width - 20
|
|
|
|
|
x: 10
|
|
|
|
|
|
|
|
|
|
Flowee.BitcoinAmountLabel {
|
|
|
|
|
visible: value > 0
|
|
|
|
|
colorize: false
|
|
|
|
|
value: request.amount
|
|
|
|
|
font.pixelSize: instructions.font.pixelSize * 1.4
|
|
|
|
|
anchors.horizontalCenter: parent.horizontalCenter
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
PageTitledBox {
|
|
|
|
|
width: parent.width
|
|
|
|
|
title: qsTr("Address", "Bitcoin Cash address")
|
|
|
|
|
Flowee.LabelWithClipboard {
|
|
|
|
|
width: parent.width
|
|
|
|
|
text: request.addressShort
|
|
|
|
|
fontSizeMode: Text.HorizontalFit
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
Flowee.Button {
|
|
|
|
|
anchors.right: parent.right
|
|
|
|
|
text: qsTr("Clear")
|
|
|
|
|
enabled: description.totalText !== "" || priceInput.paymentBackend.paymentAmount > 0;
|
|
|
|
|
onClicked: {
|
|
|
|
|
request.clear();
|
|
|
|
|
request.account = portfolio.current;
|
|
|
|
|
description.text = "";
|
|
|
|
|
priceInput.paymentBackend.paymentAmount = 0;
|
|
|
|
|
request.start();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
Item {
|
2025-02-10 20:41:03 +01:00
|
|
|
function doFocus() { priceInput.takeFocus(); }
|
|
|
|
|
|
2025-02-09 22:57:14 +01:00
|
|
|
PriceInputWidget {
|
|
|
|
|
id: priceInput
|
|
|
|
|
width: parent.width
|
|
|
|
|
|
|
|
|
|
Connections {
|
|
|
|
|
target: Fiat
|
|
|
|
|
/*
|
|
|
|
|
* The price may change simply because the market moved and we re-cheked the server,
|
|
|
|
|
* but more important is the case where the user changed which currency they use.
|
|
|
|
|
*/
|
|
|
|
|
function onPriceChanged() {
|
|
|
|
|
// set the value again to trigger an updated exchange-rate calculation to happen.
|
|
|
|
|
var price = priceInput.editor.value;
|
|
|
|
|
if (priceInput.fiatFollowsSats)
|
|
|
|
|
priceInput.paymentBackend.paymentAmount = price;
|
|
|
|
|
else
|
|
|
|
|
priceInput.paymentBackend.paymentAmountFiat = price;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
Rectangle {
|
|
|
|
|
width: parent.width
|
|
|
|
|
anchors.bottom: parent.bottom
|
|
|
|
|
color: palette.base
|
|
|
|
|
height: 215
|
|
|
|
|
}
|
|
|
|
|
NumericKeyboardWidget {
|
|
|
|
|
width: parent.width
|
|
|
|
|
height: 200
|
|
|
|
|
anchors.bottom: parent.bottom
|
|
|
|
|
anchors.bottomMargin: 10
|
|
|
|
|
onFinished: passwordData.finished();
|
|
|
|
|
dataInput: priceInput
|
|
|
|
|
|
|
|
|
|
buttonBackground: Item {
|
|
|
|
|
property int index: 0
|
|
|
|
|
property bool pressed: false
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
Item {
|
2025-02-17 15:05:41 +01:00
|
|
|
clip: true
|
2025-02-10 20:41:03 +01:00
|
|
|
function doFocus() { description.forceActiveFocus(); }
|
2025-02-09 22:57:14 +01:00
|
|
|
Column {
|
|
|
|
|
width: parent.width - 20
|
|
|
|
|
x: 10
|
|
|
|
|
spacing: 10
|
|
|
|
|
Flowee.BitcoinAmountLabel {
|
|
|
|
|
anchors.horizontalCenter: parent.horizontalCenter
|
|
|
|
|
visible: value > 0
|
|
|
|
|
colorize: false
|
|
|
|
|
value: request.amount
|
|
|
|
|
font.pixelSize: instructions.font.pixelSize * 1.4
|
|
|
|
|
}
|
|
|
|
|
PageTitledBox {
|
|
|
|
|
width: parent.width
|
|
|
|
|
title: qsTr("Description")
|
|
|
|
|
Flowee.TextField {
|
|
|
|
|
id: description
|
|
|
|
|
width: parent.width
|
|
|
|
|
onTotalTextChanged: request.message = totalText
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2025-03-03 15:32:45 +01:00
|
|
|
|
2023-05-01 21:11:11 +02:00
|
|
|
// the "payment received" screen.
|
|
|
|
|
Rectangle {
|
2025-02-10 16:04:45 +01:00
|
|
|
id: feedback
|
|
|
|
|
property bool hide: false // hide a partially paid popup
|
|
|
|
|
|
|
|
|
|
anchors.fill: swipeView
|
2023-05-01 21:11:11 +02:00
|
|
|
gradient: Gradient {
|
|
|
|
|
GradientStop {
|
|
|
|
|
position: 0.6
|
|
|
|
|
color: {
|
|
|
|
|
var state = request.state;
|
|
|
|
|
if (state === PaymentRequest.PaymentSeen || state === PaymentRequest.Unpaid)
|
|
|
|
|
return palette.base
|
|
|
|
|
if (state === PaymentRequest.DoubleSpentSeen)
|
|
|
|
|
return mainWindow.errorRedBg
|
2025-02-10 16:04:45 +01:00
|
|
|
return "#60b671" // in all other cases: green
|
2023-05-01 21:11:11 +02:00
|
|
|
}
|
|
|
|
|
Behavior on color { ColorAnimation {} }
|
|
|
|
|
}
|
|
|
|
|
GradientStop {
|
2025-02-10 16:04:45 +01:00
|
|
|
position: 0.01
|
2023-05-01 21:11:11 +02:00
|
|
|
color: palette.base
|
|
|
|
|
}
|
|
|
|
|
}
|
2025-02-10 16:04:45 +01:00
|
|
|
opacity: hide || request.state === PaymentRequest.Unpaid ? 0: 1
|
2023-06-21 17:46:17 +02:00
|
|
|
enabled: opacity > 0
|
|
|
|
|
visible: opacity > 0
|
2023-05-01 21:11:11 +02:00
|
|
|
|
2025-03-03 14:16:40 +01:00
|
|
|
onVisibleChanged: {
|
|
|
|
|
if (visible) {
|
|
|
|
|
// move it to the screen that doesn't have a textfield
|
|
|
|
|
// to ensure that the virtual keyboard gets closed.
|
|
|
|
|
swipeView.currentIndex = 0;
|
2025-03-03 15:32:45 +01:00
|
|
|
emitter.pulse(1500)
|
2025-03-03 14:16:40 +01:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2023-05-01 21:11:11 +02:00
|
|
|
// animating timer to indicate our checking the security of the transaction.
|
|
|
|
|
// (i.e. waiting for the double spent proof)
|
2025-02-10 16:04:45 +01:00
|
|
|
Flowee.Label {
|
|
|
|
|
color: "green"
|
|
|
|
|
text: "✔"
|
|
|
|
|
// y: 60
|
|
|
|
|
y: -30 // basically avoid the xheight
|
2023-05-01 21:11:11 +02:00
|
|
|
x: 30
|
|
|
|
|
opacity: {
|
2025-02-10 16:04:45 +01:00
|
|
|
if (request.state === PaymentRequest.PaymentSeenOk || request.state === PaymentRequest.Confirmed)
|
2023-05-01 21:11:11 +02:00
|
|
|
return 1;
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
2025-02-10 16:04:45 +01:00
|
|
|
font.pixelSize: 130
|
|
|
|
|
}
|
|
|
|
|
// textual feedback
|
|
|
|
|
Flowee.Label {
|
|
|
|
|
text: qsTr("Payment Seen") + " (" + ((request.amountSeen / request.amount) * 100).toFixed(2) + " %)"
|
|
|
|
|
y: 70
|
|
|
|
|
x: 20
|
|
|
|
|
opacity: request.state === PaymentRequest.PartiallyPaid ? 1 : 0
|
2023-05-01 21:11:11 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
Flowee.Label {
|
|
|
|
|
id: feedbackLabel
|
|
|
|
|
text: {
|
|
|
|
|
var s = request.state;
|
2025-02-10 16:04:45 +01:00
|
|
|
if (s === PaymentRequest.DoubleSpentSeen) // double-spent-proof received
|
2024-10-14 12:48:47 +02:00
|
|
|
return qsTr("High risk transaction");
|
2023-05-01 21:11:11 +02:00
|
|
|
if (s === PaymentRequest.PartiallyPaid)
|
|
|
|
|
return qsTr("Partially Paid");
|
|
|
|
|
if (s === PaymentRequest.PaymentSeen)
|
|
|
|
|
return qsTr("Payment Seen");
|
|
|
|
|
if (s === PaymentRequest.PaymentSeenOk)
|
|
|
|
|
return qsTr("Payment Accepted");
|
|
|
|
|
if (s === PaymentRequest.Confirmed)
|
|
|
|
|
return qsTr("Payment Settled");
|
|
|
|
|
return "INTERNAL ERROR";
|
|
|
|
|
}
|
|
|
|
|
width: parent.width - 40
|
|
|
|
|
anchors.horizontalCenter: parent.horizontalCenter
|
2025-02-10 16:04:45 +01:00
|
|
|
y: 100
|
2023-05-01 21:11:11 +02:00
|
|
|
wrapMode: Text.WrapAtWordBoundaryOrAnywhere
|
|
|
|
|
font.pointSize: 20
|
|
|
|
|
}
|
|
|
|
|
Behavior on opacity { OpacityAnimator {} }
|
|
|
|
|
|
2025-02-10 16:04:45 +01:00
|
|
|
Flowee.BigCloseButton {
|
|
|
|
|
anchors.bottom: parent.bottom
|
|
|
|
|
anchors.bottomMargin: 20
|
2023-05-01 21:11:11 +02:00
|
|
|
onClicked: {
|
|
|
|
|
request.clear();
|
|
|
|
|
description.text = "";
|
2023-05-24 11:35:25 +02:00
|
|
|
priceInput.paymentBackend.paymentAmount = 0;
|
2023-05-01 21:11:11 +02:00
|
|
|
request.account = portfolio.current;
|
|
|
|
|
request.start();
|
2025-02-10 16:04:45 +01:00
|
|
|
feedback.hide = false;
|
2023-06-14 16:58:36 +02:00
|
|
|
switchToTab(0); // go to the 'main' tab.
|
2023-05-01 21:11:11 +02:00
|
|
|
}
|
2025-02-10 16:04:45 +01:00
|
|
|
visible: request.state !== PaymentRequest.PartiallyPaid
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
Flowee.Button {
|
|
|
|
|
anchors.right: parent.right
|
|
|
|
|
anchors.rightMargin: 10
|
|
|
|
|
y: 160
|
|
|
|
|
text: qsTr("Continue")
|
|
|
|
|
visible: request.state === PaymentRequest.PartiallyPaid
|
|
|
|
|
onClicked: feedback.hide = true;
|
2023-05-01 21:11:11 +02:00
|
|
|
}
|
|
|
|
|
}
|
2025-03-03 15:32:45 +01:00
|
|
|
|
|
|
|
|
ParticleSystem {
|
|
|
|
|
anchors.fill: parent
|
|
|
|
|
ImageParticle {
|
|
|
|
|
source: "qrc:/star.png"
|
|
|
|
|
alpha: 0.3
|
|
|
|
|
colorVariation: 1
|
|
|
|
|
}
|
|
|
|
|
Gravity {
|
|
|
|
|
magnitude: 32
|
|
|
|
|
angle: 90
|
|
|
|
|
}
|
|
|
|
|
Emitter {
|
|
|
|
|
id: emitter
|
|
|
|
|
x: parent.width/2
|
|
|
|
|
y: feedback.y + 20
|
|
|
|
|
emitRate: 600
|
|
|
|
|
lifeSpan: 20000
|
|
|
|
|
lifeSpanVariation: 3000
|
|
|
|
|
enabled: false
|
|
|
|
|
velocity: AngleDirection {
|
|
|
|
|
angle: 270
|
|
|
|
|
angleVariation: 90
|
|
|
|
|
magnitude: 64
|
|
|
|
|
magnitudeVariation: 40
|
|
|
|
|
}
|
|
|
|
|
size: 10
|
|
|
|
|
sizeVariation: 6
|
|
|
|
|
}
|
|
|
|
|
}
|
2022-12-08 13:00:19 +01:00
|
|
|
}
|