[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.
This commit is contained in:
James O'Beirne
2018-04-10 16:27:40 -04:00
parent c5b277033a
commit 8cdcaee4c7
4 changed files with 49 additions and 12 deletions

View File

@@ -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()),