Skip to content

Commit fe25d2b

Browse files
committed
qml: Connect RequestPayment page to WalletQmlModel
1 parent 03042fb commit fe25d2b

File tree

4 files changed

+17
-74
lines changed

4 files changed

+17
-74
lines changed

src/qml/bitcoin.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@
2929
#include <qml/models/networktraffictower.h>
3030
#include <qml/models/nodemodel.h>
3131
#include <qml/models/options_model.h>
32+
#include <qml/models/paymentrequest.h>
3233
#include <qml/models/peerdetailsmodel.h>
3334
#include <qml/models/peerlistsortproxy.h>
3435
#include <qml/models/sendrecipient.h>
@@ -340,6 +341,7 @@ int QmlGuiMain(int argc, char* argv[])
340341
qmlRegisterType<LineGraph>("org.bitcoincore.qt", 1, 0, "LineGraph");
341342
qmlRegisterUncreatableType<PeerDetailsModel>("org.bitcoincore.qt", 1, 0, "PeerDetailsModel", "");
342343
qmlRegisterType<BitcoinAmount>("org.bitcoincore.qt", 1, 0, "BitcoinAmount");
344+
qmlRegisterType<PaymentRequest>("org.bitcoincore.qt", 1, 0, "PaymentRequest");
343345
qmlRegisterUncreatableType<Transaction>("org.bitcoincore.qt", 1, 0, "Transaction", "");
344346
qmlRegisterUncreatableType<SendRecipient>("org.bitcoincore.qt", 1, 0, "SendRecipient", "");
345347

src/qml/models/sendrecipient.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,6 @@ class SendRecipient : public QObject
3636
void setLabel(const QString& label);
3737

3838
BitcoinAmount* amount() const;
39-
void setAmount(const QString& amount);
4039
QString amountError() const;
4140
void setAmountError(const QString& error);
4241

src/qml/models/walletqmlmodel.cpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ WalletQmlModel::WalletQmlModel(std::unique_ptr<interfaces::Wallet> wallet, QObje
3030
m_activity_list_model = new ActivityListModel(this);
3131
m_coins_list_model = new CoinsListModel(this);
3232
m_send_recipients = new SendRecipientsListModel(this);
33+
m_current_payment_request = new PaymentRequest(this);
3334
}
3435

3536
WalletQmlModel::WalletQmlModel(QObject* parent)
@@ -38,13 +39,15 @@ WalletQmlModel::WalletQmlModel(QObject* parent)
3839
m_activity_list_model = new ActivityListModel(this);
3940
m_coins_list_model = new CoinsListModel(this);
4041
m_send_recipients = new SendRecipientsListModel(this);
42+
m_current_payment_request = new PaymentRequest(this);
4143
}
4244

4345
WalletQmlModel::~WalletQmlModel()
4446
{
4547
delete m_activity_list_model;
4648
delete m_coins_list_model;
4749
delete m_send_recipients;
50+
delete m_current_payment_request;
4851
if (m_current_transaction) {
4952
delete m_current_transaction;
5053
}

src/qml/pages/wallet/RequestPayment.qml

Lines changed: 12 additions & 73 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,8 @@ Page {
1616
background: null
1717

1818
property int requestCounter: 0
19+
property WalletQmlModel wallet: walletController.selectedWallet
20+
property PaymentRequest request: wallet.currentPaymentRequest
1921

2022
ScrollView {
2123
clip: true
@@ -49,74 +51,11 @@ Page {
4951

5052
spacing: 5
5153

52-
Item {
53-
BitcoinAmount {
54-
id: bitcoinAmount
55-
}
56-
57-
height: amountInput.height
54+
BitcoinAmountInputField {
5855
Layout.fillWidth: true
59-
CoreText {
60-
id: amountLabel
61-
width: 110
62-
anchors.left: parent.left
63-
anchors.verticalCenter: parent.verticalCenter
64-
horizontalAlignment: Text.AlignLeft
65-
text: "Amount"
66-
font.pixelSize: 18
67-
}
68-
69-
TextField {
70-
id: amountInput
71-
anchors.left: amountLabel.right
72-
anchors.verticalCenter: parent.verticalCenter
73-
leftPadding: 0
74-
font.family: "Inter"
75-
font.styleName: "Regular"
76-
font.pixelSize: 18
77-
color: Theme.color.neutral9
78-
placeholderTextColor: enabled ? Theme.color.neutral7 : Theme.color.neutral4
79-
background: Item {}
80-
placeholderText: "0.00000000"
81-
selectByMouse: true
82-
onTextEdited: {
83-
amountInput.text = bitcoinAmount.sanitize(amountInput.text)
84-
}
85-
}
86-
Item {
87-
width: unitLabel.width + flipIcon.width
88-
height: Math.max(unitLabel.height, flipIcon.height)
89-
anchors.right: parent.right
90-
anchors.verticalCenter: parent.verticalCenter
91-
MouseArea {
92-
anchors.fill: parent
93-
onClicked: {
94-
if (bitcoinAmount.unit == BitcoinAmount.BTC) {
95-
amountInput.text = bitcoinAmount.convert(amountInput.text, BitcoinAmount.BTC)
96-
bitcoinAmount.unit = BitcoinAmount.SAT
97-
} else {
98-
amountInput.text = bitcoinAmount.convert(amountInput.text, BitcoinAmount.SAT)
99-
bitcoinAmount.unit = BitcoinAmount.BTC
100-
}
101-
}
102-
}
103-
CoreText {
104-
id: unitLabel
105-
anchors.right: flipIcon.left
106-
anchors.verticalCenter: parent.verticalCenter
107-
text: bitcoinAmount.unitLabel
108-
font.pixelSize: 18
109-
color: enabled ? Theme.color.neutral7 : Theme.color.neutral4
110-
}
111-
Icon {
112-
id: flipIcon
113-
anchors.right: parent.right
114-
anchors.verticalCenter: parent.verticalCenter
115-
source: "image://images/flip-vertical"
116-
color: unitLabel.enabled ? Theme.color.neutral8 : Theme.color.neutral4
117-
size: 30
118-
}
119-
}
56+
enabled: walletController.initialized
57+
amount: root.request.amount
58+
errorText: root.request.amountError
12059
}
12160

12261
Separator {
@@ -147,7 +86,7 @@ Page {
14786

14887
Item {
14988
Layout.fillWidth: true
150-
Layout.minimumHeight: addressLabel.height + copyLabel.height
89+
Layout.minimumHeight: addressLabel.height + copyLabel.height + 20
15190
Layout.topMargin: 10
15291
height: addressLabel.height + copyLabel.height
15392
CoreText {
@@ -179,11 +118,12 @@ Page {
179118
radius: 5
180119
CoreText {
181120
id: address
121+
text: root.request.address
182122
anchors.fill: parent
183123
anchors.leftMargin: 5
184124
horizontalAlignment: Text.AlignLeft
185125
font.pixelSize: 18
186-
wrap: true
126+
wrapMode: Text.WrapAnywhere
187127
}
188128
}
189129
}
@@ -197,9 +137,8 @@ Page {
197137
if (!clearRequest.visible) {
198138
requestCounter = requestCounter + 1
199139
clearRequest.visible = true
140+
wallet.commitPaymentRequest()
200141
title.text = qsTr("Payment request #" + requestCounter)
201-
address.text = "bc1q f5xe y2tf 89k9 zy6k gnru wszy 5fsa truy 9te1 bu"
202-
qrImage.code = "bc1qf5xey2tf89k9zy6kgnruwszy5fsatruy9te1bu"
203142
continueButton.text = qsTr("Copy payment request")
204143
}
205144
}
@@ -220,8 +159,7 @@ Page {
220159
onClicked: {
221160
clearRequest.visible = false
222161
title.text = qsTr("Request a payment")
223-
address.text = ""
224-
qrImage.code = ""
162+
root.request.clear()
225163
continueButton.text = qsTr("Create bitcoin address")
226164
}
227165
}
@@ -240,6 +178,7 @@ Page {
240178
id: qrImage
241179
backgroundColor: "transparent"
242180
foregroundColor: Theme.color.neutral9
181+
code: root.request.address
243182
}
244183
}
245184
}

0 commit comments

Comments
 (0)