2015-12-13 14:51:43 +01:00
// Copyright (c) 2011-2015 The Bitcoin Core developers
2016-12-20 14:26:45 +01:00
// Copyright (c) 2014-2017 The Dash Core developers
2014-12-13 05:09:33 +01:00
// Distributed under the MIT software license, see the accompanying
2013-11-04 16:20:43 +01:00
// file COPYING or http://www.opensource.org/licenses/mit-license.php.
2011-07-05 22:09:39 +02:00
# include "overviewpage.h"
# include "ui_overviewpage.h"
2011-07-25 21:35:45 +02:00
# include "bitcoinunits.h"
2013-04-13 07:13:08 +02:00
# include "clientmodel.h"
# include "guiconstants.h"
# include "guiutil.h"
2016-12-20 14:27:59 +01:00
# include "init.h"
2011-07-29 14:36:35 +02:00
# include "optionsmodel.h"
2015-07-28 15:20:14 +02:00
# include "platformstyle.h"
2011-08-03 20:52:18 +02:00
# include "transactionfilterproxy.h"
2013-04-13 07:13:08 +02:00
# include "transactiontablemodel.h"
2016-11-20 07:54:33 +01:00
# include "utilitydialog.h"
2013-04-13 07:13:08 +02:00
# include "walletmodel.h"
2016-12-20 14:27:59 +01:00
# include "instantx.h"
# include "darksendconfig.h"
2016-01-24 20:05:31 +01:00
# include "masternode-sync.h"
2017-05-05 13:26:27 +02:00
# include "privatesend-client.h"
2011-07-29 14:36:35 +02:00
2011-08-03 21:28:11 +02:00
# include <QAbstractItemDelegate>
2011-08-03 20:52:18 +02:00
# include <QPainter>
2015-07-04 15:29:21 +02:00
# include <QSettings>
2014-12-23 03:28:52 +01:00
# include <QTimer>
2011-08-03 20:52:18 +02:00
2015-03-22 21:29:29 +01:00
# define ICON_OFFSET 16
2015-05-05 21:55:19 +02:00
# define DECORATION_SIZE 54
2015-03-24 04:31:15 +01:00
# define NUM_ITEMS 5
2016-06-08 20:33:00 +02:00
# define NUM_ITEMS_ADV 7
2011-08-03 21:04:15 +02:00
2011-08-03 21:28:11 +02:00
class TxViewDelegate : public QAbstractItemDelegate
2011-08-03 20:52:18 +02:00
{
2011-09-19 12:40:23 +02:00
Q_OBJECT
2011-08-03 20:52:18 +02:00
public :
2017-09-11 15:38:14 +02:00
TxViewDelegate ( const PlatformStyle * _platformStyle , QObject * parent = nullptr ) :
QAbstractItemDelegate ( parent ) , unit ( BitcoinUnits : : DASH ) ,
platformStyle ( _platformStyle )
2011-08-03 20:52:18 +02:00
{
}
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 ) ) ;
2011-08-03 20:52:18 +02:00
QRect mainRect = option . rect ;
2015-03-22 21:29:29 +01:00
mainRect . moveLeft ( ICON_OFFSET ) ;
2011-08-03 20:52:18 +02:00
QRect decorationRect ( mainRect . topLeft ( ) , QSize ( DECORATION_SIZE , DECORATION_SIZE ) ) ;
int xspace = DECORATION_SIZE + 8 ;
int ypad = 6 ;
int halfheight = ( mainRect . height ( ) - 2 * ypad ) / 2 ;
2015-03-22 21:29:29 +01:00
QRect amountRect ( mainRect . left ( ) + xspace , mainRect . top ( ) + ypad , mainRect . width ( ) - xspace - ICON_OFFSET , halfheight ) ;
2011-08-03 20:52:18 +02:00
QRect addressRect ( mainRect . left ( ) + xspace , mainRect . top ( ) + ypad + halfheight , mainRect . width ( ) - xspace , halfheight ) ;
2015-07-28 15:20:14 +02:00
icon = platformStyle - > SingleColorIcon ( icon ) ;
2011-08-03 20:52:18 +02:00
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 ) ;
2013-04-14 19:50:15 +02:00
if ( value . canConvert < QBrush > ( ) )
2011-08-03 20:52:18 +02:00
{
2013-04-14 19:50:15 +02:00
QBrush brush = qvariant_cast < QBrush > ( value ) ;
foreground = brush . color ( ) ;
2011-08-03 20:52:18 +02:00
}
painter - > setPen ( foreground ) ;
2014-08-10 02:26:04 +02:00
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 ) ;
}
2011-08-03 20:52:18 +02:00
if ( amount < 0 )
{
foreground = COLOR_NEGATIVE ;
}
2011-08-03 21:04:15 +02:00
else if ( ! confirmed )
{
foreground = COLOR_UNCONFIRMED ;
}
2011-08-03 20:52:18 +02:00
else
{
foreground = option . palette . color ( QPalette : : Text ) ;
}
painter - > setPen ( foreground ) ;
2016-06-08 20:30:57 +02:00
QString amountText = BitcoinUnits : : floorWithUnit ( unit , amount , true , BitcoinUnits : : separatorAlways ) ;
2011-08-03 20:52:18 +02:00
if ( ! confirmed )
{
amountText = QString ( " [ " ) + amountText + QString ( " ] " ) ;
}
painter - > drawText ( amountRect , Qt : : AlignRight | Qt : : AlignVCenter , amountText ) ;
painter - > setPen ( option . palette . color ( QPalette : : Text ) ) ;
2011-08-08 17:38:17 +02:00
painter - > drawText ( amountRect , Qt : : AlignLeft | Qt : : AlignVCenter , GUIUtil : : dateTimeStr ( date ) ) ;
2011-08-03 20:52:18 +02:00
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 ) ;
}
2011-08-03 20:52:18 +02:00
int unit ;
2015-07-28 15:20:14 +02:00
const PlatformStyle * platformStyle ;
2011-08-03 20:52:18 +02:00
} ;
2011-09-19 12:40:23 +02:00
# include "overviewpage.moc"
2011-07-05 22:09:39 +02:00
2015-07-28 15:20:14 +02:00
OverviewPage : : OverviewPage ( const PlatformStyle * platformStyle , QWidget * parent ) :
2011-07-05 22:09:39 +02:00
QWidget ( parent ) ,
2011-07-29 14:36:35 +02:00
ui ( new Ui : : OverviewPage ) ,
2012-10-24 21:47:07 +02:00
clientModel ( 0 ) ,
walletModel ( 0 ) ,
2011-07-29 14:36:35 +02:00
currentBalance ( - 1 ) ,
2011-08-03 20:52:18 +02:00
currentUnconfirmedBalance ( - 1 ) ,
2012-02-14 12:08:00 +01:00
currentImmatureBalance ( - 1 ) ,
2014-03-29 05:15:28 +01:00
currentWatchOnlyBalance ( - 1 ) ,
currentWatchUnconfBalance ( - 1 ) ,
currentWatchImmatureBalance ( - 1 ) ,
2017-09-11 15:38:14 +02:00
txdelegate ( new TxViewDelegate ( platformStyle , this ) )
2011-07-05 22:09:39 +02:00
{
ui - > setupUi ( this ) ;
2016-02-02 16:28:56 +01:00
QString theme = GUIUtil : : getThemeName ( ) ;
2011-07-05 22:09:39 +02:00
2011-08-03 20:52:18 +02:00
// Recent transactions
ui - > listTransactions - > setItemDelegate ( txdelegate ) ;
ui - > listTransactions - > setIconSize ( QSize ( DECORATION_SIZE , DECORATION_SIZE ) ) ;
2016-06-08 20:33:00 +02:00
// Note: minimum height of listTransactions will be set later in updateAdvancedPSUI() to reflect actual settings
2011-10-07 13:21:45 +02:00
ui - > listTransactions - > setAttribute ( Qt : : WA_MacShowFocusRect , false ) ;
2011-08-04 04:41:01 +02:00
2012-05-12 13:19:44 +02:00
connect ( ui - > listTransactions , SIGNAL ( clicked ( QModelIndex ) ) , this , SLOT ( handleTransactionClicked ( QModelIndex ) ) ) ;
2012-05-15 16:57:59 +02:00
// init "out of sync" warning labels
2016-06-06 21:52:24 +02:00
ui - > labelWalletStatus - > setText ( " ( " + tr ( " out of sync " ) + " ) " ) ;
ui - > labelPrivateSendSyncStatus - > setText ( " ( " + tr ( " out of sync " ) + " ) " ) ;
ui - > labelTransactionsStatus - > setText ( " ( " + tr ( " out of sync " ) + " ) " ) ;
2012-05-15 16:57:59 +02:00
2016-06-08 20:33:00 +02:00
// hide PS frame (helps to preserve saved size)
// we'll setup and make it visible in updateAdvancedPSUI() later if we are not in litemode
ui - > framePrivateSend - > setVisible ( false ) ;
// start with displaying the "out of sync" warnings
showOutOfSyncWarning ( true ) ;
// that's it for litemode
if ( fLiteMode ) return ;
2016-06-15 21:13:04 +02:00
// Disable any PS UI for masternode or when autobackup is disabled or failed for whatever reason
if ( fMasterNode | | nWalletBackups < = 0 ) {
DisablePrivateSendCompletely ( ) ;
if ( nWalletBackups < = 0 ) {
ui - > labelPrivateSendEnabled - > setToolTip ( tr ( " Automatic backups are disabled, no mixing available! " ) ) ;
}
2014-12-23 03:28:52 +01:00
} else {
2017-05-05 13:26:27 +02:00
if ( ! privateSendClient . fEnablePrivateSend ) {
2016-06-08 20:33:00 +02:00
ui - > togglePrivateSend - > setText ( tr ( " Start Mixing " ) ) ;
2015-06-30 03:07:32 +02:00
} else {
2016-06-08 20:33:00 +02:00
ui - > togglePrivateSend - > setText ( tr ( " Stop Mixing " ) ) ;
2015-06-30 03:07:32 +02:00
}
2017-05-05 13:26:27 +02:00
// Disable privateSendClient builtin support for automatic backups while we are in GUI,
2016-06-15 21:13:04 +02:00
// we'll handle automatic backups and user warnings in privateSendStatus()
2017-05-05 13:26:27 +02:00
privateSendClient . fCreateAutoBackups = false ;
2016-06-15 21:13:04 +02:00
2016-06-08 20:33:00 +02:00
timer = new QTimer ( this ) ;
connect ( timer , SIGNAL ( timeout ( ) ) , this , SLOT ( privateSendStatus ( ) ) ) ;
timer - > start ( 1000 ) ;
2014-12-23 03:28:52 +01:00
}
2012-05-12 13:19:44 +02:00
}
void OverviewPage : : handleTransactionClicked ( const QModelIndex & index )
{
if ( filter )
2015-07-14 13:59:05 +02:00
Q_EMIT transactionClicked ( filter - > mapToSource ( index ) ) ;
2011-07-05 22:09:39 +02:00
}
2017-09-09 09:04:02 +02:00
void OverviewPage : : handleOutOfSyncWarningClicks ( )
{
Q_EMIT outOfSyncWarningClicked ( ) ;
}
2011-07-05 22:09:39 +02:00
OverviewPage : : ~ OverviewPage ( )
{
2016-06-06 21:52:24 +02:00
if ( ! fLiteMode & & ! fMasterNode ) disconnect ( timer , SIGNAL ( timeout ( ) ) , this , SLOT ( privateSendStatus ( ) ) ) ;
2011-07-05 22:09:39 +02:00
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 )
2011-07-05 22:09:39 +02:00
{
2011-07-29 14:36:35 +02:00
currentBalance = balance ;
currentUnconfirmedBalance = unconfirmedBalance ;
2012-02-14 12:08:00 +01:00
currentImmatureBalance = immatureBalance ;
2014-12-23 03:28:52 +01:00
currentAnonymizedBalance = anonymizedBalance ;
2014-03-29 05:15:28 +01:00
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 ) ) ;
2012-02-14 12:08:00 +01:00
// 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 ;
2014-03-29 05:15:28 +01:00
bool showWatchOnlyImmature = watchImmatureBalance ! = 0 ;
2014-08-04 13:50:17 +02:00
// for symmetry reasons also show immature label when the watch-only one is shown
2014-03-29 05:15:28 +01:00
ui - > labelImmature - > setVisible ( showImmature | | showWatchOnlyImmature ) ;
ui - > labelImmatureText - > setVisible ( showImmature | | showWatchOnlyImmature ) ;
2014-08-28 23:20:46 +02:00
ui - > labelWatchImmature - > setVisible ( showWatchOnlyImmature ) ; // show watch-only immature balance
2015-02-02 16:04:09 +01:00
2016-06-06 21:52:24 +02:00
updatePrivateSendProgress ( ) ;
2015-06-30 03:07:32 +02:00
static int cachedTxLocks = 0 ;
2015-02-02 16:04:09 +01:00
if ( cachedTxLocks ! = nCompleteTXLocks ) {
cachedTxLocks = nCompleteTXLocks ;
ui - > listTransactions - > update ( ) ;
}
2011-07-05 22:09:39 +02:00
}
2011-07-07 10:59:00 +02:00
2014-07-26 21:05:11 +02:00
// 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 ) {
2014-07-26 21:05:11 +02:00
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 ) ;
}
2011-07-05 22:09:39 +02:00
}
2011-07-07 10:59:00 +02:00
2012-10-24 21:47:07 +02:00
void OverviewPage : : setClientModel ( ClientModel * model )
2011-07-11 20:42:10 +02:00
{
2012-10-24 21:47:07 +02:00
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 ;
2012-06-09 15:41:21 +02:00
if ( model & & model - > getOptionsModel ( ) )
2011-11-08 21:18:36 +01:00
{
2017-02-09 06:29:00 +01:00
// update the display unit, to not use the default ("DASH")
updateDisplayUnit ( ) ;
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 ( ) ,
2014-03-29 05:15:28 +01:00
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 ) ) ) ;
2011-07-11 20:42:10 +02:00
2012-06-09 15:41:21 +02:00
connect ( model - > getOptionsModel ( ) , SIGNAL ( displayUnitChanged ( int ) ) , this , SLOT ( updateDisplayUnit ( ) ) ) ;
2016-06-06 21:52:24 +02:00
connect ( model - > getOptionsModel ( ) , SIGNAL ( privateSendRoundsChanged ( ) ) , this , SLOT ( updatePrivateSendProgress ( ) ) ) ;
2016-07-29 07:28:57 +02:00
connect ( model - > getOptionsModel ( ) , SIGNAL ( privateSentAmountChanged ( ) ) , this , SLOT ( updatePrivateSendProgress ( ) ) ) ;
2016-06-06 21:52:24 +02:00
connect ( model - > getOptionsModel ( ) , SIGNAL ( advancedPSUIChanged ( bool ) ) , this , SLOT ( updateAdvancedPSUI ( bool ) ) ) ;
2016-06-08 20:33:00 +02:00
// explicitly update PS frame and transaction list to reflect actual settings
2016-06-06 21:52:24 +02:00
updateAdvancedPSUI ( model - > getOptionsModel ( ) - > getShowAdvancedPSUI ( ) ) ;
connect ( ui - > privateSendAuto , SIGNAL ( clicked ( ) ) , this , SLOT ( privateSendAuto ( ) ) ) ;
connect ( ui - > privateSendReset , SIGNAL ( clicked ( ) ) , this , SLOT ( privateSendReset ( ) ) ) ;
2016-11-05 17:13:16 +01:00
connect ( ui - > privateSendInfo , SIGNAL ( clicked ( ) ) , this , SLOT ( privateSendInfo ( ) ) ) ;
2016-06-06 21:52:24 +02:00
connect ( ui - > togglePrivateSend , SIGNAL ( clicked ( ) ) , this , SLOT ( togglePrivateSend ( ) ) ) ;
2014-07-26 21:05:11 +02:00
updateWatchOnlyLabels ( model - > haveWatchOnly ( ) ) ;
connect ( model , SIGNAL ( notifyWatchonlyChanged ( bool ) ) , this , SLOT ( updateWatchOnlyLabels ( bool ) ) ) ;
2011-11-08 21:18:36 +01:00
}
2011-07-29 14:36:35 +02:00
}
2012-06-09 15:41:21 +02:00
void OverviewPage : : updateDisplayUnit ( )
2011-07-29 14:36:35 +02:00
{
2012-10-24 21:47:07 +02:00
if ( walletModel & & walletModel - > getOptionsModel ( ) )
2012-06-09 15:41:21 +02:00
{
2015-07-04 06:55:52 +02:00
nDisplayUnit = walletModel - > getOptionsModel ( ) - > getDisplayUnit ( ) ;
2012-06-09 15:41:21 +02:00
if ( currentBalance ! = - 1 )
2015-04-03 00:51:08 +02:00
setBalance ( currentBalance , currentUnconfirmedBalance , currentImmatureBalance , currentAnonymizedBalance ,
2014-03-29 05:15:28 +01:00
currentWatchOnlyBalance , currentWatchUnconfBalance , currentWatchImmatureBalance ) ;
2011-08-03 20:52:18 +02:00
2012-06-09 15:41:21 +02:00
// Update txdelegate->unit with the current unit
2015-07-04 06:55:52 +02:00
txdelegate - > unit = nDisplayUnit ;
2012-06-09 15:41:21 +02:00
ui - > listTransactions - > update ( ) ;
}
2011-07-11 20:42:10 +02:00
}
2012-05-15 16:57:59 +02:00
2012-10-24 21:47:07 +02:00
void OverviewPage : : updateAlerts ( const QString & warnings )
{
this - > ui - > labelAlerts - > setVisible ( ! warnings . isEmpty ( ) ) ;
this - > ui - > labelAlerts - > setText ( warnings ) ;
}
2012-05-15 16:57:59 +02:00
void OverviewPage : : showOutOfSyncWarning ( bool fShow )
{
ui - > labelWalletStatus - > setVisible ( fShow ) ;
2016-06-06 21:52:24 +02:00
ui - > labelPrivateSendSyncStatus - > setVisible ( fShow ) ;
2012-05-15 16:57:59 +02:00
ui - > labelTransactionsStatus - > setVisible ( fShow ) ;
}
2014-12-23 03:28:52 +01:00
2016-06-06 21:52:24 +02:00
void OverviewPage : : updatePrivateSendProgress ( )
2015-01-28 08:35:17 +01:00
{
2015-07-26 01:24:19 +02:00
if ( ! masternodeSync . IsBlockchainSynced ( ) | | ShutdownRequested ( ) ) return ;
2015-07-03 00:09:14 +02:00
2015-07-04 06:55:52 +02:00
if ( ! pwalletMain ) return ;
2015-01-14 15:28:35 +01:00
2015-06-30 03:07:32 +02:00
QString strAmountAndRounds ;
2017-05-05 13:26:27 +02:00
QString strPrivateSendAmount = BitcoinUnits : : formatHtmlWithUnit ( nDisplayUnit , privateSendClient . nPrivateSendAmount * COIN , false , BitcoinUnits : : separatorAlways ) ;
2015-06-30 03:07:32 +02:00
2015-08-07 06:08:37 +02:00
if ( currentBalance = = 0 )
2015-01-28 08:35:17 +01:00
{
2016-06-06 21:52:24 +02:00
ui - > privateSendProgress - > setValue ( 0 ) ;
ui - > privateSendProgress - > setToolTip ( tr ( " No inputs detected " ) ) ;
2015-04-30 00:06:24 +02:00
// when balance is zero just show info from settings
2016-07-29 07:28:57 +02:00
strPrivateSendAmount = strPrivateSendAmount . remove ( strPrivateSendAmount . indexOf ( " . " ) , BitcoinUnits : : decimals ( nDisplayUnit ) + 1 ) ;
2017-05-05 13:26:27 +02:00
strAmountAndRounds = strPrivateSendAmount + " / " + tr ( " %n Rounds " , " " , privateSendClient . nPrivateSendRounds ) ;
2014-12-23 03:28:52 +01:00
2015-06-30 03:07:32 +02:00
ui - > labelAmountRounds - > setToolTip ( tr ( " No inputs detected " ) ) ;
ui - > labelAmountRounds - > setText ( strAmountAndRounds ) ;
2015-01-02 23:20:30 +01:00
return ;
}
2017-09-27 19:43:28 +02:00
CAmount nAnonymizableBalance = pwalletMain - > GetAnonymizableBalance ( false , false ) ;
2015-08-07 06:08:37 +02:00
2017-06-06 01:47:12 +02:00
CAmount nMaxToAnonymize = nAnonymizableBalance + currentAnonymizedBalance ;
2015-01-02 23:20:30 +01:00
2015-04-30 00:06:24 +02:00
// If it's more than the anon threshold, limit to that.
2017-05-05 13:26:27 +02:00
if ( nMaxToAnonymize > privateSendClient . nPrivateSendAmount * COIN ) nMaxToAnonymize = privateSendClient . nPrivateSendAmount * COIN ;
2014-12-26 21:00:56 +01:00
2015-01-28 08:35:17 +01:00
if ( nMaxToAnonymize = = 0 ) return ;
2017-05-05 13:26:27 +02:00
if ( nMaxToAnonymize > = privateSendClient . nPrivateSendAmount * COIN ) {
2015-06-30 03:07:32 +02:00
ui - > labelAmountRounds - > setToolTip ( tr ( " Found enough compatible inputs to anonymize %1 " )
2016-07-29 07:28:57 +02:00
. arg ( strPrivateSendAmount ) ) ;
strPrivateSendAmount = strPrivateSendAmount . remove ( strPrivateSendAmount . indexOf ( " . " ) , BitcoinUnits : : decimals ( nDisplayUnit ) + 1 ) ;
2017-05-05 13:26:27 +02:00
strAmountAndRounds = strPrivateSendAmount + " / " + tr ( " %n Rounds " , " " , privateSendClient . nPrivateSendRounds ) ;
2015-06-30 03:07:32 +02:00
} 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-07-29 07:28:57 +02:00
. arg ( strPrivateSendAmount )
2015-06-30 03:07:32 +02:00
. arg ( strMaxToAnonymize ) ) ;
strMaxToAnonymize = strMaxToAnonymize . remove ( strMaxToAnonymize . indexOf ( " . " ) , BitcoinUnits : : decimals ( nDisplayUnit ) + 1 ) ;
strAmountAndRounds = " <span style='color:red;'> " +
QString ( BitcoinUnits : : factor ( nDisplayUnit ) = = 1 ? " " : " ~ " ) + strMaxToAnonymize +
2017-05-05 13:26:27 +02:00
" / " + tr ( " %n Rounds " , " " , privateSendClient . nPrivateSendRounds ) + " </span> " ;
2015-06-30 03:07:32 +02:00
}
ui - > labelAmountRounds - > setText ( strAmountAndRounds ) ;
2017-09-27 19:43:28 +02:00
if ( ! fShowAdvancedPSUI ) return ;
CAmount nDenominatedConfirmedBalance ;
CAmount nDenominatedUnconfirmedBalance ;
CAmount nNormalizedAnonymizedBalance ;
float nAverageAnonymizedRounds ;
nDenominatedConfirmedBalance = pwalletMain - > GetDenominatedBalance ( ) ;
nDenominatedUnconfirmedBalance = pwalletMain - > GetDenominatedBalance ( true ) ;
nNormalizedAnonymizedBalance = pwalletMain - > GetNormalizedAnonymizedBalance ( ) ;
nAverageAnonymizedRounds = pwalletMain - > GetAverageAnonymizedRounds ( ) ;
2015-07-07 09:21:13 +02:00
// calculate parts of the progress, each of them shouldn't be higher than 1
// progress of denominating
2015-02-05 15:20:19 +01:00
float denomPart = 0 ;
2015-07-07 09:21:13 +02:00
// mixing progress of denominated balance
2015-07-12 18:18:03 +02:00
float anonNormPart = 0 ;
2016-10-22 18:52:14 +02:00
// completeness of full amount anonymization
2015-07-12 18:18:03 +02:00
float anonFullPart = 0 ;
2015-07-07 09:21:13 +02:00
2015-08-07 06:08:37 +02:00
CAmount denominatedBalance = nDenominatedConfirmedBalance + nDenominatedUnconfirmedBalance ;
2015-07-07 09:21:13 +02:00
denomPart = ( float ) denominatedBalance / nMaxToAnonymize ;
denomPart = denomPart > 1 ? 1 : denomPart ;
2015-08-07 05:19:10 +02:00
denomPart * = 100 ;
2015-07-07 09:21:13 +02:00
2015-08-07 06:08:37 +02:00
anonNormPart = ( float ) nNormalizedAnonymizedBalance / nMaxToAnonymize ;
2015-07-12 18:18:03 +02:00
anonNormPart = anonNormPart > 1 ? 1 : anonNormPart ;
2015-08-07 05:19:10 +02:00
anonNormPart * = 100 ;
2015-07-12 18:18:03 +02:00
2015-08-07 06:08:37 +02:00
anonFullPart = ( float ) currentAnonymizedBalance / nMaxToAnonymize ;
2015-07-12 18:18:03 +02:00
anonFullPart = anonFullPart > 1 ? 1 : anonFullPart ;
2015-08-07 05:19:10 +02:00
anonFullPart * = 100 ;
// apply some weights to them ...
float denomWeight = 1 ;
2017-05-05 13:26:27 +02:00
float anonNormWeight = privateSendClient . nPrivateSendRounds ;
2015-08-07 05:19:10 +02:00
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 ;
2015-08-02 04:05:49 +02:00
float progress = denomPartCalc + anonNormPartCalc + anonFullPartCalc ;
2015-04-08 16:41:49 +02:00
if ( progress > = 100 ) progress = 100 ;
2015-01-28 08:35:17 +01:00
2016-06-06 21:52:24 +02:00
ui - > privateSendProgress - > setValue ( progress ) ;
2015-01-28 08:35:17 +01:00
2015-08-02 04:05:49 +02:00
QString strToolPip = ( " <b> " + tr ( " Overall progress " ) + " : %1%</b><br/> " +
tr ( " Denominated " ) + " : %2%<br/> " +
tr ( " Mixed " ) + " : %3%<br/> " +
tr ( " Anonymized " ) + " : %4%<br/> " +
2017-05-05 13:26:27 +02:00
tr ( " Denominated inputs have %5 of %n rounds on average " , " " , privateSendClient . nPrivateSendRounds ) )
2015-08-07 05:19:10 +02:00
. arg ( progress ) . arg ( denomPart ) . arg ( anonNormPart ) . arg ( anonFullPart )
2015-08-07 06:08:37 +02:00
. arg ( nAverageAnonymizedRounds ) ;
2016-06-06 21:52:24 +02:00
ui - > privateSendProgress - > setToolTip ( strToolPip ) ;
2014-12-23 03:28:52 +01:00
}
2016-06-06 21:52:24 +02:00
void OverviewPage : : updateAdvancedPSUI ( bool fShowAdvancedPSUI ) {
2016-06-15 21:13:04 +02:00
this - > fShowAdvancedPSUI = fShowAdvancedPSUI ;
2016-06-08 20:33:00 +02:00
int nNumItems = ( fLiteMode | | ! fShowAdvancedPSUI ) ? NUM_ITEMS : NUM_ITEMS_ADV ;
SetupTransactionList ( nNumItems ) ;
if ( fLiteMode ) return ;
ui - > framePrivateSend - > setVisible ( true ) ;
2016-06-06 21:52:24 +02:00
ui - > labelCompletitionText - > setVisible ( fShowAdvancedPSUI ) ;
ui - > privateSendProgress - > setVisible ( fShowAdvancedPSUI ) ;
ui - > labelSubmittedDenomText - > setVisible ( fShowAdvancedPSUI ) ;
ui - > labelSubmittedDenom - > setVisible ( fShowAdvancedPSUI ) ;
ui - > privateSendAuto - > setVisible ( fShowAdvancedPSUI ) ;
ui - > privateSendReset - > setVisible ( fShowAdvancedPSUI ) ;
2016-11-05 17:13:16 +01:00
ui - > privateSendInfo - > setVisible ( true ) ;
2016-06-06 21:52:24 +02:00
ui - > labelPrivateSendLastMessage - > setVisible ( fShowAdvancedPSUI ) ;
}
2014-12-23 03:28:52 +01:00
2016-06-06 21:52:24 +02:00
void OverviewPage : : privateSendStatus ( )
2014-12-23 03:28:52 +01:00
{
2016-02-20 20:03:19 +01:00
if ( ! masternodeSync . IsBlockchainSynced ( ) | | ShutdownRequested ( ) ) return ;
2015-07-26 01:24:19 +02:00
static int64_t nLastDSProgressBlockTime = 0 ;
2016-03-02 21:26:45 +01:00
int nBestHeight = clientModel - > getNumBlocks ( ) ;
2014-12-23 03:28:52 +01:00
2016-06-27 17:25:22 +02:00
// We are processing more then 1 block per second, we'll just leave
2017-05-05 13:26:27 +02:00
if ( ( ( nBestHeight - privateSendClient . nCachedNumBlocks ) / ( GetTimeMillis ( ) - nLastDSProgressBlockTime + 1 ) > 1 ) ) return ;
2015-07-26 01:24:19 +02:00
nLastDSProgressBlockTime = GetTimeMillis ( ) ;
2014-12-23 03:28:52 +01:00
2016-06-15 21:13:04 +02:00
QString strKeysLeftText ( tr ( " keys left: %1 " ) . arg ( pwalletMain - > nKeysLeftSinceAutoBackup ) ) ;
2016-08-05 21:49:45 +02:00
if ( pwalletMain - > nKeysLeftSinceAutoBackup < PRIVATESEND_KEYS_THRESHOLD_WARNING ) {
2016-06-15 21:13:04 +02:00
strKeysLeftText = " <span style='color:red;'> " + strKeysLeftText + " </span> " ;
}
ui - > labelPrivateSendEnabled - > setToolTip ( strKeysLeftText ) ;
2017-05-05 13:26:27 +02:00
if ( ! privateSendClient . fEnablePrivateSend ) {
if ( nBestHeight ! = privateSendClient . nCachedNumBlocks ) {
privateSendClient . nCachedNumBlocks = nBestHeight ;
2016-08-19 13:47:37 +02:00
updatePrivateSendProgress ( ) ;
}
ui - > labelPrivateSendLastMessage - > setText ( " " ) ;
ui - > togglePrivateSend - > setText ( tr ( " Start Mixing " ) ) ;
QString strEnabled = tr ( " Disabled " ) ;
// Show how many keys left in advanced PS UI mode only
if ( fShowAdvancedPSUI ) strEnabled + = " , " + strKeysLeftText ;
ui - > labelPrivateSendEnabled - > setText ( strEnabled ) ;
return ;
}
2016-06-15 21:13:04 +02:00
// Warn user that wallet is running out of keys
2016-08-19 13:47:37 +02:00
// NOTE: we do NOT warn user and do NOT create autobackups if mixing is not running
2016-08-05 21:49:45 +02:00
if ( nWalletBackups > 0 & & pwalletMain - > nKeysLeftSinceAutoBackup < PRIVATESEND_KEYS_THRESHOLD_WARNING ) {
2016-07-29 10:36:49 +02:00
QSettings settings ;
if ( settings . value ( " fLowKeysWarning " ) . toBool ( ) ) {
QString strWarn = tr ( " Very low number of keys left since last automatic backup! " ) + " <br><br> " +
tr ( " We are about to create a new automatic backup for you, however "
" <span style='color:red;'> you should always make sure you have backups "
" saved in some safe place</span>! " ) + " <br><br> " +
tr ( " Note: You turn this message off in options. " ) ;
ui - > labelPrivateSendEnabled - > setToolTip ( strWarn ) ;
LogPrintf ( " OverviewPage::privateSendStatus -- Very low number of keys left since last automatic backup, warning user and trying to create new backup... \n " ) ;
QMessageBox : : warning ( this , tr ( " PrivateSend " ) , strWarn , QMessageBox : : Ok , QMessageBox : : Ok ) ;
2016-09-05 18:09:25 +02:00
} else {
2016-07-29 10:36:49 +02:00
LogPrintf ( " OverviewPage::privateSendStatus -- Very low number of keys left since last automatic backup, skipping warning and trying to create new backup... \n " ) ;
2016-09-05 18:09:25 +02:00
}
2016-06-15 21:13:04 +02:00
2016-09-05 18:09:25 +02:00
std : : string strBackupWarning ;
std : : string strBackupError ;
if ( ! AutoBackupWallet ( pwalletMain , " " , strBackupWarning , strBackupError ) ) {
if ( ! strBackupWarning . empty ( ) ) {
2016-06-15 21:13:04 +02:00
// It's still more or less safe to continue but warn user anyway
2016-09-05 18:09:25 +02:00
LogPrintf ( " OverviewPage::privateSendStatus -- WARNING! Something went wrong on automatic backup: %s \n " , strBackupWarning ) ;
2016-06-15 21:13:04 +02:00
QMessageBox : : warning ( this , tr ( " PrivateSend " ) ,
2016-09-05 18:09:25 +02:00
tr ( " WARNING! Something went wrong on automatic backup " ) + " :<br><br> " + strBackupWarning . c_str ( ) ,
2016-06-15 21:13:04 +02:00
QMessageBox : : Ok , QMessageBox : : Ok ) ;
}
2016-09-05 18:09:25 +02:00
if ( ! strBackupError . empty ( ) ) {
2016-06-15 21:13:04 +02:00
// Things are really broken, warn user and stop mixing immediately
2016-09-05 18:09:25 +02:00
LogPrintf ( " OverviewPage::privateSendStatus -- ERROR! Failed to create automatic backup: %s \n " , strBackupError ) ;
2016-06-15 21:13:04 +02:00
QMessageBox : : warning ( this , tr ( " PrivateSend " ) ,
2016-09-05 18:09:25 +02:00
tr ( " ERROR! Failed to create automatic backup " ) + " :<br><br> " + strBackupError . c_str ( ) + " <br> " +
2016-06-15 21:13:04 +02:00
tr ( " Mixing is disabled, please close your wallet and fix the issue! " ) ,
QMessageBox : : Ok , QMessageBox : : Ok ) ;
}
}
}
2017-05-05 13:26:27 +02:00
QString strEnabled = privateSendClient . fEnablePrivateSend ? tr ( " Enabled " ) : tr ( " Disabled " ) ;
2016-06-15 21:13:04 +02:00
// Show how many keys left in advanced PS UI mode only
if ( fShowAdvancedPSUI ) strEnabled + = " , " + strKeysLeftText ;
ui - > labelPrivateSendEnabled - > setText ( strEnabled ) ;
if ( nWalletBackups = = - 1 ) {
// Automatic backup failed, nothing else we can do until user fixes the issue manually
DisablePrivateSendCompletely ( ) ;
QString strError = tr ( " ERROR! Failed to create automatic backup " ) + " , " +
tr ( " see debug.log for details. " ) + " <br><br> " +
tr ( " Mixing is disabled, please close your wallet and fix the issue! " ) ;
ui - > labelPrivateSendEnabled - > setToolTip ( strError ) ;
return ;
} else if ( nWalletBackups = = - 2 ) {
// We were able to create automatic backup but keypool was not replenished because wallet is locked.
QString strWarning = tr ( " WARNING! Failed to replenish keypool, please unlock your wallet to do so. " ) ;
ui - > labelPrivateSendEnabled - > setToolTip ( strWarning ) ;
}
2014-12-23 03:28:52 +01:00
// check darksend status and unlock if needed
2017-05-05 13:26:27 +02:00
if ( nBestHeight ! = privateSendClient . nCachedNumBlocks ) {
2014-12-23 03:28:52 +01:00
// Balance and number of transactions might have changed
2017-05-05 13:26:27 +02:00
privateSendClient . nCachedNumBlocks = nBestHeight ;
2016-06-06 21:52:24 +02:00
updatePrivateSendProgress ( ) ;
2014-12-23 03:28:52 +01:00
}
2017-05-05 13:26:27 +02:00
QString strStatus = QString ( privateSendClient . GetStatus ( ) . c_str ( ) ) ;
2014-12-23 03:28:52 +01:00
2016-05-09 21:08:13 +02:00
QString s = tr ( " Last PrivateSend message: \n " ) + strStatus ;
2014-12-23 03:28:52 +01:00
2016-06-06 21:52:24 +02:00
if ( s ! = ui - > labelPrivateSendLastMessage - > text ( ) )
2016-09-05 18:09:25 +02:00
LogPrintf ( " OverviewPage::privateSendStatus -- Last PrivateSend message: %s \n " , strStatus . toStdString ( ) ) ;
2014-12-26 04:58:39 +01:00
2016-06-06 21:52:24 +02:00
ui - > labelPrivateSendLastMessage - > setText ( s ) ;
2014-12-23 03:28:52 +01:00
2017-05-05 13:26:27 +02:00
if ( privateSendClient . nSessionDenom = = 0 ) {
2015-02-04 12:00:23 +01:00
ui - > labelSubmittedDenom - > setText ( tr ( " N/A " ) ) ;
2014-12-29 16:50:40 +01:00
} else {
2017-06-30 20:30:16 +02:00
QString strDenom ( CPrivateSend : : GetDenominationsToString ( privateSendClient . nSessionDenom ) . c_str ( ) ) ;
2016-08-05 21:49:45 +02:00
ui - > labelSubmittedDenom - > setText ( strDenom ) ;
2014-12-29 16:50:40 +01:00
}
2014-12-28 00:45:07 +01:00
2014-12-23 03:28:52 +01:00
}
2016-06-06 21:52:24 +02:00
void OverviewPage : : privateSendAuto ( ) {
Backport Bitcoin PR#8085: p2p: Begin encapsulation (#1537)
* net: move CBanDB and CAddrDB out of net.h/cpp
This will eventually solve a circular dependency
* net: Create CConnman to encapsulate p2p connections
* net: Move socket binding into CConnman
* net: move OpenNetworkConnection into CConnman
* net: move ban and addrman functions into CConnman
* net: Add oneshot functions to CConnman
* net: move added node functions to CConnman
* net: Add most functions needed for vNodes to CConnman
* net: handle nodesignals in CConnman
* net: Pass CConnection to wallet rather than using the global
* net: Add rpc error for missing/disabled p2p functionality
* net: Pass CConnman around as needed
* gui: add NodeID to the peer table
* net: create generic functor accessors and move vNodes to CConnman
* net: move whitelist functions into CConnman
* net: move nLastNodeId to CConnman
* net: move nLocalHostNonce to CConnman
This behavior seems to have been quite racy and broken.
Move nLocalHostNonce into CNode, and check received nonces against all
non-fully-connected nodes. If there's a match, assume we've connected
to ourself.
* net: move messageHandlerCondition to CConnman
* net: move send/recv statistics to CConnman
* net: move SendBufferSize/ReceiveFloodSize to CConnman
* net: move nLocalServices/nRelevantServices to CConnman
These are in-turn passed to CNode at connection time. This allows us to offer
different services to different peers (or test the effects of doing so).
* net: move semOutbound and semMasternodeOutbound to CConnman
* net: SocketSendData returns written size
* net: move max/max-outbound to CConnman
* net: Pass best block known height into CConnman
CConnman then passes the current best height into CNode at creation time.
This way CConnman/CNode have no dependency on main for height, and the signals
only move in one direction.
This also helps to prevent identity leakage a tiny bit. Before this change, an
attacker could theoretically make 2 connections on different interfaces. They
would connect fully on one, and only establish the initial connection on the
other. Once they receive a new block, they would relay it to your first
connection, and immediately commence the version handshake on the second. Since
the new block height is reflected immediately, they could attempt to learn
whether the two connections were correlated.
This is, of course, incredibly unlikely to work due to the small timings
involved and receipt from other senders. But it doesn't hurt to lock-in
nBestHeight at the time of connection, rather than letting the remote choose
the time.
* net: pass CClientUIInterface into CConnman
* net: Drop StartNode/StopNode and use CConnman directly
* net: Introduce CConnection::Options to avoid passing so many params
* net: add nSendBufferMaxSize/nReceiveFloodSize to CConnection::Options
* net: move vNodesDisconnected into CConnman
* Made the ForEachNode* functions in src/net.cpp more pragmatic and self documenting
* Convert ForEachNode* functions to take a templated function argument rather than a std::function to eliminate std::function overhead
* net: move MAX_FEELER_CONNECTIONS into connman
2017-07-21 11:35:19 +02:00
privateSendClient . DoAutomaticDenominating ( * g_connman ) ;
2014-12-23 03:28:52 +01:00
}
2016-06-06 21:52:24 +02:00
void OverviewPage : : privateSendReset ( ) {
2017-05-05 13:26:27 +02:00
privateSendClient . ResetPool ( ) ;
2014-12-28 00:45:07 +01:00
2016-05-09 21:08:13 +02:00
QMessageBox : : warning ( this , tr ( " PrivateSend " ) ,
tr ( " PrivateSend was successfully reset. " ) ,
2014-12-28 00:45:07 +01:00
QMessageBox : : Ok , QMessageBox : : Ok ) ;
}
2016-11-05 17:13:16 +01:00
void OverviewPage : : privateSendInfo ( ) {
2016-11-20 07:54:33 +01:00
HelpMessageDialog dlg ( this , HelpMessageDialog : : pshelp ) ;
dlg . exec ( ) ;
2016-11-05 17:13:16 +01:00
}
2016-06-06 21:52:24 +02:00
void OverviewPage : : togglePrivateSend ( ) {
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 ( ) ) {
2016-05-09 21:08:13 +02:00
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 " ) ;
}
2017-05-05 13:26:27 +02:00
if ( ! privateSendClient . fEnablePrivateSend ) {
2017-06-30 20:30:16 +02:00
const CAmount nMinAmount = CPrivateSend : : GetSmallestDenomination ( ) + CPrivateSend : : GetMaxCollateralAmount ( ) ;
2017-02-02 09:50:21 +01:00
if ( currentBalance < nMinAmount ) {
QString strMinAmount ( BitcoinUnits : : formatWithUnit ( nDisplayUnit , nMinAmount ) ) ;
2016-05-09 21:08:13 +02:00
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 ;
}
2015-01-19 22:25:03 +01:00
2015-01-21 07:29:09 +01:00
// if wallet is locked, ask for a passphrase
if ( walletModel - > getEncryptionStatus ( ) = = WalletModel : : Locked )
{
2016-09-11 11:02:54 +02:00
WalletModel : : UnlockContext ctx ( walletModel - > requestUnlock ( true ) ) ;
2015-01-21 07:29:09 +01:00
if ( ! ctx . isValid ( ) )
{
//unlock was cancelled
2017-05-05 13:26:27 +02:00
privateSendClient . nCachedNumBlocks = std : : numeric_limits < int > : : max ( ) ;
2016-05-09 21:08:13 +02:00
QMessageBox : : warning ( this , tr ( " PrivateSend " ) ,
tr ( " Wallet is locked and user declined to unlock. Disabling PrivateSend. " ) ,
2015-01-21 07:29:09 +01:00
QMessageBox : : Ok , QMessageBox : : Ok ) ;
2016-09-05 18:09:25 +02:00
LogPrint ( " privatesend " , " OverviewPage::togglePrivateSend -- Wallet is locked and user declined to unlock. Disabling PrivateSend. \n " ) ;
2015-01-21 07:29:09 +01:00
return ;
2015-01-19 22:25:03 +01:00
}
}
2014-12-23 03:28:52 +01:00
}
2017-05-05 13:26:27 +02:00
privateSendClient . fEnablePrivateSend = ! privateSendClient . fEnablePrivateSend ;
privateSendClient . nCachedNumBlocks = std : : numeric_limits < int > : : max ( ) ;
2014-12-23 03:28:52 +01:00
2017-05-05 13:26:27 +02:00
if ( ! privateSendClient . fEnablePrivateSend ) {
2016-06-06 21:52:24 +02:00
ui - > togglePrivateSend - > setText ( tr ( " Start Mixing " ) ) ;
2017-05-05 13:26:27 +02:00
privateSendClient . UnlockCoins ( ) ;
2014-12-23 03:28:52 +01:00
} else {
2016-06-06 21:52:24 +02:00
ui - > togglePrivateSend - > setText ( tr ( " Stop Mixing " ) ) ;
2014-12-23 03:28:52 +01:00
/* show darksend configuration if client has defaults set */
2017-05-05 13:26:27 +02:00
if ( privateSendClient . nPrivateSendAmount = = 0 ) {
2014-12-23 03:28:52 +01:00
DarksendConfig dlg ( this ) ;
dlg . setModel ( walletModel ) ;
dlg . exec ( ) ;
}
}
}
2016-06-08 20:33:00 +02:00
void OverviewPage : : SetupTransactionList ( int nNumItems ) {
ui - > listTransactions - > setMinimumHeight ( nNumItems * ( DECORATION_SIZE + 2 ) ) ;
if ( walletModel & & walletModel - > getOptionsModel ( ) ) {
// Set up transaction list
2017-09-11 15:38:14 +02:00
filter . reset ( new TransactionFilterProxy ( ) ) ;
2016-06-08 20:33:00 +02:00
filter - > setSourceModel ( walletModel - > getTransactionTableModel ( ) ) ;
filter - > setLimit ( nNumItems ) ;
filter - > setDynamicSortFilter ( true ) ;
filter - > setSortRole ( Qt : : EditRole ) ;
filter - > setShowInactive ( false ) ;
filter - > sort ( TransactionTableModel : : Status , Qt : : DescendingOrder ) ;
2017-09-11 15:38:14 +02:00
ui - > listTransactions - > setModel ( filter . get ( ) ) ;
2016-06-08 20:33:00 +02:00
ui - > listTransactions - > setModelColumn ( TransactionTableModel : : ToAddress ) ;
}
}
2016-06-15 21:13:04 +02:00
void OverviewPage : : DisablePrivateSendCompletely ( ) {
ui - > togglePrivateSend - > setText ( " ( " + tr ( " Disabled " ) + " ) " ) ;
ui - > privateSendAuto - > setText ( " ( " + tr ( " Disabled " ) + " ) " ) ;
ui - > privateSendReset - > setText ( " ( " + tr ( " Disabled " ) + " ) " ) ;
ui - > framePrivateSend - > setEnabled ( false ) ;
if ( nWalletBackups < = 0 ) {
ui - > labelPrivateSendEnabled - > setText ( " <span style='color:red;'>( " + tr ( " Disabled " ) + " )</span> " ) ;
}
2017-05-05 13:26:27 +02:00
privateSendClient . fEnablePrivateSend = false ;
2017-02-09 06:29:00 +01:00
}