Files
pay/guis/mobile/ReceiveTab.qml
T

451 lines
15 KiB
QML
Raw Permalink Normal View History

/*
* This file is part of the Flowee project
* Copyright (C) 2022-2026 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-06-18 17:48:29 +02:00
import QtQuick.Controls.Basic as QQC2
2025-03-03 15:32:45 +01:00
import QtQuick.Particles
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
2026-03-13 20:21:16 +01:00
property bool qrViewActive: true
2023-05-24 11:35:25 +02:00
property bool editViewActive: false
property alias verticalTab: swipeView.currentIndex
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
2026-03-13 20:21:16 +01:00
onAmountSeenChanged: feedback.hide = false
}
2023-04-28 12:07:26 +02:00
onAccountChanged: {
2026-03-13 20:21:16 +01:00
var state = request.state
2023-05-01 21:11:11 +02:00
if (request.state === PaymentRequest.Unpaid) {
// I can only change the wallet without cost
// if no payment has been seen.
2026-03-13 20:21:16 +01:00
request.account = account
2023-04-28 12:07:26 +02:00
}
}
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)
2026-03-13 20:21:16 +01:00
request.start()
2023-04-28 12:07:26 +02:00
}
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: {
var list = ["qr-code", "edit-money", "edit-pen"]
if (tokens.showTokenTab !== Wallet.AlwaysOff)
list.push("cashtoken")
return list
}
2025-02-09 22:57:14 +01:00
MouseArea {
property bool active: index === swipeView.currentIndex
width: 50
height: 50
2026-03-13 20:21:16 +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: 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: {
2026-03-13 20:21:16 +01:00
var avail = root.height - y - swipeView.height
return Math.min(256, avail)
2025-02-09 22:57:14 +01:00
}
textVisible: false
qrText: request.qr
2026-03-07 15:41:11 +01:00
}
Flowee.Label {
visible: request.failReason !== PaymentRequest.NoFailure
text: {
2026-03-13 20:21:16 +01:00
var f = request.failReason
2026-03-07 15:41:11 +01:00
if (f === PaymentRequest.AccountEncrypted)
2026-03-13 20:21:16 +01:00
return qsTr("Encrypted Wallet")
2026-03-07 15:41:11 +01:00
if (f === PaymentRequest.AccountImporting)
2026-03-13 20:21:16 +01:00
return qsTr("Import Running...")
2026-03-07 15:41:11 +01:00
if (f === PaymentRequest.NoAccountSet)
2026-03-13 20:21:16 +01:00
return "No Account Set" // not translated b/c cause is bug in QML
return ""
2025-02-09 22:57:14 +01:00
}
2026-03-07 15:41:11 +01:00
anchors.top: qr.top
width: parent.width - 80
horizontalAlignment: Text.AlignHCenter
wrapMode: Text.WrapAtWordBoundaryOrAnywhere
font.pointSize: 18
2025-02-09 22:57:14 +01:00
}
QQC2.SwipeView {
id: swipeView
width: parent.width + 20 // to ensure swiped pages are wide enough
x: -10
height: {
2026-03-13 20:21:16 +01:00
var have = parent.height - (showInstructions ? instructions.height : 0) - 256 // qr is ideally 256
2025-02-09 22:57:14 +01:00
if (currentIndex === 1)
2026-03-13 20:21:16 +01:00
return Math.max(have, priceInput.implicitHeight + 215)
return have - 6 // spacing of 6
2025-02-09 22:57:14 +01:00
}
anchors.bottom: parent.bottom
2026-03-13 20:21:16 +01:00
onCurrentIndexChanged: currentItem.doFocus()
2025-02-10 20:41:03 +01:00
function moveTo(index) {
2026-03-13 20:21:16 +01:00
forceActiveFocus()
currentIndex = index
currentItem.doFocus()
2025-02-10 20:41:03 +01:00
}
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 {
id: generalTabAddressBox
2025-02-09 22:57:14 +01:00
width: parent.width
2026-02-17 18:44:04 +01:00
title: request.tokenAddress ?
qsTr("Token Address", "Bitcoin Cash address") :
qsTr("Address", "Bitcoin Cash address")
2025-02-09 22:57:14 +01:00
Flowee.LabelWithClipboard {
width: parent.width
text: request.addressShort
fontSizeMode: Text.HorizontalFit
}
}
Flowee.Button {
anchors.right: parent.right
text: qsTr("Clear")
2026-03-13 20:21:16 +01:00
enabled: description.totalText !== "" || priceInput.paymentBackend.paymentAmount > 0
2025-02-09 22:57:14 +01:00
onClicked: {
2026-03-13 20:21:16 +01:00
request.clear()
request.account = portfolio.current
description.text = ""
priceInput.paymentBackend.paymentAmount = 0
request.start()
2025-02-09 22:57:14 +01:00
}
}
}
}
Item {
2026-03-13 20:21:16 +01:00
function doFocus() { priceInput.takeFocus() }
2025-02-10 20:41:03 +01:00
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.
2026-03-13 20:21:16 +01:00
var price = priceInput.editor.value
2025-02-09 22:57:14 +01:00
if (priceInput.fiatFollowsSats)
2026-03-13 20:21:16 +01:00
priceInput.paymentBackend.paymentAmount = price
2025-02-09 22:57:14 +01:00
else
2026-03-13 20:21:16 +01:00
priceInput.paymentBackend.paymentAmountFiat = price
2025-02-09 22:57:14 +01:00
}
}
}
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
2026-03-13 20:21:16 +01:00
onFinished: passwordData.finished()
2025-02-09 22:57:14 +01:00
dataInput: priceInput
buttonBackground: Item {
property int index: 0
property bool pressed: false
}
}
}
Item {
2025-02-17 15:05:41 +01:00
clip: true
2026-03-13 20:21:16 +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
2026-02-13 14:05:21 +01:00
onDisplayTextChanged: request.message = displayText
2025-02-09 22:57:14 +01:00
}
}
}
}
2026-03-05 17:04:45 +01:00
Item {
visible: tokens.showTokenTab !== Wallet.AlwaysOff
2026-03-13 20:21:16 +01:00
function doFocus() { forceTokenAddressCB.forceActiveFocus() }
2026-03-05 17:04:45 +01:00
Column {
width: parent.width - 20
x: 10
Flowee.BitcoinAmountLabel {
anchors.horizontalCenter: parent.horizontalCenter
visible: value > 0
colorize: false
value: request.amount
font.pixelSize: instructions.font.pixelSize * 1.4
}
Column {
width: parent.width
spacing: 10
PageTitledBox {
width: parent.width
title: generalTabAddressBox.title
Flowee.Label {
width: parent.width
fontSizeMode: Text.HorizontalFit
text: request.addressShort
}
2026-03-05 17:04:45 +01:00
}
// TODO insert Fungible token amount
2026-03-05 17:04:45 +01:00
// TODO Select which token to request.
Flowee.CheckBox {
id: forceTokenAddressCB
2026-03-05 17:04:45 +01:00
text: qsTr("Force token address")
checked: request.tokenAddress
onCheckedChanged: request.tokenAddress = checked
}
}
}
}
2025-02-09 22:57:14 +01:00
}
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: {
2026-03-13 20:21:16 +01:00
var state = request.state
2023-05-01 21:11:11 +02:00
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
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.
2026-03-13 20:21:16 +01:00
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)
2026-03-13 20:21:16 +01:00
return 1
return 0
2023-05-01 21:11:11 +02:00
}
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: {
2026-03-13 20:21:16 +01:00
var s = request.state
2025-02-10 16:04:45 +01:00
if (s === PaymentRequest.DoubleSpentSeen) // double-spent-proof received
2026-03-13 20:21:16 +01:00
return qsTr("High risk transaction")
2023-05-01 21:11:11 +02:00
if (s === PaymentRequest.PartiallyPaid)
2026-03-13 20:21:16 +01:00
return qsTr("Partially Paid")
2023-05-01 21:11:11 +02:00
if (s === PaymentRequest.PaymentSeen)
2026-03-13 20:21:16 +01:00
return qsTr("Payment Seen")
2023-05-01 21:11:11 +02:00
if (s === PaymentRequest.PaymentSeenOk)
2026-03-13 20:21:16 +01:00
return qsTr("Payment Accepted")
2023-05-01 21:11:11 +02:00
if (s === PaymentRequest.Confirmed)
2026-03-13 20:21:16 +01:00
return qsTr("Payment Settled")
return "INTERNAL ERROR"
2023-05-01 21:11:11 +02:00
}
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: {
2026-03-13 20:21:16 +01:00
request.clear()
description.text = ""
priceInput.paymentBackend.paymentAmount = 0
request.account = portfolio.current
request.start()
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
2026-03-13 20:21:16 +01:00
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
}
}
}