Add estimated time countdown for locked balance

This commit is contained in:
Jaquee 2017-01-13 23:21:58 +01:00
parent 205bfcdd7b
commit ad5115ac3c
No known key found for this signature in database
GPG Key ID: 384E52B09F45DC39
5 changed files with 49 additions and 12 deletions

View File

@ -39,6 +39,7 @@ Rectangle {
property alias balanceText: balanceText.text
property alias networkStatus : networkStatus
property alias progressBar : progressBar
property alias minutesToUnlockTxt: unlockedBalanceLabel.text
signal dashboardClicked()
signal historyClicked()
@ -154,7 +155,8 @@ Rectangle {
}
Label {
text: qsTr("Unlocked balance") + translationManager.emptyString
id: unlockedBalanceLabel
text: qsTr("Unlocked balance")
anchors.left: parent.left
anchors.leftMargin: 50
tipText: qsTr("Test tip 2<br/><br/>line 2") + translationManager.emptyString

View File

@ -61,6 +61,10 @@ ApplicationWindow {
property int maxWindowHeight: (Screen.height < 900)? 720 : 800;
property bool daemonRunning: false
property alias toolTip: toolTip
property string walletName
property bool viewOnly: false
property bool foundNewBlock: false
property int timeToUnlock: 0
// true if wallet ever synchronized
property bool walletInitialized : false
@ -293,6 +297,15 @@ ApplicationWindow {
console.log(">>> wallet updated")
middlePanel.unlockedBalanceText = leftPanel.unlockedBalanceText = walletManager.displayAmount(currentWallet.unlockedBalance);
middlePanel.balanceText = leftPanel.balanceText = walletManager.displayAmount(currentWallet.balance);
console.log("time to unlock: ", currentWallet.history.minutesToUnlock);
// Update history if new block found since last update and balance is locked.
if(foundNewBlock && currentWallet.history.locked) {
foundNewBlock = false;
console.log("New block found - updating history")
currentWallet.history.refresh()
timeToUnlock = currentWallet.history.minutesToUnlock
leftPanel.minutesToUnlockTxt = (timeToUnlock > 0)? qsTr("Unlocked balance (~%1 min)").arg(timeToUnlock) : qsTr("Unlocked balance");
}
}
function onWalletRefresh() {
@ -337,13 +350,11 @@ ApplicationWindow {
}
}
// initialize transaction history once wallet is initializef first time;
if (!walletInitialized) {
currentWallet.history.refresh()
walletInitialized = true
}
}
onWalletUpdate();
}
@ -370,7 +381,6 @@ ApplicationWindow {
function onWalletNewBlock(blockHeight) {
// Update progress bar
var currHeight = blockHeight
//fast refresh until restoreHeight is reached
@ -380,10 +390,7 @@ ApplicationWindow {
splashCounter = currHeight
leftPanel.progressBar.updateProgress(currHeight,currentWallet.daemonBlockChainTargetHeight());
}
// Update num of confirmations on history page
// TODO: check performance on big wallets. Maybe no need to refresh full history?
currentWallet.history.refresh()
foundNewBlock = true;
}
function onWalletMoneyReceived(txId, amount) {
@ -394,6 +401,7 @@ ApplicationWindow {
function onWalletUnconfirmedMoneyReceived(txId, amount) {
// refresh history
console.log("unconfirmed money found")
currentWallet.history.refresh()
}

View File

@ -138,7 +138,7 @@ Rectangle {
if(currentWallet.addressBook.errorCode() === AddressBook.Invalid_Address)
informationPopup.text = qsTr("Invalid address")
else if(currentWallet.addressBook.errorCode() === AddressBook.Invalid_Payment_Id)
informationPopup.text = qsTr("Invalid Payment ID")
informationPopup.text = currentWallet.addressBook.errorString()
else
informationPopup.text = qsTr("Can't create entry")

View File

@ -31,7 +31,9 @@ QList<TransactionInfo *> TransactionHistory::getAll() const
QDateTime firstDateTime = QDateTime(QDate(2014, 4, 18)); // the genesis block
QDateTime lastDateTime = QDateTime::currentDateTime().addDays(1); // tomorrow (guard against jitter and timezones)
quint64 lastTxHeight = 0;
m_locked = false;
m_minutesToUnlock = 0;
TransactionHistory * parent = const_cast<TransactionHistory*>(this);
for (const auto i : m_pimpl->getAll()) {
TransactionInfo * ti = new TransactionInfo(i, parent);
@ -43,6 +45,14 @@ QList<TransactionInfo *> TransactionHistory::getAll() const
if (ti->timestamp() <= firstDateTime) {
firstDateTime = ti->timestamp();
}
// store last tx height
if (ti->confirmations() < 10 && ti->blockHeight() >= lastTxHeight ){
lastTxHeight = ti->blockHeight();
// TODO: Fetch block time and confirmations needed from wallet2?
m_minutesToUnlock = (10 - ti->confirmations()) * 2;
m_locked = true;
}
}
emit refreshFinished();
@ -81,9 +91,19 @@ QDateTime TransactionHistory::lastDateTime() const
return m_lastDateTime;
}
quint64 TransactionHistory::minutesToUnlock() const
{
return m_minutesToUnlock;
}
bool TransactionHistory::TransactionHistory::locked() const
{
return m_locked;
}
TransactionHistory::TransactionHistory(Monero::TransactionHistory *pimpl, QObject *parent)
: QObject(parent), m_pimpl(pimpl)
: QObject(parent), m_pimpl(pimpl), m_minutesToUnlock(0), m_locked(false)
{
m_firstDateTime = QDateTime(QDate(2014, 4, 18)); // the genesis block
m_lastDateTime = QDateTime::currentDateTime().addDays(1); // tomorrow (guard against jitter and timezones)

View File

@ -17,6 +17,8 @@ class TransactionHistory : public QObject
Q_PROPERTY(int count READ count)
Q_PROPERTY(QDateTime firstDateTime READ firstDateTime NOTIFY firstDateTimeChanged)
Q_PROPERTY(QDateTime lastDateTime READ lastDateTime NOTIFY lastDateTimeChanged)
Q_PROPERTY(int minutesToUnlock READ minutesToUnlock)
Q_PROPERTY(bool locked READ locked)
public:
Q_INVOKABLE TransactionInfo *transaction(int index);
@ -26,6 +28,8 @@ public:
quint64 count() const;
QDateTime firstDateTime() const;
QDateTime lastDateTime() const;
quint64 minutesToUnlock() const;
bool locked() const;
signals:
void refreshStarted() const;
@ -45,6 +49,9 @@ private:
mutable QList<TransactionInfo*> m_tinfo;
mutable QDateTime m_firstDateTime;
mutable QDateTime m_lastDateTime;
mutable int m_minutesToUnlock;
// history contains locked transfers
mutable bool m_locked;
};