From 7e19d52788d9eb6950d45e87e64811608fad9bf2 Mon Sep 17 00:00:00 2001 From: tobtoht Date: Sat, 30 Dec 2023 16:05:52 +0100 Subject: [PATCH] contacts: allow swapping name and address --- src/ContactsWidget.cpp | 14 +++++++++++++- src/dialog/ContactsDialog.ui | 20 ++++++++++---------- 2 files changed, 23 insertions(+), 11 deletions(-) diff --git a/src/ContactsWidget.cpp b/src/ContactsWidget.cpp index ecb67fb..7a32b46 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 1ec06bb..e8d176a 100644 --- a/src/dialog/ContactsDialog.ui +++ b/src/dialog/ContactsDialog.ui @@ -7,7 +7,7 @@ 0 0 400 - 136 + 131 @@ -17,13 +17,6 @@ - - - Address - - - - Name @@ -31,10 +24,17 @@ - + + + + + + Address + + - +