Skip to content

Commit 5a3bf22

Browse files
committed
wire Send flow to use BitcoinAddress model
Switch Send recipient address handling from raw QString to BitcoinAddress so address formatting/cursor. This allows the address input to have a nicely spaced address that is easier to read. - Change SendRecipient.address Q_PROPERTY to BitcoinAddress* - Instantiate BitcoinAddress in SendRecipient and validate against address()->address() - Use BitcoinAddressInputField in Send.qml instead of inline address input - Update SendRecipientsListModel and WalletQmlModel call sites for recipient->address()->address() - Update WalletQmlModelTransaction to pull address from BitcoinAddress - Extend LabeledTextInput with cursor/focus/editingFinished plumbing needed by BitcoinAddressInputField
1 parent 80e6607 commit 5a3bf22

7 files changed

Lines changed: 29 additions & 50 deletions

File tree

qml/controls/LabeledTextInput.qml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,9 +15,13 @@ Item {
1515
property alias enabled: input.enabled
1616
property alias validator: input.validator
1717
property alias maximumLength: input.maximumLength
18+
property alias cursorPosition: input.cursorPosition
19+
property alias inputActiveFocus: input.activeFocus
1820

1921
signal iconClicked
2022
signal textEdited
23+
signal editingFinished
24+
signal inputFocusChanged
2125

2226
id: root
2327
implicitHeight: input.height
@@ -45,6 +49,8 @@ Item {
4549
background: Item {}
4650
selectByMouse: true
4751
onTextEdited: root.textEdited()
52+
onEditingFinished: root.editingFinished()
53+
onActiveFocusChanged: root.inputFocusChanged()
4854
}
4955

5056
Item {

qml/models/sendrecipient.cpp

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -5,25 +5,27 @@
55
#include <qml/models/sendrecipient.h>
66

77
#include <qml/bitcoinamount.h>
8+
#include <qml/models/bitcoinaddress.h>
89
#include <qml/models/walletqmlmodel.h>
910

1011
#include <key_io.h>
1112

1213
SendRecipient::SendRecipient(WalletQmlModel* wallet, QObject* parent)
13-
: QObject(parent), m_wallet(wallet), m_amount(new BitcoinAmount(this))
14+
: QObject(parent), m_wallet(wallet), m_address(new BitcoinAddress(this)), m_amount(new BitcoinAmount(this))
1415
{
1516
connect(m_amount, &BitcoinAmount::amountChanged, this, &SendRecipient::validateAmount);
17+
connect(m_address, &BitcoinAddress::formattedAddressChanged, this, &SendRecipient::validateAddress);
1618
}
1719

18-
QString SendRecipient::address() const
20+
BitcoinAddress* SendRecipient::address() const
1921
{
2022
return m_address;
2123
}
2224

2325
void SendRecipient::setAddress(const QString& address)
2426
{
25-
if (m_address != address) {
26-
m_address = address;
27+
if (m_address->address() != address) {
28+
m_address->setAddress(address, 0);
2729
Q_EMIT addressChanged();
2830
validateAddress();
2931
}
@@ -101,18 +103,19 @@ void SendRecipient::clear()
101103
m_label = "";
102104
m_message = "";
103105
m_subtractFeeFromAmount = false;
104-
setAddress("");
106+
m_address->setAddress("", 0);
105107
m_amount->clear();
108+
Q_EMIT addressChanged();
106109
Q_EMIT labelChanged();
107110
Q_EMIT messageChanged();
108111
}
109112

110113
void SendRecipient::validateAddress()
111114
{
112-
if (!m_address.isEmpty() && !IsValidDestinationString(m_address.toStdString())) {
113-
if (IsValidDestinationString(m_address.toStdString(), *CChainParams::Main())) {
115+
if (!m_address->isEmpty() && !IsValidDestinationString(m_address->address().toStdString())) {
116+
if (IsValidDestinationString(m_address->address().toStdString(), *CChainParams::Main())) {
114117
setAddressError(tr("Address is valid for mainnet, not the current network"));
115-
} else if (IsValidDestinationString(m_address.toStdString(), *CChainParams::TestNet())) {
118+
} else if (IsValidDestinationString(m_address->address().toStdString(), *CChainParams::TestNet())) {
116119
setAddressError(tr("Address is valid for testnet, not the current network"));
117120
} else {
118121
setAddressError(tr("Invalid address format"));
@@ -145,5 +148,5 @@ void SendRecipient::validateAmount()
145148

146149
bool SendRecipient::isValid() const
147150
{
148-
return m_addressError.isEmpty() && m_amountError.isEmpty() && m_amount->satoshi() > 0 && !m_address.isEmpty();
151+
return m_addressError.isEmpty() && m_amountError.isEmpty() && m_amount->satoshi() > 0 && !m_address->isEmpty();
149152
}

qml/models/sendrecipient.h

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
#define BITCOIN_QML_MODELS_SENDRECIPIENT_H
77

88
#include <qml/bitcoinamount.h>
9+
#include <qml/models/bitcoinaddress.h>
910

1011
#include <QObject>
1112
#include <QString>
@@ -15,7 +16,7 @@ class WalletQmlModel;
1516
class SendRecipient : public QObject
1617
{
1718
Q_OBJECT
18-
Q_PROPERTY(QString address READ address WRITE setAddress NOTIFY addressChanged)
19+
Q_PROPERTY(BitcoinAddress* address READ address CONSTANT)
1920
Q_PROPERTY(QString label READ label WRITE setLabel NOTIFY labelChanged)
2021
Q_PROPERTY(QString message READ message WRITE setMessage NOTIFY messageChanged)
2122
Q_PROPERTY(BitcoinAmount* amount READ amount CONSTANT)
@@ -27,7 +28,7 @@ class SendRecipient : public QObject
2728
public:
2829
explicit SendRecipient(WalletQmlModel* wallet, QObject* parent = nullptr);
2930

30-
QString address() const;
31+
BitcoinAddress* address() const;
3132
void setAddress(const QString& address);
3233
QString addressError() const;
3334
void setAddressError(const QString& error);
@@ -64,7 +65,7 @@ class SendRecipient : public QObject
6465
void validateAmount();
6566

6667
const WalletQmlModel* m_wallet;
67-
QString m_address{""};
68+
BitcoinAddress* m_address;
6869
QString m_addressError{""};
6970
QString m_label{""};
7071
QString m_message{""};

qml/models/sendrecipientslistmodel.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ QVariant SendRecipientsListModel::data(const QModelIndex& index, int role) const
2929

3030
const auto& r = m_recipients[index.row()];
3131
switch (role) {
32-
case AddressRole: return r->address();
32+
case AddressRole: return r->address()->ellipsesAddress();
3333
case LabelRole: return r->label();
3434
case AmountRole: return r->amount()->toDisplay();
3535
case MessageRole: return r->message();

qml/models/walletqmlmodel.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -115,7 +115,7 @@ bool WalletQmlModel::prepareTransaction()
115115
std::vector<wallet::CRecipient> vecSend;
116116
CAmount total = 0;
117117
for (auto* recipient : m_send_recipients->recipients()) {
118-
CTxDestination destination = DecodeDestination(recipient->address().toStdString());
118+
CTxDestination destination = DecodeDestination(recipient->address()->address().toStdString());
119119
wallet::CRecipient c_recipient = {destination, recipient->cAmount(), recipient->subtractFeeFromAmount()};
120120
m_coin_control.m_feerate = CFeeRate(1000);
121121
vecSend.push_back(c_recipient);

qml/models/walletqmlmodeltransaction.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
#include <policy/policy.h>
1111

1212
WalletQmlModelTransaction::WalletQmlModelTransaction(const SendRecipientsListModel* recipient, QObject* parent)
13-
: QObject(parent), m_address(recipient->recipients().at(0)->address()), m_amount(recipient->totalAmountSatoshi()), m_fee(0), m_label(recipient->recipients().at(0)->label()), m_wtx(nullptr)
13+
: QObject(parent), m_address(recipient->recipients().at(0)->address()->address()), m_amount(recipient->totalAmountSatoshi()), m_fee(0), m_label(recipient->recipients().at(0)->label()), m_wtx(nullptr)
1414
{
1515
}
1616

qml/pages/wallet/Send.qml

Lines changed: 4 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -169,42 +169,11 @@ PageStack {
169169
Layout.fillWidth: true
170170
}
171171

172-
ColumnLayout {
172+
BitcoinAddressInputField {
173173
Layout.fillWidth: true
174-
175-
LabeledTextInput {
176-
id: address
177-
Layout.fillWidth: true
178-
labelText: qsTr("Send to")
179-
placeholderText: qsTr("Enter address...")
180-
text: root.recipient.address
181-
onTextEdited: root.recipient.address = address.text
182-
validator: RegularExpressionValidator {
183-
regularExpression: /^[0-9A-HJ-NP-Za-z]+$/
184-
}
185-
maximumLength: 62
186-
}
187-
188-
RowLayout {
189-
id: addressIssue
190-
Layout.fillWidth: true
191-
visible: root.recipient.addressError.length > 0
192-
193-
Icon {
194-
source: "image://images/alert-filled"
195-
size: 22
196-
color: Theme.color.red
197-
}
198-
199-
CoreText {
200-
id: warningText
201-
text: root.recipient.addressError
202-
font.pixelSize: 15
203-
color: Theme.color.red
204-
horizontalAlignment: Text.AlignLeft
205-
Layout.fillWidth: true
206-
}
207-
}
174+
enabled: walletController.initialized
175+
address: root.recipient.address
176+
errorText: root.recipient.addressError
208177
}
209178

210179
Separator {

0 commit comments

Comments
 (0)