]> Nutra Git (v1) - gamesguru/feather.git/commitdiff
subaddress: ensure at least one unused subaddress is available
authortobtoht <tob@featherwallet.org>
Wed, 26 Mar 2025 15:00:31 +0000 (16:00 +0100)
committertobtoht <tob@featherwallet.org>
Wed, 26 Mar 2025 15:00:31 +0000 (16:00 +0100)
src/libwalletqt/Subaddress.cpp
src/libwalletqt/Subaddress.h

index 95be89f693cbafb3f64a46977ca9c094be0ba003..b7e2ecc23c3443e408f644f45ed75f31c0b68742 100644 (file)
@@ -16,6 +16,10 @@ Subaddress::Subaddress(Wallet *wallet, tools::wallet2 *wallet2, QObject *parent)
 
     QString hidden = m_wallet->getCacheAttribute("feather.hiddenaddresses");
     m_hidden = hidden.split(",");
+
+    connect(this, &Subaddress::noUnusedSubaddresses, [this] {
+        this->addRow(m_wallet->currentSubaddressAccount(), "");
+    });
 }
 
 bool Subaddress::refresh(quint32 accountIndex)
@@ -24,6 +28,7 @@ bool Subaddress::refresh(quint32 accountIndex)
 
     m_rows.clear();
 
+    bool haveUnused = false;
     bool potentialWalletFileCorruption = false;
 
     for (quint32 i = 0; i < m_wallet2->get_num_subaddresses(accountIndex); ++i)
@@ -46,13 +51,17 @@ bool Subaddress::refresh(quint32 accountIndex)
 
         QString addressStr = QString::fromStdString(cryptonote::get_account_address_as_str(m_wallet2->nettype(), !index.is_zero(), address));
 
+        bool used = m_wallet2->get_subaddress_used({accountIndex, (uint32_t)i});
         m_rows.emplace_back(
             addressStr,
             QString::fromStdString(m_wallet2->get_subaddress_label(index)),
-            m_wallet2->get_subaddress_used({accountIndex, (uint32_t)i}),
+            used,
             this->isHidden(addressStr),
             this->isPinned(addressStr)
         );
+        if (!used && i > 0) {
+            haveUnused = true;
+        }
     }
 
     // Make sure keys are intact. We NEVER want to display incorrect addresses in case of memory corruption.
@@ -66,18 +75,30 @@ bool Subaddress::refresh(quint32 accountIndex)
 
     emit refreshFinished();
 
+    if (!haveUnused) {
+        emit noUnusedSubaddresses();
+    }
+
     return !potentialWalletFileCorruption;
 }
 
 void Subaddress::updateUsed(quint32 accountIndex)
 {
+    bool haveUnused = false;
     for (quint32 i = 0; i < m_rows.count(); i++) {
         SubaddressRow& row = m_rows[i];
 
-        if (m_wallet2->get_subaddress_used({accountIndex, i}) != row.used) {
+        bool used = m_wallet2->get_subaddress_used({accountIndex, i});
+        if (used != row.used) {
             row.used = !row.used;
             emit rowUpdated(i);
         }
+        if (!used && i > 0) {
+            haveUnused = true;
+        }
+    }
+    if (!haveUnused) {
+        emit noUnusedSubaddresses();
     }
 }
 
index 2f5f6a111b634e9dd93238813751117a95804f3e..03c0931f2c4d0cac895c8af526cbc84323292b66 100644 (file)
@@ -41,6 +41,7 @@ signals:
     void refreshFinished() const;
     void rowUpdated(qsizetype index) const;
     void corrupted() const;
+    void noUnusedSubaddresses() const;
 
 private:
     explicit Subaddress(Wallet *wallet, tools::wallet2 *wallet2, QObject *parent);