#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)
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) {
ui->btn_configure->setEnabled(true);
this->initComboBox();
m_comboBoxInit = true;
+ this->updateStatus();
}
void CalcWidget::initComboBox() {
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;
\ No newline at end of file
#include <QWidget>
#include <QComboBox>
+#include <QTimer>
namespace Ui {
class CalcWidget;
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
<x>0</x>
<y>0</y>
<width>800</width>
- <height>132</height>
+ <height>242</height>
</rect>
</property>
<property name="windowTitle">
</property>
<layout class="QVBoxLayout" name="verticalLayout_2">
<item>
- <layout class="QHBoxLayout" name="horizontalLayout">
- <item>
- <widget class="QLabel" name="label_2">
- <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>
+ <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="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>
</item>
<item>
</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>
void WebsocketNotifier::onWSMessage(const QJsonObject &msg) {
QString cmd = msg.value("cmd").toString();
+ m_lastMessageReceived = QDateTime::currentDateTimeUtc();
m_cache[cmd] = msg;
if (cmd == "blockheights") {
}
}
+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
static WebsocketNotifier* instance();
void emitCache();
+ bool stale(int minutes);
+
signals:
void BlockHeightsReceived(int mainnet, int stagenet);
void NodesReceived(QList<FeatherNode> &L);
static QPointer<WebsocketNotifier> m_instance;
QHash<QString, QJsonObject> m_cache;
+ QDateTime m_lastMessageReceived;
};
inline WebsocketNotifier* websocketNotifier()