2014-12-05 10:09:38 +01:00
// Copyright (c) 2011-2014 The Bitcoin developers
2015-03-18 00:06:58 +01:00
// Copyright (c) 2014-2015 The Dash developers
2013-11-04 16:20:43 +01:00
// Distributed under the MIT/X11 software license, see the accompanying
// 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"
2014-12-23 03:28:52 +01:00
# include "darksend.h"
# include "darksendconfig.h"
2013-04-13 07:13:08 +02:00
# include "guiconstants.h"
# include "guiutil.h"
2011-07-29 14:36:35 +02:00
# include "optionsmodel.h"
2011-08-03 20:52:18 +02:00
# include "transactionfilterproxy.h"
2013-04-13 07:13:08 +02:00
# include "transactiontablemodel.h"
# include "walletmodel.h"
2014-12-23 03:28:52 +01:00
# include "init.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>
2014-12-23 03:28:52 +01:00
# include <QTimer>
2011-08-03 20:52:18 +02:00
2015-03-22 20:37:30 +01:00
# define DECORATION_SIZE 48
2015-03-22 21:29:29 +01:00
# define ICON_OFFSET 16
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
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 :
2015-03-18 00:06:58 +01:00
TxViewDelegate ( ) : QAbstractItemDelegate ( ) , unit ( BitcoinUnits : : DASH )
2011-08-03 20:52:18 +02:00
{
}
inline void paint ( QPainter * painter , const QStyleOptionViewItem & option ,
const QModelIndex & index ) const
{
painter - > save ( ) ;
QIcon icon = qvariant_cast < QIcon > ( index . data ( Qt : : DecorationRole ) ) ;
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 ) ;
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 ) ;
2014-07-07 23:27:09 +02:00
QString amountText = BitcoinUnits : : formatWithUnit ( 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 ;
} ;
2011-09-19 12:40:23 +02:00
# include "overviewpage.moc"
2011-07-05 22:09:39 +02:00
OverviewPage : : OverviewPage ( QWidget * parent ) :
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 ) ,
2012-02-14 12:08:00 +01:00
txdelegate ( new TxViewDelegate ( ) ) ,
filter ( 0 )
2011-07-05 22:09:39 +02:00
{
ui - > setupUi ( this ) ;
2011-08-03 20:52:18 +02:00
// 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 ) ) ;
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
2014-12-23 03:28:52 +01:00
2012-05-15 16:57:59 +02:00
// init "out of sync" warning labels
ui - > labelWalletStatus - > setText ( " ( " + tr ( " out of sync " ) + " ) " ) ;
2015-02-12 14:32:34 +01:00
ui - > labelDarksendSyncStatus - > setText ( " ( " + tr ( " out of sync " ) + " ) " ) ;
2012-05-15 16:57:59 +02:00
ui - > labelTransactionsStatus - > setText ( " ( " + tr ( " out of sync " ) + " ) " ) ;
2015-02-01 16:53:49 +01:00
lastNewBlock = 0 ;
2014-12-23 03:28:52 +01:00
2015-01-18 16:28:16 +01:00
if ( fLiteMode ) {
ui - > frameDarksend - > setVisible ( false ) ;
2015-03-31 00:27:20 +02:00
} else if ( ! fMasterNode ) {
2015-01-18 16:28:16 +01:00
timer = new QTimer ( this ) ;
connect ( timer , SIGNAL ( timeout ( ) ) , this , SLOT ( darkSendStatus ( ) ) ) ;
timer - > start ( 333 ) ;
}
2015-03-31 00:27:20 +02:00
if ( fMasterNode ) {
2015-02-04 12:00:23 +01:00
ui - > toggleDarksend - > setText ( " ( " + tr ( " Disabled " ) + " ) " ) ;
2015-04-03 10:25:14 +02:00
ui - > darksendAuto - > setText ( " ( " + tr ( " Disabled " ) + " ) " ) ;
ui - > darksendReset - > setText ( " ( " + tr ( " Disabled " ) + " ) " ) ;
2015-03-31 00:27:20 +02:00
ui - > frameDarksend - > setEnabled ( false ) ;
2014-12-23 03:28:52 +01:00
} else if ( ! fEnableDarksend ) {
2015-02-04 12:00:23 +01:00
ui - > toggleDarksend - > setText ( tr ( " Start Darksend Mixing " ) ) ;
2014-12-23 03:28:52 +01:00
} else {
2015-02-04 12:00:23 +01:00
ui - > toggleDarksend - > setText ( tr ( " Stop Darksend Mixing " ) ) ;
2014-12-23 03:28:52 +01:00
}
2012-05-15 16:57:59 +02:00
// start with displaying the "out of sync" warnings
showOutOfSyncWarning ( true ) ;
2012-05-12 13:19:44 +02:00
}
void OverviewPage : : handleTransactionClicked ( const QModelIndex & index )
{
if ( filter )
emit transactionClicked ( filter - > mapToSource ( index ) ) ;
2011-07-05 22:09:39 +02:00
}
OverviewPage : : ~ OverviewPage ( )
{
2015-03-31 00:27:20 +02:00
if ( ! fLiteMode & & ! fMasterNode ) disconnect ( timer , SIGNAL ( timeout ( ) ) , this , SLOT ( darkSendStatus ( ) ) ) ;
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
{
2012-10-24 21:47:07 +02:00
int unit = walletModel - > getOptionsModel ( ) - > getDisplayUnit ( ) ;
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 ;
2014-07-07 23:27:09 +02:00
ui - > labelBalance - > setText ( BitcoinUnits : : formatWithUnit ( unit , balance , false , BitcoinUnits : : separatorAlways ) ) ;
ui - > labelUnconfirmed - > setText ( BitcoinUnits : : formatWithUnit ( unit , unconfirmedBalance , false , BitcoinUnits : : separatorAlways ) ) ;
ui - > labelImmature - > setText ( BitcoinUnits : : formatWithUnit ( unit , immatureBalance , false , BitcoinUnits : : separatorAlways ) ) ;
2015-04-03 00:51:08 +02:00
ui - > labelAnonymized - > setText ( BitcoinUnits : : formatWithUnit ( unit , anonymizedBalance , false , BitcoinUnits : : separatorAlways ) ) ;
2014-07-07 23:27:09 +02:00
ui - > labelTotal - > setText ( BitcoinUnits : : formatWithUnit ( unit , balance + unconfirmedBalance + immatureBalance , false , BitcoinUnits : : separatorAlways ) ) ;
ui - > labelWatchAvailable - > setText ( BitcoinUnits : : formatWithUnit ( unit , watchOnlyBalance , false , BitcoinUnits : : separatorAlways ) ) ;
ui - > labelWatchPending - > setText ( BitcoinUnits : : formatWithUnit ( unit , watchUnconfBalance , false , BitcoinUnits : : separatorAlways ) ) ;
ui - > labelWatchImmature - > setText ( BitcoinUnits : : formatWithUnit ( unit , watchImmatureBalance , false , BitcoinUnits : : separatorAlways ) ) ;
ui - > labelWatchTotal - > setText ( BitcoinUnits : : formatWithUnit ( unit , 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
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
if ( ! showWatchOnly )
ui - > labelWatchImmature - > hide ( ) ;
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
{
// Set up transaction list
2012-05-12 13:19:44 +02:00
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 ) ;
2014-02-14 07:59:07 +01:00
filter - > setShowInactive ( false ) ;
2011-11-08 21:18:36 +01:00
filter - > sort ( TransactionTableModel : : Status , Qt : : DescendingOrder ) ;
2011-07-11 20:42:10 +02:00
2011-11-08 21:18:36 +01:00
ui - > listTransactions - > setModel ( filter ) ;
ui - > listTransactions - > setModelColumn ( TransactionTableModel : : ToAddress ) ;
2011-08-03 20:52:18 +02:00
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 ( ) ) ) ;
2014-12-23 03:28:52 +01:00
2014-12-28 00:45:07 +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 ( ) ) ) ;
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
}
2012-06-09 15:41:21 +02:00
2015-03-18 00:06:58 +01:00
// update the display unit, to not use the default ("DASH")
2012-06-09 15:41:21 +02:00
updateDisplayUnit ( ) ;
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
{
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
2012-10-24 21:47:07 +02:00
txdelegate - > unit = walletModel - > getOptionsModel ( ) - > getDisplayUnit ( ) ;
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 ) ;
2015-02-12 14:32:34 +01:00
ui - > labelDarksendSyncStatus - > setVisible ( fShow ) ;
2012-05-15 16:57:59 +02:00
ui - > labelTransactionsStatus - > setVisible ( fShow ) ;
}
2014-12-23 03:28:52 +01:00
2015-01-28 08:35:17 +01:00
void OverviewPage : : updateDarksendProgress ( )
{
2015-01-14 15:28:35 +01:00
if ( IsInitialBlockDownload ( ) ) return ;
2015-01-28 08:35:17 +01:00
int64_t nBalance = pwalletMain - > GetBalance ( ) ;
if ( nBalance = = 0 )
{
2014-12-23 03:28:52 +01:00
ui - > darksendProgress - > setValue ( 0 ) ;
2015-02-04 12:00:23 +01:00
QString s ( tr ( " No inputs detected " ) ) ;
2014-12-26 04:58:39 +01:00
ui - > darksendProgress - > setToolTip ( s ) ;
2015-04-30 00:06:24 +02:00
// when balance is zero just show info from settings
QString strSettings = BitcoinUnits : : formatWithUnit (
walletModel - > getOptionsModel ( ) - > getDisplayUnit ( ) ,
nAnonymizeDarkcoinAmount * COIN
) + " / " + tr ( " %n Rounds " , " " , nDarksendRounds ) ;
ui - > labelAmountRounds - > setText ( strSettings ) ;
2014-12-23 03:28:52 +01:00
return ;
}
2015-01-28 08:35:17 +01:00
//get denominated unconfirmed inputs
if ( pwalletMain - > GetDenominatedBalance ( true , true ) > 0 )
{
2015-02-04 12:00:23 +01:00
QString s ( tr ( " Found unconfirmed denominated outputs, will wait till they confirm to recalculate. " ) ) ;
2015-01-02 23:20:30 +01:00
ui - > darksendProgress - > setToolTip ( s ) ;
return ;
}
2015-04-30 00:06:24 +02:00
int64_t nMaxToAnonymize = pwalletMain - > GetAnonymizableBalance ( true ) ;
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.
if ( nMaxToAnonymize > nAnonymizeDarkcoinAmount * COIN ) nMaxToAnonymize = nAnonymizeDarkcoinAmount * COIN ;
2014-12-26 21:00:56 +01:00
2015-01-28 08:35:17 +01:00
if ( nMaxToAnonymize = = 0 ) return ;
// calculate parts of the progress, each of them shouldn't be higher than 1:
// mixing progress of denominated balance
2015-02-05 15:20:19 +01:00
int64_t denominatedBalance = pwalletMain - > GetDenominatedBalance ( ) ;
float denomPart = 0 ;
if ( denominatedBalance > 0 )
{
2015-02-12 14:54:24 +01:00
denomPart = ( float ) pwalletMain - > GetNormalizedAnonymizedBalance ( ) / denominatedBalance ;
2015-02-05 15:20:19 +01:00
denomPart = denomPart > 1 ? 1 : denomPart ;
}
2015-01-28 08:35:17 +01:00
// % of fully anonymized balance
2015-02-05 15:20:19 +01:00
float anonPart = 0 ;
if ( nMaxToAnonymize > 0 )
{
anonPart = ( float ) pwalletMain - > GetAnonymizedBalance ( ) / nMaxToAnonymize ;
// if anonPart is > 1 then we are done, make denomPart equal 1 too
anonPart = anonPart > 1 ? ( denomPart = 1 , 1 ) : anonPart ;
}
2015-01-28 08:35:17 +01:00
// apply some weights to them (sum should be <=100) and calculate the whole progress
int progress = 80 * denomPart + 20 * anonPart ;
2015-04-08 16:41:49 +02:00
if ( progress > = 100 ) progress = 100 ;
2015-01-28 08:35:17 +01:00
ui - > darksendProgress - > setValue ( progress ) ;
2015-04-15 00:40:28 +02:00
QString strToolPip = tr ( " Progress: %1% (inputs have an average of %2 of %n rounds) " , " " , nDarksendRounds ) . arg ( progress ) . arg ( pwalletMain - > GetAverageAnonymizedRounds ( ) ) ;
ui - > darksendProgress - > setToolTip ( strToolPip ) ;
2015-04-30 00:06:24 +02:00
QString strSettings ;
if ( nMaxToAnonymize > = nAnonymizeDarkcoinAmount * COIN ) {
ui - > labelAmountRounds - > setToolTip ( tr ( " Found enough compatible inputs to anonymize %1 " )
. arg ( BitcoinUnits : : formatWithUnit (
walletModel - > getOptionsModel ( ) - > getDisplayUnit ( ) ,
nAnonymizeDarkcoinAmount * COIN
) ) ) ;
strSettings = BitcoinUnits : : formatWithUnit (
walletModel - > getOptionsModel ( ) - > getDisplayUnit ( ) ,
nAnonymizeDarkcoinAmount * COIN
) + " / " + tr ( " %n Rounds " , " " , nDarksendRounds ) ;
} else {
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 " )
. arg ( BitcoinUnits : : formatWithUnit (
walletModel - > getOptionsModel ( ) - > getDisplayUnit ( ) ,
nAnonymizeDarkcoinAmount * COIN
) )
. arg ( BitcoinUnits : : formatWithUnit (
walletModel - > getOptionsModel ( ) - > getDisplayUnit ( ) ,
nMaxToAnonymize
) ) ) ;
strSettings = " <span style='color:red;'> " + BitcoinUnits : : formatWithUnit (
walletModel - > getOptionsModel ( ) - > getDisplayUnit ( ) ,
nMaxToAnonymize
) + " / " + tr ( " %n Rounds " , " " , nDarksendRounds ) + " </span> " ;
}
ui - > labelAmountRounds - > setText ( strSettings ) ;
2014-12-23 03:28:52 +01:00
}
void OverviewPage : : darkSendStatus ( )
{
int nBestHeight = chainActive . Tip ( ) - > nHeight ;
if ( nBestHeight ! = darkSendPool . cachedNumBlocks )
{
2015-02-01 16:53:49 +01:00
//we we're processing lots of blocks, we'll just leave
if ( GetTime ( ) - lastNewBlock < 10 ) return ;
lastNewBlock = GetTime ( ) ;
2014-12-23 03:28:52 +01:00
updateDarksendProgress ( ) ;
}
if ( ! fEnableDarksend ) {
if ( nBestHeight ! = darkSendPool . cachedNumBlocks )
{
darkSendPool . cachedNumBlocks = nBestHeight ;
2015-02-04 12:00:23 +01:00
ui - > darksendEnabled - > setText ( tr ( " Disabled " ) ) ;
2014-12-23 03:28:52 +01:00
ui - > darksendStatus - > setText ( " " ) ;
2015-02-04 12:00:23 +01:00
ui - > toggleDarksend - > setText ( tr ( " Start Darksend 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 ;
/* *******************************************************/
2015-02-04 12:00:23 +01:00
ui - > darksendEnabled - > setText ( tr ( " Enabled " ) ) ;
2014-12-23 03:28:52 +01:00
}
2015-06-24 18:08:14 +02:00
QString strStatus = QString ( darkSendPool . GetStatus ( ) . c_str ( ) ) ;
2014-12-23 03:28:52 +01:00
2015-04-15 00:40:28 +02:00
QString s = tr ( " Last Darksend message: \n " ) + strStatus ;
2014-12-23 03:28:52 +01:00
if ( s ! = ui - > darksendStatus - > text ( ) )
2015-04-15 00:40:28 +02:00
LogPrintf ( " Last Darksend 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 ) ;
2014-12-29 16:50:40 +01:00
if ( darkSendPool . sessionDenom = = 0 ) {
2015-02-04 12:00:23 +01:00
ui - > labelSubmittedDenom - > setText ( tr ( " N/A " ) ) ;
2014-12-29 16:50:40 +01:00
} else {
std : : string out ;
darkSendPool . GetDenominationsToString ( darkSendPool . sessionDenom , out ) ;
QString s2 ( out . c_str ( ) ) ;
2014-12-31 03:54:00 +01:00
ui - > labelSubmittedDenom - > setText ( s2 ) ;
2014-12-29 16:50:40 +01:00
}
2014-12-28 00:45:07 +01:00
2014-12-23 03:28:52 +01:00
}
2014-12-28 00:45:07 +01:00
void OverviewPage : : darksendAuto ( ) {
2014-12-23 03:28:52 +01:00
darkSendPool . DoAutomaticDenominating ( ) ;
}
2014-12-28 00:45:07 +01:00
void OverviewPage : : darksendReset ( ) {
2014-12-28 15:46:39 +01:00
darkSendPool . Reset ( ) ;
2014-12-28 00:45:07 +01:00
QMessageBox : : warning ( this , tr ( " Darksend " ) ,
tr ( " Darksend was successfully reset. " ) ,
QMessageBox : : Ok , QMessageBox : : Ok ) ;
}
2014-12-23 03:28:52 +01:00
void OverviewPage : : toggleDarksend ( ) {
2014-12-26 04:58:39 +01:00
if ( ! fEnableDarksend ) {
int64_t balance = pwalletMain - > GetBalance ( ) ;
2015-01-15 12:15:01 +01:00
float minAmount = 1.49 * COIN ;
if ( balance < minAmount ) {
QString strMinAmount (
BitcoinUnits : : formatWithUnit (
walletModel - > getOptionsModel ( ) - > getDisplayUnit ( ) ,
minAmount ) ) ;
2014-12-26 04:58:39 +01:00
QMessageBox : : warning ( this , tr ( " Darksend " ) ,
2015-01-15 12:15:01 +01:00
tr ( " Darksend 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 )
{
WalletModel : : UnlockContext ctx ( walletModel - > requestUnlock ( false ) ) ;
if ( ! ctx . isValid ( ) )
{
//unlock was cancelled
darkSendPool . cachedNumBlocks = 0 ;
QMessageBox : : warning ( this , tr ( " Darksend " ) ,
tr ( " Wallet is locked and user declined to unlock. Disabling Darksend. " ) ,
QMessageBox : : Ok , QMessageBox : : Ok ) ;
if ( fDebug ) LogPrintf ( " Wallet is locked and user declined to unlock. Disabling Darksend. \n " ) ;
return ;
2015-01-19 22:25:03 +01:00
}
}
2014-12-23 03:28:52 +01:00
}
darkSendPool . cachedNumBlocks = 0 ;
fEnableDarksend = ! fEnableDarksend ;
if ( ! fEnableDarksend ) {
2015-02-04 12:00:23 +01:00
ui - > toggleDarksend - > setText ( tr ( " Start Darksend Mixing " ) ) ;
2014-12-23 03:28:52 +01:00
} else {
2015-02-04 12:00:23 +01:00
ui - > toggleDarksend - > setText ( tr ( " Stop Darksend Mixing " ) ) ;
2014-12-23 03:28:52 +01:00
/* show darksend configuration if client has defaults set */
if ( nAnonymizeDarkcoinAmount = = 0 ) {
DarksendConfig dlg ( this ) ;
dlg . setModel ( walletModel ) ;
dlg . exec ( ) ;
}
darkSendPool . DoAutomaticDenominating ( ) ;
}
}