Skip to content

Commit

Permalink
Allow sending (actually preparing tx) offline, fix cryptonotefoundati…
Browse files Browse the repository at this point in the history
…on#42

but when there's connection make user wait for sync
  • Loading branch information
aivve committed Jan 15, 2021
1 parent ff4facc commit 542ffd9
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 5 deletions.
5 changes: 5 additions & 0 deletions src/NodeAdapter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -405,6 +405,11 @@ CryptoNote::NetNodeConfig NodeAdapter::makeNetNodeConfig() const {
return config;
}

bool NodeAdapter::isOffline() {
Q_ASSERT(m_node == nullptr);
return getConnectionsCount() == 0;
}

}

#include "NodeAdapter.moc"
1 change: 1 addition & 0 deletions src/NodeAdapter.h
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@ class NodeAdapter : public QObject, public INodeCallback {
void peerCountUpdated(Node& _node, size_t _count) Q_DECL_OVERRIDE;
void localBlockchainUpdated(Node& _node, uint64_t _height) Q_DECL_OVERRIDE;
void lastKnownBlockHeightUpdated(Node& _node, uint64_t _height) Q_DECL_OVERRIDE;
bool isOffline();

private:
Node* m_node;
Expand Down
10 changes: 8 additions & 2 deletions src/WalletAdapter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -48,8 +48,7 @@ WalletAdapter& WalletAdapter::instance() {
}

WalletAdapter::WalletAdapter() : QObject(), m_wallet(nullptr), m_mutex(), m_isBackupInProgress(false),
m_syncSpeed(0), m_syncPeriod(0),
m_isSynchronized(false), m_newTransactionsNotificationTimer(),
m_syncSpeed(0), m_syncPeriod(0), m_isSynchronized(false), m_newTransactionsNotificationTimer(),
m_lastWalletTransactionId(std::numeric_limits<quint64>::max()) {
connect(this, &WalletAdapter::walletInitCompletedSignal, this, &WalletAdapter::onWalletInitCompleted, Qt::QueuedConnection);
connect(this, &WalletAdapter::walletSendTransactionCompletedSignal, this, &WalletAdapter::onWalletSendTransactionCompleted, Qt::QueuedConnection);
Expand Down Expand Up @@ -523,6 +522,13 @@ void WalletAdapter::synchronizationProgressUpdated(uint32_t _current, uint32_t _
m_perfData.clear();
}
m_isSynchronized = false;

if (NodeAdapter::instance().isOffline()) {
Q_EMIT walletStateChangedSignal(QString(tr("Offline")));
Q_EMIT walletSynchronizationProgressUpdatedSignal(_current, _total);
return;
}

const uint32_t speedCalcPeriod = 10;
const uint32_t periodDay = 60 * 60 * 24;
const uint32_t syncPeriodMax = std::numeric_limits<uint32_t>::max();
Expand Down
8 changes: 5 additions & 3 deletions src/gui/SendFrame.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ SendFrame::SendFrame(QWidget* _parent) : QFrame(_parent), m_ui(new Ui::SendFrame
m_ui->m_feeSpin->setSuffix(" " + CurrencyAdapter::instance().getCurrencyTicker().toUpper());
m_ui->m_donateSpin->setSuffix(" " + CurrencyAdapter::instance().getCurrencyTicker().toUpper());
m_ui->m_remote_label->hide();
m_ui->m_sendButton->setEnabled(false);
//m_ui->m_sendButton->setEnabled(false);
m_ui->m_feeSpin->setMinimum(getMinimalFee());

QLabel *label1 = new QLabel(tr("Low"), this);
Expand Down Expand Up @@ -100,8 +100,10 @@ void SendFrame::walletSynchronized(int _error, const QString& _error_text) {
}

void SendFrame::walletSynchronizationInProgress(quint64 _current, quint64 _total) {
m_glassFrame->install(this);
m_glassFrame->updateSynchronizationState(_current, _total);
if (!NodeAdapter::instance().isOffline()) {
m_glassFrame->install(this);
m_glassFrame->updateSynchronizationState(_current, _total);
}
}

void SendFrame::setAddress(const QString& _address) {
Expand Down

0 comments on commit 542ffd9

Please sign in to comment.