Skip to content

Commit

Permalink
GUI: Add GUIUtil::formatMultiAssetAmount to handle a CAmountMap
Browse files Browse the repository at this point in the history
  • Loading branch information
luke-jr authored and instagibbs committed Apr 9, 2019
1 parent 988ed5e commit 6342d80
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 0 deletions.
20 changes: 20 additions & 0 deletions src/qt/guiutil.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -794,6 +794,26 @@ QString formatAssetAmount(const CAsset& asset, const CAmount& amount, const int
return str;
}

QString formatMultiAssetAmount(const CAmountMap& amountmap, const int bitcoin_unit, BitcoinUnits::SeparatorStyle separators, QString line_separator)
{
QStringList ret;
if (amountmap.count(Params().GetConsensus().pegged_asset) && amountmap.at(Params().GetConsensus().pegged_asset)) {
ret << formatAssetAmount(Params().GetConsensus().pegged_asset, amountmap.at(Params().GetConsensus().pegged_asset), bitcoin_unit, separators);
}
for (const auto& assetamount : amountmap) {
if (assetamount.first == Params().GetConsensus().pegged_asset) {
// Already handled first
continue;
}
if (!assetamount.second) {
// Don't include zero-amount assets
continue;
}
ret << formatAssetAmount(assetamount.first, assetamount.second, bitcoin_unit, separators);
}
return ret.join(line_separator);
}

QString formatDurationStr(int secs)
{
QStringList strList;
Expand Down
3 changes: 3 additions & 0 deletions src/qt/guiutil.h
Original file line number Diff line number Diff line change
Expand Up @@ -192,6 +192,9 @@ namespace GUIUtil
/* Format an amount of assets in a user-friendly style */
QString formatAssetAmount(const CAsset&, const CAmount&, int bitcoin_unit, BitcoinUnits::SeparatorStyle);

/* Format one or more asset+amounts in a user-friendly style */
QString formatMultiAssetAmount(const CAmountMap&, int bitcoin_unit, BitcoinUnits::SeparatorStyle, QString line_separator);

/* Convert seconds into a QString with days, hours, mins, secs */
QString formatDurationStr(int secs);

Expand Down

0 comments on commit 6342d80

Please sign in to comment.