Skip to content

Commit dd8bd45

Browse files
w0xltjonatack
andcommitted
gui: add more detailed address error message
Co-authored-by: Jon Atack <[email protected]>
1 parent e3ce019 commit dd8bd45

File tree

6 files changed

+65
-14
lines changed

6 files changed

+65
-14
lines changed

src/qt/editaddressdialog.cpp

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,10 @@
33
// file COPYING or http://www.opensource.org/licenses/mit-license.php.
44

55
#include <qt/editaddressdialog.h>
6-
#include <qt/forms/ui_editaddressdialog.h>
76

7+
#include <key_io.h>
88
#include <qt/addresstablemodel.h>
9+
#include <qt/forms/ui_editaddressdialog.h>
910
#include <qt/guiutil.h>
1011

1112
#include <QDataWidgetMapper>
@@ -44,6 +45,8 @@ EditAddressDialog::EditAddressDialog(Mode _mode, QWidget *parent) :
4445
connect(delegate, &GUIUtil::ItemDelegate::keyEscapePressed, this, &EditAddressDialog::reject);
4546
mapper->setItemDelegate(delegate);
4647

48+
connect(ui->addressEdit, &QValidatedLineEdit::textEdited, this, &EditAddressDialog::addressEdited);
49+
4750
GUIUtil::handleCloseWindowShortcut(this);
4851
}
4952

@@ -164,3 +167,13 @@ void EditAddressDialog::setAddress(const QString &_address)
164167
this->address = _address;
165168
ui->addressEdit->setText(_address);
166169
}
170+
171+
// Address changed
172+
void EditAddressDialog::addressEdited(const QString& address)
173+
{
174+
if (!address.isEmpty() && !IsValidDestination(DecodeDestination(address.toStdString()))) {
175+
ui->errorMessage->setText(tr("Warning: Invalid Bitcoin address"));
176+
} else {
177+
ui->errorMessage->setText("");
178+
}
179+
}

src/qt/editaddressdialog.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,9 @@ class EditAddressDialog : public QDialog
4242
public Q_SLOTS:
4343
void accept() override;
4444

45+
private Q_SLOTS:
46+
void addressEdited(const QString& address);
47+
4548
private:
4649
bool saveCurrentRow();
4750

src/qt/forms/editaddressdialog.ui

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
<x>0</x>
88
<y>0</y>
99
<width>457</width>
10-
<height>126</height>
10+
<height>138</height>
1111
</rect>
1212
</property>
1313
<property name="windowTitle">
@@ -53,6 +53,16 @@
5353
</property>
5454
</widget>
5555
</item>
56+
<item row="2" column="1">
57+
<widget class="QLabel" name="errorMessage">
58+
<property name="styleSheet">
59+
<string notr="true">color:red;</string>
60+
</property>
61+
<property name="text">
62+
<string/>
63+
</property>
64+
</widget>
65+
</item>
5666
</layout>
5767
</item>
5868
<item>

src/qt/forms/sendcoinsentry.ui

