Move cdiv to globals.h

tobtoht-patch-1
tobtoht 4 years ago
parent 70f1846de6
commit 51a0f86652

@ -9,12 +9,14 @@
#include <QDesktopWidget> #include <QDesktopWidget>
#include "appcontext.h" #include "appcontext.h"
#include "globals.h"
#include "utils/tails.h" #include "utils/tails.h"
#include "utils/whonix.h" #include "utils/whonix.h"
#include "utils/utils.h" #include "utils/utils.h"
#include "utils/prices.h" #include "utils/prices.h"
#include "utils/networktype.h" #include "utils/networktype.h"
#include "utils/wsclient.h" #include "utils/wsclient.h"
#include "utils/config.h"
// libwalletqt // libwalletqt
#include "libwalletqt/WalletManager.h" #include "libwalletqt/WalletManager.h"
@ -28,7 +30,6 @@
#include "model/SubaddressModel.h" #include "model/SubaddressModel.h"
#include "utils/keysfiles.h" #include "utils/keysfiles.h"
#include "utils/networktype.h" #include "utils/networktype.h"
#include "utils/config.h"
Prices *AppContext::prices = nullptr; Prices *AppContext::prices = nullptr;
@ -195,7 +196,7 @@ void AppContext::initWS() {
void AppContext::onCancelTransaction(PendingTransaction *tx, const QString &address) { void AppContext::onCancelTransaction(PendingTransaction *tx, const QString &address) {
// tx cancelled by user // tx cancelled by user
double amount = tx->amount() / AppContext::cdiv; double amount = tx->amount() / globals::cdiv;
emit createTransactionCancelled(address, amount); emit createTransactionCancelled(address, amount);
this->currentWallet->disposeTransaction(tx); this->currentWallet->disposeTransaction(tx);
} }
@ -234,8 +235,8 @@ void AppContext::onCreateTransaction(const QString &address, const double amount
return; return;
} }
auto balance = this->currentWallet->balance() / AppContext::cdiv; auto balance = this->currentWallet->balance() / globals::cdiv;
auto unlocked_balance = this->currentWallet->unlockedBalance() / AppContext::cdiv; auto unlocked_balance = this->currentWallet->unlockedBalance() / globals::cdiv;
if(!all && amount > unlocked_balance) { if(!all && amount > unlocked_balance) {
emit createTransactionError("Not enough money to spend"); emit createTransactionError("Not enough money to spend");
return; return;
@ -244,7 +245,7 @@ void AppContext::onCreateTransaction(const QString &address, const double amount
return; return;
} }
auto amount_num = static_cast<quint64>(amount * AppContext::cdiv); auto amount_num = static_cast<quint64>(amount * globals::cdiv);
qDebug() << "creating tx"; qDebug() << "creating tx";
if(all || amount == balance) if(all || amount == balance)
this->currentWallet->createTransactionAllAsync(address, "", this->tx_mixin, this->tx_priority); this->currentWallet->createTransactionAllAsync(address, "", this->tx_mixin, this->tx_priority);
@ -691,19 +692,19 @@ AppContext::~AppContext() {
// ############################################## LIBWALLET QT ######################################################### // ############################################## LIBWALLET QT #########################################################
void AppContext::onMoneySpent(const QString &txId, quint64 amount) { 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); qDebug() << Q_FUNC_INFO << txId << " " << QString::number(amount_num);
} }
void AppContext::onMoneyReceived(const QString &txId, quint64 amount) { void AppContext::onMoneyReceived(const QString &txId, quint64 amount) {
// Incoming tx included in a block. // 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); qDebug() << Q_FUNC_INFO << txId << " " << QString::number(amount_num);
} }
void AppContext::onUnconfirmedMoneyReceived(const QString &txId, quint64 amount) { void AppContext::onUnconfirmedMoneyReceived(const QString &txId, quint64 amount) {
// Incoming transaction in pool // 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); qDebug() << Q_FUNC_INFO << txId << " " << QString::number(amount_num);
if(this->currentWallet->synchronized()) { if(this->currentWallet->synchronized()) {
@ -792,10 +793,10 @@ void AppContext::updateBalance() {
if(!this->currentWallet) if(!this->currentWallet)
throw std::runtime_error("this should not happen, ever"); 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'); 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'); auto unlocked_str = QString::number(unlocked, 'f');
emit balanceUpdated(balance, unlocked, balance_str, unlocked_str); emit balanceUpdated(balance, unlocked, balance_str, unlocked_str);

@ -69,7 +69,6 @@ public:
const unsigned int kdfRounds = 1; const unsigned int kdfRounds = 1;
PendingTransaction::Priority tx_priority = PendingTransaction::Priority::Priority_Low; PendingTransaction::Priority tx_priority = PendingTransaction::Priority::Priority_Low;
quint32 tx_mixin = static_cast<const quint32 &>(10); quint32 tx_mixin = static_cast<const quint32 &>(10);
static constexpr const double cdiv = 1e12;
QString seedLanguage = "English"; // 14 word `monero-seed` only has English QString seedLanguage = "English"; // 14 word `monero-seed` only has English
QNetworkAccessManager *network; QNetworkAccessManager *network;

@ -8,6 +8,7 @@
#include "model/ModelUtils.h" #include "model/ModelUtils.h"
#include "libwalletqt/WalletManager.h" #include "libwalletqt/WalletManager.h"
#include "txconfadvdialog.h" #include "txconfadvdialog.h"
#include "globals.h"
#include <QMessageBox> #include <QMessageBox>
@ -31,15 +32,15 @@ TxConfDialog::TxConfDialog(AppContext *ctx, PendingTransaction *tx, const QStrin
}; };
QString amount = WalletManager::displayAmount(tx->amount()); 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)); ui->label_amount->setText(QString("%1 (%2 %3)").arg(amount, amount_fiat, preferredCur));
QString fee = WalletManager::displayAmount(tx->fee()); 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)); ui->label_fee->setText(QString("%1 (%2 %3)").arg(fee, fee_fiat, preferredCur));
QString total = WalletManager::displayAmount(tx->amount() + tx->fee()); 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_total->setText(QString("%1 (%2 %3)").arg(total, total_fiat, preferredCur));
ui->label_address->setText(ModelUtils::displayAddress(address, 2)); ui->label_address->setText(ModelUtils::displayAddress(address, 2));

