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

[qt] [tests] Clarify address book error messages, add tests #12830

Merged
merged 4 commits into from Apr 25, 2018
Merged
Changes from 1 commit
Commits
File filter...
Filter file types
Jump to…
Jump to file or symbol
Failed to load files and symbols.

Always

Just for now

[qt] Display more helpful message when adding a send address has failed

Addresses #12796.

When we're unable to add a sending address to the address book because it
already exists as a receiving address, display a message indicating as much.
This should help avoid confusion about an address supposedly already in the
book but which isn't currently visible in the interface.
  • Loading branch information...
jamesob committed Apr 10, 2018
commit 8cdcaee4c7b256c5c3b70f1cfb04a5fb547311cd
@@ -407,21 +407,31 @@ bool AddressTableModel::removeRows(int row, int count, const QModelIndex &parent
return true;
}

/* Look up label for address in address book, if not found return empty string.
*/
QString AddressTableModel::labelForAddress(const QString &address) const
{
{
CTxDestination destination = DecodeDestination(address.toStdString());
std::string name;
if (walletModel->wallet().getAddress(destination, &name))
{
return QString::fromStdString(name);
}
std::string name;
if (getAddressData(address, &name, /* purpose= */ nullptr)) {
return QString::fromStdString(name);
}
return QString();
}

QString AddressTableModel::purposeForAddress(const QString &address) const
{
std::string purpose;
if (getAddressData(address, /* name= */ nullptr, &purpose)) {
return QString::fromStdString(purpose);
}
return QString();
}

bool AddressTableModel::getAddressData(const QString &address,
std::string* name,
std::string* purpose) const {
CTxDestination destination = DecodeDestination(address.toStdString());
return walletModel->wallet().getAddress(destination, name, /* is_mine= */ nullptr, purpose);
}

int AddressTableModel::lookupAddress(const QString &address) const
{
QModelIndexList lst = match(index(0, Address, QModelIndex()),
@@ -67,10 +67,12 @@ class AddressTableModel : public QAbstractTableModel
*/
QString addRow(const QString &type, const QString &label, const QString &address, const OutputType address_type);

/* Look up label for address in address book, if not found return empty string.
*/
/** Look up label for address in address book, if not found return empty string. */
QString labelForAddress(const QString &address) const;

/** Look up purpose for address in address book, if not found return empty string. */
QString purposeForAddress(const QString &address) const;

/* Look up row index of an address in the model.
Return -1 if not found.
*/
@@ -86,6 +88,9 @@ class AddressTableModel : public QAbstractTableModel
QStringList columns;
EditStatus editStatus;

/** Look up address book data given an address string. */
bool getAddressData(const QString &address, std::string* name, std::string* purpose) const;

/** Notify listeners that data changed. */
void emitDataChanged(int index);

@@ -109,7 +109,7 @@ void EditAddressDialog::accept()
break;
case AddressTableModel::DUPLICATE_ADDRESS:
QMessageBox::warning(this, windowTitle(),
tr("The entered address \"%1\" is already in the address book.").arg(ui->addressEdit->text()),
getDuplicateAddressWarning(),
QMessageBox::Ok, QMessageBox::Ok);
break;
case AddressTableModel::WALLET_UNLOCK_FAILURE:
@@ -129,6 +129,25 @@ void EditAddressDialog::accept()
QDialog::accept();
}

QString EditAddressDialog::getDuplicateAddressWarning() const
{
QString dup_address = ui->addressEdit->text();
QString existing_label = model->labelForAddress(dup_address);
QString existing_purpose = model->purposeForAddress(dup_address);

if (existing_purpose == "receive" &&
(mode == NewSendingAddress || mode == EditSendingAddress)) {
return tr(
"Address \"%1\" already exists as a receiving address with label "
"\"%2\" and so cannot be added as a sending address."
).arg(dup_address).arg(existing_label);
}
return tr(
"The entered address \"%1\" is already in the address book with "
"label \"%2\"."
).arg(dup_address).arg(existing_label);
}

QString EditAddressDialog::getAddress() const
{
return address;
@@ -45,6 +45,9 @@ public Q_SLOTS:
private:
bool saveCurrentRow();

/** Return a descriptive string when adding an already-existing address fails. */
QString getDuplicateAddressWarning() const;

Ui::EditAddressDialog *ui;
QDataWidgetMapper *mapper;
Mode mode;
ProTip! Use n and p to navigate between commits in a pull request.
You can’t perform that action at this time.