Lines changed: 21 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
<x>0</x>
88
<y>0</y>
99
<width>729</width>
10-
<height>150</height>
10+
<height>172</height>
1111
</rect>
1212
</property>
1313
<property name="focusPolicy">
@@ -33,7 +33,17 @@
3333
<property name="verticalSpacing">
3434
<number>8</number>
3535
</property>
36-
<item row="0" column="0">
36+
<item row="0" column="1">
37+
<widget class="QLabel" name="errorMessage">
38+
<property name="styleSheet">
39+
<string notr="true">color:red;</string>
40+
</property>
41+
<property name="text">
42+
<string/>
43+
</property>
44+
</widget>
45+
</item>
46+
<item row="1" column="0">
3747
<widget class="QLabel" name="payToLabel">
3848
<property name="text">
3949
<string>Pay &amp;To:</string>
@@ -46,7 +56,7 @@
4656
</property>
4757
</widget>
4858
</item>
49-
<item row="0" column="1">
59+
<item row="1" column="1">
5060
<layout class="QHBoxLayout" name="payToLayout">
5161
<property name="spacing">
5262
<number>0</number>
@@ -126,7 +136,7 @@
126136
</item>
127137
</layout>
128138
</item>
129-
<item row="1" column="0">
139+
<item row="2" column="0">
130140
<widget class="QLabel" name="labellLabel">
131141
<property name="text">
132142
<string>&amp;Label:</string>
@@ -139,7 +149,7 @@
139149
</property>
140150
</widget>
141151
</item>
142-
<item row="1" column="1">
152+
<item row="2" column="1">
143153
<widget class="QLineEdit" name="addAsLabel">
144154
<property name="toolTip">
145155
<string>Enter a label for this address to add it to the list of used addresses</string>
@@ -149,7 +159,7 @@
149159
</property>
150160
</widget>
151161
</item>
152-
<item row="2" column="0">
162+
<item row="3" column="0">
153163
<widget class="QLabel" name="amountLabel">
154164
<property name="text">
155165
<string>A&amp;mount:</string>
@@ -162,7 +172,7 @@
162172
</property>
163173
</widget>
164174
</item>
165-
<item row="2" column="1">
175+
<item row="3" column="1">
166176
<layout class="QHBoxLayout" name="horizontalLayoutAmount" stretch="0,1,0">
167177
<item>
168178
<widget class="BitcoinAmountField" name="payAmount">
@@ -174,7 +184,7 @@
174184
<item>
175185
<widget class="QCheckBox" name="checkboxSubtractFeeFromAmount">
176186
<property name="toolTip">
177-
<string>The fee will be deducted from the amount being sent. The recipient will receive less bitcoins than you enter in the amount field. If multiple recipients are selected, the fee is split equally.</string>
187+
<string>The fee will be deducted from the amount being sent. The recipient will receive less bitcoin than you enter in the amount field. If multiple recipients are selected, the fee is split equally.</string>
178188
</property>
179189
<property name="text">
180190
<string>S&amp;ubtract fee from amount</string>
@@ -190,7 +200,7 @@
190200
</item>
191201
</layout>
192202
</item>
193-
<item row="3" column="0">
203+
<item row="4" column="0">
194204
<widget class="QLabel" name="messageLabel">
195205
<property name="text">
196206
<string>Message:</string>
@@ -200,7 +210,7 @@
200210
</property>
201211
</widget>
202212
</item>
203-
<item row="3" column="1">
213+
<item row="4" column="1">
204214
<widget class="QLabel" name="messageTextLabel">
205215
<property name="toolTip">
206216
<string>A message that was attached to the bitcoin: URI which will be stored with the transaction for your reference. Note: This message will not be sent over the Bitcoin network.</string>
@@ -210,7 +220,7 @@
210220
</property>
211221
</widget>
212222
</item>
213-
<item row="4" column="0" colspan="2">
223+
<item row="5" column="0" colspan="2">
214224
<widget class="Line" name="line">
215225
<property name="orientation">
216226
<enum>Qt::Horizontal</enum>

src/qt/sendcoinsentry.cpp

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,13 @@
77
#endif
88

99
#include <qt/sendcoinsentry.h>
10-
#include <qt/forms/ui_sendcoinsentry.h>
10+
11+
#include <key_io.h>
12+
1113

1214
#include <qt/addressbookpage.h>
1315
#include <qt/addresstablemodel.h>
16+
#include <qt/forms/ui_sendcoinsentry.h>
1417
#include <qt/guiutil.h>
1518
#include <qt/optionsmodel.h>
1619
#include <qt/platformstyle.h>
@@ -50,6 +53,7 @@ SendCoinsEntry::SendCoinsEntry(const PlatformStyle *_platformStyle, QWidget *par
5053
connect(ui->deleteButton_is, &QPushButton::clicked, this, &SendCoinsEntry::deleteClicked);
5154
connect(ui->deleteButton_s, &QPushButton::clicked, this, &SendCoinsEntry::deleteClicked);
5255
connect(ui->useAvailableBalanceButton, &QPushButton::clicked, this, &SendCoinsEntry::useAvailableBalanceClicked);
56+
connect(ui->payTo, &QValidatedLineEdit::textEdited, this, &SendCoinsEntry::addressEdited);
5357
}
5458

5559
SendCoinsEntry::~SendCoinsEntry()
@@ -266,3 +270,13 @@ bool SendCoinsEntry::updateLabel(const QString &address)
266270

267271
return false;
268272
}
273+
274+
// Address changed
275+
void SendCoinsEntry::addressEdited(const QString& address)
276+
{
277+
if (!address.isEmpty() && !IsValidDestination(DecodeDestination(address.toStdString()))) {
278+
ui->errorMessage->setText(tr("Warning: Invalid Bitcoin address"));
279+
} else {
280+
ui->errorMessage->setText("");
281+
}
282+
}

src/qt/sendcoinsentry.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,7 @@ private Q_SLOTS:
6868
void on_addressBookButton_clicked();
6969
void on_pasteButton_clicked();
7070
void updateDisplayUnit();
71+
void addressEdited(const QString &);
7172

7273
protected:
7374
void changeEvent(QEvent* e) override;

0 commit comments

Comments
 (0)