mirror of
https://github.com/feather-wallet/feather.git
synced 2025-04-16 18:01:54 +00:00
balance: add fiat balance
This commit is contained in:
parent
88ab38a193
commit
e7a6e4f16a
4 changed files with 115 additions and 41 deletions
src
|
@ -6,6 +6,9 @@
|
|||
|
||||
#include "libwalletqt/WalletManager.h"
|
||||
#include "utils/Utils.h"
|
||||
#include "utils/config.h"
|
||||
#include "utils/AppData.h"
|
||||
#include "constants.h"
|
||||
|
||||
BalanceDialog::BalanceDialog(QWidget *parent, Wallet *wallet)
|
||||
: WindowModalDialog(parent)
|
||||
|
@ -23,15 +26,33 @@ BalanceDialog::BalanceDialog(QWidget *parent, Wallet *wallet)
|
|||
ui->label_spendable->setFont(Utils::getMonospaceFont());
|
||||
ui->label_total->setFont(Utils::getMonospaceFont());
|
||||
|
||||
ui->label_unconfirmedFiat->setFont(Utils::getMonospaceFont());
|
||||
ui->label_spendableFiat->setFont(Utils::getMonospaceFont());
|
||||
ui->label_totalFiat->setFont(Utils::getMonospaceFont());
|
||||
|
||||
if (conf()->get(Config::disableWebsocket).toBool()) {
|
||||
ui->label_unconfirmedFiat->hide();
|
||||
ui->label_spendableFiat->hide();
|
||||
ui->label_totalFiat->hide();
|
||||
}
|
||||
|
||||
this->updateBalance();
|
||||
|
||||
this->adjustSize();
|
||||
}
|
||||
|
||||
void BalanceDialog::updateBalance() {
|
||||
ui->label_unconfirmed->setText(WalletManager::displayAmount(m_wallet->balance() - m_wallet->unlockedBalance()));
|
||||
quint64 unconfirmedBalance = m_wallet->balance() - m_wallet->unlockedBalance();
|
||||
|
||||
ui->label_unconfirmed->setText(WalletManager::displayAmount(unconfirmedBalance));
|
||||
ui->label_spendable->setText(WalletManager::displayAmount(m_wallet->unlockedBalance()));
|
||||
ui->label_total->setText(WalletManager::displayAmount(m_wallet->balance()));
|
||||
|
||||
if (!conf()->get(Config::disableWebsocket).toBool()) {
|
||||
ui->label_unconfirmedFiat->setText(appData()->prices.atomicUnitsToPreferredFiatString(unconfirmedBalance));
|
||||
ui->label_spendableFiat->setText(appData()->prices.atomicUnitsToPreferredFiatString(m_wallet->unlockedBalance()));
|
||||
ui->label_totalFiat->setText(appData()->prices.atomicUnitsToPreferredFiatString(m_wallet->balance()));
|
||||
}
|
||||
}
|
||||
|
||||
BalanceDialog::~BalanceDialog() = default;
|
||||
|
|
|
@ -6,8 +6,8 @@
|
|||
<rect>
|
||||
<x>0</x>
|
||||
<y>0</y>
|
||||
<width>405</width>
|
||||
<height>162</height>
|
||||
<width>202</width>
|
||||
<height>140</height>
|
||||
</rect>
|
||||
</property>
|
||||
<property name="windowTitle">
|
||||
|
@ -15,24 +15,30 @@
|
|||
</property>
|
||||
<layout class="QVBoxLayout" name="verticalLayout">
|
||||
<item>
|
||||
<layout class="QFormLayout" name="formLayout">
|
||||
<item row="0" column="0">
|
||||
<widget class="HelpLabel" name="label_unconfirmed_help">
|
||||
<property name="text">
|
||||
<string>Unconfirmed</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="0" column="1">
|
||||
<widget class="QLabel" name="label_unconfirmed">
|
||||
<layout class="QGridLayout" name="gridLayout">
|
||||
<item row="1" column="1">
|
||||
<widget class="QLabel" name="label_spendable">
|
||||
<property name="text">
|
||||
<string>0.0</string>
|
||||
</property>
|
||||
<property name="alignment">
|
||||
<set>Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter</set>
|
||||
<set>Qt::AlignmentFlag::AlignRight|Qt::AlignmentFlag::AlignTrailing|Qt::AlignmentFlag::AlignVCenter</set>
|
||||
</property>
|
||||
<property name="textInteractionFlags">
|
||||
<set>Qt::LinksAccessibleByMouse|Qt::TextSelectableByMouse</set>
|
||||
<set>Qt::TextInteractionFlag::LinksAccessibleByMouse|Qt::TextInteractionFlag::TextSelectableByMouse</set>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="3" column="1">
|
||||
<widget class="QLabel" name="label_total">
|
||||
<property name="text">
|
||||
<string>0.0</string>
|
||||
</property>
|
||||
<property name="alignment">
|
||||
<set>Qt::AlignmentFlag::AlignRight|Qt::AlignmentFlag::AlignTrailing|Qt::AlignmentFlag::AlignVCenter</set>
|
||||
</property>
|
||||
<property name="textInteractionFlags">
|
||||
<set>Qt::TextInteractionFlag::LinksAccessibleByMouse|Qt::TextInteractionFlag::TextSelectableByMouse</set>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
|
@ -43,26 +49,6 @@
|
|||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="1" column="1">
|
||||
<widget class="QLabel" name="label_spendable">
|
||||
<property name="text">
|
||||
<string>0.0</string>
|
||||
</property>
|
||||
<property name="alignment">
|
||||
<set>Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter</set>
|
||||
</property>
|
||||
<property name="textInteractionFlags">
|
||||
<set>Qt::LinksAccessibleByMouse|Qt::TextSelectableByMouse</set>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="2" column="1">
|
||||
<widget class="Line" name="line">
|
||||
<property name="orientation">
|
||||
<enum>Qt::Horizontal</enum>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="3" column="0">
|
||||
<widget class="QLabel" name="label_7">
|
||||
<property name="text">
|
||||
|
@ -70,16 +56,69 @@
|
|||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="3" column="1">
|
||||
<widget class="QLabel" name="label_total">
|
||||
<item row="0" column="1">
|
||||
<widget class="QLabel" name="label_unconfirmed">
|
||||
<property name="text">
|
||||
<string>0.0</string>
|
||||
</property>
|
||||
<property name="alignment">
|
||||
<set>Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter</set>
|
||||
<set>Qt::AlignmentFlag::AlignRight|Qt::AlignmentFlag::AlignTrailing|Qt::AlignmentFlag::AlignVCenter</set>
|
||||
</property>
|
||||
<property name="textInteractionFlags">
|
||||
<set>Qt::LinksAccessibleByMouse|Qt::TextSelectableByMouse</set>
|
||||
<set>Qt::TextInteractionFlag::LinksAccessibleByMouse|Qt::TextInteractionFlag::TextSelectableByMouse</set>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="0" column="0">
|
||||
<widget class="HelpLabel" name="label_unconfirmed_help">
|
||||
<property name="text">
|
||||
<string>Unconfirmed</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="2" column="1" colspan="2">
|
||||
<widget class="Line" name="line">
|
||||
<property name="orientation">
|
||||
<enum>Qt::Orientation::Horizontal</enum>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="0" column="2">
|
||||
<widget class="QLabel" name="label_unconfirmedFiat">
|
||||
<property name="text">
|
||||
<string>(0)</string>
|
||||
</property>
|
||||
<property name="alignment">
|
||||
<set>Qt::AlignmentFlag::AlignRight|Qt::AlignmentFlag::AlignTrailing|Qt::AlignmentFlag::AlignVCenter</set>
|
||||
</property>
|
||||
<property name="textInteractionFlags">
|
||||
<set>Qt::TextInteractionFlag::LinksAccessibleByMouse|Qt::TextInteractionFlag::TextSelectableByMouse</set>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="1" column="2">
|
||||
<widget class="QLabel" name="label_spendableFiat">
|
||||
<property name="text">
|
||||
<string>(0)</string>
|
||||
</property>
|
||||
<property name="alignment">
|
||||
<set>Qt::AlignmentFlag::AlignRight|Qt::AlignmentFlag::AlignTrailing|Qt::AlignmentFlag::AlignVCenter</set>
|
||||
</property>
|
||||
<property name="textInteractionFlags">
|
||||
<set>Qt::TextInteractionFlag::LinksAccessibleByMouse|Qt::TextInteractionFlag::TextSelectableByMouse</set>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="3" column="2">
|
||||
<widget class="QLabel" name="label_totalFiat">
|
||||
<property name="text">
|
||||
<string>(0)</string>
|
||||
</property>
|
||||
<property name="alignment">
|
||||
<set>Qt::AlignmentFlag::AlignRight|Qt::AlignmentFlag::AlignTrailing|Qt::AlignmentFlag::AlignVCenter</set>
|
||||
</property>
|
||||
<property name="textInteractionFlags">
|
||||
<set>Qt::TextInteractionFlag::LinksAccessibleByMouse|Qt::TextInteractionFlag::TextSelectableByMouse</set>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
|
@ -88,10 +127,10 @@
|
|||
<item>
|
||||
<widget class="QDialogButtonBox" name="buttonBox">
|
||||
<property name="orientation">
|
||||
<enum>Qt::Horizontal</enum>
|
||||
<enum>Qt::Orientation::Horizontal</enum>
|
||||
</property>
|
||||
<property name="standardButtons">
|
||||
<set>QDialogButtonBox::Ok</set>
|
||||
<set>QDialogButtonBox::StandardButton::Ok</set>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
|
|
|
@ -6,6 +6,9 @@
|
|||
#include <QJsonArray>
|
||||
#include <QJsonObject>
|
||||
|
||||
#include "config.h"
|
||||
#include "constants.h"
|
||||
|
||||
Prices::Prices(QObject *parent)
|
||||
: QObject(parent)
|
||||
{
|
||||
|
@ -74,3 +77,13 @@ double Prices::convert(QString symbolFrom, QString symbolTo, double amount) {
|
|||
return 0.0;
|
||||
}
|
||||
|
||||
QString Prices::atomicUnitsToPreferredFiatString(quint64 amount, bool wrapInParens) {
|
||||
QString fiatCurrency = conf()->get(Config::preferredFiatCurrency).toString();
|
||||
double fiatAmount = convert("XMR", fiatCurrency, amount / constants::cdiv);
|
||||
QString currencyString = Utils::amountToCurrencyString(fiatAmount, fiatCurrency);
|
||||
|
||||
if (wrapInParens) {
|
||||
return QString("(%1)").arg(currencyString);
|
||||
}
|
||||
return currencyString;
|
||||
}
|
||||
|
|
|
@ -30,6 +30,7 @@ public slots:
|
|||
void fiatPricesReceived(const QJsonObject &data);
|
||||
|
||||
double convert(QString symbolFrom, QString symbolTo, double amount);
|
||||
QString atomicUnitsToPreferredFiatString(quint64 amount, bool wrapInParens = false);
|
||||
|
||||
signals:
|
||||
void fiatPricesUpdated();
|
||||
|
|
Loading…
Reference in a new issue