2015-12-13 14:51:43 +01:00
// Copyright (c) 2011-2015 The Bitcoin Core developers
2021-04-20 21:33:02 +02:00
// Copyright (c) 2014-2021 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.
2020-03-19 23:46:56 +01:00
# include <qt/overviewpage.h>
# include <qt/forms/ui_overviewpage.h>
# include <qt/bitcoinunits.h>
# include <qt/clientmodel.h>
# include <qt/guiutil.h>
# include <qt/optionsmodel.h>
# include <qt/transactionfilterproxy.h>
# include <qt/transactiontablemodel.h>
# include <qt/utilitydialog.h>
# include <qt/walletmodel.h>
2021-10-01 21:19:08 +02:00
# include <coinjoin/options.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
2020-09-25 18:04:53 +02:00
# define ITEM_HEIGHT 54
# define NUM_ITEMS_DISABLED 5
2020-09-29 01:16:03 +02:00
# define NUM_ITEMS_ENABLED_NORMAL 6
# define NUM_ITEMS_ENABLED_ADVANCED 8
2011-08-03 21:04:15 +02:00
2020-10-01 16:05:57 +02:00
Q_DECLARE_METATYPE ( interfaces : : WalletBalances )
2018-03-31 12:41:33 +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 :
2020-07-26 13:20:19 +02:00
explicit TxViewDelegate ( QObject * parent = nullptr ) :
QAbstractItemDelegate ( ) , unit ( BitcoinUnits : : DASH )
2011-08-03 20:52:18 +02:00
{
}
inline void paint ( QPainter * painter , const QStyleOptionViewItem & option ,
2021-06-15 14:24:53 +02:00
const QModelIndex & index ) const override
2011-08-03 20:52:18 +02:00
{
painter - > save ( ) ;
QRect mainRect = option . rect ;
2020-09-25 18:04:53 +02:00
int xspace = 8 ;
int ypad = 8 ;
2011-08-03 20:52:18 +02:00
int halfheight = ( mainRect . height ( ) - 2 * ypad ) / 2 ;
2020-09-25 18:04:53 +02:00
QRect rectTopHalf ( mainRect . left ( ) + xspace , mainRect . top ( ) + ypad , mainRect . width ( ) - xspace , halfheight ) ;
QRect rectBottomHalf ( mainRect . left ( ) + xspace , mainRect . top ( ) + ypad + halfheight + 5 , mainRect . width ( ) - xspace , halfheight ) ;
QRect rectBounding ;
QColor colorForeground ;
2020-09-29 03:09:20 +02:00
qreal initialFontSize = painter - > font ( ) . pointSizeF ( ) ;
2020-09-25 18:04:53 +02:00
// Grab model indexes for desired data from TransactionTableModel
QModelIndex indexDate = index . sibling ( index . row ( ) , TransactionTableModel : : Date ) ;
QModelIndex indexAmount = index . sibling ( index . row ( ) , TransactionTableModel : : Amount ) ;
QModelIndex indexAddress = index . sibling ( index . row ( ) , TransactionTableModel : : ToAddress ) ;
// Draw first line (with slightly bigger font than the second line will get)
// Content: Date/Time, Optional IS indicator, Amount
2020-09-29 03:09:20 +02:00
painter - > setFont ( GUIUtil : : getFont ( GUIUtil : : FontWeight : : Normal , false , GUIUtil : : getScaledFontSize ( initialFontSize * 1.17 ) ) ) ;
2020-09-25 18:04:53 +02:00
// Date/Time
colorForeground = qvariant_cast < QColor > ( indexDate . data ( Qt : : ForegroundRole ) ) ;
QString strDate = indexDate . data ( Qt : : DisplayRole ) . toString ( ) ;
painter - > setPen ( colorForeground ) ;
painter - > drawText ( rectTopHalf , Qt : : AlignLeft | Qt : : AlignVCenter , strDate , & rectBounding ) ;
// Optional IS indicator
QIcon iconInstantSend = qvariant_cast < QIcon > ( indexAddress . data ( TransactionTableModel : : RawDecorationRole ) ) ;
QRect rectInstantSend ( rectBounding . right ( ) + 5 , rectTopHalf . top ( ) , 16 , halfheight ) ;
iconInstantSend . paint ( painter , rectInstantSend ) ;
// Amount
colorForeground = qvariant_cast < QColor > ( indexAmount . data ( Qt : : ForegroundRole ) ) ;
// Note: do NOT use Qt::DisplayRole, have format properly here
qint64 nAmount = index . data ( TransactionTableModel : : AmountRole ) . toLongLong ( ) ;
QString strAmount = BitcoinUnits : : floorWithUnit ( unit , nAmount , true , BitcoinUnits : : separatorAlways ) ;
painter - > setPen ( colorForeground ) ;
painter - > drawText ( rectTopHalf , Qt : : AlignRight | Qt : : AlignVCenter , strAmount ) ;
// Draw second line (with the initial font)
// Content: Address/label, Optional Watchonly indicator
2020-09-29 03:09:20 +02:00
painter - > setFont ( GUIUtil : : getFont ( GUIUtil : : FontWeight : : Normal , false , GUIUtil : : getScaledFontSize ( initialFontSize ) ) ) ;
2020-09-25 18:04:53 +02:00
// Address/Label
colorForeground = qvariant_cast < QColor > ( indexAddress . data ( Qt : : ForegroundRole ) ) ;
QString address = indexAddress . data ( Qt : : DisplayRole ) . toString ( ) ;
painter - > setPen ( colorForeground ) ;
painter - > drawText ( rectBottomHalf , Qt : : AlignLeft | Qt : : AlignVCenter , address , & rectBounding ) ;
// Optional Watchonly indicator
2014-08-10 02:26:04 +02:00
if ( index . data ( TransactionTableModel : : WatchonlyRole ) . toBool ( ) )
{
QIcon iconWatchonly = qvariant_cast < QIcon > ( index . data ( TransactionTableModel : : WatchonlyDecorationRole ) ) ;
2020-09-25 18:04:53 +02:00
QRect rectWatchonly ( rectBounding . right ( ) + 5 , rectBottomHalf . top ( ) , 16 , halfheight ) ;
iconWatchonly . paint ( painter , rectWatchonly ) ;
2011-08-03 21:04:15 +02:00
}
2011-08-03 20:52:18 +02:00
painter - > restore ( ) ;
}
2021-06-15 14:24:53 +02:00
inline QSize sizeHint ( const QStyleOptionViewItem & option , const QModelIndex & index ) const override
2011-08-03 21:28:11 +02:00
{
2020-09-25 18:04:53 +02:00
return QSize ( ITEM_HEIGHT , ITEM_HEIGHT ) ;
2011-08-03 21:28:11 +02:00
}
2011-08-03 20:52:18 +02:00
int unit ;
} ;
2020-03-19 23:46:56 +01:00
# include <qt/overviewpage.moc>
2011-07-05 22:09:39 +02:00
2020-07-26 13:20:19 +02:00
OverviewPage : : OverviewPage ( QWidget * parent ) :
2011-07-05 22:09:39 +02:00
QWidget ( parent ) ,
2018-02-21 17:32:08 +01:00
timer ( nullptr ) ,
2011-07-29 14:36:35 +02:00
ui ( new Ui : : OverviewPage ) ,
2019-01-14 15:20:45 +01:00
clientModel ( nullptr ) ,
walletModel ( nullptr ) ,
2019-04-25 17:37:39 +02:00
cachedNumISLocks ( - 1 ) ,
2020-07-26 13:20:19 +02:00
txdelegate ( new TxViewDelegate ( this ) )
2011-07-05 22:09:39 +02:00
{
ui - > setupUi ( this ) ;
2020-06-04 03:18:29 +02:00
GUIUtil : : setFont ( { ui - > label_4 ,
ui - > label_5 ,
2021-03-17 23:36:11 +01:00
ui - > labelCoinJoinHeader
2020-06-16 13:52:46 +02:00
} , GUIUtil : : FontWeight : : Bold , 16 ) ;
2020-06-16 00:11:08 +02:00
GUIUtil : : setFont ( { ui - > labelTotalText ,
2020-06-04 03:18:29 +02:00
ui - > labelWatchTotal ,
2020-06-16 00:11:08 +02:00
ui - > labelTotal
2020-06-16 13:52:46 +02:00
} , GUIUtil : : FontWeight : : Bold , 14 ) ;
2020-06-16 00:11:08 +02:00
GUIUtil : : setFont ( { ui - > labelBalanceText ,
ui - > labelPendingText ,
ui - > labelImmatureText ,
ui - > labelWatchonly ,
ui - > labelSpendable
2020-06-16 13:52:46 +02:00
} , GUIUtil : : FontWeight : : Bold ) ;
2020-06-04 03:18:29 +02:00
2020-09-29 01:15:20 +02:00
GUIUtil : : updateFonts ( ) ;
2018-03-31 12:41:33 +02:00
m_balances . balance = - 1 ;
2011-08-03 20:52:18 +02:00
// Recent transactions
ui - > listTransactions - > setItemDelegate ( txdelegate ) ;
2021-03-17 23:36:11 +01:00
// Note: minimum height of listTransactions will be set later in updateAdvancedCJUI() 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
2018-08-21 10:54:43 +02:00
connect ( ui - > listTransactions , & QListView : : clicked , this , & OverviewPage : : handleTransactionClicked ) ;
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 " ) + " ) " ) ;
2021-03-17 23:36:11 +01:00
ui - > labelCoinJoinSyncStatus - > setText ( " ( " + tr ( " out of sync " ) + " ) " ) ;
2016-06-06 21:52:24 +02:00
ui - > labelTransactionsStatus - > setText ( " ( " + tr ( " out of sync " ) + " ) " ) ;
2012-05-15 16:57:59 +02:00
2021-07-11 11:28:50 +02:00
QString strCoinJoinName = QString : : fromStdString ( gCoinJoinName ) ;
ui - > labelCoinJoinHeader - > setText ( strCoinJoinName ) ;
ui - > labelAnonymizedText - > setText ( tr ( " %1 Balance " ) . arg ( strCoinJoinName ) ) ;
2021-03-24 11:13:25 +01:00
2016-06-08 20:33:00 +02:00
// hide PS frame (helps to preserve saved size)
2021-03-17 23:36:11 +01:00
// we'll setup and make it visible in coinJoinStatus() later
ui - > frameCoinJoin - > setVisible ( false ) ;
2016-06-08 20:33:00 +02:00
// start with displaying the "out of sync" warnings
showOutOfSyncWarning ( true ) ;
2020-09-28 09:41:19 +02:00
timer = new QTimer ( this ) ;
2021-08-17 17:55:26 +02:00
connect ( timer , & QTimer : : timeout , [ this ] { coinJoinStatus ( ) ; } ) ;
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 ( )
{
delete ui ;
}
2020-10-01 16:05:57 +02:00
void OverviewPage : : setBalance ( const interfaces : : WalletBalances & balances )
2011-07-05 22:09:39 +02:00
{
2018-03-31 12:41:33 +02:00
int unit = walletModel - > getOptionsModel ( ) - > getDisplayUnit ( ) ;
m_balances = balances ;
ui - > labelBalance - > setText ( BitcoinUnits : : floorHtmlWithUnit ( unit , balances . balance , false , BitcoinUnits : : separatorAlways ) ) ;
ui - > labelUnconfirmed - > setText ( BitcoinUnits : : floorHtmlWithUnit ( unit , balances . unconfirmed_balance , false , BitcoinUnits : : separatorAlways ) ) ;
ui - > labelImmature - > setText ( BitcoinUnits : : floorHtmlWithUnit ( unit , balances . immature_balance , false , BitcoinUnits : : separatorAlways ) ) ;
ui - > labelAnonymized - > setText ( BitcoinUnits : : floorHtmlWithUnit ( unit , balances . anonymized_balance , false , BitcoinUnits : : separatorAlways ) ) ;
ui - > labelTotal - > setText ( BitcoinUnits : : floorHtmlWithUnit ( unit , balances . balance + balances . unconfirmed_balance + balances . immature_balance , false , BitcoinUnits : : separatorAlways ) ) ;
ui - > labelWatchAvailable - > setText ( BitcoinUnits : : floorHtmlWithUnit ( unit , balances . watch_only_balance , false , BitcoinUnits : : separatorAlways ) ) ;
ui - > labelWatchPending - > setText ( BitcoinUnits : : floorHtmlWithUnit ( unit , balances . unconfirmed_watch_only_balance , false , BitcoinUnits : : separatorAlways ) ) ;
ui - > labelWatchImmature - > setText ( BitcoinUnits : : floorHtmlWithUnit ( unit , balances . immature_watch_only_balance , false , BitcoinUnits : : separatorAlways ) ) ;
ui - > labelWatchTotal - > setText ( BitcoinUnits : : floorHtmlWithUnit ( unit , balances . watch_only_balance + balances . unconfirmed_watch_only_balance + balances . immature_watch_only_balance , false , BitcoinUnits : : separatorAlways ) ) ;
// only show immature (newly mined) balance if it's non-zero, so as not to complicate things
2012-02-14 12:08:00 +01:00
// for the non-mining users
2020-07-14 22:16:38 +02:00
bool fDebugUI = gArgs . GetBoolArg ( " -debug-ui " , false ) ;
2018-03-31 12:41:33 +02:00
bool showImmature = fDebugUI | | balances . immature_balance ! = 0 ;
bool showWatchOnlyImmature = fDebugUI | | balances . immature_watch_only_balance ! = 0 ;
2014-03-29 05:15:28 +01:00
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
2021-03-17 23:36:11 +01:00
updateCoinJoinProgress ( ) ;
2015-06-30 03:07:32 +02:00
2019-04-25 17:37:39 +02:00
if ( walletModel ) {
int numISLocks = walletModel - > getNumISLocks ( ) ;
if ( cachedNumISLocks ! = numISLocks ) {
cachedNumISLocks = numISLocks ;
ui - > listTransactions - > update ( ) ;
}
2015-02-02 16:04:09 +01:00
}
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
2018-08-21 10:54:43 +02:00
connect ( model , & ClientModel : : alertsChanged , this , & OverviewPage : : updateAlerts ) ;
2012-10-24 21:47:07 +02:00
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
2020-10-01 16:05:57 +02:00
interfaces : : Wallet & wallet = model - > wallet ( ) ;
interfaces : : WalletBalances balances = wallet . getBalances ( ) ;
2018-03-31 12:41:33 +02:00
setBalance ( balances ) ;
2018-08-21 10:54:43 +02:00
connect ( model , & WalletModel : : balanceChanged , this , & OverviewPage : : setBalance ) ;
2011-07-11 20:42:10 +02:00
2018-08-21 10:54:43 +02:00
connect ( model - > getOptionsModel ( ) , & OptionsModel : : displayUnitChanged , this , & OverviewPage : : updateDisplayUnit ) ;
2017-04-18 00:56:44 +02:00
updateWatchOnlyLabels ( wallet . haveWatchOnly ( ) | | gArgs . GetBoolArg ( " -debug-ui " , false ) ) ;
2018-08-21 10:54:43 +02:00
connect ( model , & WalletModel : : notifyWatchonlyChanged , this , & OverviewPage : : updateWatchOnlyLabels ) ;
2018-03-29 17:08:00 +02:00
// explicitly update PS frame and transaction list to reflect actual settings
2021-03-17 23:36:11 +01:00
updateAdvancedCJUI ( model - > getOptionsModel ( ) - > getShowAdvancedCJUI ( ) ) ;
2018-03-29 17:08:00 +02:00
2021-08-17 17:55:26 +02:00
connect ( model - > getOptionsModel ( ) , & OptionsModel : : coinJoinRoundsChanged , this , & OverviewPage : : updateCoinJoinProgress ) ;
connect ( model - > getOptionsModel ( ) , & OptionsModel : : coinJoinAmountChanged , this , & OverviewPage : : updateCoinJoinProgress ) ;
connect ( model - > getOptionsModel ( ) , & OptionsModel : : AdvancedCJUIChanged , this , & OverviewPage : : updateAdvancedCJUI ) ;
2021-03-17 23:36:11 +01:00
connect ( model - > getOptionsModel ( ) , & OptionsModel : : coinJoinEnabledChanged , [ = ] ( ) {
coinJoinStatus ( true ) ;
2020-09-28 09:41:19 +02:00
} ) ;
2016-06-06 21:52:24 +02:00
2021-03-17 23:36:11 +01:00
// Disable coinJoinClient builtin support for automatic backups while we are in GUI,
// we'll handle automatic backups and user warnings in coinJoinStatus()
walletModel - > coinJoin ( ) . disableAutobackups ( ) ;
2020-08-28 11:52:00 +02:00
2021-08-17 17:55:26 +02:00
connect ( ui - > toggleCoinJoin , & QPushButton : : clicked , this , & OverviewPage : : toggleCoinJoin ) ;
2018-07-07 23:18:29 +02:00
2021-03-17 23:36:11 +01:00
// coinjoin buttons will not react to spacebar must be clicked on
ui - > toggleCoinJoin - > setFocusPolicy ( Qt : : NoFocus ) ;
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 ( ) ;
2018-03-31 12:41:33 +02:00
if ( m_balances . balance ! = - 1 ) {
setBalance ( m_balances ) ;
}
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 ) ;
2021-03-17 23:36:11 +01:00
ui - > labelCoinJoinSyncStatus - > setVisible ( fShow ) ;
2012-05-15 16:57:59 +02:00
ui - > labelTransactionsStatus - > setVisible ( fShow ) ;
}
2014-12-23 03:28:52 +01:00
2021-03-17 23:36:11 +01:00
void OverviewPage : : updateCoinJoinProgress ( )
2015-01-28 08:35:17 +01:00
{
2021-03-19 16:02:25 +01:00
if ( ! walletModel | | ! clientModel | | clientModel - > node ( ) . shutdownRequested ( ) | | ! clientModel - > masternodeSync ( ) . isBlockchainSynced ( ) ) return ;
2015-01-14 15:28:35 +01:00
2015-06-30 03:07:32 +02:00
QString strAmountAndRounds ;
2021-03-17 23:36:11 +01:00
QString strCoinJoinAmount = BitcoinUnits : : formatHtmlWithUnit ( nDisplayUnit , clientModel - > coinJoinOptions ( ) . getAmount ( ) * COIN , false , BitcoinUnits : : separatorAlways ) ;
2015-06-30 03:07:32 +02:00
2018-03-31 12:41:33 +02:00
if ( m_balances . balance = = 0 )
2015-01-28 08:35:17 +01:00
{
2021-03-17 23:36:11 +01:00
ui - > coinJoinProgress - > setValue ( 0 ) ;
ui - > coinJoinProgress - > setToolTip ( tr ( " No inputs detected " ) ) ;
2015-04-30 00:06:24 +02:00
// when balance is zero just show info from settings
2021-03-17 23:36:11 +01:00
strCoinJoinAmount = strCoinJoinAmount . remove ( strCoinJoinAmount . indexOf ( " . " ) , BitcoinUnits : : decimals ( nDisplayUnit ) + 1 ) ;
strAmountAndRounds = strCoinJoinAmount + " / " + tr ( " %n Rounds " , " " , clientModel - > coinJoinOptions ( ) . getRounds ( ) ) ;
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-04-18 00:56:44 +02:00
CAmount nAnonymizableBalance = walletModel - > wallet ( ) . getAnonymizableBalance ( false , false ) ;
2015-08-07 06:08:37 +02:00
2018-03-31 12:41:33 +02:00
CAmount nMaxToAnonymize = nAnonymizableBalance + m_balances . anonymized_balance ;
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.
2021-03-17 23:36:11 +01:00
if ( nMaxToAnonymize > clientModel - > coinJoinOptions ( ) . getAmount ( ) * COIN ) nMaxToAnonymize = clientModel - > coinJoinOptions ( ) . getAmount ( ) * COIN ;
2014-12-26 21:00:56 +01:00
2015-01-28 08:35:17 +01:00
if ( nMaxToAnonymize = = 0 ) return ;
2021-03-17 23:36:11 +01:00
if ( nMaxToAnonymize > = clientModel - > coinJoinOptions ( ) . getAmount ( ) * COIN ) {
2020-05-02 17:50:03 +02:00
ui - > labelAmountRounds - > setToolTip ( tr ( " Found enough compatible inputs to mix %1 " )
2021-03-17 23:36:11 +01:00
. arg ( strCoinJoinAmount ) ) ;
strCoinJoinAmount = strCoinJoinAmount . remove ( strCoinJoinAmount . indexOf ( " . " ) , BitcoinUnits : : decimals ( nDisplayUnit ) + 1 ) ;
strAmountAndRounds = strCoinJoinAmount + " / " + tr ( " %n Rounds " , " " , clientModel - > coinJoinOptions ( ) . getRounds ( ) ) ;
2015-06-30 03:07:32 +02:00
} else {
QString strMaxToAnonymize = BitcoinUnits : : formatHtmlWithUnit ( nDisplayUnit , nMaxToAnonymize , false , BitcoinUnits : : separatorAlways ) ;
2020-07-14 15:11:07 +02:00
ui - > labelAmountRounds - > setToolTip ( tr ( " Not enough compatible inputs to mix <span style='%1'>%2</span>,<br> "
" will mix <span style='%1'>%3</span> instead " )
. arg ( GUIUtil : : getThemedStyleQString ( GUIUtil : : ThemedStyle : : TS_ERROR ) )
2021-03-17 23:36:11 +01:00
. arg ( strCoinJoinAmount )
2015-06-30 03:07:32 +02:00
. arg ( strMaxToAnonymize ) ) ;
strMaxToAnonymize = strMaxToAnonymize . remove ( strMaxToAnonymize . indexOf ( " . " ) , BitcoinUnits : : decimals ( nDisplayUnit ) + 1 ) ;
2019-11-22 19:13:47 +01:00
strAmountAndRounds = " <span style=' " + GUIUtil : : getThemedStyleQString ( GUIUtil : : ThemedStyle : : TS_ERROR ) + " '> " +
2015-06-30 03:07:32 +02:00
QString ( BitcoinUnits : : factor ( nDisplayUnit ) = = 1 ? " " : " ~ " ) + strMaxToAnonymize +
2021-03-17 23:36:11 +01:00
" / " + tr ( " %n Rounds " , " " , clientModel - > coinJoinOptions ( ) . getRounds ( ) ) + " </span> " ;
2015-06-30 03:07:32 +02:00
}
ui - > labelAmountRounds - > setText ( strAmountAndRounds ) ;
2021-03-17 23:36:11 +01:00
if ( ! fShowAdvancedCJUI ) return ;
2017-09-27 19:43:28 +02:00
CAmount nDenominatedConfirmedBalance ;
CAmount nDenominatedUnconfirmedBalance ;
CAmount nNormalizedAnonymizedBalance ;
float nAverageAnonymizedRounds ;
2017-04-18 00:56:44 +02:00
nDenominatedConfirmedBalance = walletModel - > wallet ( ) . getDenominatedBalance ( false ) ;
nDenominatedUnconfirmedBalance = walletModel - > wallet ( ) . getDenominatedBalance ( true ) ;
nNormalizedAnonymizedBalance = walletModel - > wallet ( ) . getNormalizedAnonymizedBalance ( ) ;
nAverageAnonymizedRounds = walletModel - > wallet ( ) . getAverageAnonymizedRounds ( ) ;
2017-09-27 19:43:28 +02:00
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
2018-03-31 12:41:33 +02:00
anonFullPart = ( float ) m_balances . anonymized_balance / 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 ;
2021-03-17 23:36:11 +01:00
float anonNormWeight = clientModel - > coinJoinOptions ( ) . getRounds ( ) ;
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
2021-03-17 23:36:11 +01:00
ui - > coinJoinProgress - > 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/> " +
2020-01-04 12:20:43 +01:00
tr ( " Partially mixed " ) + " : %3%<br/> " +
tr ( " Mixed " ) + " : %4%<br/> " +
2021-03-17 23:36:11 +01:00
tr ( " Denominated inputs have %5 of %n rounds on average " , " " , clientModel - > coinJoinOptions ( ) . getRounds ( ) ) )
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 ) ;
2021-03-17 23:36:11 +01:00
ui - > coinJoinProgress - > setToolTip ( strToolPip ) ;
2014-12-23 03:28:52 +01:00
}
2021-03-17 23:36:11 +01:00
void OverviewPage : : updateAdvancedCJUI ( bool fShowAdvancedCJUI )
2020-08-28 11:52:00 +02:00
{
2021-05-07 18:41:32 +02:00
if ( ! walletModel | | ! clientModel ) return ;
2020-08-28 11:52:00 +02:00
2021-03-17 23:36:11 +01:00
this - > fShowAdvancedCJUI = fShowAdvancedCJUI ;
coinJoinStatus ( true ) ;
2016-06-06 21:52:24 +02:00
}
2014-12-23 03:28:52 +01:00
2021-03-17 23:36:11 +01:00
void OverviewPage : : coinJoinStatus ( bool fForce )
2014-12-23 03:28:52 +01:00
{
2020-08-28 11:52:00 +02:00
if ( ! walletModel | | ! clientModel ) return ;
2016-02-20 20:03:19 +01:00
2021-03-19 16:02:25 +01:00
if ( ! fForce & & ( clientModel - > node ( ) . shutdownRequested ( ) | | ! clientModel - > masternodeSync ( ) . isBlockchainSynced ( ) ) ) return ;
2020-03-19 23:48:24 +01:00
2020-09-28 09:41:19 +02:00
// Disable any PS UI for masternode or when autobackup is disabled or failed for whatever reason
if ( fMasternodeMode | | nWalletBackups < = 0 ) {
2021-03-17 23:36:11 +01:00
DisableCoinJoinCompletely ( ) ;
2020-09-28 09:41:19 +02:00
if ( nWalletBackups < = 0 ) {
2021-03-17 23:36:11 +01:00
ui - > labelCoinJoinEnabled - > setToolTip ( tr ( " Automatic backups are disabled, no mixing available! " ) ) ;
2020-09-28 09:41:19 +02:00
}
return ;
}
2021-03-17 23:36:11 +01:00
bool fIsEnabled = clientModel - > coinJoinOptions ( ) . isEnabled ( ) ;
ui - > frameCoinJoin - > setVisible ( fIsEnabled ) ;
2020-09-25 18:04:53 +02:00
if ( ! fIsEnabled ) {
SetupTransactionList ( NUM_ITEMS_DISABLED ) ;
2020-09-28 09:41:19 +02:00
if ( timer ! = nullptr ) {
timer - > stop ( ) ;
}
2020-09-25 18:04:53 +02:00
return ;
}
2020-09-28 09:41:19 +02:00
if ( timer ! = nullptr & & ! timer - > isActive ( ) ) {
timer - > start ( 1000 ) ;
}
2021-03-17 23:36:11 +01:00
// Wrap all coinjoin related widgets we want to show/hide state based.
2020-09-25 18:04:53 +02:00
// Value of the map contains a flag if this widget belongs to the advanced
2021-03-17 23:36:11 +01:00
// CoinJoin UI option or not. True if it does, false if not.
std : : map < QWidget * , bool > coinJoinWidgets = {
2020-09-25 18:04:53 +02:00
{ ui - > labelCompletitionText , true } ,
2021-03-17 23:36:11 +01:00
{ ui - > coinJoinProgress , true } ,
2020-09-25 18:04:53 +02:00
{ ui - > labelSubmittedDenomText , true } ,
{ ui - > labelSubmittedDenom , true } ,
{ ui - > labelAmountAndRoundsText , false } ,
{ ui - > labelAmountRounds , false }
} ;
2020-07-20 17:01:11 +02:00
auto setWidgetsVisible = [ & ] ( bool fVisible ) {
2020-09-25 18:04:53 +02:00
static bool fInitial { true } ;
static bool fLastVisible { false } ;
static bool fLastShowAdvanced { false } ;
// Only update the widget's visibility if something changed since the last call of setWidgetsVisible
2021-03-17 23:36:11 +01:00
if ( fLastShowAdvanced = = fShowAdvancedCJUI & & fLastVisible = = fVisible ) {
2020-09-25 18:04:53 +02:00
if ( fInitial ) {
fInitial = false ;
} else {
return ;
}
2020-07-20 17:01:11 +02:00
}
2020-09-25 18:04:53 +02:00
// Set visible if: fVisible and not advanced UI element or advanced ui element and advanced ui active
2021-03-17 23:36:11 +01:00
for ( const auto & it : coinJoinWidgets ) {
it . first - > setVisible ( fVisible & & ( ! it . second | | it . second = = fShowAdvancedCJUI ) ) ;
2020-09-25 18:04:53 +02:00
}
fLastVisible = fVisible ;
2021-03-17 23:36:11 +01:00
fLastShowAdvanced = fShowAdvancedCJUI ;
2020-07-20 17:01:11 +02:00
} ;
2015-07-26 01:24:19 +02:00
static int64_t nLastDSProgressBlockTime = 0 ;
2017-04-17 21:37:36 +02:00
int nBestHeight = clientModel - > node ( ) . getNumBlocks ( ) ;
2014-12-23 03:28:52 +01:00
2020-03-19 23:48:24 +01:00
// We are processing more than 1 block per second, we'll just leave
2021-03-17 23:36:11 +01:00
if ( nBestHeight > walletModel - > coinJoin ( ) . getCachedBlocks ( ) & & GetTime ( ) - nLastDSProgressBlockTime < = 1 ) return ;
2020-03-19 23:48:24 +01:00
nLastDSProgressBlockTime = GetTime ( ) ;
2014-12-23 03:28:52 +01:00
2020-03-19 23:48:24 +01:00
QString strKeysLeftText ( tr ( " keys left: %1 " ) . arg ( walletModel - > getKeysLeftSinceAutoBackup ( ) ) ) ;
2021-03-17 23:36:11 +01:00
if ( walletModel - > getKeysLeftSinceAutoBackup ( ) < COINJOIN_KEYS_THRESHOLD_WARNING ) {
2019-11-22 19:13:47 +01:00
strKeysLeftText = " <span style=' " + GUIUtil : : getThemedStyleQString ( GUIUtil : : ThemedStyle : : TS_ERROR ) + " '> " + strKeysLeftText + " </span> " ;
2016-06-15 21:13:04 +02:00
}
2021-03-17 23:36:11 +01:00
ui - > labelCoinJoinEnabled - > setToolTip ( strKeysLeftText ) ;
2016-06-15 21:13:04 +02:00
2021-07-11 11:28:50 +02:00
QString strCoinJoinName = QString : : fromStdString ( gCoinJoinName ) ;
2021-03-17 23:36:11 +01:00
if ( ! walletModel - > coinJoin ( ) . isMixing ( ) ) {
if ( nBestHeight ! = walletModel - > coinJoin ( ) . getCachedBlocks ( ) ) {
walletModel - > coinJoin ( ) . setCachedBlocks ( nBestHeight ) ;
updateCoinJoinProgress ( ) ;
2016-08-19 13:47:37 +02:00
}
2020-07-20 17:01:11 +02:00
setWidgetsVisible ( false ) ;
2021-07-11 11:28:50 +02:00
ui - > toggleCoinJoin - > setText ( tr ( " Start %1 " ) . arg ( strCoinJoinName ) ) ;
2016-08-19 13:47:37 +02:00
QString strEnabled = tr ( " Disabled " ) ;
// Show how many keys left in advanced PS UI mode only
2021-03-17 23:36:11 +01:00
if ( fShowAdvancedCJUI ) strEnabled + = " , " + strKeysLeftText ;
ui - > labelCoinJoinEnabled - > setText ( strEnabled ) ;
2016-08-19 13:47:37 +02:00
2020-09-25 18:04:53 +02:00
// If mixing isn't active always show the lower number of txes because there are
// anyway the most PS widgets hidden.
SetupTransactionList ( NUM_ITEMS_ENABLED_NORMAL ) ;
2016-08-19 13:47:37 +02:00
return ;
2020-09-25 18:04:53 +02:00
} else {
2021-03-17 23:36:11 +01:00
SetupTransactionList ( fShowAdvancedCJUI ? NUM_ITEMS_ENABLED_ADVANCED : NUM_ITEMS_ENABLED_NORMAL ) ;
2016-08-19 13:47:37 +02:00
}
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
2021-03-17 23:36:11 +01:00
if ( nWalletBackups > 0 & & walletModel - > getKeysLeftSinceAutoBackup ( ) < COINJOIN_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 "
2020-07-14 15:11:07 +02:00
" <span style='%1'> you should always make sure you have backups "
" saved in some safe place</span>! " ) . arg ( GUIUtil : : getThemedStyleQString ( GUIUtil : : ThemedStyle : : TS_COMMAND ) ) + " <br><br> " +
2018-06-18 18:07:09 +02:00
tr ( " Note: You can turn this message off in options. " ) ;
2021-03-17 23:36:11 +01:00
ui - > labelCoinJoinEnabled - > setToolTip ( strWarn ) ;
LogPrint ( BCLog : : COINJOIN , " OverviewPage::coinJoinStatus -- Very low number of keys left since last automatic backup, warning user and trying to create new backup... \n " ) ;
2021-07-11 11:28:50 +02:00
QMessageBox : : warning ( this , strCoinJoinName , strWarn , QMessageBox : : Ok , QMessageBox : : Ok ) ;
2016-09-05 18:09:25 +02:00
} else {
2021-03-17 23:36:11 +01:00
LogPrint ( BCLog : : COINJOIN , " OverviewPage::coinJoinStatus -- 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
2020-03-19 23:48:24 +01:00
QString strBackupWarning ;
QString strBackupError ;
if ( ! walletModel - > autoBackupWallet ( strBackupWarning , strBackupError ) ) {
if ( ! strBackupWarning . isEmpty ( ) ) {
2016-06-15 21:13:04 +02:00
// It's still more or less safe to continue but warn user anyway
2021-03-17 23:36:11 +01:00
LogPrint ( BCLog : : COINJOIN , " OverviewPage::coinJoinStatus -- WARNING! Something went wrong on automatic backup: %s \n " , strBackupWarning . toStdString ( ) ) ;
2016-06-15 21:13:04 +02:00
2021-07-11 11:28:50 +02:00
QMessageBox : : warning ( this , strCoinJoinName ,
2020-03-19 23:48:24 +01:00
tr ( " WARNING! Something went wrong on automatic backup " ) + " :<br><br> " + strBackupWarning ,
2016-06-15 21:13:04 +02:00
QMessageBox : : Ok , QMessageBox : : Ok ) ;
}
2020-03-19 23:48:24 +01:00
if ( ! strBackupError . isEmpty ( ) ) {
2016-06-15 21:13:04 +02:00
// Things are really broken, warn user and stop mixing immediately
2021-03-17 23:36:11 +01:00
LogPrint ( BCLog : : COINJOIN , " OverviewPage::coinJoinStatus -- ERROR! Failed to create automatic backup: %s \n " , strBackupError . toStdString ( ) ) ;
2016-06-15 21:13:04 +02:00
2021-07-11 11:28:50 +02:00
QMessageBox : : warning ( this , strCoinJoinName ,
2020-03-19 23:48:24 +01:00
tr ( " ERROR! Failed to create automatic backup " ) + " :<br><br> " + strBackupError + " <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 ) ;
}
}
}
2021-03-17 23:36:11 +01:00
QString strEnabled = walletModel - > coinJoin ( ) . isMixing ( ) ? tr ( " Enabled " ) : tr ( " Disabled " ) ;
2016-06-15 21:13:04 +02:00
// Show how many keys left in advanced PS UI mode only
2021-03-17 23:36:11 +01:00
if ( fShowAdvancedCJUI ) strEnabled + = " , " + strKeysLeftText ;
ui - > labelCoinJoinEnabled - > setText ( strEnabled ) ;
2016-06-15 21:13:04 +02:00
if ( nWalletBackups = = - 1 ) {
// Automatic backup failed, nothing else we can do until user fixes the issue manually
2021-03-17 23:36:11 +01:00
DisableCoinJoinCompletely ( ) ;
2016-06-15 21:13:04 +02:00
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! " ) ;
2021-03-17 23:36:11 +01:00
ui - > labelCoinJoinEnabled - > setToolTip ( strError ) ;
2016-06-15 21:13:04 +02:00
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. " ) ;
2021-03-17 23:36:11 +01:00
ui - > labelCoinJoinEnabled - > setToolTip ( strWarning ) ;
2016-06-15 21:13:04 +02:00
}
2021-03-17 23:36:11 +01:00
// check coinjoin status and unlock if needed
if ( nBestHeight ! = walletModel - > coinJoin ( ) . getCachedBlocks ( ) ) {
2014-12-23 03:28:52 +01:00
// Balance and number of transactions might have changed
2021-03-17 23:36:11 +01:00
walletModel - > coinJoin ( ) . setCachedBlocks ( nBestHeight ) ;
updateCoinJoinProgress ( ) ;
2014-12-23 03:28:52 +01:00
}
2020-07-20 17:01:11 +02:00
setWidgetsVisible ( true ) ;
2014-12-23 03:28:52 +01:00
2021-03-17 23:36:11 +01:00
ui - > labelSubmittedDenom - > setText ( QString ( walletModel - > coinJoin ( ) . getSessionDenoms ( ) . c_str ( ) ) ) ;
2014-12-23 03:28:52 +01:00
}
2021-03-17 23:36:11 +01:00
void OverviewPage : : toggleCoinJoin ( ) {
2015-07-04 15:29:21 +02:00
QSettings settings ;
// Popup some information on first mixing
QString hasMixed = settings . value ( " hasMixed " ) . toString ( ) ;
2021-07-11 11:28:50 +02:00
QString strCoinJoinName = QString : : fromStdString ( gCoinJoinName ) ;
2015-07-04 15:29:21 +02:00
if ( hasMixed . isEmpty ( ) ) {
2021-07-11 11:28:50 +02:00
QMessageBox : : information ( this , strCoinJoinName ,
tr ( " If you don't want to see internal %1 fees/transactions select \" Most Common \" as Type on the \" Transactions \" tab. " ) . arg ( strCoinJoinName ) ,
2015-07-04 15:29:21 +02:00
QMessageBox : : Ok , QMessageBox : : Ok ) ;
settings . setValue ( " hasMixed " , " hasMixed " ) ;
}
2020-07-16 14:23:58 +02:00
2021-03-17 23:36:11 +01:00
if ( ! walletModel - > coinJoin ( ) . isMixing ( ) ) {
auto & options = walletModel - > node ( ) . coinJoinOptions ( ) ;
2020-08-28 11:52:00 +02:00
const CAmount nMinAmount = options . getSmallestDenomination ( ) + options . getMaxCollateralAmount ( ) ;
2018-03-31 12:41:33 +02:00
if ( m_balances . balance < nMinAmount ) {
2017-02-02 09:50:21 +01:00
QString strMinAmount ( BitcoinUnits : : formatWithUnit ( nDisplayUnit , nMinAmount ) ) ;
2021-07-11 11:28:50 +02:00
QMessageBox : : warning ( this , strCoinJoinName ,
tr ( " %1 requires at least %2 to use. " ) . arg ( strCoinJoinName ) . 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
2020-03-19 23:48:24 +01:00
if ( walletModel & & walletModel - > getEncryptionStatus ( ) = = WalletModel : : Locked )
2015-01-21 07:29:09 +01:00
{
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
2021-03-17 23:36:11 +01:00
walletModel - > coinJoin ( ) . resetCachedBlocks ( ) ;
2021-07-11 11:28:50 +02:00
QMessageBox : : warning ( this , strCoinJoinName ,
tr ( " Wallet is locked and user declined to unlock. Disabling %1. " ) . arg ( strCoinJoinName ) ,
2015-01-21 07:29:09 +01:00
QMessageBox : : Ok , QMessageBox : : Ok ) ;
2021-03-17 23:36:11 +01:00
LogPrint ( BCLog : : COINJOIN , " OverviewPage::toggleCoinJoin -- Wallet is locked and user declined to unlock. Disabling CoinJoin. \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
}
2021-03-17 23:36:11 +01:00
walletModel - > coinJoin ( ) . resetCachedBlocks ( ) ;
2014-12-23 03:28:52 +01:00
2021-03-17 23:36:11 +01:00
if ( walletModel - > coinJoin ( ) . isMixing ( ) ) {
2021-07-11 11:28:50 +02:00
ui - > toggleCoinJoin - > setText ( tr ( " Start %1 " ) . arg ( strCoinJoinName ) ) ;
2021-03-17 23:36:11 +01:00
walletModel - > coinJoin ( ) . resetPool ( ) ;
walletModel - > coinJoin ( ) . stopMixing ( ) ;
2014-12-23 03:28:52 +01:00
} else {
2021-07-11 11:28:50 +02:00
ui - > toggleCoinJoin - > setText ( tr ( " Stop %1 " ) . arg ( strCoinJoinName ) ) ;
2021-03-17 23:36:11 +01:00
walletModel - > coinJoin ( ) . startMixing ( ) ;
2014-12-23 03:28:52 +01:00
}
}
2016-06-08 20:33:00 +02:00
2020-09-25 18:04:53 +02:00
void OverviewPage : : SetupTransactionList ( int nNumItems )
{
if ( walletModel = = nullptr | | walletModel - > getTransactionTableModel ( ) = = nullptr ) {
return ;
}
2016-06-08 20:33:00 +02:00
2020-09-25 18:04:53 +02:00
// Set up transaction list
if ( filter = = nullptr ) {
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 - > setDynamicSortFilter ( true ) ;
filter - > setSortRole ( Qt : : EditRole ) ;
filter - > setShowInactive ( false ) ;
2017-12-22 06:03:27 +01:00
filter - > sort ( TransactionTableModel : : Date , Qt : : DescendingOrder ) ;
2017-09-11 15:38:14 +02:00
ui - > listTransactions - > setModel ( filter . get ( ) ) ;
2016-06-08 20:33:00 +02:00
}
2020-09-25 18:04:53 +02:00
if ( filter - > rowCount ( ) = = nNumItems ) {
return ;
}
filter - > setLimit ( nNumItems ) ;
2020-09-29 01:16:03 +02:00
ui - > listTransactions - > setMinimumHeight ( nNumItems * ITEM_HEIGHT ) ;
2016-06-08 20:33:00 +02:00
}
2016-06-15 21:13:04 +02:00
2021-03-17 23:36:11 +01:00
void OverviewPage : : DisableCoinJoinCompletely ( )
2020-08-28 11:52:00 +02:00
{
if ( walletModel = = nullptr ) {
return ;
}
2021-03-17 23:36:11 +01:00
ui - > toggleCoinJoin - > setText ( " ( " + tr ( " Disabled " ) + " ) " ) ;
ui - > frameCoinJoin - > setEnabled ( false ) ;
2016-06-15 21:13:04 +02:00
if ( nWalletBackups < = 0 ) {
2021-03-17 23:36:11 +01:00
ui - > labelCoinJoinEnabled - > setText ( " <span style=' " + GUIUtil : : getThemedStyleQString ( GUIUtil : : ThemedStyle : : TS_ERROR ) + " '>( " + tr ( " Disabled " ) + " )</span> " ) ;
2016-06-15 21:13:04 +02:00
}
2021-03-17 23:36:11 +01:00
walletModel - > coinJoin ( ) . stopMixing ( ) ;
2017-02-09 06:29:00 +01:00
}