Fix sum of selected transactions being slighty off

due to floating point operations
This commit is contained in:
moneromooo.monero 2016-11-10 19:55:44 +00:00
parent 68736ab834
commit 69146567bf
6 changed files with 28 additions and 5 deletions

View file

@ -48,13 +48,19 @@ Rectangle {
for (var i = 0; i < count; ++i) { for (var i = 0; i < count; ++i) {
var idx = model.index(i, 0) var idx = model.index(i, 0)
var isout = model.data(idx, TransactionHistoryModel.TransactionIsOutRole); var isout = model.data(idx, TransactionHistoryModel.TransactionIsOutRole);
var amount = model.data(idx, TransactionHistoryModel.TransactionAmountRole); var amount = model.data(idx, TransactionHistoryModel.TransactionAtomicAmountRole);
if (isout) if (isout)
total -= amount total = walletManager.subi(total, amount)
else else
total += amount total = walletManager.addi(total, amount)
} }
return count + qsTr(" selected: ") + total;
var sign = ""
if (total < 0) {
total = -total
sign = "-"
}
return count + qsTr(" selected: ") + sign + walletManager.displayAmount(total);
} }
onModelChanged: { onModelChanged: {

View file

@ -25,6 +25,11 @@ double TransactionInfo::amount() const
return WalletManager::instance()->displayAmount(m_pimpl->amount()).toDouble(); return WalletManager::instance()->displayAmount(m_pimpl->amount()).toDouble();
} }
quint64 TransactionInfo::atomicAmount() const
{
return m_pimpl->amount();
}
QString TransactionInfo::displayAmount() const QString TransactionInfo::displayAmount() const
{ {
return WalletManager::instance()->displayAmount(m_pimpl->amount()); return WalletManager::instance()->displayAmount(m_pimpl->amount());

View file

@ -12,6 +12,7 @@ class TransactionInfo : public QObject
Q_PROPERTY(bool isPending READ isPending) Q_PROPERTY(bool isPending READ isPending)
Q_PROPERTY(bool isFailed READ isFailed) Q_PROPERTY(bool isFailed READ isFailed)
Q_PROPERTY(double amount READ amount) Q_PROPERTY(double amount READ amount)
Q_PROPERTY(quint64 atomicAmount READ atomicAmount)
Q_PROPERTY(QString displayAmount READ displayAmount) Q_PROPERTY(QString displayAmount READ displayAmount)
Q_PROPERTY(QString fee READ fee) Q_PROPERTY(QString fee READ fee)
Q_PROPERTY(quint64 blockHeight READ blockHeight) Q_PROPERTY(quint64 blockHeight READ blockHeight)
@ -42,6 +43,7 @@ public:
bool isPending() const; bool isPending() const;
bool isFailed() const; bool isFailed() const;
double amount() const; double amount() const;
quint64 atomicAmount() const;
QString displayAmount() const; QString displayAmount() const;
QString fee() const; QString fee() const;
quint64 blockHeight() const; quint64 blockHeight() const;

View file

@ -101,6 +101,11 @@ public:
void setLogLevel(int logLevel); void setLogLevel(int logLevel);
Q_INVOKABLE quint64 add(quint64 x, quint64 y) const { return x + y; }
Q_INVOKABLE quint64 sub(quint64 x, quint64 y) const { return x - y; }
Q_INVOKABLE qint64 addi(qint64 x, qint64 y) const { return x + y; }
Q_INVOKABLE qint64 subi(qint64 x, qint64 y) const { return x - y; }
signals: signals:
void walletOpened(Wallet * wallet); void walletOpened(Wallet * wallet);

View file

@ -68,6 +68,9 @@ QVariant TransactionHistoryModel::data(const QModelIndex &index, int role) const
case TransactionDisplayAmountRole: case TransactionDisplayAmountRole:
result = tInfo->displayAmount(); result = tInfo->displayAmount();
break; break;
case TransactionAtomicAmountRole:
result = tInfo->atomicAmount();
break;
case TransactionFeeRole: case TransactionFeeRole:
result = tInfo->fee(); result = tInfo->fee();
break; break;
@ -112,6 +115,7 @@ QHash<int, QByteArray> TransactionHistoryModel::roleNames() const
roleNames.insert(TransactionFailedRole, "isFailed"); roleNames.insert(TransactionFailedRole, "isFailed");
roleNames.insert(TransactionAmountRole, "amount"); roleNames.insert(TransactionAmountRole, "amount");
roleNames.insert(TransactionDisplayAmountRole, "displayAmount"); roleNames.insert(TransactionDisplayAmountRole, "displayAmount");
roleNames.insert(TransactionAtomicAmountRole, "atomicAmount");
roleNames.insert(TransactionFeeRole, "fee"); roleNames.insert(TransactionFeeRole, "fee");
roleNames.insert(TransactionBlockHeightRole, "blockHeight"); roleNames.insert(TransactionBlockHeightRole, "blockHeight");
roleNames.insert(TransactionHashRole, "hash"); roleNames.insert(TransactionHashRole, "hash");

View file

@ -32,7 +32,8 @@ public:
TransactionIsOutRole, TransactionIsOutRole,
// extra roles for date and time (as UI wants date and time separately) // extra roles for date and time (as UI wants date and time separately)
TransactionDateRole, TransactionDateRole,
TransactionTimeRole TransactionTimeRole,
TransactionAtomicAmountRole
}; };
Q_ENUM(TransactionInfoRole) Q_ENUM(TransactionInfoRole)