]> Nutra Git (v1) - gamesguru/feather.git/commitdiff
contacts: allow swapping name and address
authortobtoht <tob@featherwallet.org>
Sat, 30 Dec 2023 15:05:52 +0000 (16:05 +0100)
committertobtoht <tob@featherwallet.org>
Sat, 30 Dec 2023 15:05:52 +0000 (16:05 +0100)
src/ContactsWidget.cpp
src/dialog/ContactsDialog.ui

index ecb67fbbb0cd823a14e4324153b20967cdab02b9..7a32b46b26f46c1ebd68aac50dd5ac3795b80a72 100644 (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;
index 1ec06bbae5df47161a22b88cfaf3037bda725420..e8d176aa5051b0f92c0d7b15d4af232ed458e720 100644 (file)
@@ -7,7 +7,7 @@
     <x>0</x>
     <y>0</y>
     <width>400</width>
-    <height>136</height>
+    <height>131</height>
    </rect>
   </property>
   <property name="windowTitle">
    <item>
     <layout class="QFormLayout" name="formLayout">
      <item row="0" column="0">
-      <widget class="QLabel" name="label_2">
+      <widget class="QLabel" name="label_3">
        <property name="text">
-        <string>Address</string>
+        <string>Name</string>
        </property>
       </widget>
      </item>
+     <item row="0" column="1">
+      <widget class="QLineEdit" name="lineEdit_name"/>
+     </item>
      <item row="1" column="0">
-      <widget class="QLabel" name="label_3">
+      <widget class="QLabel" name="label_2">
        <property name="text">
-        <string>Name</string>
+        <string>Address</string>
        </property>
       </widget>
      </item>
-     <item row="0" column="1">
-      <widget class="QLineEdit" name="lineEdit_address"/>
-     </item>
      <item row="1" column="1">
-      <widget class="QLineEdit" name="lineEdit_name"/>
+      <widget class="QLineEdit" name="lineEdit_address"/>
      </item>
     </layout>
    </item>