@ -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 <QtGlobal>
namespace globals
{
const qreal cdiv = 1e12;
}
#endif //FEATHER_GLOBALS_H

@ -4,6 +4,7 @@
#include "TransactionHistoryModel.h" #include "TransactionHistoryModel.h"
#include "TransactionHistory.h" #include "TransactionHistory.h"
#include "TransactionInfo.h" #include "TransactionInfo.h"
#include "globals.h"
#include <QDateTime> #include <QDateTime>
#include <QDebug> #include <QDebug>
@ -151,7 +152,7 @@ QVariant TransactionHistoryModel::parseTransactionInfo(const TransactionInfo &tI
} }
case Column::Amount: 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; amount = (tInfo.direction() == TransactionInfo::Direction_Out && tInfo.amount() > 0) ? "-" + amount : "+" + amount;
return amount; return amount;
} }

@ -7,6 +7,7 @@
#include "libwalletqt/Wallet.h" #include "libwalletqt/Wallet.h"
#include "appcontext.h" #include "appcontext.h"
#include "globals.h"
#include "utils/xmrto.h" #include "utils/xmrto.h"
XmrToOrder::XmrToOrder(AppContext *ctx, UtilsNetworking *network, QString baseUrl, bool clearnet, XmrToRates *rates, QObject *parent) : 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) { 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. // listener for all outgoing transactions - will try to match the exact amount to this order.
if(this->state == OrderState::Status_OrderUnpaid){ 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) { if(!status) {
this->errorMsg = "TX failed to commit"; this->errorMsg = "TX failed to commit";
this->changeState(OrderState::Status_OrderFailed); this->changeState(OrderState::Status_OrderFailed);
@ -221,7 +222,7 @@ void XmrToOrder::changeState(OrderState _state) {
case OrderState::Status_OrderUnpaid: case OrderState::Status_OrderUnpaid:
// need to send Monero // need to send Monero
if(!m_paymentRequested) { 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) { if (this->incoming_amount_total >= unlocked_balance) {
this->state = OrderState::Status_OrderFailed; this->state = OrderState::Status_OrderFailed;
emit orderFailed(this); emit orderFailed(this);

Loading…
Cancel
Save