mirror of
https://github.com/feather-wallet/feather.git
synced 2024-12-22 19:49:28 +00:00
History: add balance column
This commit is contained in:
parent
7f914ed682
commit
9ec53dc7d5
7 changed files with 40 additions and 10 deletions
2
monero
2
monero
|
@ -1 +1 @@
|
||||||
Subproject commit 9e4a4d305c0a24f294d9f75d33065381b6fba520
|
Subproject commit ecca08f4c0b1e5a012cdd20110b015c540bce0c6
|
|
@ -64,13 +64,22 @@ void TransactionHistory::refresh(quint32 accountIndex)
|
||||||
m_locked = false;
|
m_locked = false;
|
||||||
m_minutesToUnlock = 0;
|
m_minutesToUnlock = 0;
|
||||||
|
|
||||||
|
quint64 balance = 0;
|
||||||
|
|
||||||
m_pimpl->refresh();
|
m_pimpl->refresh();
|
||||||
for (const auto i : m_pimpl->getAll()) {
|
for (const auto i : m_pimpl->getAll()) {
|
||||||
if (i->subaddrAccount() != accountIndex) {
|
if (i->subaddrAccount() != accountIndex) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
m_tinfo.append(new TransactionInfo(i, this));
|
if (i->direction() == Monero::TransactionInfo::Direction_In) {
|
||||||
|
balance += i->amount();
|
||||||
|
}
|
||||||
|
else if (i->direction() == Monero::TransactionInfo::Direction_Out) {
|
||||||
|
balance -= i->amount() + i->fee();
|
||||||
|
}
|
||||||
|
|
||||||
|
m_tinfo.append(new TransactionInfo(i, balance, this));
|
||||||
|
|
||||||
const TransactionInfo *ti = m_tinfo.back();
|
const TransactionInfo *ti = m_tinfo.back();
|
||||||
// looking for transactions timestamp scope
|
// looking for transactions timestamp scope
|
||||||
|
@ -159,7 +168,7 @@ bool TransactionHistory::writeCSV(const QString &path) {
|
||||||
});
|
});
|
||||||
|
|
||||||
for (const auto &tx : transactions) {
|
for (const auto &tx : transactions) {
|
||||||
TransactionInfo info(tx, this);
|
TransactionInfo info(tx, 0, this);
|
||||||
|
|
||||||
// collect column data
|
// collect column data
|
||||||
QDateTime timeStamp = info.timestamp();
|
QDateTime timeStamp = info.timestamp();
|
||||||
|
|
|
@ -37,6 +37,11 @@ quint64 TransactionInfo::balanceDelta() const
|
||||||
return m_amount;
|
return m_amount;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
quint64 TransactionInfo::balance() const
|
||||||
|
{
|
||||||
|
return m_balance;
|
||||||
|
}
|
||||||
|
|
||||||
double TransactionInfo::amount() const
|
double TransactionInfo::amount() const
|
||||||
{
|
{
|
||||||
// there's no unsigned uint64 for JS, so better use double
|
// there's no unsigned uint64 for JS, so better use double
|
||||||
|
@ -167,7 +172,7 @@ QString TransactionInfo::rings_formatted() const
|
||||||
return rings;
|
return rings;
|
||||||
}
|
}
|
||||||
|
|
||||||
TransactionInfo::TransactionInfo(const Monero::TransactionInfo *pimpl, QObject *parent)
|
TransactionInfo::TransactionInfo(const Monero::TransactionInfo *pimpl, quint64 balance, QObject *parent)
|
||||||
: QObject(parent)
|
: QObject(parent)
|
||||||
, m_amount(pimpl->amount())
|
, m_amount(pimpl->amount())
|
||||||
, m_blockHeight(pimpl->blockHeight())
|
, m_blockHeight(pimpl->blockHeight())
|
||||||
|
@ -184,6 +189,7 @@ TransactionInfo::TransactionInfo(const Monero::TransactionInfo *pimpl, QObject *
|
||||||
, m_timestamp(QDateTime::fromSecsSinceEpoch(pimpl->timestamp()))
|
, m_timestamp(QDateTime::fromSecsSinceEpoch(pimpl->timestamp()))
|
||||||
, m_unlockTime(pimpl->unlockTime())
|
, m_unlockTime(pimpl->unlockTime())
|
||||||
, m_coinbase(pimpl->isCoinbase())
|
, m_coinbase(pimpl->isCoinbase())
|
||||||
|
, m_balance(balance)
|
||||||
{
|
{
|
||||||
for (auto const &t: pimpl->transfers())
|
for (auto const &t: pimpl->transfers())
|
||||||
{
|
{
|
||||||
|
|
|
@ -53,6 +53,7 @@ public:
|
||||||
bool isFailed() const;
|
bool isFailed() const;
|
||||||
bool isCoinbase() const;
|
bool isCoinbase() const;
|
||||||
quint64 balanceDelta() const;
|
quint64 balanceDelta() const;
|
||||||
|
quint64 balance() const;
|
||||||
double amount() const;
|
double amount() const;
|
||||||
quint64 atomicAmount() const;
|
quint64 atomicAmount() const;
|
||||||
QString displayAmount() const;
|
QString displayAmount() const;
|
||||||
|
@ -80,7 +81,7 @@ public:
|
||||||
QString rings_formatted() const;
|
QString rings_formatted() const;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
explicit TransactionInfo(const Monero::TransactionInfo *pimpl, QObject *parent = nullptr);
|
explicit TransactionInfo(const Monero::TransactionInfo *pimpl, quint64 balance, QObject *parent = nullptr);
|
||||||
private:
|
private:
|
||||||
friend class TransactionHistory;
|
friend class TransactionHistory;
|
||||||
mutable QList<Transfer*> m_transfers;
|
mutable QList<Transfer*> m_transfers;
|
||||||
|
@ -102,6 +103,7 @@ private:
|
||||||
QDateTime m_timestamp;
|
QDateTime m_timestamp;
|
||||||
quint64 m_unlockTime;
|
quint64 m_unlockTime;
|
||||||
bool m_coinbase;
|
bool m_coinbase;
|
||||||
|
quint64 m_balance;
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif // TRANSACTIONINFO_H
|
#endif // TRANSACTIONINFO_H
|
||||||
|
|
|
@ -181,6 +181,7 @@ void HistoryView::resetViewToDefaults()
|
||||||
header()->showSection(TransactionHistoryModel::Description);
|
header()->showSection(TransactionHistoryModel::Description);
|
||||||
header()->showSection(TransactionHistoryModel::Amount);
|
header()->showSection(TransactionHistoryModel::Amount);
|
||||||
header()->showSection(TransactionHistoryModel::FiatAmount);
|
header()->showSection(TransactionHistoryModel::FiatAmount);
|
||||||
|
header()->hideSection(TransactionHistoryModel::Balance);
|
||||||
|
|
||||||
// Reset column order to logical indices
|
// Reset column order to logical indices
|
||||||
for (int i = 0; i < header()->count(); ++i) {
|
for (int i = 0; i < header()->count(); ++i) {
|
||||||
|
|
|
@ -67,7 +67,7 @@ QVariant TransactionHistoryModel::data(const QModelIndex &index, int role) const
|
||||||
|
|
||||||
bool found = m_transactionHistory->transaction(index.row(), [this, &index, &result, &role](const TransactionInfo &tInfo) {
|
bool found = m_transactionHistory->transaction(index.row(), [this, &index, &result, &role](const TransactionInfo &tInfo) {
|
||||||
if(role == Qt::DisplayRole || role == Qt::EditRole || role == Qt::UserRole) {
|
if(role == Qt::DisplayRole || role == Qt::EditRole || role == Qt::UserRole) {
|
||||||
result = parseTransactionInfo(tInfo, index.column(), role);
|
result = parseTransactionInfo(tInfo, index.row(), index.column(), role);
|
||||||
}
|
}
|
||||||
else if (role == Qt::TextAlignmentRole) {
|
else if (role == Qt::TextAlignmentRole) {
|
||||||
switch (index.column()) {
|
switch (index.column()) {
|
||||||
|
@ -139,14 +139,14 @@ QVariant TransactionHistoryModel::data(const QModelIndex &index, int role) const
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
QVariant TransactionHistoryModel::parseTransactionInfo(const TransactionInfo &tInfo, int column, int role) const
|
QVariant TransactionHistoryModel::parseTransactionInfo(const TransactionInfo &tInfo, int row, int column, int role) const
|
||||||
{
|
{
|
||||||
switch (column)
|
switch (column)
|
||||||
{
|
{
|
||||||
case Column::Date:
|
case Column::Date:
|
||||||
{
|
{
|
||||||
if (role == Qt::UserRole) {
|
if (role == Qt::UserRole) {
|
||||||
return tInfo.timestamp();
|
return row;
|
||||||
}
|
}
|
||||||
return tInfo.timestamp().toString(QString("%1 %2 ").arg(config()->get(Config::dateFormat).toString(),
|
return tInfo.timestamp().toString(QString("%1 %2 ").arg(config()->get(Config::dateFormat).toString(),
|
||||||
config()->get(Config::timeFormat).toString()));
|
config()->get(Config::timeFormat).toString()));
|
||||||
|
@ -158,7 +158,7 @@ QVariant TransactionHistoryModel::parseTransactionInfo(const TransactionInfo &tI
|
||||||
if (role == Qt::UserRole) {
|
if (role == Qt::UserRole) {
|
||||||
return tInfo.balanceDelta();
|
return tInfo.balanceDelta();
|
||||||
}
|
}
|
||||||
QString amount = QString::number(tInfo.balanceDelta() / constants::cdiv, 'f', config()->get(Config::amountPrecision).toInt());
|
auto amount = this->formatAmount(tInfo.balanceDelta());
|
||||||
amount = (tInfo.direction() == TransactionInfo::Direction_Out) ? "-" + amount : "+" + amount;
|
amount = (tInfo.direction() == TransactionInfo::Direction_Out) ? "-" + amount : "+" + amount;
|
||||||
return amount;
|
return amount;
|
||||||
}
|
}
|
||||||
|
@ -188,6 +188,10 @@ QVariant TransactionHistoryModel::parseTransactionInfo(const TransactionInfo &tI
|
||||||
double fiat_rounded = ceil(Utils::roundSignificant(usd_amount, 3) * 100.0) / 100.0;
|
double fiat_rounded = ceil(Utils::roundSignificant(usd_amount, 3) * 100.0) / 100.0;
|
||||||
return QString("%1").arg(Utils::amountToCurrencyString(fiat_rounded, preferredFiatCurrency));
|
return QString("%1").arg(Utils::amountToCurrencyString(fiat_rounded, preferredFiatCurrency));
|
||||||
}
|
}
|
||||||
|
case Column::Balance:
|
||||||
|
{
|
||||||
|
return this->formatAmount(tInfo.balance());
|
||||||
|
}
|
||||||
default:
|
default:
|
||||||
{
|
{
|
||||||
qCritical() << "Unimplemented role";
|
qCritical() << "Unimplemented role";
|
||||||
|
@ -196,6 +200,10 @@ QVariant TransactionHistoryModel::parseTransactionInfo(const TransactionInfo &tI
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
QString TransactionHistoryModel::formatAmount(quint64 amount) const {
|
||||||
|
return QString::number(amount / constants::cdiv, 'f', config()->get(Config::amountPrecision).toInt());
|
||||||
|
}
|
||||||
|
|
||||||
QVariant TransactionHistoryModel::headerData(int section, Qt::Orientation orientation, int role) const {
|
QVariant TransactionHistoryModel::headerData(int section, Qt::Orientation orientation, int role) const {
|
||||||
Q_UNUSED(orientation)
|
Q_UNUSED(orientation)
|
||||||
if (role != Qt::DisplayRole) {
|
if (role != Qt::DisplayRole) {
|
||||||
|
@ -213,6 +221,8 @@ QVariant TransactionHistoryModel::headerData(int section, Qt::Orientation orient
|
||||||
return QString("Txid");
|
return QString("Txid");
|
||||||
case Column::FiatAmount:
|
case Column::FiatAmount:
|
||||||
return QString("Fiat");
|
return QString("Fiat");
|
||||||
|
case Column::Balance:
|
||||||
|
return QString("Balance");
|
||||||
default:
|
default:
|
||||||
return QVariant();
|
return QVariant();
|
||||||
}
|
}
|
||||||
|
|
|
@ -27,6 +27,7 @@ public:
|
||||||
Description,
|
Description,
|
||||||
Amount,
|
Amount,
|
||||||
FiatAmount,
|
FiatAmount,
|
||||||
|
Balance,
|
||||||
COUNT
|
COUNT
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -47,7 +48,8 @@ signals:
|
||||||
void transactionHistoryChanged();
|
void transactionHistoryChanged();
|
||||||
|
|
||||||
private:
|
private:
|
||||||
QVariant parseTransactionInfo(const TransactionInfo &tInfo, int column, int role) const;
|
QVariant parseTransactionInfo(const TransactionInfo &tInfo, int row, int column, int role) const;
|
||||||
|
QString formatAmount(quint64 amount) const;
|
||||||
|
|
||||||
TransactionHistory * m_transactionHistory;
|
TransactionHistory * m_transactionHistory;
|
||||||
};
|
};
|
||||||
|
|
Loading…
Reference in a new issue