Skip to content

Commit 5ba790f

Browse files
committed
qml: Connect RequestPayment to WalletQmlModel
1 parent 4664627 commit 5ba790f

File tree

3 files changed

+17
-74
lines changed

3 files changed

+17
-74
lines changed

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: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,13 +23,16 @@
2323

2424
unsigned int WalletQmlModel::m_next_payment_request_id{1};
2525

26+
unsigned int WalletQmlModel::m_next_payment_request_id{1};
27+
2628
WalletQmlModel::WalletQmlModel(std::unique_ptr<interfaces::Wallet> wallet, QObject *parent)
2729
: QObject(parent)
2830
{
2931
m_wallet = std::move(wallet);
3032
m_activity_list_model = new ActivityListModel(this);
3133
m_coins_list_model = new CoinsListModel(this);
3234
m_send_recipients = new SendRecipientsListModel(this);
35+
m_current_payment_request = new PaymentRequest(this);
3336
}
3437

3538
WalletQmlModel::WalletQmlModel(QObject* parent)
@@ -38,13 +41,15 @@ WalletQmlModel::WalletQmlModel(QObject* parent)
3841
m_activity_list_model = new ActivityListModel(this);
3942
m_coins_list_model = new CoinsListModel(this);
4043
m_send_recipients = new SendRecipientsListModel(this);
44+
m_current_payment_request = new PaymentRequest(this);
4145
}
4246

4347
WalletQmlModel::~WalletQmlModel()
4448
{
4549
delete m_activity_list_model;
4650
delete m_coins_list_model;
4751
delete m_send_recipients;
52+
delete m_current_payment_request;
4853
if (m_current_transaction) {
4954
delete m_current_transaction;
5055
}

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)