Merge pull request #4036

6f2aafd Fix behavior when switching nodes (j-berman)
This commit is contained in:
luigi1111 2022-09-28 14:20:56 -05:00
commit 085f4af1dc
No known key found for this signature in database
GPG key ID: F4ACA0183641E010
2 changed files with 22 additions and 8 deletions

View file

@ -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;
}
@ -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();
}
@ -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)
{
@ -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,
@ -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
{
@ -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;
}
@ -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)

View file

@ -461,6 +461,7 @@ private:
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;