Skip to content

Commit 7a9de81

Browse files
committed
gui: add more detailed address error message
1 parent e3ce019 commit 7a9de81

File tree

6 files changed

+80
-12
lines changed

6 files changed

+80
-12
lines changed

src/qt/editaddressdialog.cpp

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010

1111
#include <QDataWidgetMapper>
1212
#include <QMessageBox>
13+
#include <key_io.h>
1314

1415

1516
EditAddressDialog::EditAddressDialog(Mode _mode, QWidget *parent) :
@@ -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,22 @@ 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& text)
173+
{
174+
if (text.isEmpty()) // Nothing entered
175+
{
176+
ui->errorMessage->setText("");
177+
return;
178+
}
179+
180+
if (!IsValidDestination(DecodeDestination(text.toStdString()))) // Invalid address
181+
{
182+
ui->errorMessage->setText(tr("Warning: Invalid Bitcoin address"));
183+
}
184+
else // Valid address
185+
{
186+
ui->errorMessage->setText("");
187+
}
188+
}

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 &);
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: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,8 @@
1919
#include <QApplication>
2020
#include <QClipboard>
2121

22+
#include <key_io.h>
23+
2224
SendCoinsEntry::SendCoinsEntry(const PlatformStyle *_platformStyle, QWidget *parent) :
2325
QStackedWidget(parent),
2426
ui(new Ui::SendCoinsEntry),
@@ -50,6 +52,7 @@ SendCoinsEntry::SendCoinsEntry(const PlatformStyle *_platformStyle, QWidget *par
5052
connect(ui->deleteButton_is, &QPushButton::clicked, this, &SendCoinsEntry::deleteClicked);
5153
connect(ui->deleteButton_s, &QPushButton::clicked, this, &SendCoinsEntry::deleteClicked);
5254
connect(ui->useAvailableBalanceButton, &QPushButton::clicked, this, &SendCoinsEntry::useAvailableBalanceClicked);
55+
connect(ui->payTo, &QValidatedLineEdit::textEdited, this, &SendCoinsEntry::addressEdited);
5356
}
5457

5558
SendCoinsEntry::~SendCoinsEntry()
@@ -266,3 +269,22 @@ bool SendCoinsEntry::updateLabel(const QString &address)
266269

267270
return false;
268271
}
272+
273+
// Address changed
274+
void SendCoinsEntry::addressEdited(const QString& text)
275+
{
276+
if (text.isEmpty()) // Nothing entered
277+
{
278+
ui->errorMessage->setText("");
279+
return;
280+
}
281+
282+
if (!IsValidDestination(DecodeDestination(text.toStdString()))) // Invalid address
283+
{
284+
ui->errorMessage->setText(tr("Warning: Invalid Bitcoin address"));
285+
}
286+
else // Valid address
287+
{
288+
ui->errorMessage->setText("");
289+
}
290+
}

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)