Show unconfirmed balance on overview page

This commit is contained in:
Wladimir J. van der Laan 2011-07-11 20:42:10 +02:00
parent eee0d2391c
commit df5ccbd2b2
10 changed files with 72 additions and 28 deletions

View file

@ -16,13 +16,15 @@ This has been implemented:
- 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

View file

@ -217,19 +217,13 @@ void BitcoinGUI::setWalletModel(WalletModel *walletModel)
{
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 @@ void BitcoinGUI::aboutClicked()
dlg.exec();
}
void BitcoinGUI::setBalance(qint64 balance)
{
overviewPage->setBalance(balance);
}
void BitcoinGUI::setNumConnections(int count)
{
QString icon;
@ -346,11 +335,6 @@ void BitcoinGUI::setNumBlocks(int count)
.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

View file

@ -79,10 +79,8 @@ private:
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.

View file

@ -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>

View file

@ -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 @@ OverviewPage::OverviewPage(QWidget *parent) :
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 @@ OverviewPage::~OverviewPage()
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)));
}

View file

@ -6,6 +6,7 @@
namespace Ui {
class OverviewPage;
}
class WalletModel;
class OverviewPage : public QWidget
{
@ -15,12 +16,15 @@ public:
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;
};

View file

@ -28,6 +28,11 @@ qint64 WalletModel::getBalance() const
return wallet->GetBalance();
}
qint64 WalletModel::getUnconfirmedBalance() const
{
return wallet->GetUnconfirmedBalance();
}
int WalletModel::getNumTransactions() const
{
int numTransactions = 0;

View file

@ -31,6 +31,7 @@ public:
TransactionTableModel *getTransactionTableModel();
qint64 getBalance() const;
qint64 getUnconfirmedBalance() const;
int getNumTransactions() const;
/* Send coins */

View file

@ -570,6 +570,21 @@ int64 CWallet::GetBalance() const
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
{

View file

@ -57,6 +57,7 @@ public:
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);