diff --git a/src/appcontext.cpp b/src/appcontext.cpp index e2826a3..3870c2d 100644 --- a/src/appcontext.cpp +++ b/src/appcontext.cpp @@ -9,12 +9,14 @@ #include #include "appcontext.h" +#include "globals.h" #include "utils/tails.h" #include "utils/whonix.h" #include "utils/utils.h" #include "utils/prices.h" #include "utils/networktype.h" #include "utils/wsclient.h" +#include "utils/config.h" // libwalletqt #include "libwalletqt/WalletManager.h" @@ -28,7 +30,6 @@ #include "model/SubaddressModel.h" #include "utils/keysfiles.h" #include "utils/networktype.h" -#include "utils/config.h" Prices *AppContext::prices = nullptr; @@ -195,7 +196,7 @@ void AppContext::initWS() { void AppContext::onCancelTransaction(PendingTransaction *tx, const QString &address) { // tx cancelled by user - double amount = tx->amount() / AppContext::cdiv; + double amount = tx->amount() / globals::cdiv; emit createTransactionCancelled(address, amount); this->currentWallet->disposeTransaction(tx); } @@ -234,8 +235,8 @@ void AppContext::onCreateTransaction(const QString &address, const double amount return; } - auto balance = this->currentWallet->balance() / AppContext::cdiv; - auto unlocked_balance = this->currentWallet->unlockedBalance() / AppContext::cdiv; + auto balance = this->currentWallet->balance() / globals::cdiv; + auto unlocked_balance = this->currentWallet->unlockedBalance() / globals::cdiv; if(!all && amount > unlocked_balance) { emit createTransactionError("Not enough money to spend"); return; @@ -244,7 +245,7 @@ void AppContext::onCreateTransaction(const QString &address, const double amount return; } - auto amount_num = static_cast(amount * AppContext::cdiv); + auto amount_num = static_cast(amount * globals::cdiv); qDebug() << "creating tx"; if(all || amount == balance) this->currentWallet->createTransactionAllAsync(address, "", this->tx_mixin, this->tx_priority); @@ -691,19 +692,19 @@ AppContext::~AppContext() { // ############################################## LIBWALLET QT ######################################################### void AppContext::onMoneySpent(const QString &txId, quint64 amount) { - auto amount_num = amount / AppContext::cdiv; + auto amount_num = amount / globals::cdiv; qDebug() << Q_FUNC_INFO << txId << " " << QString::number(amount_num); } void AppContext::onMoneyReceived(const QString &txId, quint64 amount) { // Incoming tx included in a block. - auto amount_num = amount / AppContext::cdiv; + auto amount_num = amount / globals::cdiv; qDebug() << Q_FUNC_INFO << txId << " " << QString::number(amount_num); } void AppContext::onUnconfirmedMoneyReceived(const QString &txId, quint64 amount) { // Incoming transaction in pool - auto amount_num = amount / AppContext::cdiv; + auto amount_num = amount / globals::cdiv; qDebug() << Q_FUNC_INFO << txId << " " << QString::number(amount_num); if(this->currentWallet->synchronized()) { @@ -792,10 +793,10 @@ void AppContext::updateBalance() { if(!this->currentWallet) throw std::runtime_error("this should not happen, ever"); - AppContext::balance = this->currentWallet->balance() / AppContext::cdiv; + AppContext::balance = this->currentWallet->balance() / globals::cdiv; auto balance_str = QString::number(balance, 'f'); - double unlocked = this->currentWallet->unlockedBalance() / AppContext::cdiv; + double unlocked = this->currentWallet->unlockedBalance() / globals::cdiv; auto unlocked_str = QString::number(unlocked, 'f'); emit balanceUpdated(balance, unlocked, balance_str, unlocked_str); diff --git a/src/appcontext.h b/src/appcontext.h index dd9057c..cdf7160 100644 --- a/src/appcontext.h +++ b/src/appcontext.h @@ -69,7 +69,6 @@ public: const unsigned int kdfRounds = 1; PendingTransaction::Priority tx_priority = PendingTransaction::Priority::Priority_Low; quint32 tx_mixin = static_cast(10); - static constexpr const double cdiv = 1e12; QString seedLanguage = "English"; // 14 word `monero-seed` only has English QNetworkAccessManager *network; diff --git a/src/dialog/txconfdialog.cpp b/src/dialog/txconfdialog.cpp index 0724a98..7bb9a11 100644 --- a/src/dialog/txconfdialog.cpp +++ b/src/dialog/txconfdialog.cpp @@ -8,6 +8,7 @@ #include "model/ModelUtils.h" #include "libwalletqt/WalletManager.h" #include "txconfadvdialog.h" +#include "globals.h" #include @@ -31,15 +32,15 @@ TxConfDialog::TxConfDialog(AppContext *ctx, PendingTransaction *tx, const QStrin }; QString amount = WalletManager::displayAmount(tx->amount()); - QString amount_fiat = convert(tx->amount() / AppContext::cdiv); + QString amount_fiat = convert(tx->amount() / globals::cdiv); ui->label_amount->setText(QString("%1 (%2 %3)").arg(amount, amount_fiat, preferredCur)); QString fee = WalletManager::displayAmount(tx->fee()); - QString fee_fiat = convert(tx->fee() / AppContext::cdiv); + QString fee_fiat = convert(tx->fee() / globals::cdiv); ui->label_fee->setText(QString("%1 (%2 %3)").arg(fee, fee_fiat, preferredCur)); QString total = WalletManager::displayAmount(tx->amount() + tx->fee()); - QString total_fiat = convert((tx->amount() + tx->fee()) / AppContext::cdiv); + QString total_fiat = convert((tx->amount() + tx->fee()) / globals::cdiv); ui->label_total->setText(QString("%1 (%2 %3)").arg(total, total_fiat, preferredCur)); ui->label_address->setText(ModelUtils::displayAddress(address, 2)); diff --git a/src/globals.h b/src/globals.h new file mode 100644 index 0000000..d3e01cd --- /dev/null +++ b/src/globals.h @@ -0,0 +1,14 @@ +// SPDX-License-Identifier: BSD-3-Clause +// Copyright (c) 2020, The Monero Project. + +#ifndef FEATHER_GLOBALS_H +#define FEATHER_GLOBALS_H + +#include + +namespace globals +{ + const qreal cdiv = 1e12; +} + +#endif //FEATHER_GLOBALS_H diff --git a/src/model/TransactionHistoryModel.cpp b/src/model/TransactionHistoryModel.cpp index 6819e04..969dae7 100644 --- a/src/model/TransactionHistoryModel.cpp +++ b/src/model/TransactionHistoryModel.cpp @@ -4,6 +4,7 @@ #include "TransactionHistoryModel.h" #include "TransactionHistory.h" #include "TransactionInfo.h" +#include "globals.h" #include #include @@ -151,7 +152,7 @@ QVariant TransactionHistoryModel::parseTransactionInfo(const TransactionInfo &tI } case Column::Amount: { - QString amount = QString::number(tInfo.atomicAmount() / 1e12, 'f', 4); + QString amount = QString::number(tInfo.atomicAmount() / globals::cdiv, 'f', 4); amount = (tInfo.direction() == TransactionInfo::Direction_Out && tInfo.amount() > 0) ? "-" + amount : "+" + amount; return amount; } diff --git a/src/utils/xmrtoorder.cpp b/src/utils/xmrtoorder.cpp index b5556d6..6adef58 100644 --- a/src/utils/xmrtoorder.cpp +++ b/src/utils/xmrtoorder.cpp @@ -7,6 +7,7 @@ #include "libwalletqt/Wallet.h" #include "appcontext.h" +#include "globals.h" #include "utils/xmrto.h" XmrToOrder::XmrToOrder(AppContext *ctx, UtilsNetworking *network, QString baseUrl, bool clearnet, XmrToRates *rates, QObject *parent) : @@ -38,7 +39,7 @@ void XmrToOrder::onTransactionCancelled(const QString &address, double amount) { void XmrToOrder::onTransactionCommitted(bool status, PendingTransaction *tx, const QStringList& txid) { // listener for all outgoing transactions - will try to match the exact amount to this order. if(this->state == OrderState::Status_OrderUnpaid){ - if(tx->amount() / AppContext::cdiv == this->incoming_amount_total) { + if(tx->amount() / globals::cdiv == this->incoming_amount_total) { if(!status) { this->errorMsg = "TX failed to commit"; this->changeState(OrderState::Status_OrderFailed); @@ -221,7 +222,7 @@ void XmrToOrder::changeState(OrderState _state) { case OrderState::Status_OrderUnpaid: // need to send Monero if(!m_paymentRequested) { - auto unlocked_balance = m_ctx->currentWallet->unlockedBalance() / AppContext::cdiv; + auto unlocked_balance = m_ctx->currentWallet->unlockedBalance() / globals::cdiv; if (this->incoming_amount_total >= unlocked_balance) { this->state = OrderState::Status_OrderFailed; emit orderFailed(this);