From fdc7a09c6c4b6fb1c3c60c6d991206a51549a729 Mon Sep 17 00:00:00 2001 From: tobtoht Date: Thu, 10 Oct 2024 14:22:47 +0200 Subject: [PATCH] coins: don't refresh for each freeze/thaw --- src/CoinsWidget.cpp | 10 ++---- src/SendWidget.h | 2 +- src/libwalletqt/Coins.cpp | 68 +++++++++++++++++++++------------------ src/libwalletqt/Coins.h | 8 ++--- 4 files changed, 43 insertions(+), 45 deletions(-) diff --git a/src/CoinsWidget.cpp b/src/CoinsWidget.cpp index 9c582da..8c15c7a 100644 --- a/src/CoinsWidget.cpp +++ b/src/CoinsWidget.cpp @@ -324,18 +324,12 @@ QVector CoinsWidget::currentEntries() { } void CoinsWidget::freezeCoins(QStringList &pubkeys) { - for (auto &pubkey : pubkeys) { - m_wallet->coins()->freeze(pubkey); - } - m_wallet->coins()->refresh(); + m_wallet->coins()->freeze(pubkeys); m_wallet->updateBalance(); } void CoinsWidget::thawCoins(QStringList &pubkeys) { - for (auto &pubkey : pubkeys) { - m_wallet->coins()->thaw(pubkey); - } - m_wallet->coins()->refresh(); + m_wallet->coins()->thaw(pubkeys); m_wallet->updateBalance(); } diff --git a/src/SendWidget.h b/src/SendWidget.h index 1b310f2..85efbf8 100644 --- a/src/SendWidget.h +++ b/src/SendWidget.h @@ -49,7 +49,7 @@ public slots: void disallowSending(); private slots: - void onDataPasted(const QString &data); + void onDataFromQR(const QString &data); private: void setupComboBox(); diff --git a/src/libwalletqt/Coins.cpp b/src/libwalletqt/Coins.cpp index c5de0aa..27b08b9 100644 --- a/src/libwalletqt/Coins.cpp +++ b/src/libwalletqt/Coins.cpp @@ -105,48 +105,52 @@ quint64 Coins::count() const return m_rows.length(); } -void Coins::freeze(QString &publicKey) +void Coins::freeze(QStringList &publicKeys) { crypto::public_key pk; - if (!epee::string_tools::hex_to_pod(publicKey.toStdString(), pk)) - { - qWarning() << "Invalid public key: " << publicKey; - return; + + for (const auto& publicKey : publicKeys) { + if (!epee::string_tools::hex_to_pod(publicKey.toStdString(), pk)) + { + qWarning() << "Invalid public key: " << publicKey; + continue; + } + + try + { + m_wallet2->freeze(pk); + } + catch (const std::exception& e) + { + qWarning() << "freeze: " << e.what(); + } } - try - { - m_wallet2->freeze(pk); - refresh(); - } - catch (const std::exception& e) - { - qWarning() << "freeze: " << e.what(); - } - - emit coinFrozen(); + refresh(); } -void Coins::thaw(QString &publicKey) +void Coins::thaw(QStringList &publicKeys) { crypto::public_key pk; - if (!epee::string_tools::hex_to_pod(publicKey.toStdString(), pk)) - { - qWarning() << "Invalid public key: " << publicKey; - return; + + for (const auto& publicKey : publicKeys) { + if (!epee::string_tools::hex_to_pod(publicKey.toStdString(), pk)) + { + qWarning() << "Invalid public key: " << publicKey; + continue; + } + + try + { + m_wallet2->thaw(pk); + } + catch (const std::exception& e) + { + qWarning() << "thaw: " << e.what(); + } } - try - { - m_wallet2->thaw(pk); - refresh(); - } - catch (const std::exception& e) - { - qWarning() << "thaw: " << e.what(); - } - - emit coinThawed(); + refresh(); } QVector Coins::coins_from_txid(const QString &txid) diff --git a/src/libwalletqt/Coins.h b/src/libwalletqt/Coins.h index ce875c0..7ea1e40 100644 --- a/src/libwalletqt/Coins.h +++ b/src/libwalletqt/Coins.h @@ -31,8 +31,10 @@ public: CoinsInfo * coin(int index); void refresh(); void refreshUnlocked(); - void freeze(QString &publicKey); - void thaw(QString &publicKey); + + void freeze(QStringList &publicKeys); + void thaw(QStringList &publicKeys); + QVector coins_from_txid(const QString &txid); QVector coinsFromKeyImage(const QStringList &keyimages); void setDescription(const QString &publicKey, quint32 accountIndex, const QString &description); @@ -43,8 +45,6 @@ public: signals: void refreshStarted() const; void refreshFinished() const; - void coinFrozen() const; - void coinThawed() const; void descriptionChanged() const; private: