]> Nutra Git (v1) - gamesguru/feather.git/commitdiff
Calc: status warning
authortobtoht <thotbot@protonmail.com>
Wed, 23 Feb 2022 22:27:20 +0000 (23:27 +0100)
committertobtoht <thotbot@protonmail.com>
Wed, 23 Feb 2022 23:40:54 +0000 (00:40 +0100)
src/CalcWidget.cpp
src/CalcWidget.h
src/CalcWidget.ui
src/utils/WebsocketNotifier.cpp
src/utils/WebsocketNotifier.h

index 91c0cabc82b750ac1a91dc601de6f0d28b13824d..69050d758f5b0f63bea230c8a07e46befa4c666c 100644 (file)
@@ -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;
\ No newline at end of file
index 2a1a2917b0b22305e01f152eefa225b0f515de85..3c5da01976b9a3d720b081f2ead2fd24941dd7c7 100644 (file)
@@ -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
index 3fa1db2bf88c4a2aea05f505404ac3840273dfa9..1c4bf02bd130e398861d77d43931a5a3c49ab010 100644 (file)
@@ -7,7 +7,7 @@
     <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>
index ee1edd754dc5869ca52080187a90e314f1b0089c..ad436df1b7dce7dea1adbd17e08e40bc597ccebe 100644 (file)
@@ -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
 
index 5fb7eed2f7220ffd51c1a2a9f457a71c4c8d77a8..388a9d4527fbdc55b1a8be7a3b618e70bfa61a55 100644 (file)
@@ -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()