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/ColorScheme.h"
|
||||
#include "utils/config.h"
|
||||
#include "utils/WebsocketClient.h"
|
||||
#include "utils/WebsocketNotifier.h"
|
||||
|
||||
CalcWidget::CalcWidget(QWidget *parent)
|
||||
: QWidget(parent)
|
||||
|
@ -44,6 +46,13 @@ CalcWidget::CalcWidget(QWidget *parent)
|
|||
QTimer::singleShot(1, [this]{
|
||||
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) {
|
||||
|
@ -86,6 +95,7 @@ void CalcWidget::onPricesReceived() {
|
|||
ui->btn_configure->setEnabled(true);
|
||||
this->initComboBox();
|
||||
m_comboBoxInit = true;
|
||||
this->updateStatus();
|
||||
}
|
||||
|
||||
void CalcWidget::initComboBox() {
|
||||
|
@ -144,4 +154,18 @@ void CalcWidget::setupComboBox(QComboBox *comboBox, const QStringList &crypto, c
|
|||
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;
|
|
@ -6,6 +6,7 @@
|
|||
|
||||
#include <QWidget>
|
||||
#include <QComboBox>
|
||||
#include <QTimer>
|
||||
|
||||
namespace Ui {
|
||||
class CalcWidget;
|
||||
|
@ -30,9 +31,11 @@ private slots:
|
|||
private:
|
||||
void convert(bool reverse);
|
||||
void setupComboBox(QComboBox *comboBox, const QStringList &crypto, const QStringList &fiat);
|
||||
void updateStatus();
|
||||
|
||||
QScopedPointer<Ui::CalcWidget> ui;
|
||||
bool m_comboBoxInit = false;
|
||||
QTimer m_statusTimer;
|
||||
};
|
||||
|
||||
#endif // FEATHER_CALCWIDGET_H
|
||||
|
|
|
@ -7,7 +7,7 @@
|
|||
<x>0</x>
|
||||
<y>0</y>
|
||||
<width>800</width>
|
||||
<height>132</height>
|
||||
<height>242</height>
|
||||
</rect>
|
||||
</property>
|
||||
<property name="windowTitle">
|
||||
|
@ -15,41 +15,51 @@
|
|||
</property>
|
||||
<layout class="QVBoxLayout" name="verticalLayout_2">
|
||||
<item>
|
||||
<layout class="QHBoxLayout" name="horizontalLayout">
|
||||
<widget class="QFrame" name="frame_warning">
|
||||
<property name="frameShape">
|
||||
<enum>QFrame::StyledPanel</enum>
|
||||
</property>
|
||||
<property name="frameShadow">
|
||||
<enum>QFrame::Raised</enum>
|
||||
</property>
|
||||
<layout class="QHBoxLayout" name="horizontalLayout_3">
|
||||
<item>
|
||||
<widget class="QLabel" name="label_2">
|
||||
<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>Crypto/fiat and fiat/fiat calculator.</string>
|
||||
<string>icon</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<spacer name="horizontalSpacer">
|
||||
<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>40</width>
|
||||
<width>10</width>
|
||||
<height>20</height>
|
||||
</size>
|
||||
</property>
|
||||
</spacer>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QPushButton" name="btn_configure">
|
||||
<widget class="QLabel" name="label_warning">
|
||||
<property name="text">
|
||||
<string>Configure</string>
|
||||
<string>Warning text</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
</layout>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="Line" name="line">
|
||||
<property name="orientation">
|
||||
<enum>Qt::Horizontal</enum>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
|
@ -122,12 +132,36 @@
|
|||
</layout>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QLabel" name="labelWarning">
|
||||
<property name="text">
|
||||
<string>Exchange rates are updated every 2 minutes.</string>
|
||||
<widget class="Line" name="line">
|
||||
<property name="orientation">
|
||||
<enum>Qt::Horizontal</enum>
|
||||
</property>
|
||||
</widget>
|
||||
</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>
|
||||
</widget>
|
||||
<customwidgets>
|
||||
|
|
|
@ -20,6 +20,7 @@ QPointer<WebsocketNotifier> WebsocketNotifier::m_instance(nullptr);
|
|||
void WebsocketNotifier::onWSMessage(const QJsonObject &msg) {
|
||||
QString cmd = msg.value("cmd").toString();
|
||||
|
||||
m_lastMessageReceived = QDateTime::currentDateTimeUtc();
|
||||
m_cache[cmd] = msg;
|
||||
|
||||
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) {
|
||||
// TODO: Refactor, should be filtered client side
|
||||
|
||||
|
|
|
@ -27,6 +27,8 @@ public:
|
|||
static WebsocketNotifier* instance();
|
||||
void emitCache();
|
||||
|
||||
bool stale(int minutes);
|
||||
|
||||
signals:
|
||||
void BlockHeightsReceived(int mainnet, int stagenet);
|
||||
void NodesReceived(QList<FeatherNode> &L);
|
||||
|
@ -54,6 +56,7 @@ private:
|
|||
static QPointer<WebsocketNotifier> m_instance;
|
||||
|
||||
QHash<QString, QJsonObject> m_cache;
|
||||
QDateTime m_lastMessageReceived;
|
||||
};
|
||||
|
||||
inline WebsocketNotifier* websocketNotifier()
|
||||
|
|
Loading…
Reference in a new issue