|
|
@ -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) {
|
|
|
|
|
|
|
|
QMessageBox::warning(this, "Fiat conversion error", "Could not create transaction.");
|
|
|
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
emit createTransaction(recipient, amount, description, false);
|
|
|
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
amount = this->amount();
|
|
|
|
amount = this->amount();
|
|
|
|
bool sendAll = amount == -1.0;
|
|
|
|
bool sendAll = (ui->lineAmount->text() == "all");
|
|
|
|
if(amount == 0.0){
|
|
|
|
if (amount == 0 && !sendAll) {
|
|
|
|
QMessageBox::warning(this, "Amount error", "Invalid amount specified.");
|
|
|
|
QMessageBox::warning(this, "Amount error", "Invalid amount specified.");
|
|
|
|
return;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
emit createTransaction(recipient, amount, description, sendAll);
|
|
|
|
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.");
|
|
|
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
emit createTransaction(recipient, amount, description, false);
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void SendWidget::aliasClicked() {
|
|
|
|
void SendWidget::aliasClicked() {
|
|
|
@ -129,11 +128,12 @@ 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();
|
|
|
@ -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) {
|
|
|
|