mirror of
https://github.com/feather-wallet/feather.git
synced 2025-01-03 17:39:49 +00:00
Calc: status warning
This commit is contained in:
parent
dac8769e7e
commit
b8018d61a2
5 changed files with 107 additions and 38 deletions
|
@ -10,6 +10,8 @@
|
||||||
#include "utils/AppData.h"
|
#include "utils/AppData.h"
|
||||||
#include "utils/ColorScheme.h"
|
#include "utils/ColorScheme.h"
|
||||||
#include "utils/config.h"
|
#include "utils/config.h"
|
||||||
|
#include "utils/WebsocketClient.h"
|
||||||
|
#include "utils/WebsocketNotifier.h"
|
||||||
|
|
||||||
CalcWidget::CalcWidget(QWidget *parent)
|
CalcWidget::CalcWidget(QWidget *parent)
|
||||||
: QWidget(parent)
|
: QWidget(parent)
|
||||||
|
@ -44,6 +46,13 @@ CalcWidget::CalcWidget(QWidget *parent)
|
||||||
QTimer::singleShot(1, [this]{
|
QTimer::singleShot(1, [this]{
|
||||||
this->skinChanged();
|
this->skinChanged();
|
||||||
});
|
});
|
||||||
|
|
||||||
|
m_statusTimer.start(5000);
|
||||||
|
connect(&m_statusTimer, &QTimer::timeout, this, &CalcWidget::updateStatus);
|
||||||
|
QPixmap warningIcon = QPixmap(":/assets/images/warning.png");
|
||||||
|
ui->icon_warning->setPixmap(warningIcon.scaledToWidth(32, Qt::SmoothTransformation));
|
||||||
|
|
||||||
|
this->updateStatus();
|
||||||
}
|
}
|
||||||
|
|
||||||
void CalcWidget::convert(bool reverse) {
|
void CalcWidget::convert(bool reverse) {
|
||||||
|
@ -86,6 +95,7 @@ void CalcWidget::onPricesReceived() {
|
||||||
ui->btn_configure->setEnabled(true);
|
ui->btn_configure->setEnabled(true);
|
||||||
this->initComboBox();
|
this->initComboBox();
|
||||||
m_comboBoxInit = true;
|
m_comboBoxInit = true;
|
||||||
|
this->updateStatus();
|
||||||
}
|
}
|
||||||
|
|
||||||
void CalcWidget::initComboBox() {
|
void CalcWidget::initComboBox() {
|
||||||
|
@ -144,4 +154,18 @@ void CalcWidget::setupComboBox(QComboBox *comboBox, const QStringList &crypto, c
|
||||||
comboBox->addItems(fiat);
|
comboBox->addItems(fiat);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void CalcWidget::updateStatus() {
|
||||||
|
if (!m_comboBoxInit) {
|
||||||
|
ui->label_warning->setText("Waiting on exchange data.");
|
||||||
|
ui->frame_warning->show();
|
||||||
|
}
|
||||||
|
else if (websocketNotifier()->stale(10)) {
|
||||||
|
ui->label_warning->setText("No new exchange rates received for over 10 minutes.");
|
||||||
|
ui->frame_warning->show();
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
ui->frame_warning->hide();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
CalcWidget::~CalcWidget() = default;
|
CalcWidget::~CalcWidget() = default;
|
|
@ -6,6 +6,7 @@
|
||||||
|
|
||||||
#include <QWidget>
|
#include <QWidget>
|
||||||
#include <QComboBox>
|
#include <QComboBox>
|
||||||
|
#include <QTimer>
|
||||||
|
|
||||||
namespace Ui {
|
namespace Ui {
|
||||||
class CalcWidget;
|
class CalcWidget;
|
||||||
|
@ -30,9 +31,11 @@ private slots:
|
||||||
private:
|
private:
|
||||||
void convert(bool reverse);
|
void convert(bool reverse);
|
||||||
void setupComboBox(QComboBox *comboBox, const QStringList &crypto, const QStringList &fiat);
|
void setupComboBox(QComboBox *comboBox, const QStringList &crypto, const QStringList &fiat);
|
||||||
|
void updateStatus();
|
||||||
|
|
||||||
QScopedPointer<Ui::CalcWidget> ui;
|
QScopedPointer<Ui::CalcWidget> ui;
|
||||||
bool m_comboBoxInit = false;
|
bool m_comboBoxInit = false;
|
||||||
|
QTimer m_statusTimer;
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif // FEATHER_CALCWIDGET_H
|
#endif // FEATHER_CALCWIDGET_H
|
||||||
|
|
|
@ -7,7 +7,7 @@
|
||||||
<x>0</x>
|
<x>0</x>
|
||||||
<y>0</y>
|
<y>0</y>
|
||||||
<width>800</width>
|
<width>800</width>
|
||||||
<height>132</height>
|
<height>242</height>
|
||||||
</rect>
|
</rect>
|
||||||
</property>
|
</property>
|
||||||
<property name="windowTitle">
|
<property name="windowTitle">
|
||||||
|
@ -15,41 +15,51 @@
|
||||||
</property>
|
</property>
|
||||||
<layout class="QVBoxLayout" name="verticalLayout_2">
|
<layout class="QVBoxLayout" name="verticalLayout_2">
|
||||||
<item>
|
<item>
|
||||||
<layout class="QHBoxLayout" name="horizontalLayout">
|
<widget class="QFrame" name="frame_warning">
|
||||||
<item>
|
<property name="frameShape">
|
||||||
<widget class="QLabel" name="label_2">
|
<enum>QFrame::StyledPanel</enum>
|
||||||
<property name="text">
|
|
||||||
<string>Crypto/fiat and fiat/fiat calculator.</string>
|
|
||||||
</property>
|
|
||||||
</widget>
|
|
||||||
</item>
|
|
||||||
<item>
|
|
||||||
<spacer name="horizontalSpacer">
|
|
||||||
<property name="orientation">
|
|
||||||
<enum>Qt::Horizontal</enum>
|
|
||||||
</property>
|
|
||||||
<property name="sizeHint" stdset="0">
|
|
||||||
<size>
|
|
||||||
<width>40</width>
|
|
||||||
<height>20</height>
|
|
||||||
</size>
|
|
||||||
</property>
|
|
||||||
</spacer>
|
|
||||||
</item>
|
|
||||||
<item>
|
|
||||||
<widget class="QPushButton" name="btn_configure">
|
|
||||||
<property name="text">
|
|
||||||
<string>Configure</string>
|
|
||||||
</property>
|
|
||||||
</widget>
|
|
||||||
</item>
|
|
||||||
</layout>
|
|
||||||
</item>
|
|
||||||
<item>
|
|
||||||
<widget class="Line" name="line">
|
|
||||||
<property name="orientation">
|
|
||||||
<enum>Qt::Horizontal</enum>
|
|
||||||
</property>
|
</property>
|
||||||
|
<property name="frameShadow">
|
||||||
|
<enum>QFrame::Raised</enum>
|
||||||
|
</property>
|
||||||
|
<layout class="QHBoxLayout" name="horizontalLayout_3">
|
||||||
|
<item>
|
||||||
|
<widget class="QLabel" name="icon_warning">
|
||||||
|
<property name="sizePolicy">
|
||||||
|
<sizepolicy hsizetype="Maximum" vsizetype="Preferred">
|
||||||
|
<horstretch>0</horstretch>
|
||||||
|
<verstretch>0</verstretch>
|
||||||
|
</sizepolicy>
|
||||||
|
</property>
|
||||||
|
<property name="text">
|
||||||
|
<string>icon</string>
|
||||||
|
</property>
|
||||||
|
</widget>
|
||||||
|
</item>
|
||||||
|
<item>
|
||||||
|
<spacer name="horizontalSpacer_2">
|
||||||
|
<property name="orientation">
|
||||||
|
<enum>Qt::Horizontal</enum>
|
||||||
|
</property>
|
||||||
|
<property name="sizeType">
|
||||||
|
<enum>QSizePolicy::Maximum</enum>
|
||||||
|
</property>
|
||||||
|
<property name="sizeHint" stdset="0">
|
||||||
|
<size>
|
||||||
|
<width>10</width>
|
||||||
|
<height>20</height>
|
||||||
|
</size>
|
||||||
|
</property>
|
||||||
|
</spacer>
|
||||||
|
</item>
|
||||||
|
<item>
|
||||||
|
<widget class="QLabel" name="label_warning">
|
||||||
|
<property name="text">
|
||||||
|
<string>Warning text</string>
|
||||||
|
</property>
|
||||||
|
</widget>
|
||||||
|
</item>
|
||||||
|
</layout>
|
||||||
</widget>
|
</widget>
|
||||||
</item>
|
</item>
|
||||||
<item>
|
<item>
|
||||||
|
@ -122,12 +132,36 @@
|
||||||
</layout>
|
</layout>
|
||||||
</item>
|
</item>
|
||||||
<item>
|
<item>
|
||||||
<widget class="QLabel" name="labelWarning">
|
<widget class="Line" name="line">
|
||||||
<property name="text">
|
<property name="orientation">
|
||||||
<string>Exchange rates are updated every 2 minutes.</string>
|
<enum>Qt::Horizontal</enum>
|
||||||
</property>
|
</property>
|
||||||
</widget>
|
</widget>
|
||||||
</item>
|
</item>
|
||||||
|
<item>
|
||||||
|
<layout class="QHBoxLayout" name="horizontalLayout">
|
||||||
|
<item>
|
||||||
|
<spacer name="horizontalSpacer">
|
||||||
|
<property name="orientation">
|
||||||
|
<enum>Qt::Horizontal</enum>
|
||||||
|
</property>
|
||||||
|
<property name="sizeHint" stdset="0">
|
||||||
|
<size>
|
||||||
|
<width>40</width>
|
||||||
|
<height>20</height>
|
||||||
|
</size>
|
||||||
|
</property>
|
||||||
|
</spacer>
|
||||||
|
</item>
|
||||||
|
<item>
|
||||||
|
<widget class="QPushButton" name="btn_configure">
|
||||||
|
<property name="text">
|
||||||
|
<string>Configure</string>
|
||||||
|
</property>
|
||||||
|
</widget>
|
||||||
|
</item>
|
||||||
|
</layout>
|
||||||
|
</item>
|
||||||
</layout>
|
</layout>
|
||||||
</widget>
|
</widget>
|
||||||
<customwidgets>
|
<customwidgets>
|
||||||
|
|
|
@ -20,6 +20,7 @@ QPointer<WebsocketNotifier> WebsocketNotifier::m_instance(nullptr);
|
||||||
void WebsocketNotifier::onWSMessage(const QJsonObject &msg) {
|
void WebsocketNotifier::onWSMessage(const QJsonObject &msg) {
|
||||||
QString cmd = msg.value("cmd").toString();
|
QString cmd = msg.value("cmd").toString();
|
||||||
|
|
||||||
|
m_lastMessageReceived = QDateTime::currentDateTimeUtc();
|
||||||
m_cache[cmd] = msg;
|
m_cache[cmd] = msg;
|
||||||
|
|
||||||
if (cmd == "blockheights") {
|
if (cmd == "blockheights") {
|
||||||
|
@ -92,6 +93,10 @@ void WebsocketNotifier::emitCache() {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool WebsocketNotifier::stale(int minutes) {
|
||||||
|
return m_lastMessageReceived < QDateTime::currentDateTimeUtc().addSecs(-(minutes*60));
|
||||||
|
}
|
||||||
|
|
||||||
void WebsocketNotifier::onWSNodes(const QJsonArray &nodes) {
|
void WebsocketNotifier::onWSNodes(const QJsonArray &nodes) {
|
||||||
// TODO: Refactor, should be filtered client side
|
// TODO: Refactor, should be filtered client side
|
||||||
|
|
||||||
|
|
|
@ -27,6 +27,8 @@ public:
|
||||||
static WebsocketNotifier* instance();
|
static WebsocketNotifier* instance();
|
||||||
void emitCache();
|
void emitCache();
|
||||||
|
|
||||||
|
bool stale(int minutes);
|
||||||
|
|
||||||
signals:
|
signals:
|
||||||
void BlockHeightsReceived(int mainnet, int stagenet);
|
void BlockHeightsReceived(int mainnet, int stagenet);
|
||||||
void NodesReceived(QList<FeatherNode> &L);
|
void NodesReceived(QList<FeatherNode> &L);
|
||||||
|
@ -54,6 +56,7 @@ private:
|
||||||
static QPointer<WebsocketNotifier> m_instance;
|
static QPointer<WebsocketNotifier> m_instance;
|
||||||
|
|
||||||
QHash<QString, QJsonObject> m_cache;
|
QHash<QString, QJsonObject> m_cache;
|
||||||
|
QDateTime m_lastMessageReceived;
|
||||||
};
|
};
|
||||||
|
|
||||||
inline WebsocketNotifier* websocketNotifier()
|
inline WebsocketNotifier* websocketNotifier()
|
||||||
|
|
Loading…
Reference in a new issue