dash/src/qt/overviewpage.cpp

557 lines
22 KiB
C++
Raw Normal View History

// Copyright (c) 2011-2015 The Bitcoin Core developers
// Copyright (c) 2014-2016 The Dash Core developers
2014-12-13 05:09:33 +01:00
// Distributed under the MIT software license, see the accompanying
// file COPYING or http://www.opensource.org/licenses/mit-license.php.
#include "overviewpage.h"
#include "ui_overviewpage.h"
#include "bitcoinunits.h"
#include "clientmodel.h"
2014-12-23 03:28:52 +01:00
#include "darksend.h"
#include "darksendconfig.h"
#include "guiconstants.h"
#include "guiutil.h"
#include "optionsmodel.h"
#include "platformstyle.h"
#include "transactionfilterproxy.h"
#include "transactiontablemodel.h"
#include "walletmodel.h"
2014-12-23 03:28:52 +01:00
#include "init.h"
#include "masternode-sync.h"
2011-08-03 21:28:11 +02:00
#include <QAbstractItemDelegate>
#include <QPainter>
2015-07-04 15:29:21 +02:00
#include <QSettings>
2014-12-23 03:28:52 +01:00
#include <QTimer>
#define ICON_OFFSET 16
#define DECORATION_SIZE 54
2015-03-24 04:31:15 +01:00
#define NUM_ITEMS 5
2011-08-03 21:04:15 +02:00
2011-08-03 21:28:11 +02:00
class TxViewDelegate : public QAbstractItemDelegate
{
Q_OBJECT
public:
TxViewDelegate(const PlatformStyle *platformStyle):
QAbstractItemDelegate(), unit(BitcoinUnits::DASH),
platformStyle(platformStyle)
{
}
inline void paint(QPainter *painter, const QStyleOptionViewItem &option,
const QModelIndex &index ) const
{
painter->save();
2014-11-06 20:55:52 +01:00
QIcon icon = qvariant_cast<QIcon>(index.data(TransactionTableModel::RawDecorationRole));
QRect mainRect = option.rect;
mainRect.moveLeft(ICON_OFFSET);
QRect decorationRect(mainRect.topLeft(), QSize(DECORATION_SIZE, DECORATION_SIZE));
int xspace = DECORATION_SIZE + 8;
int ypad = 6;
int halfheight = (mainRect.height() - 2*ypad)/2;
QRect amountRect(mainRect.left() + xspace, mainRect.top()+ypad, mainRect.width() - xspace - ICON_OFFSET, halfheight);
QRect addressRect(mainRect.left() + xspace, mainRect.top()+ypad+halfheight, mainRect.width() - xspace, halfheight);
icon = platformStyle->SingleColorIcon(icon);
icon.paint(painter, decorationRect);
QDateTime date = index.data(TransactionTableModel::DateRole).toDateTime();
QString address = index.data(Qt::DisplayRole).toString();
qint64 amount = index.data(TransactionTableModel::AmountRole).toLongLong();
bool confirmed = index.data(TransactionTableModel::ConfirmedRole).toBool();
QVariant value = index.data(Qt::ForegroundRole);
QColor foreground = option.palette.color(QPalette::Text);
if(value.canConvert<QBrush>())
{
QBrush brush = qvariant_cast<QBrush>(value);
foreground = brush.color();
}
painter->setPen(foreground);
QRect boundingRect;
painter->drawText(addressRect, Qt::AlignLeft|Qt::AlignVCenter, address, &boundingRect);
if (index.data(TransactionTableModel::WatchonlyRole).toBool())
{
QIcon iconWatchonly = qvariant_cast<QIcon>(index.data(TransactionTableModel::WatchonlyDecorationRole));
QRect watchonlyRect(boundingRect.right() + 5, mainRect.top()+ypad+halfheight, 16, halfheight);
iconWatchonly.paint(painter, watchonlyRect);
}
if(amount < 0)
{
foreground = COLOR_NEGATIVE;
}
2011-08-03 21:04:15 +02:00
else if(!confirmed)
{
foreground = COLOR_UNCONFIRMED;
}
else
{
foreground = option.palette.color(QPalette::Text);
}
painter->setPen(foreground);
QString amountText = BitcoinUnits::formatWithUnit(unit, amount, true, BitcoinUnits::separatorAlways);
if(!confirmed)
{
amountText = QString("[") + amountText + QString("]");
}
painter->drawText(amountRect, Qt::AlignRight|Qt::AlignVCenter, amountText);
painter->setPen(option.palette.color(QPalette::Text));
painter->drawText(amountRect, Qt::AlignLeft|Qt::AlignVCenter, GUIUtil::dateTimeStr(date));
painter->restore();
}
2011-08-03 21:28:11 +02:00
inline QSize sizeHint(const QStyleOptionViewItem &option, const QModelIndex &index) const
{
return QSize(DECORATION_SIZE, DECORATION_SIZE);
}
int unit;
const PlatformStyle *platformStyle;
};
#include "overviewpage.moc"
OverviewPage::OverviewPage(const PlatformStyle *platformStyle, QWidget *parent) :
QWidget(parent),
ui(new Ui::OverviewPage),
clientModel(0),
walletModel(0),
currentBalance(-1),
currentUnconfirmedBalance(-1),
currentImmatureBalance(-1),
currentWatchOnlyBalance(-1),
currentWatchUnconfBalance(-1),
currentWatchImmatureBalance(-1),
txdelegate(new TxViewDelegate(platformStyle)),
filter(0)
{
ui->setupUi(this);
QString theme = GUIUtil::getThemeName();
// Recent transactions
ui->listTransactions->setItemDelegate(txdelegate);
ui->listTransactions->setIconSize(QSize(DECORATION_SIZE, DECORATION_SIZE));
2011-08-03 21:04:15 +02:00
ui->listTransactions->setMinimumHeight(NUM_ITEMS * (DECORATION_SIZE + 2));
ui->listTransactions->setAttribute(Qt::WA_MacShowFocusRect, false);
connect(ui->listTransactions, SIGNAL(clicked(QModelIndex)), this, SLOT(handleTransactionClicked(QModelIndex)));
2014-12-23 03:28:52 +01:00
// init "out of sync" warning labels
ui->labelWalletStatus->setText("(" + tr("out of sync") + ")");
ui->labelDarksendSyncStatus->setText("(" + tr("out of sync") + ")");
ui->labelTransactionsStatus->setText("(" + tr("out of sync") + ")");
if(fLiteMode){
ui->frameDarksend->setVisible(false);
2014-12-23 03:28:52 +01:00
} else {
if(fMasterNode){
ui->toggleDarksend->setText("(" + tr("Disabled") + ")");
ui->darksendAuto->setText("(" + tr("Disabled") + ")");
ui->darksendReset->setText("(" + tr("Disabled") + ")");
ui->frameDarksend->setEnabled(false);
} else {
if(!fEnableDarksend){
ui->toggleDarksend->setText(tr("Start Mixing"));
} else {
ui->toggleDarksend->setText(tr("Stop Mixing"));
}
timer = new QTimer(this);
connect(timer, SIGNAL(timeout()), this, SLOT(darkSendStatus()));
timer->start(1000);
}
2014-12-23 03:28:52 +01:00
}
// start with displaying the "out of sync" warnings
showOutOfSyncWarning(true);
}
void OverviewPage::handleTransactionClicked(const QModelIndex &index)
{
if(filter)
Q_EMIT transactionClicked(filter->mapToSource(index));
}
OverviewPage::~OverviewPage()
{
if(!fLiteMode && !fMasterNode) disconnect(timer, SIGNAL(timeout()), this, SLOT(darkSendStatus()));
delete ui;
}
2015-04-03 00:51:08 +02:00
void OverviewPage::setBalance(const CAmount& balance, const CAmount& unconfirmedBalance, const CAmount& immatureBalance, const CAmount& anonymizedBalance, const CAmount& watchOnlyBalance, const CAmount& watchUnconfBalance, const CAmount& watchImmatureBalance)
{
currentBalance = balance;
currentUnconfirmedBalance = unconfirmedBalance;
currentImmatureBalance = immatureBalance;
2014-12-23 03:28:52 +01:00
currentAnonymizedBalance = anonymizedBalance;
currentWatchOnlyBalance = watchOnlyBalance;
currentWatchUnconfBalance = watchUnconfBalance;
currentWatchImmatureBalance = watchImmatureBalance;
2015-07-06 03:05:39 +02:00
ui->labelBalance->setText(BitcoinUnits::floorHtmlWithUnit(nDisplayUnit, balance, false, BitcoinUnits::separatorAlways));
ui->labelUnconfirmed->setText(BitcoinUnits::floorHtmlWithUnit(nDisplayUnit, unconfirmedBalance, false, BitcoinUnits::separatorAlways));
ui->labelImmature->setText(BitcoinUnits::floorHtmlWithUnit(nDisplayUnit, immatureBalance, false, BitcoinUnits::separatorAlways));
ui->labelAnonymized->setText(BitcoinUnits::floorHtmlWithUnit(nDisplayUnit, anonymizedBalance, false, BitcoinUnits::separatorAlways));
ui->labelTotal->setText(BitcoinUnits::floorHtmlWithUnit(nDisplayUnit, balance + unconfirmedBalance + immatureBalance, false, BitcoinUnits::separatorAlways));
ui->labelWatchAvailable->setText(BitcoinUnits::floorHtmlWithUnit(nDisplayUnit, watchOnlyBalance, false, BitcoinUnits::separatorAlways));
ui->labelWatchPending->setText(BitcoinUnits::floorHtmlWithUnit(nDisplayUnit, watchUnconfBalance, false, BitcoinUnits::separatorAlways));
ui->labelWatchImmature->setText(BitcoinUnits::floorHtmlWithUnit(nDisplayUnit, watchImmatureBalance, false, BitcoinUnits::separatorAlways));
ui->labelWatchTotal->setText(BitcoinUnits::floorHtmlWithUnit(nDisplayUnit, watchOnlyBalance + watchUnconfBalance + watchImmatureBalance, false, BitcoinUnits::separatorAlways));
// only show immature (newly mined) balance if it's non-zero, so as not to complicate things
// for the non-mining users
bool showImmature = immatureBalance != 0;
bool showWatchOnlyImmature = watchImmatureBalance != 0;
// for symmetry reasons also show immature label when the watch-only one is shown
ui->labelImmature->setVisible(showImmature || showWatchOnlyImmature);
ui->labelImmatureText->setVisible(showImmature || showWatchOnlyImmature);
ui->labelWatchImmature->setVisible(showWatchOnlyImmature); // show watch-only immature balance
2015-02-02 16:04:09 +01:00
updateDarksendProgress();
static int cachedTxLocks = 0;
2015-02-02 16:04:09 +01:00
if(cachedTxLocks != nCompleteTXLocks){
cachedTxLocks = nCompleteTXLocks;
ui->listTransactions->update();
}
}
// show/hide watch-only labels
void OverviewPage::updateWatchOnlyLabels(bool showWatchOnly)
{
ui->labelSpendable->setVisible(showWatchOnly); // show spendable label (only when watch-only is active)
ui->labelWatchonly->setVisible(showWatchOnly); // show watch-only label
ui->lineWatchBalance->setVisible(showWatchOnly); // show watch-only balance separator line
ui->labelWatchAvailable->setVisible(showWatchOnly); // show watch-only available balance
ui->labelWatchPending->setVisible(showWatchOnly); // show watch-only pending balance
ui->labelWatchTotal->setVisible(showWatchOnly); // show watch-only total balance
2015-07-31 08:40:06 +02:00
if (!showWatchOnly){
ui->labelWatchImmature->hide();
2015-07-31 08:40:06 +02:00
}
else{
ui->labelBalance->setIndent(20);
ui->labelUnconfirmed->setIndent(20);
ui->labelImmature->setIndent(20);
ui->labelTotal->setIndent(20);
}
}
void OverviewPage::setClientModel(ClientModel *model)
{
this->clientModel = model;
if(model)
{
// Show warning if this is a prerelease version
connect(model, SIGNAL(alertsChanged(QString)), this, SLOT(updateAlerts(QString)));
updateAlerts(model->getStatusBarWarnings());
}
}
void OverviewPage::setWalletModel(WalletModel *model)
{
this->walletModel = model;
if(model && model->getOptionsModel())
2011-11-08 21:18:36 +01:00
{
// Set up transaction list
filter = new TransactionFilterProxy();
2011-11-08 21:18:36 +01:00
filter->setSourceModel(model->getTransactionTableModel());
filter->setLimit(NUM_ITEMS);
filter->setDynamicSortFilter(true);
filter->setSortRole(Qt::EditRole);
filter->setShowInactive(false);
2011-11-08 21:18:36 +01:00
filter->sort(TransactionTableModel::Status, Qt::DescendingOrder);
2011-11-08 21:18:36 +01:00
ui->listTransactions->setModel(filter);
ui->listTransactions->setModelColumn(TransactionTableModel::ToAddress);
2011-11-08 21:18:36 +01:00
// Keep up to date with wallet
2015-04-03 00:51:08 +02:00
setBalance(model->getBalance(), model->getUnconfirmedBalance(), model->getImmatureBalance(), model->getAnonymizedBalance(),
model->getWatchBalance(), model->getWatchUnconfirmedBalance(), model->getWatchImmatureBalance());
2015-04-03 00:51:08 +02:00
connect(model, SIGNAL(balanceChanged(CAmount,CAmount,CAmount,CAmount,CAmount,CAmount,CAmount)), this, SLOT(setBalance(CAmount,CAmount,CAmount,CAmount,CAmount,CAmount,CAmount)));
connect(model->getOptionsModel(), SIGNAL(displayUnitChanged(int)), this, SLOT(updateDisplayUnit()));
connect(model->getOptionsModel(), SIGNAL(darksendRoundsChanged()), this, SLOT(updateDarksendProgress()));
connect(model->getOptionsModel(), SIGNAL(anonymizeDashAmountChanged()), this, SLOT(updateDarksendProgress()));
2014-12-23 03:28:52 +01:00
connect(ui->darksendAuto, SIGNAL(clicked()), this, SLOT(darksendAuto()));
connect(ui->darksendReset, SIGNAL(clicked()), this, SLOT(darksendReset()));
2014-12-23 03:28:52 +01:00
connect(ui->toggleDarksend, SIGNAL(clicked()), this, SLOT(toggleDarksend()));
updateWatchOnlyLabels(model->haveWatchOnly());
connect(model, SIGNAL(notifyWatchonlyChanged(bool)), this, SLOT(updateWatchOnlyLabels(bool)));
2011-11-08 21:18:36 +01:00
}
2015-03-18 00:06:58 +01:00
// update the display unit, to not use the default ("DASH")
updateDisplayUnit();
}
void OverviewPage::updateDisplayUnit()
{
if(walletModel && walletModel->getOptionsModel())
{
nDisplayUnit = walletModel->getOptionsModel()->getDisplayUnit();
if(currentBalance != -1)
2015-04-03 00:51:08 +02:00
setBalance(currentBalance, currentUnconfirmedBalance, currentImmatureBalance, currentAnonymizedBalance,
currentWatchOnlyBalance, currentWatchUnconfBalance, currentWatchImmatureBalance);
// Update txdelegate->unit with the current unit
txdelegate->unit = nDisplayUnit;
ui->listTransactions->update();
}
}
void OverviewPage::updateAlerts(const QString &warnings)
{
this->ui->labelAlerts->setVisible(!warnings.isEmpty());
this->ui->labelAlerts->setText(warnings);
}
void OverviewPage::showOutOfSyncWarning(bool fShow)
{
ui->labelWalletStatus->setVisible(fShow);
ui->labelDarksendSyncStatus->setVisible(fShow);
ui->labelTransactionsStatus->setVisible(fShow);
}
2014-12-23 03:28:52 +01:00
void OverviewPage::updateDarksendProgress()
{
if(!masternodeSync.IsBlockchainSynced() || ShutdownRequested()) return;
2015-07-03 00:09:14 +02:00
if(!pwalletMain) return;
QString strAmountAndRounds;
2016-01-31 14:23:02 +01:00
QString strAnonymizeDashAmount = BitcoinUnits::formatHtmlWithUnit(nDisplayUnit, nAnonymizeDashAmount * COIN, false, BitcoinUnits::separatorAlways);
if(currentBalance == 0)
{
2014-12-23 03:28:52 +01:00
ui->darksendProgress->setValue(0);
ui->darksendProgress->setToolTip(tr("No inputs detected"));
// when balance is zero just show info from settings
2016-01-31 14:23:02 +01:00
strAnonymizeDashAmount = strAnonymizeDashAmount.remove(strAnonymizeDashAmount.indexOf("."), BitcoinUnits::decimals(nDisplayUnit) + 1);
strAmountAndRounds = strAnonymizeDashAmount + " / " + tr("%n Rounds", "", nDarksendRounds);
2014-12-23 03:28:52 +01:00
ui->labelAmountRounds->setToolTip(tr("No inputs detected"));
ui->labelAmountRounds->setText(strAmountAndRounds);
return;
}
CAmount nDenominatedConfirmedBalance;
CAmount nDenominatedUnconfirmedBalance;
CAmount nAnonymizableBalance;
CAmount nNormalizedAnonymizedBalance;
double nAverageAnonymizedRounds;
{
nDenominatedConfirmedBalance = pwalletMain->GetDenominatedBalance();
nDenominatedUnconfirmedBalance = pwalletMain->GetDenominatedBalance(true);
nAnonymizableBalance = pwalletMain->GetAnonymizableBalance();
nNormalizedAnonymizedBalance = pwalletMain->GetNormalizedAnonymizedBalance();
nAverageAnonymizedRounds = pwalletMain->GetAverageAnonymizedRounds();
}
CAmount nMaxToAnonymize = nAnonymizableBalance + currentAnonymizedBalance + nDenominatedUnconfirmedBalance;
// If it's more than the anon threshold, limit to that.
2016-01-31 14:23:02 +01:00
if(nMaxToAnonymize > nAnonymizeDashAmount*COIN) nMaxToAnonymize = nAnonymizeDashAmount*COIN;
if(nMaxToAnonymize == 0) return;
2016-01-31 14:23:02 +01:00
if(nMaxToAnonymize >= nAnonymizeDashAmount * COIN) {
ui->labelAmountRounds->setToolTip(tr("Found enough compatible inputs to anonymize %1")
2016-01-31 14:23:02 +01:00
.arg(strAnonymizeDashAmount));
strAnonymizeDashAmount = strAnonymizeDashAmount.remove(strAnonymizeDashAmount.indexOf("."), BitcoinUnits::decimals(nDisplayUnit) + 1);
strAmountAndRounds = strAnonymizeDashAmount + " / " + tr("%n Rounds", "", nDarksendRounds);
} else {
QString strMaxToAnonymize = BitcoinUnits::formatHtmlWithUnit(nDisplayUnit, nMaxToAnonymize, false, BitcoinUnits::separatorAlways);
ui->labelAmountRounds->setToolTip(tr("Not enough compatible inputs to anonymize <span style='color:red;'>%1</span>,<br>"
"will anonymize <span style='color:red;'>%2</span> instead")
2016-01-31 14:23:02 +01:00
.arg(strAnonymizeDashAmount)
.arg(strMaxToAnonymize));
strMaxToAnonymize = strMaxToAnonymize.remove(strMaxToAnonymize.indexOf("."), BitcoinUnits::decimals(nDisplayUnit) + 1);
strAmountAndRounds = "<span style='color:red;'>" +
QString(BitcoinUnits::factor(nDisplayUnit) == 1 ? "" : "~") + strMaxToAnonymize +
" / " + tr("%n Rounds", "", nDarksendRounds) + "</span>";
}
ui->labelAmountRounds->setText(strAmountAndRounds);
// calculate parts of the progress, each of them shouldn't be higher than 1
// progress of denominating
float denomPart = 0;
// mixing progress of denominated balance
2015-07-12 18:18:03 +02:00
float anonNormPart = 0;
// completeness of full amount anonimization
float anonFullPart = 0;
CAmount denominatedBalance = nDenominatedConfirmedBalance + nDenominatedUnconfirmedBalance;
denomPart = (float)denominatedBalance / nMaxToAnonymize;
denomPart = denomPart > 1 ? 1 : denomPart;
denomPart *= 100;
anonNormPart = (float)nNormalizedAnonymizedBalance / nMaxToAnonymize;
2015-07-12 18:18:03 +02:00
anonNormPart = anonNormPart > 1 ? 1 : anonNormPart;
anonNormPart *= 100;
2015-07-12 18:18:03 +02:00
anonFullPart = (float)currentAnonymizedBalance / nMaxToAnonymize;
2015-07-12 18:18:03 +02:00
anonFullPart = anonFullPart > 1 ? 1 : anonFullPart;
anonFullPart *= 100;
// apply some weights to them ...
float denomWeight = 1;
float anonNormWeight = nDarksendRounds;
float anonFullWeight = 2;
float fullWeight = denomWeight + anonNormWeight + anonFullWeight;
// ... and calculate the whole progress
float denomPartCalc = ceilf((denomPart * denomWeight / fullWeight) * 100) / 100;
float anonNormPartCalc = ceilf((anonNormPart * anonNormWeight / fullWeight) * 100) / 100;
float anonFullPartCalc = ceilf((anonFullPart * anonFullWeight / fullWeight) * 100) / 100;
float progress = denomPartCalc + anonNormPartCalc + anonFullPartCalc;
if(progress >= 100) progress = 100;
ui->darksendProgress->setValue(progress);
QString strToolPip = ("<b>" + tr("Overall progress") + ": %1%</b><br/>" +
tr("Denominated") + ": %2%<br/>" +
tr("Mixed") + ": %3%<br/>" +
tr("Anonymized") + ": %4%<br/>" +
tr("Denominated inputs have %5 of %n rounds on average", "", nDarksendRounds))
.arg(progress).arg(denomPart).arg(anonNormPart).arg(anonFullPart)
.arg(nAverageAnonymizedRounds);
ui->darksendProgress->setToolTip(strToolPip);
2014-12-23 03:28:52 +01:00
}
void OverviewPage::darkSendStatus()
{
2016-02-20 20:03:19 +01:00
if(!masternodeSync.IsBlockchainSynced() || ShutdownRequested()) return;
static int64_t nLastDSProgressBlockTime = 0;
int nBestHeight = clientModel->getNumBlocks();
2014-12-23 03:28:52 +01:00
// we we're processing more then 1 block per second, we'll just leave
if(((nBestHeight - darkSendPool.cachedNumBlocks) / (GetTimeMillis() - nLastDSProgressBlockTime + 1) > 1)) return;
nLastDSProgressBlockTime = GetTimeMillis();
2014-12-23 03:28:52 +01:00
if(!fEnableDarksend) {
if(nBestHeight != darkSendPool.cachedNumBlocks)
{
darkSendPool.cachedNumBlocks = nBestHeight;
updateDarksendProgress();
2014-12-23 03:28:52 +01:00
2015-02-04 12:00:23 +01:00
ui->darksendEnabled->setText(tr("Disabled"));
2014-12-23 03:28:52 +01:00
ui->darksendStatus->setText("");
ui->toggleDarksend->setText(tr("Start Mixing"));
2014-12-23 03:28:52 +01:00
}
return;
}
// check darksend status and unlock if needed
if(nBestHeight != darkSendPool.cachedNumBlocks)
{
// Balance and number of transactions might have changed
darkSendPool.cachedNumBlocks = nBestHeight;
updateDarksendProgress();
2014-12-23 03:28:52 +01:00
2015-02-04 12:00:23 +01:00
ui->darksendEnabled->setText(tr("Enabled"));
2014-12-23 03:28:52 +01:00
}
QString strStatus = QString(darkSendPool.GetStatus().c_str());
2014-12-23 03:28:52 +01:00
QString s = tr("Last PrivateSend message:\n") + strStatus;
2014-12-23 03:28:52 +01:00
if(s != ui->darksendStatus->text())
LogPrintf("Last PrivateSend message: %s\n", strStatus.toStdString());
2014-12-26 04:58:39 +01:00
2014-12-23 03:28:52 +01:00
ui->darksendStatus->setText(s);
if(darkSendPool.sessionDenom == 0){
2015-02-04 12:00:23 +01:00
ui->labelSubmittedDenom->setText(tr("N/A"));
} else {
std::string out;
darkSendPool.GetDenominationsToString(darkSendPool.sessionDenom, out);
QString s2(out.c_str());
ui->labelSubmittedDenom->setText(s2);
}
2014-12-23 03:28:52 +01:00
}
void OverviewPage::darksendAuto(){
2014-12-23 03:28:52 +01:00
darkSendPool.DoAutomaticDenominating();
}
void OverviewPage::darksendReset(){
darkSendPool.Reset();
QMessageBox::warning(this, tr("PrivateSend"),
tr("PrivateSend was successfully reset."),
QMessageBox::Ok, QMessageBox::Ok);
}
2014-12-23 03:28:52 +01:00
void OverviewPage::toggleDarksend(){
2015-07-04 15:29:21 +02:00
QSettings settings;
// Popup some information on first mixing
QString hasMixed = settings.value("hasMixed").toString();
if(hasMixed.isEmpty()){
QMessageBox::information(this, tr("PrivateSend"),
tr("If you don't want to see internal PrivateSend fees/transactions select \"Most Common\" as Type on the \"Transactions\" tab."),
2015-07-04 15:29:21 +02:00
QMessageBox::Ok, QMessageBox::Ok);
settings.setValue("hasMixed", "hasMixed");
}
2014-12-26 04:58:39 +01:00
if(!fEnableDarksend){
int64_t balance = currentBalance;
float minAmount = 1.49 * COIN;
if(balance < minAmount){
QString strMinAmount(BitcoinUnits::formatWithUnit(nDisplayUnit, minAmount));
QMessageBox::warning(this, tr("PrivateSend"),
tr("PrivateSend requires at least %1 to use.").arg(strMinAmount),
2014-12-26 04:58:39 +01:00
QMessageBox::Ok, QMessageBox::Ok);
return;
}
// if wallet is locked, ask for a passphrase
if (walletModel->getEncryptionStatus() == WalletModel::Locked)
{
WalletModel::UnlockContext ctx(walletModel->requestUnlock(false));
if(!ctx.isValid())
{
//unlock was cancelled
darkSendPool.cachedNumBlocks = std::numeric_limits<int>::max();
QMessageBox::warning(this, tr("PrivateSend"),
tr("Wallet is locked and user declined to unlock. Disabling PrivateSend."),
QMessageBox::Ok, QMessageBox::Ok);
if (fDebug) LogPrintf("Wallet is locked and user declined to unlock. Disabling PrivateSend.\n");
return;
}
}
2014-12-23 03:28:52 +01:00
}
fEnableDarksend = !fEnableDarksend;
darkSendPool.cachedNumBlocks = std::numeric_limits<int>::max();
2014-12-23 03:28:52 +01:00
if(!fEnableDarksend){
ui->toggleDarksend->setText(tr("Start Mixing"));
darkSendPool.UnlockCoins();
2014-12-23 03:28:52 +01:00
} else {
ui->toggleDarksend->setText(tr("Stop Mixing"));
2014-12-23 03:28:52 +01:00
/* show darksend configuration if client has defaults set */
2016-01-31 14:23:02 +01:00
if(nAnonymizeDashAmount == 0){
2014-12-23 03:28:52 +01:00
DarksendConfig dlg(this);
dlg.setModel(walletModel);
dlg.exec();
}
}
}