Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add more detailed address error message #533

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
24 changes: 24 additions & 0 deletions src/qt/editaddressdialog.cpp
Expand Up @@ -10,6 +10,7 @@

#include <QDataWidgetMapper>
#include <QMessageBox>
#include <key_io.h>


EditAddressDialog::EditAddressDialog(Mode _mode, QWidget *parent) :
Expand Down Expand Up @@ -44,6 +45,8 @@ EditAddressDialog::EditAddressDialog(Mode _mode, QWidget *parent) :
connect(delegate, &GUIUtil::ItemDelegate::keyEscapePressed, this, &EditAddressDialog::reject);
mapper->setItemDelegate(delegate);

connect(ui->addressEdit, &QValidatedLineEdit::textEdited, this, &EditAddressDialog::addressEdited);

GUIUtil::handleCloseWindowShortcut(this);
}

Expand Down Expand Up @@ -164,3 +167,24 @@ void EditAddressDialog::setAddress(const QString &_address)
this->address = _address;
ui->addressEdit->setText(_address);
}

// Address changed
void EditAddressDialog::addressEdited(const QString& text)
{
if (text.isEmpty()) // Nothing entered
{
ui->errorMessage->setText("");
return;
}

std::string error_msg;

if (!IsValidDestination(DecodeDestination(text.toStdString(), error_msg))) // Invalid address
{
ui->errorMessage->setText(QString::fromStdString(error_msg));
}
else // Valid address
{
ui->errorMessage->setText("");
}
}
3 changes: 3 additions & 0 deletions src/qt/editaddressdialog.h
Expand Up @@ -42,6 +42,9 @@ class EditAddressDialog : public QDialog
public Q_SLOTS:
void accept() override;

private Q_SLOTS:
void addressEdited(const QString &);

private:
bool saveCurrentRow();

Expand Down
12 changes: 11 additions & 1 deletion src/qt/forms/editaddressdialog.ui
Expand Up @@ -7,7 +7,7 @@
<x>0</x>
<y>0</y>
<width>457</width>
<height>126</height>
<height>138</height>
</rect>
</property>
<property name="windowTitle">
Expand Down Expand Up @@ -53,6 +53,16 @@
</property>
</widget>
</item>
<item row="2" column="1">
<widget class="QLabel" name="errorMessage">
<property name="styleSheet">
<string notr="true">color:red;</string>
Copy link
Member

@hebasto hebasto Jan 24, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is hardcoded red color visually compatible with dark themes/appearance? Maybe add some relevant screenshots?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There is a screenshot posted by @jonatack here:
#534 (review)

But this style is already used in sendcoinsdialog.ui and sendcoinsdialog.cpp for invalid custom change addresses and insufficient funds , so it seems to be a well tested configuration.

</property>
<property name="text">
<string/>
</property>
</widget>
</item>
</layout>
</item>
<item>
Expand Down
32 changes: 21 additions & 11 deletions src/qt/forms/sendcoinsentry.ui
Expand Up @@ -7,7 +7,7 @@
<x>0</x>
<y>0</y>
<width>729</width>
<height>150</height>
<height>172</height>
</rect>
</property>
<property name="focusPolicy">
Expand All @@ -33,7 +33,17 @@
<property name="verticalSpacing">
<number>8</number>
</property>
<item row="0" column="0">
<item row="0" column="1">
<widget class="QLabel" name="errorMessage">
<property name="styleSheet">
<string notr="true">color:red;</string>
</property>
<property name="text">
<string/>
</property>
</widget>
</item>
<item row="1" column="0">
<widget class="QLabel" name="payToLabel">
<property name="text">
<string>Pay &amp;To:</string>
Expand All @@ -46,7 +56,7 @@
</property>
</widget>
</item>
<item row="0" column="1">
<item row="1" column="1">
<layout class="QHBoxLayout" name="payToLayout">
<property name="spacing">
<number>0</number>
Expand Down Expand Up @@ -126,7 +136,7 @@
</item>
</layout>
</item>
<item row="1" column="0">
<item row="2" column="0">
<widget class="QLabel" name="labellLabel">
<property name="text">
<string>&amp;Label:</string>
Expand All @@ -139,7 +149,7 @@
</property>
</widget>
</item>
<item row="1" column="1">
<item row="2" column="1">
<widget class="QLineEdit" name="addAsLabel">
<property name="toolTip">
<string>Enter a label for this address to add it to the list of used addresses</string>
Expand All @@ -149,7 +159,7 @@
</property>
</widget>
</item>
<item row="2" column="0">
<item row="3" column="0">
<widget class="QLabel" name="amountLabel">
<property name="text">
<string>A&amp;mount:</string>
Expand All @@ -162,7 +172,7 @@
</property>
</widget>
</item>
<item row="2" column="1">
<item row="3" column="1">
<layout class="QHBoxLayout" name="horizontalLayoutAmount" stretch="0,1,0">
<item>
<widget class="BitcoinAmountField" name="payAmount">
Expand All @@ -174,7 +184,7 @@
<item>
<widget class="QCheckBox" name="checkboxSubtractFeeFromAmount">
<property name="toolTip">
<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>
<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>
</property>
<property name="text">
<string>S&amp;ubtract fee from amount</string>
Expand All @@ -190,7 +200,7 @@
</item>
</layout>
</item>
<item row="3" column="0">
<item row="4" column="0">
<widget class="QLabel" name="messageLabel">
<property name="text">
<string>Message:</string>
Expand All @@ -200,7 +210,7 @@
</property>
</widget>
</item>
<item row="3" column="1">
<item row="4" column="1">
<widget class="QLabel" name="messageTextLabel">
<property name="toolTip">
<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>
Expand All @@ -210,7 +220,7 @@
</property>
</widget>
</item>
<item row="4" column="0" colspan="2">
<item row="5" column="0" colspan="2">
<widget class="Line" name="line">
<property name="orientation">
<enum>Qt::Horizontal</enum>
Expand Down
24 changes: 24 additions & 0 deletions src/qt/sendcoinsentry.cpp
Expand Up @@ -19,6 +19,8 @@
#include <QApplication>
#include <QClipboard>

#include <key_io.h>

SendCoinsEntry::SendCoinsEntry(const PlatformStyle *_platformStyle, QWidget *parent) :
QStackedWidget(parent),
ui(new Ui::SendCoinsEntry),
Expand Down Expand Up @@ -50,6 +52,7 @@ SendCoinsEntry::SendCoinsEntry(const PlatformStyle *_platformStyle, QWidget *par
connect(ui->deleteButton_is, &QPushButton::clicked, this, &SendCoinsEntry::deleteClicked);
connect(ui->deleteButton_s, &QPushButton::clicked, this, &SendCoinsEntry::deleteClicked);
connect(ui->useAvailableBalanceButton, &QPushButton::clicked, this, &SendCoinsEntry::useAvailableBalanceClicked);
connect(ui->payTo, &QValidatedLineEdit::textEdited, this, &SendCoinsEntry::addressEdited);
}

SendCoinsEntry::~SendCoinsEntry()
Expand Down Expand Up @@ -266,3 +269,24 @@ bool SendCoinsEntry::updateLabel(const QString &address)

return false;
}

// Address changed
void SendCoinsEntry::addressEdited(const QString& text)
{
if (text.isEmpty()) // Nothing entered
{
ui->errorMessage->setText("");
return;
}

std::string error_msg;

if (!IsValidDestination(DecodeDestination(text.toStdString(), error_msg))) // Invalid address
{
ui->errorMessage->setText(QString::fromStdString(error_msg));
}
else // Valid address
{
ui->errorMessage->setText("");
}
}
1 change: 1 addition & 0 deletions src/qt/sendcoinsentry.h
Expand Up @@ -68,6 +68,7 @@ private Q_SLOTS:
void on_addressBookButton_clicked();
void on_pasteButton_clicked();
void updateDisplayUnit();
void addressEdited(const QString &);

protected:
void changeEvent(QEvent* e) override;
Expand Down