2015-04-29 17:03:08 +00:00
|
|
|
// Copyright (c) 2011-2015 The Cryptonote developers
|
|
|
|
// Distributed under the MIT/X11 software license, see the accompanying
|
|
|
|
// file COPYING or http://www.opensource.org/licenses/mit-license.php.
|
|
|
|
|
|
|
|
#include "AddressBookModel.h"
|
|
|
|
#include "CurrencyAdapter.h"
|
|
|
|
#include "MainWindow.h"
|
|
|
|
#include "NodeAdapter.h"
|
|
|
|
#include "SendFrame.h"
|
|
|
|
#include "TransferFrame.h"
|
|
|
|
#include "WalletAdapter.h"
|
|
|
|
#include "WalletEvents.h"
|
|
|
|
|
|
|
|
#include "ui_sendframe.h"
|
|
|
|
|
|
|
|
namespace WalletGui {
|
|
|
|
|
|
|
|
SendFrame::SendFrame(QWidget* _parent) : QFrame(_parent), m_ui(new Ui::SendFrame) {
|
|
|
|
m_ui->setupUi(this);
|
|
|
|
clearAllClicked();
|
|
|
|
mixinValueChanged(m_ui->m_mixinSlider->value());
|
|
|
|
|
|
|
|
connect(&WalletAdapter::instance(), &WalletAdapter::walletSendTransactionCompletedSignal, this, &SendFrame::sendTransactionCompleted,
|
|
|
|
Qt::QueuedConnection);
|
|
|
|
connect(&WalletAdapter::instance(), &WalletAdapter::walletActualBalanceUpdatedSignal, this, &SendFrame::walletActualBalanceUpdated,
|
|
|
|
Qt::QueuedConnection);
|
|
|
|
|
|
|
|
m_ui->m_tickerLabel->setText(CurrencyAdapter::instance().getCurrencyTicker().toUpper());
|
|
|
|
}
|
|
|
|
|
|
|
|
SendFrame::~SendFrame() {
|
|
|
|
}
|
|
|
|
|
|
|
|
void SendFrame::addRecipientClicked() {
|
|
|
|
TransferFrame* newTransfer = new TransferFrame(m_ui->m_transfersScrollarea);
|
|
|
|
m_ui->m_send_frame_layout->insertWidget(m_transfers.size(), newTransfer);
|
|
|
|
m_transfers.append(newTransfer);
|
|
|
|
if (m_transfers.size() == 1) {
|
|
|
|
newTransfer->disableRemoveButton(true);
|
|
|
|
} else {
|
|
|
|
m_transfers[0]->disableRemoveButton(false);
|
|
|
|
}
|
|
|
|
|
|
|
|
connect(newTransfer, &TransferFrame::destroyed, [this](QObject* _obj) {
|
|
|
|
m_transfers.removeOne(static_cast<TransferFrame*>(_obj));
|
|
|
|
if (m_transfers.size() == 1) {
|
|
|
|
m_transfers[0]->disableRemoveButton(true);
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
void SendFrame::clearAllClicked() {
|
|
|
|
Q_FOREACH (TransferFrame* transfer, m_transfers) {
|
|
|
|
transfer->close();
|
|
|
|
}
|
|
|
|
|
|
|
|
m_transfers.clear();
|
|
|
|
addRecipientClicked();
|
|
|
|
m_ui->m_paymentIdEdit->clear();
|
|
|
|
m_ui->m_mixinSlider->setValue(2);
|
|
|
|
}
|
|
|
|
|
|
|
|
void SendFrame::sendClicked() {
|
2015-09-18 12:37:30 +00:00
|
|
|
QVector<CryptoNote::WalletLegacyTransfer> walletTransfers;
|
2015-04-29 17:03:08 +00:00
|
|
|
Q_FOREACH (TransferFrame * transfer, m_transfers) {
|
|
|
|
QString address = transfer->getAddress();
|
|
|
|
if (!CurrencyAdapter::instance().validateAddress(address)) {
|
|
|
|
QCoreApplication::postEvent(
|
|
|
|
&MainWindow::instance(),
|
|
|
|
new ShowMessageEvent(tr("Invalid recipient address"), QtCriticalMsg));
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2015-09-18 12:37:30 +00:00
|
|
|
CryptoNote::WalletLegacyTransfer walletTransfer;
|
2015-04-29 17:03:08 +00:00
|
|
|
walletTransfer.address = address.toStdString();
|
|
|
|
uint64_t amount = CurrencyAdapter::instance().parseAmount(transfer->getAmountString());
|
|
|
|
walletTransfer.amount = amount;
|
|
|
|
walletTransfers.push_back(walletTransfer);
|
|
|
|
QString label = transfer->getLabel();
|
|
|
|
if (!label.isEmpty()) {
|
|
|
|
AddressBookModel::instance().addAddress(label, address);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-04-30 12:11:48 +00:00
|
|
|
quint64 fee = CurrencyAdapter::instance().getMinimumFee();
|
2015-04-29 17:03:08 +00:00
|
|
|
if (WalletAdapter::instance().isOpen()) {
|
|
|
|
WalletAdapter::instance().sendTransaction(walletTransfers, fee, m_ui->m_paymentIdEdit->text(), m_ui->m_mixinSlider->value());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void SendFrame::mixinValueChanged(int _value) {
|
|
|
|
m_ui->m_mixinEdit->setText(QString::number(_value));
|
|
|
|
}
|
|
|
|
|
2015-04-30 12:11:48 +00:00
|
|
|
void SendFrame::sendTransactionCompleted(CryptoNote::TransactionId _id, bool _error, const QString& _errorText) {
|
2015-04-29 17:03:08 +00:00
|
|
|
Q_UNUSED(_id);
|
2015-04-30 12:11:48 +00:00
|
|
|
if (_error) {
|
|
|
|
QCoreApplication::postEvent(
|
|
|
|
&MainWindow::instance(),
|
|
|
|
new ShowMessageEvent(_errorText, QtCriticalMsg));
|
|
|
|
} else {
|
|
|
|
clearAllClicked();
|
|
|
|
}
|
2015-04-29 17:03:08 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void SendFrame::walletActualBalanceUpdated(quint64 _balance) {
|
|
|
|
m_ui->m_balanceLabel->setText(CurrencyAdapter::instance().formatAmount(_balance));
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|