From d90ca3737c286526a77622af43be62b59cbb6960 Mon Sep 17 00:00:00 2001 From: w0xlt <94266259+w0xlt@users.noreply.github.com> Date: Fri, 21 Jan 2022 07:20:28 -0300 Subject: [PATCH] gui: add more detailed address error message --- src/qt/editaddressdialog.cpp | 24 +++++++++++++++++++++++ src/qt/editaddressdialog.h | 3 +++ src/qt/forms/editaddressdialog.ui | 12 +++++++++++- src/qt/forms/sendcoinsentry.ui | 32 ++++++++++++++++++++----------- src/qt/sendcoinsentry.cpp | 24 +++++++++++++++++++++++ src/qt/sendcoinsentry.h | 1 + 6 files changed, 84 insertions(+), 12 deletions(-) diff --git a/src/qt/editaddressdialog.cpp b/src/qt/editaddressdialog.cpp index fa27635981d..c80c330894a 100644 --- a/src/qt/editaddressdialog.cpp +++ b/src/qt/editaddressdialog.cpp @@ -10,6 +10,7 @@ #include #include +#include EditAddressDialog::EditAddressDialog(Mode _mode, QWidget *parent) : @@ -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); } @@ -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(""); + } +} \ No newline at end of file diff --git a/src/qt/editaddressdialog.h b/src/qt/editaddressdialog.h index f7ad80bb2df..5edba2cc1b3 100644 --- a/src/qt/editaddressdialog.h +++ b/src/qt/editaddressdialog.h @@ -42,6 +42,9 @@ class EditAddressDialog : public QDialog public Q_SLOTS: void accept() override; +private Q_SLOTS: + void addressEdited(const QString &); + private: bool saveCurrentRow(); diff --git a/src/qt/forms/editaddressdialog.ui b/src/qt/forms/editaddressdialog.ui index e968271107f..a5836805174 100644 --- a/src/qt/forms/editaddressdialog.ui +++ b/src/qt/forms/editaddressdialog.ui @@ -7,7 +7,7 @@ 0 0 457 - 126 + 138 @@ -53,6 +53,16 @@ + + + + color:red; + + + + + + diff --git a/src/qt/forms/sendcoinsentry.ui b/src/qt/forms/sendcoinsentry.ui index 934363af1f1..10c192e66d3 100644 --- a/src/qt/forms/sendcoinsentry.ui +++ b/src/qt/forms/sendcoinsentry.ui @@ -7,7 +7,7 @@ 0 0 729 - 150 + 172 @@ -33,7 +33,17 @@ 8 - + + + + color:red; + + + + + + + Pay &To: @@ -46,7 +56,7 @@ - + 0 @@ -126,7 +136,7 @@ - + &Label: @@ -139,7 +149,7 @@ - + Enter a label for this address to add it to the list of used addresses @@ -149,7 +159,7 @@ - + A&mount: @@ -162,7 +172,7 @@ - + @@ -174,7 +184,7 @@ - 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. + 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. S&ubtract fee from amount @@ -190,7 +200,7 @@ - + Message: @@ -200,7 +210,7 @@ - + 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. @@ -210,7 +220,7 @@ - + Qt::Horizontal diff --git a/src/qt/sendcoinsentry.cpp b/src/qt/sendcoinsentry.cpp index 339ac580d80..9053121a510 100644 --- a/src/qt/sendcoinsentry.cpp +++ b/src/qt/sendcoinsentry.cpp @@ -19,6 +19,8 @@ #include #include +#include + SendCoinsEntry::SendCoinsEntry(const PlatformStyle *_platformStyle, QWidget *parent) : QStackedWidget(parent), ui(new Ui::SendCoinsEntry), @@ -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() @@ -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(""); + } +} \ No newline at end of file diff --git a/src/qt/sendcoinsentry.h b/src/qt/sendcoinsentry.h index e8db1e3a5ce..d16377265a9 100644 --- a/src/qt/sendcoinsentry.h +++ b/src/qt/sendcoinsentry.h @@ -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;