mirror of
https://github.com/ElementsProject/elements.git
synced 2026-08-13 12:33:42 +02:00
GUI: Abstract asset+amount formatting into new GUIUtil::formatAssetAmount
This commit is contained in:
parent
89275ebf21
commit
988ed5effc
3 changed files with 27 additions and 16 deletions
|
|
@ -11,6 +11,7 @@
|
|||
|
||||
#include <asset.h>
|
||||
#include <base58.h>
|
||||
#include "assetsdir.h"
|
||||
#include <chainparams.h>
|
||||
#include <primitives/transaction.h>
|
||||
#include <key_io.h>
|
||||
|
|
@ -773,6 +774,26 @@ QString boostPathToQString(const fs::path &path)
|
|||
return QString::fromStdString(path.string(utf8));
|
||||
}
|
||||
|
||||
QString formatAssetAmount(const CAsset& asset, const CAmount& amount, const int bitcoin_unit, BitcoinUnits::SeparatorStyle separators)
|
||||
{
|
||||
if (asset == Params().GetConsensus().pegged_asset) {
|
||||
return BitcoinUnits::formatWithUnit(bitcoin_unit, amount, false, separators);
|
||||
}
|
||||
|
||||
qlonglong whole = amount / 100000000;
|
||||
qlonglong fraction = amount % 100000000;
|
||||
QString str = QString("%1").arg(whole);
|
||||
if (fraction) {
|
||||
str += QString(".%1").arg(fraction, 8, 10, QLatin1Char('0'));
|
||||
}
|
||||
std::string asset_label = gAssetsDir.GetLabel(asset);
|
||||
if (asset_label.empty()) {
|
||||
asset_label = asset.GetHex();
|
||||
}
|
||||
str += QString(" ") + QString::fromStdString(asset_label);
|
||||
return str;
|
||||
}
|
||||
|
||||
QString formatDurationStr(int secs)
|
||||
{
|
||||
QStringList strList;
|
||||
|
|
|
|||
|
|
@ -7,6 +7,8 @@
|
|||
|
||||
#include <amount.h>
|
||||
#include <fs.h>
|
||||
#include "bitcoinunits.h"
|
||||
#include <asset.h>
|
||||
|
||||
#include <QEvent>
|
||||
#include <QHeaderView>
|
||||
|
|
@ -187,6 +189,9 @@ namespace GUIUtil
|
|||
/* Convert OS specific boost path to QString through UTF-8 */
|
||||
QString boostPathToQString(const fs::path &path);
|
||||
|
||||
/* Format an amount of assets in a user-friendly style */
|
||||
QString formatAssetAmount(const CAsset&, const CAmount&, int bitcoin_unit, BitcoinUnits::SeparatorStyle);
|
||||
|
||||
/* Convert seconds into a QString with days, hours, mins, secs */
|
||||
QString formatDurationStr(int secs);
|
||||
|
||||
|
|
|
|||
|
|
@ -429,22 +429,7 @@ QVariant TransactionTableModel::addressColor(const TransactionRecord *wtx) const
|
|||
|
||||
QString TransactionTableModel::formatTxAmount(const TransactionRecord *wtx, bool showUnconfirmed, BitcoinUnits::SeparatorStyle separators) const
|
||||
{
|
||||
QString str;
|
||||
if (wtx->asset == ::policyAsset) {
|
||||
str = BitcoinUnits::formatWithUnit(walletModel->getOptionsModel()->getDisplayUnit(), wtx->amount, false, separators);
|
||||
} else {
|
||||
qlonglong whole = wtx->amount / 100000000;
|
||||
qlonglong fraction = wtx->amount % 100000000;
|
||||
str = QString("%1").arg(whole);
|
||||
if (fraction) {
|
||||
str += QString(".%1").arg(fraction, 8, 10, QLatin1Char('0'));
|
||||
}
|
||||
std::string asset_label = gAssetsDir.GetLabel(wtx->asset);
|
||||
if (asset_label.empty()) {
|
||||
asset_label = wtx->asset.GetHex();
|
||||
}
|
||||
str += QString(" ") + QString::fromStdString(asset_label);
|
||||
}
|
||||
QString str = GUIUtil::formatAssetAmount(wtx->asset, wtx->amount, walletModel->getOptionsModel()->getDisplayUnit(), separators);
|
||||
if(showUnconfirmed)
|
||||
{
|
||||
if(!wtx->status.countsForBalance)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue