Mercurial > hg > bitcoin
changeset 1173:2f76dc263dfe draft
Show unconfirmed balance on overview page
author | Wladimir J. van der Laan <laanwj@gmail.com> |
---|---|
date | Mon, 11 Jul 2011 20:42:10 +0200 |
parents | 5651e898d08f |
children | 599cda298163 |
files | README.rst src/qt/bitcoingui.cpp src/qt/bitcoingui.h src/qt/forms/overviewpage.ui src/qt/overviewpage.cpp src/qt/overviewpage.h src/qt/walletmodel.cpp src/qt/walletmodel.h src/wallet.cpp src/wallet.h |
diffstat | 10 files changed, 72 insertions(+), 28 deletions(-) [+] |
line wrap: on
line diff
--- a/README.rst +++ b/README.rst @@ -16,13 +16,15 @@ - Tabbed interface +- Overview page with current balance, unconfirmed balance, etc + +- User friendly transaction list with status icons, real-time filtering and a context menu that allows editing and copying labels + - Asks for confirmation before sending coins - CSV export of transactions and address book -- User friendly transaction list with status icons, real-time filtering and a context menu that allows editing and copying labels - -- Show alternative icon when on testnet +- Shows alternative icon when connected to testnet - Progress bar on initial block download
--- a/src/qt/bitcoingui.cpp +++ b/src/qt/bitcoingui.cpp @@ -217,19 +217,13 @@ { this->walletModel = walletModel; - // Keep up to date with wallet - setBalance(walletModel->getBalance()); - connect(walletModel, SIGNAL(balanceChanged(qint64)), this, SLOT(setBalance(qint64))); - - setNumTransactions(walletModel->getNumTransactions()); - connect(walletModel, SIGNAL(numTransactionsChanged(int)), this, SLOT(setNumTransactions(int))); - // Report errors from wallet thread connect(walletModel, SIGNAL(error(QString,QString)), this, SLOT(error(QString,QString))); // Put transaction list in tabs transactionView->setModel(walletModel); + overviewPage->setModel(walletModel); addressBookPage->setModel(walletModel->getAddressTableModel()); receiveCoinsPage->setModel(walletModel->getAddressTableModel()); sendCoinsPage->setModel(walletModel); @@ -280,11 +274,6 @@ dlg.exec(); } -void BitcoinGUI::setBalance(qint64 balance) -{ - overviewPage->setBalance(balance); -} - void BitcoinGUI::setNumConnections(int count) { QString icon; @@ -346,11 +335,6 @@ .arg(QLocale::system().toString(lastBlockDate))); } -void BitcoinGUI::setNumTransactions(int count) -{ - overviewPage->setNumTransactions(count); -} - void BitcoinGUI::error(const QString &title, const QString &message) { // Report errors from network/worker thread
--- a/src/qt/bitcoingui.h +++ b/src/qt/bitcoingui.h @@ -79,10 +79,8 @@ void createTrayIcon(); public slots: - void setBalance(qint64 balance); void setNumConnections(int count); void setNumBlocks(int count); - void setNumTransactions(int count); void error(const QString &title, const QString &message); /* It is currently not possible to pass a return value to another thread through BlockingQueuedConnection, so use an indirected pointer.
--- a/src/qt/forms/overviewpage.ui +++ b/src/qt/forms/overviewpage.ui @@ -46,20 +46,34 @@ </property> </widget> </item> - <item row="1" column="0"> + <item row="2" column="0"> <widget class="QLabel" name="label_2"> <property name="text"> <string>Number of transactions:</string> </property> </widget> </item> - <item row="1" column="1"> + <item row="2" column="1"> <widget class="QLabel" name="labelNumTransactions"> <property name="text"> <string>0</string> </property> </widget> </item> + <item row="1" column="0"> + <widget class="QLabel" name="label_3"> + <property name="text"> + <string>Unconfirmed:</string> + </property> + </widget> + </item> + <item row="1" column="1"> + <widget class="QLabel" name="labelUnconfirmed"> + <property name="text"> + <string>0 BTC</string> + </property> + </widget> + </item> </layout> </widget> </item>
--- a/src/qt/overviewpage.cpp +++ b/src/qt/overviewpage.cpp @@ -1,6 +1,7 @@ #include "overviewpage.h" #include "ui_overviewpage.h" +#include "walletmodel.h" #include "guiutil.h" OverviewPage::OverviewPage(QWidget *parent) : @@ -14,9 +15,14 @@ ui->labelBalance->setToolTip(tr("Your current balance")); ui->labelBalance->setTextInteractionFlags(Qt::TextSelectableByMouse|Qt::TextSelectableByKeyboard); + // Balance: <balance> + ui->labelUnconfirmed->setFont(QFont("Monospace", -1, QFont::Bold)); + ui->labelUnconfirmed->setToolTip(tr("Balance of transactions that have yet to be confirmed")); + ui->labelUnconfirmed->setTextInteractionFlags(Qt::TextSelectableByMouse|Qt::TextSelectableByKeyboard); + + ui->labelNumTransactions->setToolTip(tr("Total number of transactions in wallet")); + // Overview page should show: - // Balance - // Unconfirmed balance // Last received transaction(s) // Last sent transaction(s) } @@ -26,12 +32,26 @@ delete ui; } -void OverviewPage::setBalance(qint64 balance) +void OverviewPage::setBalance(qint64 balance, qint64 unconfirmedBalance) { ui->labelBalance->setText(GUIUtil::formatMoney(balance) + QString(" BTC")); + ui->labelUnconfirmed->setText(GUIUtil::formatMoney(unconfirmedBalance) + QString(" BTC")); } void OverviewPage::setNumTransactions(int count) { ui->labelNumTransactions->setText(QLocale::system().toString(count)); } + +void OverviewPage::setModel(WalletModel *model) +{ + this->model = model; + + // Keep up to date with wallet + setBalance(model->getBalance(), model->getUnconfirmedBalance()); + connect(model, SIGNAL(balanceChanged(qint64)), this, SLOT(setBalance(qint64))); + + setNumTransactions(model->getNumTransactions()); + connect(model, SIGNAL(numTransactionsChanged(int)), this, SLOT(setNumTransactions(int))); + +}
--- a/src/qt/overviewpage.h +++ b/src/qt/overviewpage.h @@ -6,6 +6,7 @@ namespace Ui { class OverviewPage; } +class WalletModel; class OverviewPage : public QWidget { @@ -15,12 +16,15 @@ explicit OverviewPage(QWidget *parent = 0); ~OverviewPage(); + void setModel(WalletModel *model); + public slots: - void setBalance(qint64 balance); + void setBalance(qint64 balance, qint64 unconfirmedBalance); void setNumTransactions(int count); private: Ui::OverviewPage *ui; + WalletModel *model; };
--- a/src/qt/walletmodel.cpp +++ b/src/qt/walletmodel.cpp @@ -28,6 +28,11 @@ return wallet->GetBalance(); } +qint64 WalletModel::getUnconfirmedBalance() const +{ + return wallet->GetUnconfirmedBalance(); +} + int WalletModel::getNumTransactions() const { int numTransactions = 0;
--- a/src/qt/walletmodel.h +++ b/src/qt/walletmodel.h @@ -31,6 +31,7 @@ TransactionTableModel *getTransactionTableModel(); qint64 getBalance() const; + qint64 getUnconfirmedBalance() const; int getNumTransactions() const; /* Send coins */
--- a/src/wallet.cpp +++ b/src/wallet.cpp @@ -570,6 +570,21 @@ return nTotal; } +int64 CWallet::GetUnconfirmedBalance() const +{ + int64 nTotal = 0; + CRITICAL_BLOCK(cs_mapWallet) + { + for (map<uint256, CWalletTx>::const_iterator it = mapWallet.begin(); it != mapWallet.end(); ++it) + { + const CWalletTx* pcoin = &(*it).second; + if (pcoin->IsFinal() && pcoin->IsConfirmed()) + continue; + nTotal += pcoin->GetAvailableCredit(); + } + } + return nTotal; +} bool CWallet::SelectCoinsMinConf(int64 nTargetValue, int nConfMine, int nConfTheirs, set<pair<const CWalletTx*,unsigned int> >& setCoinsRet, int64& nValueRet) const {
--- a/src/wallet.h +++ b/src/wallet.h @@ -57,6 +57,7 @@ void ReacceptWalletTransactions(); void ResendWalletTransactions(); int64 GetBalance() const; + int64 GetUnconfirmedBalance() const; bool CreateTransaction(const std::vector<std::pair<CScript, int64> >& vecSend, CWalletTx& wtxNew, CReserveKey& reservekey, int64& nFeeRet); bool CreateTransaction(CScript scriptPubKey, int64 nValue, CWalletTx& wtxNew, CReserveKey& reservekey, int64& nFeeRet); bool CommitTransaction(CWalletTx& wtxNew, CReserveKey& reservekey);