diff --git a/pages/History.qml b/pages/History.qml index a6c216bf..61ff0515 100644 --- a/pages/History.qml +++ b/pages/History.qml @@ -48,13 +48,19 @@ Rectangle { for (var i = 0; i < count; ++i) { var idx = model.index(i, 0) var isout = model.data(idx, TransactionHistoryModel.TransactionIsOutRole); - var amount = model.data(idx, TransactionHistoryModel.TransactionAmountRole); + var amount = model.data(idx, TransactionHistoryModel.TransactionAtomicAmountRole); if (isout) - total -= amount + total = walletManager.subi(total, amount) 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: { diff --git a/src/libwalletqt/TransactionInfo.cpp b/src/libwalletqt/TransactionInfo.cpp index 248fd73e..fb096a14 100644 --- a/src/libwalletqt/TransactionInfo.cpp +++ b/src/libwalletqt/TransactionInfo.cpp @@ -25,6 +25,11 @@ double TransactionInfo::amount() const return WalletManager::instance()->displayAmount(m_pimpl->amount()).toDouble(); } +quint64 TransactionInfo::atomicAmount() const +{ + return m_pimpl->amount(); +} + QString TransactionInfo::displayAmount() const { return WalletManager::instance()->displayAmount(m_pimpl->amount()); diff --git a/src/libwalletqt/TransactionInfo.h b/src/libwalletqt/TransactionInfo.h index f30f42fa..7e9396a1 100644 --- a/src/libwalletqt/TransactionInfo.h +++ b/src/libwalletqt/TransactionInfo.h @@ -12,6 +12,7 @@ class TransactionInfo : public QObject Q_PROPERTY(bool isPending READ isPending) Q_PROPERTY(bool isFailed READ isFailed) Q_PROPERTY(double amount READ amount) + Q_PROPERTY(quint64 atomicAmount READ atomicAmount) Q_PROPERTY(QString displayAmount READ displayAmount) Q_PROPERTY(QString fee READ fee) Q_PROPERTY(quint64 blockHeight READ blockHeight) @@ -42,6 +43,7 @@ public: bool isPending() const; bool isFailed() const; double amount() const; + quint64 atomicAmount() const; QString displayAmount() const; QString fee() const; quint64 blockHeight() const; diff --git a/src/libwalletqt/WalletManager.h b/src/libwalletqt/WalletManager.h index 7f8a583c..8e63050a 100644 --- a/src/libwalletqt/WalletManager.h +++ b/src/libwalletqt/WalletManager.h @@ -101,6 +101,11 @@ public: 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: void walletOpened(Wallet * wallet); diff --git a/src/model/TransactionHistoryModel.cpp b/src/model/TransactionHistoryModel.cpp index 1ad17944..cf280e99 100644 --- a/src/model/TransactionHistoryModel.cpp +++ b/src/model/TransactionHistoryModel.cpp @@ -68,6 +68,9 @@ QVariant TransactionHistoryModel::data(const QModelIndex &index, int role) const case TransactionDisplayAmountRole: result = tInfo->displayAmount(); break; + case TransactionAtomicAmountRole: + result = tInfo->atomicAmount(); + break; case TransactionFeeRole: result = tInfo->fee(); break; @@ -112,6 +115,7 @@ QHash TransactionHistoryModel::roleNames() const roleNames.insert(TransactionFailedRole, "isFailed"); roleNames.insert(TransactionAmountRole, "amount"); roleNames.insert(TransactionDisplayAmountRole, "displayAmount"); + roleNames.insert(TransactionAtomicAmountRole, "atomicAmount"); roleNames.insert(TransactionFeeRole, "fee"); roleNames.insert(TransactionBlockHeightRole, "blockHeight"); roleNames.insert(TransactionHashRole, "hash"); diff --git a/src/model/TransactionHistoryModel.h b/src/model/TransactionHistoryModel.h index 0960ceae..8b18f887 100644 --- a/src/model/TransactionHistoryModel.h +++ b/src/model/TransactionHistoryModel.h @@ -32,7 +32,8 @@ public: TransactionIsOutRole, // extra roles for date and time (as UI wants date and time separately) TransactionDateRole, - TransactionTimeRole + TransactionTimeRole, + TransactionAtomicAmountRole }; Q_ENUM(TransactionInfoRole)