Make balance display more concise

This commit is contained in:
tobtoht 2020-12-31 03:14:48 +01:00
parent 1c088cc925
commit fc7762c457
3 changed files with 14 additions and 3 deletions

View file

@ -665,9 +665,9 @@ void MainWindow::onBalanceUpdated(quint64 balance, quint64 spendable) {
qDebug() << Q_FUNC_INFO;
bool hide = config()->get(Config::hideBalance).toBool();
QString label_str = QString("Balance: %1 XMR").arg(QString::number(spendable / globals::cdiv, 'f'));
QString label_str = QString("Balance: %1 XMR").arg(Utils::balanceFormat(spendable));
if (balance > spendable)
label_str += QString(" (+%1 XMR unconfirmed)").arg(QString::number((balance - spendable) / globals::cdiv, 'f'));
label_str += QString(" (+%1 XMR unconfirmed)").arg(Utils::balanceFormat(balance - spendable));
if (hide)
label_str = "Balance: HIDDEN";
@ -842,7 +842,7 @@ void MainWindow::create_status_bar() {
this->statusBar()->addWidget(m_statusLabelNetStats);
m_statusLabelBalance = new ClickableLabel(this);
m_statusLabelBalance->setText("Balance: 0.00 XMR");
m_statusLabelBalance->setText("Balance: 0 XMR");
m_statusLabelBalance->setTextInteractionFlags(Qt::TextSelectableByMouse);
this->statusBar()->addPermanentWidget(m_statusLabelBalance);
connect(m_statusLabelBalance, &ClickableLabel::clicked, this, &MainWindow::showBalanceDialog);

View file

@ -13,6 +13,7 @@
#include "utils/config.h"
#include "utils/tails.h"
#include "utils/whonix.h"
#include "globals.h"
// Application log for current session
QVector<logMessage> applicationLog = QVector<logMessage>(); // todo: replace with ring buffer
@ -532,3 +533,12 @@ int Utils::maxLength(const QVector<QString> &array) {
}
return maxLength;
}
QString Utils::balanceFormat(quint64 balance) {
QString str = QString::number(balance / globals::cdiv, 'f', 4);
str.remove(QRegExp("0+$"));
str.remove(QRegExp("\\.$"));
return str;
}

View file

@ -98,6 +98,7 @@ public:
static QString amountToCurrencyString(double amount, const QString &currencyCode);
static int maxLength(const QVector<QString> &array);
static QMap<QString, QLocale> localeCache;
static QString balanceFormat(quint64 balance);
template<typename QEnum>
static QString QtEnumToString (const QEnum value)