mirror of
https://github.com/feather-wallet/feather.git
synced 2025-03-12 09:37:47 +00:00
Settings: amount precision affects balance
This commit is contained in:
parent
811421dca9
commit
c22ce173d6
4 changed files with 12 additions and 5 deletions
|
@ -208,10 +208,15 @@ QString WalletManager::maximumAllowedAmountAsString() const
|
|||
return WalletManager::displayAmount(WalletManager::maximumAllowedAmount());
|
||||
}
|
||||
|
||||
QString WalletManager::displayAmount(quint64 amount, bool trailing_zeroes)
|
||||
QString WalletManager::displayAmount(quint64 amount, bool trailing_zeroes, int decimals)
|
||||
{
|
||||
auto amountStr = QString::fromStdString(Monero::Wallet::displayAmount(amount));
|
||||
|
||||
if (decimals < 12) {
|
||||
int i = amountStr.indexOf(".");
|
||||
amountStr.remove(i+decimals+1, 12);
|
||||
}
|
||||
|
||||
if (!trailing_zeroes) {
|
||||
amountStr.remove(QRegExp("0+$"));
|
||||
amountStr.remove(QRegExp("\\.$"));
|
||||
|
|
|
@ -108,7 +108,7 @@ public:
|
|||
Q_INVOKABLE QString errorString() const;
|
||||
|
||||
//! since we can't call static method from QML, move it to this class
|
||||
Q_INVOKABLE static QString displayAmount(quint64 amount, bool trailing_zeroes = true);
|
||||
Q_INVOKABLE static QString displayAmount(quint64 amount, bool trailing_zeroes = true, int decimals = 12);
|
||||
Q_INVOKABLE static quint64 amountFromString(const QString &amount);
|
||||
Q_INVOKABLE static quint64 amountFromDouble(double amount);
|
||||
Q_INVOKABLE quint64 maximumAllowedAmount() const;
|
||||
|
|
|
@ -478,19 +478,20 @@ void MainWindow::onBalanceUpdated(quint64 balance, quint64 spendable) {
|
|||
|
||||
bool hide = config()->get(Config::hideBalance).toBool();
|
||||
int displaySetting = config()->get(Config::balanceDisplay).toInt();
|
||||
int decimals = config()->get(Config::amountPrecision).toInt();
|
||||
|
||||
QString balance_str = "Balance: ";
|
||||
if (hide) {
|
||||
balance_str += "HIDDEN";
|
||||
}
|
||||
else if (displaySetting == Config::totalBalance) {
|
||||
balance_str += QString("%1 XMR").arg(WalletManager::displayAmount(balance, false));
|
||||
balance_str += QString("%1 XMR").arg(WalletManager::displayAmount(balance, false, decimals));
|
||||
}
|
||||
else if (displaySetting == Config::spendable || displaySetting == Config::spendablePlusUnconfirmed) {
|
||||
balance_str += QString("%1 XMR").arg(WalletManager::displayAmount(spendable, false));
|
||||
balance_str += QString("%1 XMR").arg(WalletManager::displayAmount(spendable, false, decimals));
|
||||
|
||||
if (displaySetting == Config::spendablePlusUnconfirmed && balance > spendable) {
|
||||
balance_str += QString(" (+%1 XMR unconfirmed)").arg(WalletManager::displayAmount(balance - spendable, false));
|
||||
balance_str += QString(" (+%1 XMR unconfirmed)").arg(WalletManager::displayAmount(balance - spendable, false, decimals));
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -148,6 +148,7 @@ void Settings::comboBox_localMoneroFrontendChanged(int pos) {
|
|||
|
||||
void Settings::comboBox_amountPrecisionChanged(int pos) {
|
||||
config()->set(Config::amountPrecision, pos);
|
||||
m_ctx->updateBalance();
|
||||
emit amountPrecisionChanged(pos);
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue