mirror of
				https://git.wownero.com/wowlet/wowlet.git
				synced 2024-08-15 01:03:14 +00:00 
			
		
		
		
	Merge pull request 'Send: don't lose precision' (#281) from tobtoht/feather:send_no_lose_precision into master
Reviewed-on: https://git.wownero.com/feather/feather/pulls/281
This commit is contained in:
		
						commit
						c2ec2c5dc9
					
				
					 7 changed files with 47 additions and 41 deletions
				
			
		| 
						 | 
					@ -206,10 +206,11 @@ void AppContext::onSweepOutput(const QString &keyImage, QString address, bool ch
 | 
				
			||||||
void AppContext::onCreateTransaction(XmrToOrder *order) {
 | 
					void AppContext::onCreateTransaction(XmrToOrder *order) {
 | 
				
			||||||
    // tx creation via xmr.to
 | 
					    // tx creation via xmr.to
 | 
				
			||||||
    const QString description = QString("XmrTo order %1").arg(order->uuid);
 | 
					    const QString description = QString("XmrTo order %1").arg(order->uuid);
 | 
				
			||||||
    this->onCreateTransaction(order->receiving_subaddress, order->incoming_amount_total, description, false);
 | 
					    quint64 amount = WalletManager::amountFromDouble(order->incoming_amount_total);
 | 
				
			||||||
 | 
					    this->onCreateTransaction(order->receiving_subaddress, amount, description, false);
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
void AppContext::onCreateTransaction(const QString &address, const double amount, const QString &description, bool all) {
 | 
					void AppContext::onCreateTransaction(const QString &address, quint64 amount, const QString &description, bool all) {
 | 
				
			||||||
    // tx creation
 | 
					    // tx creation
 | 
				
			||||||
    this->tmpTxDescription = description;
 | 
					    this->tmpTxDescription = description;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
| 
						 | 
					@ -218,13 +219,13 @@ void AppContext::onCreateTransaction(const QString &address, const double amount
 | 
				
			||||||
        return;
 | 
					        return;
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    if (!all && amount <= 0) {
 | 
					    if (!all && amount == 0) {
 | 
				
			||||||
        emit createTransactionError("Cannot send nothing");
 | 
					        emit createTransactionError("Cannot send nothing");
 | 
				
			||||||
        return;
 | 
					        return;
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    auto balance = this->currentWallet->balance() / globals::cdiv;
 | 
					    auto balance = this->currentWallet->balance();
 | 
				
			||||||
    auto unlocked_balance = this->currentWallet->unlockedBalance() / globals::cdiv;
 | 
					    auto unlocked_balance = this->currentWallet->unlockedBalance();
 | 
				
			||||||
    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;
 | 
				
			||||||
| 
						 | 
					@ -233,12 +234,11 @@ void AppContext::onCreateTransaction(const QString &address, const double amount
 | 
				
			||||||
        return;
 | 
					        return;
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    auto amount_num = static_cast<quint64>(amount * globals::cdiv);
 | 
					 | 
				
			||||||
    qDebug() << "creating tx";
 | 
					    qDebug() << "creating tx";
 | 
				
			||||||
    if(all || amount == balance)
 | 
					    if (all)
 | 
				
			||||||
        this->currentWallet->createTransactionAllAsync(address, "", this->tx_mixin, this->tx_priority);
 | 
					        this->currentWallet->createTransactionAllAsync(address, "", this->tx_mixin, this->tx_priority);
 | 
				
			||||||
    else
 | 
					    else
 | 
				
			||||||
        this->currentWallet->createTransactionAsync(address, "", amount_num, this->tx_mixin, this->tx_priority);
 | 
					        this->currentWallet->createTransactionAsync(address, "", amount, this->tx_mixin, this->tx_priority);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    emit initiateTransaction();
 | 
					    emit initiateTransaction();
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -109,7 +109,7 @@ public:
 | 
				
			||||||
 | 
					
 | 
				
			||||||
public slots:
 | 
					public slots:
 | 
				
			||||||
    void onOpenWallet(const QString& path, const QString &password);
 | 
					    void onOpenWallet(const QString& path, const QString &password);
 | 
				
			||||||
    void onCreateTransaction(const QString &address, double amount, const QString &description, bool all);
 | 
					    void onCreateTransaction(const QString &address, quint64 amount, const QString &description, bool all);
 | 
				
			||||||
    void onCreateTransaction(XmrToOrder *order);
 | 
					    void onCreateTransaction(XmrToOrder *order);
 | 
				
			||||||
    void onCancelTransaction(PendingTransaction *tx, const QString &address);
 | 
					    void onCancelTransaction(PendingTransaction *tx, const QString &address);
 | 
				
			||||||
    void onSweepOutput(const QString &keyImage, QString address, bool churn, int outputs) const;
 | 
					    void onSweepOutput(const QString &keyImage, QString address, bool churn, int outputs) const;
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -255,12 +255,12 @@ QString WalletManager::displayAmount(quint64 amount)
 | 
				
			||||||
    return QString::fromStdString(Monero::Wallet::displayAmount(amount));
 | 
					    return QString::fromStdString(Monero::Wallet::displayAmount(amount));
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
quint64 WalletManager::amountFromString(const QString &amount) const
 | 
					quint64 WalletManager::amountFromString(const QString &amount)
 | 
				
			||||||
{
 | 
					{
 | 
				
			||||||
    return Monero::Wallet::amountFromString(amount.toStdString());
 | 
					    return Monero::Wallet::amountFromString(amount.toStdString());
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
quint64 WalletManager::amountFromDouble(double amount) const
 | 
					quint64 WalletManager::amountFromDouble(double amount)
 | 
				
			||||||
{
 | 
					{
 | 
				
			||||||
    return Monero::Wallet::amountFromDouble(amount);
 | 
					    return Monero::Wallet::amountFromDouble(amount);
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -113,8 +113,8 @@ public:
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    //! since we can't call static method from QML, move it to this class
 | 
					    //! since we can't call static method from QML, move it to this class
 | 
				
			||||||
    Q_INVOKABLE static QString displayAmount(quint64 amount);
 | 
					    Q_INVOKABLE static QString displayAmount(quint64 amount);
 | 
				
			||||||
    Q_INVOKABLE quint64 amountFromString(const QString &amount) const;
 | 
					    Q_INVOKABLE static quint64 amountFromString(const QString &amount);
 | 
				
			||||||
    Q_INVOKABLE quint64 amountFromDouble(double amount) const;
 | 
					    Q_INVOKABLE static quint64 amountFromDouble(double amount);
 | 
				
			||||||
    Q_INVOKABLE quint64 maximumAllowedAmount() const;
 | 
					    Q_INVOKABLE quint64 maximumAllowedAmount() const;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    // QML JS engine doesn't support unsigned integers
 | 
					    // QML JS engine doesn't support unsigned integers
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -149,7 +149,7 @@ MainWindow::MainWindow(AppContext *ctx, QWidget *parent) :
 | 
				
			||||||
    ui->fiatTickerLayout->addWidget(m_balanceWidget);
 | 
					    ui->fiatTickerLayout->addWidget(m_balanceWidget);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    // Send widget
 | 
					    // Send widget
 | 
				
			||||||
    connect(ui->sendWidget, &SendWidget::createTransaction, m_ctx, QOverload<const QString &, const double, const QString &, bool>::of(&AppContext::onCreateTransaction));
 | 
					    connect(ui->sendWidget, &SendWidget::createTransaction, m_ctx, QOverload<const QString &, quint64, const QString &, bool>::of(&AppContext::onCreateTransaction));
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    // Nodes
 | 
					    // Nodes
 | 
				
			||||||
    connect(m_ctx->nodes, &Nodes::nodeExhausted, this, &MainWindow::showNodeExhaustedMessage);
 | 
					    connect(m_ctx->nodes, &Nodes::nodeExhausted, this, &MainWindow::showNodeExhaustedMessage);
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -5,6 +5,7 @@
 | 
				
			||||||
#include "sendwidget.h"
 | 
					#include "sendwidget.h"
 | 
				
			||||||
#include "mainwindow.h"
 | 
					#include "mainwindow.h"
 | 
				
			||||||
#include "ui_sendwidget.h"
 | 
					#include "ui_sendwidget.h"
 | 
				
			||||||
 | 
					#include "globals.h"
 | 
				
			||||||
 | 
					
 | 
				
			||||||
SendWidget::SendWidget(QWidget *parent) :
 | 
					SendWidget::SendWidget(QWidget *parent) :
 | 
				
			||||||
        QWidget(parent),
 | 
					        QWidget(parent),
 | 
				
			||||||
| 
						 | 
					@ -87,7 +88,6 @@ void SendWidget::sendClicked() {
 | 
				
			||||||
        return;
 | 
					        return;
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    double amount;
 | 
					 | 
				
			||||||
    QString currency = ui->comboCurrencySelection->currentText();
 | 
					    QString currency = ui->comboCurrencySelection->currentText();
 | 
				
			||||||
    QString recipient = ui->lineAddress->text().simplified().remove(' ');
 | 
					    QString recipient = ui->lineAddress->text().simplified().remove(' ');
 | 
				
			||||||
    QString description = ui->lineDescription->text();
 | 
					    QString description = ui->lineDescription->text();
 | 
				
			||||||
| 
						 | 
					@ -96,24 +96,23 @@ void SendWidget::sendClicked() {
 | 
				
			||||||
        return;
 | 
					        return;
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    if (currency != "XMR") {
 | 
					    quint64 amount;
 | 
				
			||||||
        amount = this->conversionAmount();
 | 
					    if (currency == "XMR") {
 | 
				
			||||||
        if(amount <= 0.0) {
 | 
					        amount = this->amount();
 | 
				
			||||||
 | 
					        bool sendAll = (ui->lineAmount->text() == "all");
 | 
				
			||||||
 | 
					        if (amount == 0 && !sendAll) {
 | 
				
			||||||
 | 
					            QMessageBox::warning(this, "Amount error", "Invalid amount specified.");
 | 
				
			||||||
 | 
					            return;
 | 
				
			||||||
 | 
					        }
 | 
				
			||||||
 | 
					        emit createTransaction(recipient, amount, description, sendAll);
 | 
				
			||||||
 | 
					    } else {
 | 
				
			||||||
 | 
					        amount = WalletManager::amountFromDouble(this->conversionAmount());
 | 
				
			||||||
 | 
					        if (amount == 0) {
 | 
				
			||||||
            QMessageBox::warning(this, "Fiat conversion error", "Could not create transaction.");
 | 
					            QMessageBox::warning(this, "Fiat conversion error", "Could not create transaction.");
 | 
				
			||||||
            return;
 | 
					            return;
 | 
				
			||||||
        }
 | 
					        }
 | 
				
			||||||
        emit createTransaction(recipient, amount, description, false);
 | 
					        emit createTransaction(recipient, amount, description, false);
 | 
				
			||||||
        return;
 | 
					 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					 | 
				
			||||||
    amount = this->amount();
 | 
					 | 
				
			||||||
    bool sendAll = amount == -1.0;
 | 
					 | 
				
			||||||
    if(amount == 0.0){
 | 
					 | 
				
			||||||
        QMessageBox::warning(this, "Amount error", "Invalid amount specified.");
 | 
					 | 
				
			||||||
        return;
 | 
					 | 
				
			||||||
    }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
    emit createTransaction(recipient, amount, description, sendAll);
 | 
					 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
void SendWidget::aliasClicked() {
 | 
					void SendWidget::aliasClicked() {
 | 
				
			||||||
| 
						 | 
					@ -129,13 +128,14 @@ void SendWidget::clearClicked() {
 | 
				
			||||||
 | 
					
 | 
				
			||||||
void SendWidget::btnMaxClicked() {
 | 
					void SendWidget::btnMaxClicked() {
 | 
				
			||||||
    ui->lineAmount->setText("all");
 | 
					    ui->lineAmount->setText("all");
 | 
				
			||||||
 | 
					    this->updateConversionLabel();
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
void SendWidget::updateConversionLabel() {
 | 
					void SendWidget::updateConversionLabel() {
 | 
				
			||||||
    auto amount = this->amount();
 | 
					    auto amount = this->amountDouble();
 | 
				
			||||||
    if(amount == -1) return;
 | 
					
 | 
				
			||||||
    ui->label_conversionAmount->setText("");
 | 
					    ui->label_conversionAmount->setText("");
 | 
				
			||||||
    if(amount <= 0) {
 | 
					    if (amount <= 0) {
 | 
				
			||||||
        ui->label_conversionAmount->hide();
 | 
					        ui->label_conversionAmount->hide();
 | 
				
			||||||
        return;
 | 
					        return;
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
| 
						 | 
					@ -147,7 +147,7 @@ void SendWidget::updateConversionLabel() {
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        } else {
 | 
					        } else {
 | 
				
			||||||
            auto preferredFiatCurrency = config()->get(Config::preferredFiatCurrency).toString();
 | 
					            auto preferredFiatCurrency = config()->get(Config::preferredFiatCurrency).toString();
 | 
				
			||||||
            double conversionAmount = AppContext::prices->convert("XMR", preferredFiatCurrency, this->amount());
 | 
					            double conversionAmount = AppContext::prices->convert("XMR", preferredFiatCurrency, this->amountDouble());
 | 
				
			||||||
            return QString("~%1 %2").arg(QString::number(conversionAmount, 'f', 2), preferredFiatCurrency);
 | 
					            return QString("~%1 %2").arg(QString::number(conversionAmount, 'f', 2), preferredFiatCurrency);
 | 
				
			||||||
        }
 | 
					        }
 | 
				
			||||||
    }();
 | 
					    }();
 | 
				
			||||||
| 
						 | 
					@ -158,18 +158,23 @@ void SendWidget::updateConversionLabel() {
 | 
				
			||||||
 | 
					
 | 
				
			||||||
double SendWidget::conversionAmount() {
 | 
					double SendWidget::conversionAmount() {
 | 
				
			||||||
    QString currency = ui->comboCurrencySelection->currentText();
 | 
					    QString currency = ui->comboCurrencySelection->currentText();
 | 
				
			||||||
    return AppContext::prices->convert(currency, "XMR", this->amount());
 | 
					    return AppContext::prices->convert(currency, "XMR", this->amountDouble());
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
double SendWidget::amount() {
 | 
					quint64 SendWidget::amount() {
 | 
				
			||||||
    // grab amount from "amount" text box
 | 
					    // grab amount from "amount" text box
 | 
				
			||||||
    QString amount = ui->lineAmount->text();
 | 
					    QString amount = ui->lineAmount->text();
 | 
				
			||||||
    if(amount == "all") return -1.0;
 | 
					    if (amount == "all") return 0;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    amount.replace(',', '.');
 | 
					    amount.replace(',', '.');
 | 
				
			||||||
    if(amount.isEmpty()) return 0.0;
 | 
					    if (amount.isEmpty()) return 0;
 | 
				
			||||||
    auto amount_num = amount.toDouble();
 | 
					
 | 
				
			||||||
    if(amount_num <= 0) return 0.0;
 | 
					    return WalletManager::amountFromString(amount);
 | 
				
			||||||
    return amount_num;
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					double SendWidget::amountDouble() {
 | 
				
			||||||
 | 
					    quint64 amount = this->amount();
 | 
				
			||||||
 | 
					    return amount / globals::cdiv;
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
void SendWidget::onOpenAliasResolved(const QString &address, const QString &openAlias) {
 | 
					void SendWidget::onOpenAliasResolved(const QString &address, const QString &openAlias) {
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -44,14 +44,15 @@ public slots:
 | 
				
			||||||
 | 
					
 | 
				
			||||||
signals:
 | 
					signals:
 | 
				
			||||||
    void resolveOpenAlias(const QString &address);
 | 
					    void resolveOpenAlias(const QString &address);
 | 
				
			||||||
    void createTransaction(const QString &address, double amount, const QString &description, bool all);
 | 
					    void createTransaction(const QString &address, quint64 amount, const QString &description, bool all);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
private:
 | 
					private:
 | 
				
			||||||
    void setupComboBox();
 | 
					    void setupComboBox();
 | 
				
			||||||
 | 
					    double amountDouble();
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    Ui::SendWidget *ui;
 | 
					    Ui::SendWidget *ui;
 | 
				
			||||||
    AppContext *m_ctx;
 | 
					    AppContext *m_ctx;
 | 
				
			||||||
    double amount();
 | 
					    quint64 amount();
 | 
				
			||||||
    double conversionAmount();
 | 
					    double conversionAmount();
 | 
				
			||||||
};
 | 
					};
 | 
				
			||||||
 | 
					
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue