From: tobtoht Date: Sat, 30 Dec 2023 15:05:52 +0000 (+0100) Subject: contacts: allow swapping name and address X-Git-Url: https://git.nutra.tk/v1?a=commitdiff_plain;h=7e19d52788d9eb6950d45e87e64811608fad9bf2;p=gamesguru%2Ffeather.git contacts: allow swapping name and address --- diff --git a/src/ContactsWidget.cpp b/src/ContactsWidget.cpp index ecb67fbb..7a32b46b 100644 --- a/src/ContactsWidget.cpp +++ b/src/ContactsWidget.cpp @@ -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; diff --git a/src/dialog/ContactsDialog.ui b/src/dialog/ContactsDialog.ui index 1ec06bba..e8d176aa 100644 --- a/src/dialog/ContactsDialog.ui +++ b/src/dialog/ContactsDialog.ui @@ -7,7 +7,7 @@ 0 0 400 - 136 + 131 @@ -17,24 +17,24 @@ - + - Address + Name + + + - + - Name + Address - - - - +