contacts: allow swapping name and address

This commit is contained in:
tobtoht
2023-12-30 16:05:52 +01:00
parent 7e74d0e1d1
commit 7e19d52788
2 changed files with 23 additions and 11 deletions
+13 -1
View File
@@ -126,11 +126,23 @@ void ContactsWidget::newContact(QString address, QString name)
name = dialog.getName();
bool addressValid = WalletManager::addressValid(address, m_wallet->nettype());
if (!addressValid) {
bool nameIsAddress = WalletManager::addressValid(name, m_wallet->nettype());
if (addressValid && nameIsAddress) {
Utils::showError(this, "Unable to add contact", "Name can not be an address", {}, "add_contact");
return;
}
if (!addressValid && !nameIsAddress) {
Utils::showError(this, "Unable to add contact", "Invalid address", {"Use 'Tools -> Address checker' to check if the address is valid."}, "add_contact");
return;
}
if (!addressValid && nameIsAddress) {
// User accidentally swapped name and address, allow it
std::swap(address, name);
}
int num_addresses = m_wallet->addressBook()->count();
QString address_entry;
QString name_entry;