Skip to content

Commit ca046aa

Browse files
committed
[UI] - Dashboard chart load, min update time interval, not update view so often when node is syncing.
- Try chart refresh when the wallet is synced.
1 parent 3c711ef commit ca046aa

File tree

2 files changed

+21
-4
lines changed

2 files changed

+21
-4
lines changed

src/qt/pivx/dashboardwidget.cpp

Lines changed: 18 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
#include "walletmodel.h"
1212
#include "clientmodel.h"
1313
#include "optionsmodel.h"
14+
#include "utiltime.h"
1415
#include <QPainter>
1516
#include <QModelIndex>
1617
#include <QList>
@@ -20,6 +21,7 @@
2021
#define NUM_ITEMS 3
2122
#define SHOW_EMPTY_CHART_VIEW_THRESHOLD 4000
2223
#define REQUEST_LOAD_TASK 1
24+
#define CHART_LOAD_MIN_TIME_INTERVAL 15
2325

2426
#include "moc_dashboardwidget.cpp"
2527

@@ -231,9 +233,8 @@ void DashboardWidget::loadWalletModel(){
231233
void DashboardWidget::onTxArrived(const QString& hash) {
232234
showList();
233235
#ifdef USE_QTCHARTS
234-
if (hasStakes() && walletModel->isCoinStakeMine(hash)) {
235-
refreshChart();
236-
}
236+
if (walletModel->isCoinStakeMine(hash))
237+
tryChartRefresh();
237238
#endif
238239
}
239240

@@ -307,6 +308,9 @@ void DashboardWidget::walletSynced(bool sync){
307308
if (this->isSync != sync) {
308309
this->isSync = sync;
309310
ui->layoutWarning->setVisible(!this->isSync);
311+
#ifdef USE_QTCHARTS
312+
tryChartRefresh();
313+
#endif
310314
}
311315
}
312316

@@ -315,11 +319,21 @@ void DashboardWidget::changeTheme(bool isLightTheme, QString& theme){
315319
#ifdef USE_QTCHARTS
316320
if (chart) this->changeChartColors();
317321
#endif
318-
319322
}
320323

321324
#ifdef USE_QTCHARTS
322325

326+
void DashboardWidget::tryChartRefresh() {
327+
if (hasStakes()) {
328+
// Check for min update time to not reload the UI so often if the node is syncing.
329+
int64_t now = GetTime();
330+
if (lastRefreshTime + CHART_LOAD_MIN_TIME_INTERVAL < now) {
331+
lastRefreshTime = now;
332+
refreshChart();
333+
}
334+
}
335+
}
336+
323337
void DashboardWidget::setChartShow(ChartShowType type) {
324338
this->chartShow = type;
325339
if (chartShow == MONTH) {

src/qt/pivx/dashboardwidget.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -142,6 +142,8 @@ private slots:
142142

143143
#ifdef USE_QTCHARTS
144144

145+
int64_t lastRefreshTime = 0;
146+
145147
// Chart
146148
TransactionFilterProxy* stakesFilter = nullptr;
147149
bool isChartInitialized = false;
@@ -166,6 +168,7 @@ private slots:
166168
void initChart();
167169
void showHideEmptyChart(bool show, bool loading, bool forceView = false);
168170
bool refreshChart();
171+
void tryChartRefresh();
169172
QMap<int, std::pair<qint64, qint64>> getAmountBy();
170173
ChartData loadChartData(bool withMonthNames);
171174
void updateAxisX(const QStringList *arg = nullptr);

0 commit comments

Comments
 (0)