|
5 | 5 | #include <qml/models/sendrecipient.h> |
6 | 6 |
|
7 | 7 | #include <qml/bitcoinamount.h> |
| 8 | +#include <qml/models/bitcoinaddress.h> |
8 | 9 | #include <qml/models/walletqmlmodel.h> |
9 | 10 |
|
10 | 11 | #include <key_io.h> |
11 | 12 |
|
12 | 13 | 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)) |
14 | 15 | { |
15 | 16 | connect(m_amount, &BitcoinAmount::amountChanged, this, &SendRecipient::validateAmount); |
| 17 | + connect(m_address, &BitcoinAddress::formattedAddressChanged, this, &SendRecipient::validateAddress); |
16 | 18 | } |
17 | 19 |
|
18 | | -QString SendRecipient::address() const |
| 20 | +BitcoinAddress* SendRecipient::address() const |
19 | 21 | { |
20 | 22 | return m_address; |
21 | 23 | } |
22 | 24 |
|
23 | 25 | void SendRecipient::setAddress(const QString& address) |
24 | 26 | { |
25 | | - if (m_address != address) { |
26 | | - m_address = address; |
| 27 | + if (m_address->address() != address) { |
| 28 | + m_address->setAddress(address, 0); |
27 | 29 | Q_EMIT addressChanged(); |
28 | 30 | validateAddress(); |
29 | 31 | } |
@@ -101,18 +103,19 @@ void SendRecipient::clear() |
101 | 103 | m_label = ""; |
102 | 104 | m_message = ""; |
103 | 105 | m_subtractFeeFromAmount = false; |
104 | | - setAddress(""); |
| 106 | + m_address->setAddress("", 0); |
105 | 107 | m_amount->clear(); |
| 108 | + Q_EMIT addressChanged(); |
106 | 109 | Q_EMIT labelChanged(); |
107 | 110 | Q_EMIT messageChanged(); |
108 | 111 | } |
109 | 112 |
|
110 | 113 | void SendRecipient::validateAddress() |
111 | 114 | { |
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())) { |
114 | 117 | 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())) { |
116 | 119 | setAddressError(tr("Address is valid for testnet, not the current network")); |
117 | 120 | } else { |
118 | 121 | setAddressError(tr("Invalid address format")); |
@@ -145,5 +148,5 @@ void SendRecipient::validateAmount() |
145 | 148 |
|
146 | 149 | bool SendRecipient::isValid() const |
147 | 150 | { |
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(); |
149 | 152 | } |
0 commit comments