fix(wallet): stop reachability checks while closed

This commit is contained in:
Ricardo Guilherme Schmidt 2026-07-17 20:05:03 -03:00
parent 969a98aa27
commit 7a09449371
No known key found for this signature in database
GPG Key ID: 1396EA17DE132FFE
3 changed files with 22 additions and 4 deletions

View File

@ -88,7 +88,6 @@ void WalletController::start()
if (m_started)
return;
m_started = true;
m_reachabilityTimer->start();
QTimer::singleShot(0, this, &WalletController::openOnStartup);
}
@ -207,6 +206,7 @@ bool WalletController::open()
void WalletController::disconnect()
{
++m_operationGeneration;
stopReachability();
m_wallet.disconnect();
m_state.isWalletOpen = false;
m_state.syncStatus = QStringLiteral("closed");
@ -276,9 +276,23 @@ void WalletController::applySnapshot(const WalletSnapshot& snapshot)
if (!snapshot.sequencerAddress.isEmpty())
m_state.sequencerAddress = snapshot.sequencerAddress;
emit stateChanged();
if (!m_reachabilityTimer->isActive())
m_reachabilityTimer->start();
checkReachability();
}
void WalletController::stopReachability()
{
m_reachabilityTimer->stop();
++m_reachabilityGeneration;
if (m_reachabilityReply) {
QNetworkReply* reply = m_reachabilityReply;
m_reachabilityReply = nullptr;
m_reachabilityEndpoint.clear();
reply->abort();
}
}
void WalletController::checkReachability()
{
if (!m_state.isWalletOpen || m_state.sequencerAddress.isEmpty())

View File

@ -65,6 +65,7 @@ private:
bool beginOpen(const QString& config, const QString& storage);
void applySnapshot(const WalletSnapshot& snapshot);
void checkReachability();
void stopReachability();
WalletProvider& m_wallet;
QString m_settingsApplication;

View File

@ -474,14 +474,17 @@ void LogosWalletProviderTest::controllerStopsReachabilityChecksAfterDisconnect()
QVERIFY(controller.open());
QTRY_VERIFY_WITH_TIMEOUT(!finished.isEmpty(), 1000);
controller.disconnect();
finished.clear();
auto* timer = controller.findChild<QTimer*>();
QVERIFY(timer);
QVERIFY(timer->isActive());
controller.disconnect();
QVERIFY(!timer->isActive());
finished.clear();
timer->setInterval(1);
controller.start();
QTest::qWait(50);
QVERIFY(!timer->isActive());
QCOMPARE(finished.count(), 0);
settings.clear();