Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix behavior when switching nodes #4036

Merged
merged 1 commit into from
Sep 28, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 21 additions & 8 deletions src/libwalletqt/Wallet.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -101,20 +101,30 @@ NetworkType::Type Wallet::nettype() const
void Wallet::updateConnectionStatusAsync()
{
m_scheduler.run([this] {
qDebug() << "updateConnectionStatusAsync current status:" << m_connectionStatus;
if (m_connectionStatus == Wallet::ConnectionStatus_Disconnected)
{
setConnectionStatus(ConnectionStatus_Connecting);
}
ConnectionStatus newStatus = static_cast<ConnectionStatus>(m_walletImpl->connected());
setConnectionStatus(newStatus);
qDebug() << "Newest wallet status:" << newStatus;
if (m_connectionStatus != newStatus)
{
setConnectionStatus(newStatus);
if (newStatus == ConnectionStatus_Connected)
{
startRefresh();
}
}
// Release lock
m_connectionStatusRunning = false;
m_connectionStatusTime.restart();
});
}

Wallet::ConnectionStatus Wallet::connected(bool forceCheck)
{
if (!m_initialized)
if (!m_initialized || m_initializing)
{
return ConnectionStatus_Connecting;
}
Expand All @@ -123,7 +133,6 @@ Wallet::ConnectionStatus Wallet::connected(bool forceCheck)
if (forceCheck || (m_connectionStatusTime.elapsed() / 1000 > m_connectionStatusTtl && !m_connectionStatusRunning) || m_connectionStatusTime.elapsed() > 30000) {
qDebug() << "Checking connection status";
m_connectionStatusRunning = true;
m_connectionStatusTime.restart();
updateConnectionStatusAsync();
}

Expand Down Expand Up @@ -156,10 +165,9 @@ void Wallet::setConnectionStatus(ConnectionStatus value)
}

m_connectionStatus = value;
emit connectionStatusChanged(m_connectionStatus);
emit connectionStatusChanged(value);

bool disconnected = m_connectionStatus == Wallet::ConnectionStatus_Connecting ||
m_connectionStatus == Wallet::ConnectionStatus_Disconnected;
bool disconnected = value != Wallet::ConnectionStatus_Connected;

if (m_disconnected != disconnected)
{
Expand Down Expand Up @@ -280,6 +288,8 @@ void Wallet::initAsync(
const QString &proxyAddress /* = "" */)
{
qDebug() << "initAsync: " + daemonAddress;
m_initializing = true;
pauseRefresh();
const auto future = m_scheduler.run([this, daemonAddress, trustedDaemon, upperTransactionLimit, isRecovering, isRecoveringFromDevice, restoreHeight, proxyAddress] {
m_initialized = init(
daemonAddress,
Expand All @@ -289,12 +299,12 @@ void Wallet::initAsync(
isRecoveringFromDevice,
restoreHeight,
proxyAddress);
m_initializing = false;
if (m_initialized)
{
emit walletCreationHeightChanged();
qDebug() << "init async finished - starting refresh";
qDebug() << "init async finished: " + daemonAddress;
connected(true);
startRefresh();
}
else
{
Expand Down Expand Up @@ -544,12 +554,14 @@ bool Wallet::refresh(bool historyAndSubaddresses /* = true */)

void Wallet::startRefresh()
{
qDebug() << "Starting refresh";
m_refreshEnabled = true;
m_refreshNow = true;
}

void Wallet::pauseRefresh()
{
qDebug() << "Pausing refresh";
m_refreshEnabled = false;
}

Expand Down Expand Up @@ -1138,6 +1150,7 @@ Wallet::Wallet(Monero::Wallet *w, QObject *parent)
, m_connectionStatusTtl(WALLET_CONNECTION_STATUS_CACHE_TTL_SECONDS)
, m_disconnected(true)
, m_initialized(false)
, m_initializing(false)
, m_currentSubaddressAccount(0)
, m_subaddress(new Subaddress(m_walletImpl->subaddress(), this))
, m_subaddressModel(nullptr)
Expand Down
1 change: 1 addition & 0 deletions src/libwalletqt/Wallet.h
Original file line number Diff line number Diff line change
Expand Up @@ -461,6 +461,7 @@ class Wallet : public QObject, public PassprasePrompter
mutable QElapsedTimer m_connectionStatusTime;
bool m_disconnected;
std::atomic<bool> m_initialized;
std::atomic<bool> m_initializing;
uint32_t m_currentSubaddressAccount;
Subaddress * m_subaddress;
mutable SubaddressModel * m_subaddressModel;
Expand Down