Include Satoshi ticker, include Monero ticker, and introduce 24h pct change for WOW
This commit is contained in:
parent
096b28318c
commit
2ccefe0883
|
@ -7,6 +7,7 @@
|
||||||
#include <QCoreApplication>
|
#include <QCoreApplication>
|
||||||
#include <QSystemTrayIcon>
|
#include <QSystemTrayIcon>
|
||||||
#include <QMessageBox>
|
#include <QMessageBox>
|
||||||
|
#include <QGroupBox>
|
||||||
#include <QFileDialog>
|
#include <QFileDialog>
|
||||||
|
|
||||||
#include "mainwindow.h"
|
#include "mainwindow.h"
|
||||||
|
@ -129,15 +130,29 @@ MainWindow::MainWindow(AppContext *ctx, QWidget *parent) :
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
// ticker widgets
|
// ticker widgets
|
||||||
m_tickerWidgets.append(new TickerWidget(this, "WOW"));
|
m_tickerWOW = new TickerWidget(this, "WOW");
|
||||||
m_tickerWidgets.append(new TickerWidget(this, "BTC"));
|
ui->tickerLayout->addWidget(m_tickerWOW);
|
||||||
for(auto tickerWidget: m_tickerWidgets) {
|
|
||||||
ui->tickerLayout->addWidget(tickerWidget);
|
|
||||||
}
|
|
||||||
|
|
||||||
m_balanceWidget = new TickerWidget(this, "WOW", "Balance", true, true);
|
m_tickerSAT = new TickerWidget(this, "Satoshi");
|
||||||
|
m_tickerSAT->hidePct(true);
|
||||||
|
ui->tickerLayout->addWidget(m_tickerSAT);
|
||||||
|
|
||||||
|
m_tickerBTC = new TickerWidget(this, "BTC");
|
||||||
|
ui->tickerLayout->addWidget(m_tickerBTC);
|
||||||
|
|
||||||
|
m_tickerXMR = new TickerWidget(this, "XMR");
|
||||||
|
ui->tickerLayout->addWidget(m_tickerXMR);
|
||||||
|
|
||||||
|
m_balanceWidget = new TickerWidget(this, "Balance");
|
||||||
|
m_balanceWidget->hidePct(true);
|
||||||
ui->fiatTickerLayout->addWidget(m_balanceWidget);
|
ui->fiatTickerLayout->addWidget(m_balanceWidget);
|
||||||
|
|
||||||
|
connect(m_tickerWOW, &TickerWidget::reload, this, &MainWindow::onUpdateWowWidget);
|
||||||
|
connect(m_tickerBTC, &TickerWidget::reload, this, &MainWindow::onUpdateBTCWidget);
|
||||||
|
connect(m_tickerSAT, &TickerWidget::reload, this, &MainWindow::onUpdateSATWidget);
|
||||||
|
connect(m_tickerSAT, &TickerWidget::reload, this, &MainWindow::onUpdateXMRWidget);
|
||||||
|
connect(m_balanceWidget, &TickerWidget::reload, this, &MainWindow::onUpdateFiatBalanceWidget);
|
||||||
|
|
||||||
// Send widget
|
// Send widget
|
||||||
connect(ui->sendWidget, &SendWidget::createTransaction, m_ctx, QOverload<const QString, quint64, const QString, bool>::of(&AppContext::onCreateTransaction));
|
connect(ui->sendWidget, &SendWidget::createTransaction, m_ctx, QOverload<const QString, quint64, const QString, bool>::of(&AppContext::onCreateTransaction));
|
||||||
connect(ui->sendWidget, &SendWidget::createTransactionMultiDest, m_ctx, &AppContext::onCreateTransactionMultiDest);
|
connect(ui->sendWidget, &SendWidget::createTransactionMultiDest, m_ctx, &AppContext::onCreateTransactionMultiDest);
|
||||||
|
@ -252,10 +267,7 @@ MainWindow::MainWindow(AppContext *ctx, QWidget *parent) :
|
||||||
}
|
}
|
||||||
|
|
||||||
// settings connects
|
// settings connects
|
||||||
// Update ticker widget(s) on home tab when settings preferred fiat currency is changed
|
connect(m_windowSettings, &Settings::preferredFiatCurrencyChanged, this, &MainWindow::onUpdateFiatBalanceWidget);
|
||||||
for(auto tickerWidget: m_tickerWidgets)
|
|
||||||
connect(m_windowSettings, &Settings::preferredFiatCurrencyChanged, tickerWidget, &TickerWidget::init);
|
|
||||||
connect(m_windowSettings, &Settings::preferredFiatCurrencyChanged, m_balanceWidget, &TickerWidget::init);
|
|
||||||
connect(m_windowSettings, &Settings::preferredFiatCurrencyChanged, m_ctx, &AppContext::onPreferredFiatCurrencyChanged);
|
connect(m_windowSettings, &Settings::preferredFiatCurrencyChanged, m_ctx, &AppContext::onPreferredFiatCurrencyChanged);
|
||||||
connect(m_windowSettings, &Settings::preferredFiatCurrencyChanged, ui->sendWidget, QOverload<>::of(&SendWidget::onPreferredFiatCurrencyChanged));
|
connect(m_windowSettings, &Settings::preferredFiatCurrencyChanged, ui->sendWidget, QOverload<>::of(&SendWidget::onPreferredFiatCurrencyChanged));
|
||||||
|
|
||||||
|
@ -632,7 +644,6 @@ void MainWindow::onBalanceUpdated(quint64 balance, quint64 spendable) {
|
||||||
|
|
||||||
m_statusLabelBalance->setToolTip("Click for details");
|
m_statusLabelBalance->setToolTip("Click for details");
|
||||||
m_statusLabelBalance->setText(label_str);
|
m_statusLabelBalance->setText(label_str);
|
||||||
m_balanceWidget->setHidden(hide);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void MainWindow::setStatusText(const QString &text, bool override, int timeout) {
|
void MainWindow::setStatusText(const QString &text, bool override, int timeout) {
|
||||||
|
@ -1322,6 +1333,85 @@ void MainWindow::showBalanceDialog() {
|
||||||
dialog->deleteLater();
|
dialog->deleteLater();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void MainWindow::onUpdateSATWidget() {
|
||||||
|
if(!AppContext::prices->markets.count() || !AppContext::prices->rates.count())
|
||||||
|
return;
|
||||||
|
auto wowObj = AppContext::prices->markets["WOW"];
|
||||||
|
QString satStr = QString::number(wowObj.price_sat);
|
||||||
|
m_tickerSAT->setFiatText(satStr);
|
||||||
|
}
|
||||||
|
|
||||||
|
void MainWindow::onUpdateWowWidget() {
|
||||||
|
if(!AppContext::prices->markets.count() || !AppContext::prices->rates.count())
|
||||||
|
return;
|
||||||
|
QString fiatCurrency = config()->get(Config::preferredFiatCurrency).toString();
|
||||||
|
if(!AppContext::prices->rates.contains(fiatCurrency)){
|
||||||
|
config()->set(Config::preferredFiatCurrency, "USD");
|
||||||
|
fiatCurrency = "USD";
|
||||||
|
}
|
||||||
|
|
||||||
|
auto wowObj = AppContext::prices->markets["WOW"];
|
||||||
|
auto currencyText = Utils::amountToCurrencyString(wowObj.price_usd, fiatCurrency);
|
||||||
|
m_tickerWOW->setFiatText(currencyText);
|
||||||
|
|
||||||
|
auto pct24h = AppContext::prices->markets["WOW"].price_usd_change_pct_24h;
|
||||||
|
auto pct24hText = QString::number(pct24h, 'f', 2);
|
||||||
|
this->m_tickerWOW->setPctText(pct24hText, pct24h >= 0.0);
|
||||||
|
}
|
||||||
|
|
||||||
|
void MainWindow::onUpdateBTCWidget() {
|
||||||
|
if(!AppContext::prices->markets.count() || !AppContext::prices->rates.count())
|
||||||
|
return;
|
||||||
|
QString fiatCurrency = config()->get(Config::preferredFiatCurrency).toString();
|
||||||
|
if(!AppContext::prices->rates.contains(fiatCurrency)){
|
||||||
|
config()->set(Config::preferredFiatCurrency, "USD");
|
||||||
|
fiatCurrency = "USD";
|
||||||
|
}
|
||||||
|
|
||||||
|
double conversion = AppContext::prices->convert("BTC", fiatCurrency, 1.0);
|
||||||
|
auto conversionText = Utils::amountToCurrencyString(conversion, fiatCurrency);
|
||||||
|
m_tickerBTC->setFiatText(conversionText);
|
||||||
|
|
||||||
|
auto pct24h = AppContext::prices->markets["BTC"].price_usd_change_pct_24h;
|
||||||
|
auto pct24hText = QString::number(pct24h, 'f', 2);
|
||||||
|
this->m_tickerBTC->setPctText(pct24hText, pct24h >= 0.0);
|
||||||
|
}
|
||||||
|
|
||||||
|
void MainWindow::onUpdateXMRWidget() {
|
||||||
|
if(!AppContext::prices->markets.count() || !AppContext::prices->rates.count())
|
||||||
|
return;
|
||||||
|
QString fiatCurrency = config()->get(Config::preferredFiatCurrency).toString();
|
||||||
|
if(!AppContext::prices->rates.contains(fiatCurrency)){
|
||||||
|
config()->set(Config::preferredFiatCurrency, "USD");
|
||||||
|
fiatCurrency = "USD";
|
||||||
|
}
|
||||||
|
|
||||||
|
double conversion = AppContext::prices->convert("XMR", fiatCurrency, 1.0);
|
||||||
|
auto conversionText = Utils::amountToCurrencyString(conversion, fiatCurrency);
|
||||||
|
m_tickerXMR->setFiatText(conversionText);
|
||||||
|
|
||||||
|
auto pct24h = AppContext::prices->markets["XMR"].price_usd_change_pct_24h;
|
||||||
|
auto pct24hText = QString::number(pct24h, 'f', 2);
|
||||||
|
this->m_tickerXMR->setPctText(pct24hText, pct24h >= 0.0);
|
||||||
|
}
|
||||||
|
|
||||||
|
void MainWindow::onUpdateFiatBalanceWidget() {
|
||||||
|
bool hide = config()->get(Config::hideBalance).toBool();
|
||||||
|
m_balanceWidget->setHidden(hide);
|
||||||
|
|
||||||
|
if(!AppContext::prices->markets.count() || !AppContext::prices->rates.count())
|
||||||
|
return;
|
||||||
|
QString fiatCurrency = config()->get(Config::preferredFiatCurrency).toString();
|
||||||
|
if(!AppContext::prices->rates.contains(fiatCurrency)){
|
||||||
|
config()->set(Config::preferredFiatCurrency, "USD");
|
||||||
|
fiatCurrency = "USD";
|
||||||
|
}
|
||||||
|
|
||||||
|
double conversion = AppContext::prices->convert("WOW", fiatCurrency, AppContext::balance);
|
||||||
|
auto conversionText = Utils::amountToCurrencyString(conversion, fiatCurrency);
|
||||||
|
m_balanceWidget->setFiatText(conversionText);
|
||||||
|
}
|
||||||
|
|
||||||
QString MainWindow::statusDots() {
|
QString MainWindow::statusDots() {
|
||||||
m_statusDots++;
|
m_statusDots++;
|
||||||
m_statusDots = m_statusDots % 4;
|
m_statusDots = m_statusDots % 4;
|
||||||
|
|
|
@ -147,6 +147,13 @@ public slots:
|
||||||
void onCreateTransactionSuccess(PendingTransaction *tx, const QVector<QString> &address);
|
void onCreateTransactionSuccess(PendingTransaction *tx, const QVector<QString> &address);
|
||||||
void onTransactionCommitted(bool status, PendingTransaction *tx, const QStringList& txid);
|
void onTransactionCommitted(bool status, PendingTransaction *tx, const QStringList& txid);
|
||||||
|
|
||||||
|
// tickers
|
||||||
|
void onUpdateWowWidget();
|
||||||
|
void onUpdateFiatBalanceWidget();
|
||||||
|
void onUpdateBTCWidget();
|
||||||
|
void onUpdateSATWidget();
|
||||||
|
void onUpdateXMRWidget();
|
||||||
|
|
||||||
signals:
|
signals:
|
||||||
void closed();
|
void closed();
|
||||||
|
|
||||||
|
@ -191,7 +198,10 @@ private:
|
||||||
QAction *m_trayActionSend;
|
QAction *m_trayActionSend;
|
||||||
QAction *m_trayActionHistory;
|
QAction *m_trayActionHistory;
|
||||||
|
|
||||||
QList<TickerWidget*> m_tickerWidgets;
|
TickerWidget *m_tickerWOW;
|
||||||
|
TickerWidget *m_tickerBTC;
|
||||||
|
TickerWidget *m_tickerSAT;
|
||||||
|
TickerWidget *m_tickerXMR;
|
||||||
TickerWidget *m_balanceWidget;
|
TickerWidget *m_balanceWidget;
|
||||||
|
|
||||||
// lower status bar
|
// lower status bar
|
||||||
|
|
|
@ -41,7 +41,9 @@ void Prices::cryptoPricesReceived(const QJsonArray &data) {
|
||||||
ms.symbol = obj.value("symbol").toString().toUpper();
|
ms.symbol = obj.value("symbol").toString().toUpper();
|
||||||
ms.image = obj.value("image").toString();
|
ms.image = obj.value("image").toString();
|
||||||
ms.name = obj.value("name").toString();
|
ms.name = obj.value("name").toString();
|
||||||
ms.price_usd = obj.value("current_price").toDouble();
|
ms.price_usd = obj.value("current_price").toDouble(0);
|
||||||
|
ms.price_btc = obj.value("current_price_btc").toDouble(0.0);
|
||||||
|
ms.price_sat = obj.value("current_price_satoshi").toInt(0);
|
||||||
ms.price_usd_change_pct_24h = obj.value("price_change_percentage_24h").toDouble();
|
ms.price_usd_change_pct_24h = obj.value("price_change_percentage_24h").toDouble();
|
||||||
|
|
||||||
if(ms.price_usd <= 0) continue;
|
if(ms.price_usd <= 0) continue;
|
||||||
|
|
|
@ -15,6 +15,8 @@ struct marketStruct {
|
||||||
QString name;
|
QString name;
|
||||||
QString image;
|
QString image;
|
||||||
double price_usd;
|
double price_usd;
|
||||||
|
double price_btc;
|
||||||
|
uint price_sat;
|
||||||
double price_usd_change_pct_24h;
|
double price_usd_change_pct_24h;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
@ -6,67 +6,36 @@
|
||||||
|
|
||||||
#include "mainwindow.h"
|
#include "mainwindow.h"
|
||||||
|
|
||||||
TickerWidget::TickerWidget(QWidget *parent, QString symbol, QString title, bool convertBalance, bool hidePercent) :
|
TickerWidget::TickerWidget(QWidget *parent, QString title) :
|
||||||
QWidget(parent),
|
QWidget(parent),
|
||||||
ui(new Ui::TickerWidget),
|
ui(new Ui::TickerWidget)
|
||||||
m_symbol(std::move(symbol)),
|
|
||||||
m_convertBalance(convertBalance),
|
|
||||||
m_hidePercent(hidePercent)
|
|
||||||
{
|
{
|
||||||
ui->setupUi(this);
|
ui->setupUi(this);
|
||||||
m_ctx = MainWindow::getContext();
|
m_ctx = MainWindow::getContext();
|
||||||
|
|
||||||
// default values before API data
|
|
||||||
if (title == "") title = m_symbol;
|
|
||||||
this->ui->tickerBox->setTitle(title);
|
|
||||||
QString defaultPct = "0.0";
|
QString defaultPct = "0.0";
|
||||||
QString defaultFiat = "...";
|
QString defaultFiat = "...";
|
||||||
|
|
||||||
this->setFontSizes();
|
this->setFontSizes();
|
||||||
this->setPctText(defaultPct, true);
|
this->setPctText(defaultPct, true);
|
||||||
this->setFiatText(defaultFiat, 0.0);
|
this->setFiatText(defaultFiat);
|
||||||
|
this->setTitleText(title);
|
||||||
|
|
||||||
ui->tickerPct->setHidden(hidePercent);
|
connect(AppContext::prices, &Prices::fiatPricesUpdated, this, &TickerWidget::reload);
|
||||||
|
connect(AppContext::prices, &Prices::cryptoPricesUpdated, this, &TickerWidget::reload);
|
||||||
connect(AppContext::prices, &Prices::fiatPricesUpdated, this, &TickerWidget::init);
|
connect(m_ctx, &AppContext::balanceUpdated, this, &TickerWidget::reload);
|
||||||
connect(AppContext::prices, &Prices::cryptoPricesUpdated, this, &TickerWidget::init);
|
|
||||||
if (convertBalance)
|
|
||||||
connect(m_ctx, &AppContext::balanceUpdated, this, &TickerWidget::init);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void TickerWidget::init() {
|
void TickerWidget::setFiatText(QString &text) {
|
||||||
if(!AppContext::prices->markets.count() || !AppContext::prices->rates.count())
|
ui->tickerFiat->setText(text);
|
||||||
return;
|
|
||||||
|
|
||||||
QString fiatCurrency = config()->get(Config::preferredFiatCurrency).toString();
|
|
||||||
|
|
||||||
if(!AppContext::prices->rates.contains(fiatCurrency)){
|
|
||||||
config()->set(Config::preferredFiatCurrency, "USD");
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
double amount = m_convertBalance ? AppContext::balance : 1.0;
|
|
||||||
double conversion = AppContext::prices->convert(m_symbol, fiatCurrency, amount);
|
|
||||||
if (conversion < 0) return;
|
|
||||||
|
|
||||||
auto markets = AppContext::prices->markets;
|
|
||||||
if(!markets.contains(m_symbol)) return;
|
|
||||||
|
|
||||||
bool hidePercent = (conversion == 0 || m_hidePercent);
|
|
||||||
if (hidePercent) {
|
|
||||||
ui->tickerPct->hide();
|
|
||||||
} else {
|
|
||||||
auto pct24h = markets[m_symbol].price_usd_change_pct_24h;
|
|
||||||
auto pct24hText = QString::number(pct24h, 'f', 2);
|
|
||||||
this->setPctText(pct24hText, pct24h >= 0.0);
|
|
||||||
}
|
|
||||||
|
|
||||||
this->setFiatText(fiatCurrency, conversion);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void TickerWidget::setFiatText(QString &fiatCurrency, double amount) {
|
void TickerWidget::setTitleText(QString text) {
|
||||||
QString conversionText = Utils::amountToCurrencyString(amount, fiatCurrency);
|
ui->tickerBox->setTitle(text);
|
||||||
ui->tickerFiat->setText(conversionText);
|
}
|
||||||
|
|
||||||
|
void TickerWidget::hidePct(bool hide) {
|
||||||
|
ui->tickerPct->setHidden(hide);
|
||||||
}
|
}
|
||||||
|
|
||||||
void TickerWidget::setPctText(QString &text, bool positive) {
|
void TickerWidget::setPctText(QString &text, bool positive) {
|
||||||
|
|
|
@ -17,21 +17,19 @@ class TickerWidget : public QWidget
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
|
|
||||||
public:
|
public:
|
||||||
explicit TickerWidget(QWidget *parent, QString symbol, QString title = "", bool convertBalance = false, bool hidePercent = false);
|
explicit TickerWidget(QWidget *parent, QString title = "");
|
||||||
void setFiatText(QString &fiatCurrency, double amount);
|
void setFiatText(QString &text);
|
||||||
|
void setTitleText(QString text);
|
||||||
void setPctText(QString &text, bool positive);
|
void setPctText(QString &text, bool positive);
|
||||||
void setFontSizes();
|
void setFontSizes();
|
||||||
|
void hidePct(bool hide);
|
||||||
~TickerWidget() override;
|
~TickerWidget() override;
|
||||||
|
|
||||||
|
signals:
|
||||||
public slots:
|
void reload();
|
||||||
void init();
|
|
||||||
|
|
||||||
private:
|
private:
|
||||||
Ui::TickerWidget *ui;
|
Ui::TickerWidget *ui;
|
||||||
QString m_symbol;
|
|
||||||
bool m_convertBalance;
|
|
||||||
bool m_hidePercent;
|
|
||||||
AppContext *m_ctx;
|
AppContext *m_ctx;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue