Permalink
Browse files

Update Stake For Charity

Add Change Address
Make Change Address, min and max write to wallet.
Add Labels
Change getS4C calls

Add missed .ui files from earlier commits
  • Loading branch information...
Tranz5 committed Sep 28, 2014
1 parent c9e91a0 commit 95bbc2f976d10845b05393b886cd090d6b7a793f
View
@@ -1241,8 +1241,8 @@ Array RPCConvertValues(const std::string &strMethod, const std::vector<std::stri
if (strMethod == "loadwallet" && n > 3) ConvertTo<bool>(params[3]);
if (strMethod == "loadwallet" && n > 4) ConvertTo<boost::int64_t>(params[4]);
if (strMethod == "stakeforcharity" && n > 1) ConvertTo<int>(params[1]);
if (strMethod == "stakeforcharity" && n > 2) ConvertTo<double>(params[2]);
if (strMethod == "stakeforcharity" && n > 3) ConvertTo<double>(params[3]);
if (strMethod == "stakeforcharity" && n > 4) ConvertTo<double>(params[4]);
return params;
}
View
@@ -664,16 +664,24 @@ void BitcoinGUI::lockIconClicked()
void BitcoinGUI::stakingIconClicked()
{
TRY_LOCK(cs_main, lockMain);
if(!lockMain)
return;
TRY_LOCK(cs_main, lockMain);
if(!lockMain)
return;
uint64 nMinWeight = 0, nMaxWeight = 0;
walletStack->getStakeWeight(nMinWeight,nMaxWeight,nWeight);
uint64 nMinWeight = 0, nMaxWeight = 0;
walletStack->getStakeWeight(nMinWeight,nMaxWeight,nWeight);
int unit = clientModel->getOptionsModel()->getDisplayUnit();
CBitcoinAddress strAddress;
CBitcoinAddress strChangeAddress;
int nPer;
int64 nMin;
int64 nMax;
walletStack->getStakeForCharity(nPer, strAddress, strChangeAddress, nMin, nMax);
int unit = clientModel->getOptionsModel()->getDisplayUnit();
message(tr("Extended Staking Information"),
message(tr("Extended Staking Information"),
tr("Client Version: %1\n"
"Protocol Version: %2\n\n"
"Last PoS Block Number: %3\n"
@@ -705,8 +713,8 @@ void BitcoinGUI::stakingIconClicked()
.arg(BitcoinUnits::formatWithUnit(unit, walletStack->getReserveBalance()))
.arg(BitcoinUnits::formatWithUnit(unit, nSplitThreshold, false))
.arg(BitcoinUnits::formatWithUnit(unit, nCombineThreshold, false))
.arg(walletStack->getStakeForCharityAddress())
.arg(walletStack->getStakeForCharityPercent())
.arg(strAddress.ToString().c_str())
.arg(nPer)
.arg(walletManager->GetWalletCount())
.arg(walletStack->getTotStakeWeight())
.arg(BitcoinUnits::formatWithUnit(unit, clientModel->getMoneySupply(), false))
View
@@ -6,6 +6,8 @@
#include "addressbookpage.h"
#include "init.h"
#include <QLineEdit>
StakeForCharityDialog::StakeForCharityDialog(QWidget *parent) :
QWidget(parent),
@@ -26,22 +28,38 @@ void StakeForCharityDialog::setModel(WalletModel *model)
{
this->model = model;
QString strAddress = model->getStakeForCharityAddress();
QString strPer = QString::number(model->getStakeForCharityPercent());
CBitcoinAddress strAddress;
CBitcoinAddress strChangeAddress;
int nPer;
int64 nMin;
int64 nMax;
model->getStakeForCharity(nPer, strAddress, strChangeAddress, nMin, nMax);
if (!strAddress.isEmpty() && strPer.toInt() > 0 )
if (strAddress.IsValid() && nPer > 0 )
{
ui->charityAddressEdit->setText(strAddress);
ui->charityPercentEdit->setText(strPer);
ui->charityAddressEdit->setText(strAddress.ToString().c_str());
ui->charityPercentEdit->setText(QString::number(nPer));
if (strChangeAddress.IsValid())
ui->charityChangeAddressEdit->setText(strChangeAddress.ToString().c_str());
if (nMin > 0 && nMin != MIN_TX_FEE)
ui->charityMinEdit->setText(QString::number(nMin/COIN));
if (nMax > 0 && nMax != MAX_MONEY)
ui->charityMaxEdit->setText(QString::number(nMax/COIN));
ui->message->setStyleSheet("QLabel { color: green; }");
ui->message->setText(tr("Thank you for giving to\n") + strAddress + tr("."));
ui->message->setText(tr("Thank you for giving to\n") + strAddress.ToString().c_str() + tr("."));
}
}
void StakeForCharityDialog::setAddress(const QString &address)
{
ui->charityAddressEdit->setText(address);
ui->charityAddressEdit->setFocus();
setAddress(address, ui->charityAddressEdit);
}
void StakeForCharityDialog::setAddress(const QString &address, QLineEdit *addrEdit)
{
addrEdit->setText(address);
addrEdit->setFocus();
}
void StakeForCharityDialog::on_addressBookButton_clicked()
@@ -51,9 +69,18 @@ void StakeForCharityDialog::on_addressBookButton_clicked()
AddressBookPage dlg(AddressBookPage::ForSending, AddressBookPage::SendingTab, this);
dlg.setModel(model->getAddressTableModel());
if (dlg.exec())
{
setAddress(dlg.getReturnValue());
}
setAddress(dlg.getReturnValue(), ui->charityAddressEdit);
}
}
void StakeForCharityDialog::on_changeAddressBookButton_clicked()
{
if (model && model->getAddressTableModel())
{
AddressBookPage dlg(AddressBookPage::ForSending, AddressBookPage::ReceivingTab, this);
dlg.setModel(model->getAddressTableModel());
if (dlg.exec())
setAddress(dlg.getReturnValue(), ui->charityChangeAddressEdit);
}
}
@@ -69,12 +96,13 @@ void StakeForCharityDialog::on_enableButton_clicked()
bool fValidConversion = false;
int64 nMinAmount = MIN_TXOUT_AMOUNT;
int64 nMaxAmount = MAX_MONEY;
CBitcoinAddress changeAddress = "";
CBitcoinAddress address = ui->charityAddressEdit->text().toStdString();
if (!address.IsValid())
{
ui->message->setStyleSheet("QLabel { color: red; }");
ui->message->setText(tr("The entered address: ") + ui->charityAddressEdit->text() + tr(" is invalid.\nPlease check the address and try again."));
ui->message->setText(tr("The entered address:\n") + ui->charityAddressEdit->text() + tr(" is invalid.\nPlease check the address and try again."));
ui->charityAddressEdit->setFocus();
return;
}
@@ -112,7 +140,34 @@ void StakeForCharityDialog::on_enableButton_clicked()
}
}
model->setStakeForCharity(true, nCharityPercent, address, nMinAmount, nMaxAmount);
if (nMinAmount >= nMaxAmount)
{
ui->message->setStyleSheet("QLabel { color: red; }");
ui->message->setText(tr("Min Amount > Max Amount, please re-enter."));
ui->charityMinEdit->setFocus();
return;
}
if (!ui->charityChangeAddressEdit->text().isEmpty())
{
changeAddress = ui->charityChangeAddressEdit->text().toStdString();
if (!changeAddress.IsValid())
{
ui->message->setStyleSheet("QLabel { color: red; }");
ui->message->setText(tr("The entered change address:\n") + ui->charityChangeAddressEdit->text() + tr(" is invalid.\nPlease check the address and try again."));
ui->charityChangeAddressEdit->setFocus();
return;
}
else if (!model->isMine(changeAddress))
{
ui->message->setStyleSheet("QLabel { color: red; }");
ui->message->setText(tr("The entered change address:\n") + ui->charityChangeAddressEdit->text() + tr(" is not owned.\nPlease check the address and try again."));
ui->charityChangeAddressEdit->setFocus();
return;
}
}
model->setStakeForCharity(true, nCharityPercent, address, changeAddress, nMinAmount, nMaxAmount);
if(!fGlobalStakeForCharity)
fGlobalStakeForCharity = true;
ui->message->setStyleSheet("QLabel { color: green; }");
@@ -124,11 +179,13 @@ void StakeForCharityDialog::on_disableButton_clicked()
{
int nCharityPercent = 0;
CBitcoinAddress address = "";
CBitcoinAddress changeAddress = "";
int64 nMinAmount = MIN_TXOUT_AMOUNT;
int64 nMaxAmount = MAX_MONEY;
model->setStakeForCharity(false, nCharityPercent, address, nMinAmount, nMaxAmount);
model->setStakeForCharity(false, nCharityPercent, address, changeAddress, nMinAmount, nMaxAmount);
ui->charityAddressEdit->clear();
ui->charityChangeAddressEdit->clear();
ui->charityMaxEdit->clear();
ui->charityMinEdit->clear();
ui->charityPercentEdit->clear();
View
@@ -9,6 +9,7 @@ namespace Ui {
class WalletModel;
QT_BEGIN_NAMESPACE
class QLineEdit;
QT_END_NAMESPACE
class StakeForCharityDialog : public QWidget
@@ -21,10 +22,12 @@ class StakeForCharityDialog : public QWidget
void setModel(WalletModel *model);
void setAddress(const QString &address);
void setAddress(const QString &address, QLineEdit *addrEdit);
private slots:
void on_enableButton_clicked();
void on_disableButton_clicked();
void on_addressBookButton_clicked();
void on_changeAddressBookButton_clicked();
private:
Oops, something went wrong.

0 comments on commit 95bbc2f

Please sign in to comment.