Handle pending outgoing txns properly
This commit is contained in:
@@ -272,6 +272,34 @@ void Controller::processUnspent(const json& reply, QMap<QString, CAmount>* balan
|
||||
processFn(reply["pending_utxos"].get<json::array_t>());
|
||||
};
|
||||
|
||||
void Controller::updateUIBalances() {
|
||||
CAmount balT = getModel()->getBalT();
|
||||
CAmount balZ = getModel()->getBalZ();
|
||||
CAmount balVerified = getModel()->getBalVerified();
|
||||
|
||||
// Reduce the BalanceZ by the pending outgoing amount. We're adding
|
||||
// here because totalPending is already negative for outgoing txns.
|
||||
balZ = balZ + getModel()->getTotalPending();
|
||||
|
||||
CAmount balTotal = balT + balZ;
|
||||
CAmount balAvailable = balT + balVerified;
|
||||
|
||||
// Balances table
|
||||
ui->balSheilded ->setText(balZ.toDecimalZECString());
|
||||
ui->balVerified ->setText(balVerified.toDecimalZECString());
|
||||
ui->balTransparent->setText(balT.toDecimalZECString());
|
||||
ui->balTotal ->setText(balTotal.toDecimalZECString());
|
||||
|
||||
ui->balSheilded ->setToolTip(balZ.toDecimalUSDString());
|
||||
ui->balVerified ->setToolTip(balVerified.toDecimalUSDString());
|
||||
ui->balTransparent->setToolTip(balT.toDecimalUSDString());
|
||||
ui->balTotal ->setToolTip(balTotal.toDecimalUSDString());
|
||||
|
||||
// Send tab
|
||||
ui->txtAvailableZEC->setText(balAvailable.toDecimalZECString());
|
||||
ui->txtAvailableUSD->setText(balAvailable.toDecimalUSDString());
|
||||
}
|
||||
|
||||
void Controller::refreshBalances() {
|
||||
if (!zrpc->haveConnection())
|
||||
return noConnection();
|
||||
@@ -282,29 +310,18 @@ void Controller::refreshBalances() {
|
||||
CAmount balZ = CAmount::fromqint64(reply["zbalance"].get<json::number_unsigned_t>());
|
||||
CAmount balVerified = CAmount::fromqint64(reply["verified_zbalance"].get<json::number_unsigned_t>());
|
||||
|
||||
CAmount balTotal = balT + balZ;
|
||||
CAmount balAvailable = balT + balVerified;
|
||||
model->setBalT(balT);
|
||||
model->setBalZ(balZ);
|
||||
model->setBalVerified(balVerified);
|
||||
|
||||
// This is for the websockets
|
||||
AppDataModel::getInstance()->setBalances(balT, balZ);
|
||||
|
||||
// This is for the datamodel
|
||||
CAmount balAvailable = balT + balVerified;
|
||||
model->setAvailableBalance(balAvailable);
|
||||
|
||||
// Balances table
|
||||
ui->balSheilded ->setText(balZ.toDecimalZECString());
|
||||
ui->balVerified ->setText(balVerified.toDecimalZECString());
|
||||
ui->balTransparent->setText(balT.toDecimalZECString());
|
||||
ui->balTotal ->setText(balTotal.toDecimalZECString());
|
||||
|
||||
ui->balSheilded ->setToolTip(balZ.toDecimalUSDString());
|
||||
ui->balVerified ->setToolTip(balVerified.toDecimalUSDString());
|
||||
ui->balTransparent->setToolTip(balT.toDecimalUSDString());
|
||||
ui->balTotal ->setToolTip(balTotal.toDecimalUSDString());
|
||||
|
||||
// Send tab
|
||||
ui->txtAvailableZEC->setText(balAvailable.toDecimalZECString());
|
||||
ui->txtAvailableUSD->setText(balAvailable.toDecimalUSDString());
|
||||
updateUIBalances();
|
||||
});
|
||||
|
||||
// 2. Get the UTXOs
|
||||
@@ -409,6 +426,21 @@ void Controller::refreshTransactions() {
|
||||
|
||||
}
|
||||
|
||||
// Calculate the total unspent amount that's pending. This will need to be
|
||||
// shown in the UI so the user can keep track of pending funds
|
||||
CAmount totalPending;
|
||||
for (auto txitem : txdata) {
|
||||
if (txitem.confirmations == 0) {
|
||||
for (auto item: txitem.items) {
|
||||
totalPending = totalPending + item.amount;
|
||||
}
|
||||
}
|
||||
}
|
||||
getModel()->setTotalPending(totalPending);
|
||||
|
||||
// Update UI Balance
|
||||
updateUIBalances();
|
||||
|
||||
// Update model data, which updates the table view
|
||||
transactionsTableModel->replaceData(txdata);
|
||||
});
|
||||
|
||||
@@ -103,6 +103,7 @@ private:
|
||||
|
||||
void processUnspent (const json& reply, QMap<QString, CAmount>* newBalances, QList<UnspentOutput>* newUnspentOutputs);
|
||||
void updateUI (bool anyUnconfirmed);
|
||||
void updateUIBalances ();
|
||||
|
||||
void getInfoThenRefresh (bool force);
|
||||
|
||||
|
||||
@@ -24,6 +24,7 @@ DataModel::~DataModel() {
|
||||
}
|
||||
|
||||
void DataModel::setLatestBlock(int blockHeight) {
|
||||
QReadLocker locker(lock);
|
||||
this->latestBlock = blockHeight;
|
||||
}
|
||||
|
||||
|
||||
@@ -26,7 +26,7 @@ public:
|
||||
void markAddressUsed(QString address);
|
||||
|
||||
void setLatestBlock(int blockHeight);
|
||||
int getLatestBlock() { return this->latestBlock; }
|
||||
int getLatestBlock() { QReadLocker locker(lock); return this->latestBlock; }
|
||||
|
||||
void setEncryptionStatus(bool encrypted, bool locked) { this->isEncrypted = encrypted; this->isLocked = locked; }
|
||||
QPair<bool, bool> getEncryptionStatus() { return qMakePair(this->isEncrypted, this->isLocked); }
|
||||
@@ -37,8 +37,20 @@ public:
|
||||
const QMap<QString, CAmount> getAllBalances() { QReadLocker locker(lock); return *balances; }
|
||||
const QMap<QString, bool> getUsedAddresses() { QReadLocker locker(lock); return *usedAddresses; }
|
||||
|
||||
CAmount getAvailableBalance() { return availableBalance; }
|
||||
void setAvailableBalance(CAmount a) { this->availableBalance = a; }
|
||||
CAmount getAvailableBalance() { QReadLocker locker(lock); return availableBalance; }
|
||||
void setAvailableBalance(CAmount a) { QReadLocker locker(lock); this->availableBalance = a; }
|
||||
|
||||
CAmount getBalT() { QReadLocker locker(lock); return balT; }
|
||||
void setBalT(CAmount a) { QReadLocker locker(lock); this->balT = a; }
|
||||
|
||||
CAmount getBalZ() { QReadLocker locker(lock); return balZ; }
|
||||
void setBalZ(CAmount a) { QReadLocker locker(lock); this->balZ = a; }
|
||||
|
||||
CAmount getBalVerified() { QReadLocker locker(lock); return balVerified; }
|
||||
void setBalVerified(CAmount a) { QReadLocker locker(lock); this->balVerified = a; }
|
||||
|
||||
CAmount getTotalPending() { QReadLocker locker(lock); return totalPending; }
|
||||
void setTotalPending(CAmount a) { QReadLocker locker(lock); this->totalPending = a; }
|
||||
|
||||
DataModel();
|
||||
~DataModel();
|
||||
@@ -55,9 +67,13 @@ private:
|
||||
QList<QString>* taddresses = nullptr;
|
||||
|
||||
CAmount availableBalance;
|
||||
CAmount totalPending; // Outgoing pending is -ve
|
||||
|
||||
CAmount balT;
|
||||
CAmount balZ;
|
||||
CAmount balVerified;
|
||||
|
||||
QReadWriteLock* lock;
|
||||
|
||||
};
|
||||
|
||||
#endif // DATAMODEL_H
|
||||
Reference in New Issue
Block a user