Files
pay/guis/mobile/ReceiveTab.qml
T

361 lines
12 KiB
QML
Raw Permalink Normal View History

/*
* This file is part of the Flowee project
2024-10-14 12:48:47 +02:00
* Copyright (C) 2022-2024 Tom Zander <tom@flowee.org>
*
* 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-02-09 22:57:14 +01:00
import QtQuick.Controls as QQC2
import "../Flowee" as Flowee
import Flowee.org.pay
FocusScope {
2025-02-09 22:57:14 +01:00
id: root
property string icon: "qrc:/receive.svg"
2025-02-09 22:57:14 +01:00
property string title: qsTr("Receive")
property bool showInstructions: true
property QtObject account: portfolio.current
2023-05-24 11:35:25 +02:00
property bool qrViewActive: true;
property bool editViewActive: false
2025-02-10 16:04:45 +01:00
focus: true
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;
}
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
color: palette.highlight
visible: parent.active
opacity: 0.15
}
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")
opacity: editViewActive ? 0 : 0.5
Behavior on opacity { OpacityAnimator { } }
visible: root.showInstructions
}
Flowee.QRWidget {
id: qr
width: parent.width
y: root.showInstructions ? instructions.height : 0
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-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
fiatFollowsSats: false
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-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
}
}
}
}
}
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
enabled: opacity > 0
visible: opacity > 0
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;
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
}
}
}