Clean up rpc methods
This commit is contained in:
70
src/rpc.cpp
70
src/rpc.cpp
@@ -337,23 +337,29 @@ void RPC::refreshAddresses() {
|
||||
});
|
||||
}
|
||||
|
||||
void RPC::refreshBalances() {
|
||||
// 1. Get the Balances
|
||||
getBalance([=] (json reply) {
|
||||
ui->balSheilded ->setText(QString::fromStdString(reply["private"]) % " " % Utils::getTokenName());
|
||||
ui->balTransparent ->setText(QString::fromStdString(reply["transparent"]) % " " % Utils::getTokenName());
|
||||
ui->balTotal ->setText(QString::fromStdString(reply["total"]) % " " % Utils::getTokenName());
|
||||
});
|
||||
// Function to create the data model and update the views, used below.
|
||||
void RPC::updateUI(bool anyUnconfirmed) {
|
||||
ui->unconfirmedWarning->setVisible(anyUnconfirmed);
|
||||
|
||||
// 2. Get the UTXOs
|
||||
// First, create a new UTXO list, deleting the old one;
|
||||
delete utxos;
|
||||
utxos = new QList<UnspentOutput>();
|
||||
delete allBalances;
|
||||
allBalances = new QMap<QString, double>();
|
||||
// Update balances model data, which will update the table too
|
||||
balancesTableModel->setNewData(allBalances, utxos);
|
||||
|
||||
// Function to process reply of the listunspent and z_listunspent API calls, used below.
|
||||
auto processUnspent = [=] (const json& reply) -> bool {
|
||||
// Add all the addresses into the inputs combo box
|
||||
auto lastFromAddr = ui->inputsCombo->currentText().split("(")[0].trimmed();
|
||||
|
||||
ui->inputsCombo->clear();
|
||||
auto i = allBalances->constBegin();
|
||||
while (i != allBalances->constEnd()) {
|
||||
QString item = i.key() % "(" % QString::number(i.value(), 'g', 8) % " " % Utils::getTokenName() % ")";
|
||||
ui->inputsCombo->addItem(item);
|
||||
if (item.startsWith(lastFromAddr)) ui->inputsCombo->setCurrentText(item);
|
||||
|
||||
++i;
|
||||
}
|
||||
};
|
||||
|
||||
// Function to process reply of the listunspent and z_listunspent API calls, used below.
|
||||
bool RPC::processUnspent(const json& reply) {
|
||||
bool anyUnconfirmed = false;
|
||||
for (auto& it : reply.get<json::array_t>()) {
|
||||
QString qsAddr = QString::fromStdString(it["address"]);
|
||||
@@ -374,28 +380,22 @@ void RPC::refreshBalances() {
|
||||
(*allBalances)[qsAddr] = (*allBalances)[qsAddr] + it["amount"].get<json::number_float_t>();
|
||||
}
|
||||
return anyUnconfirmed;
|
||||
};
|
||||
};
|
||||
|
||||
// Function to create the data model and update the views, used below.
|
||||
auto updateUI = [=] (bool anyUnconfirmed) {
|
||||
ui->unconfirmedWarning->setVisible(anyUnconfirmed);
|
||||
void RPC::refreshBalances() {
|
||||
// 1. Get the Balances
|
||||
getBalance([=] (json reply) {
|
||||
ui->balSheilded ->setText(QString::fromStdString(reply["private"]) % " " % Utils::getTokenName());
|
||||
ui->balTransparent ->setText(QString::fromStdString(reply["transparent"]) % " " % Utils::getTokenName());
|
||||
ui->balTotal ->setText(QString::fromStdString(reply["total"]) % " " % Utils::getTokenName());
|
||||
});
|
||||
|
||||
// Update balances model data, which will update the table too
|
||||
balancesTableModel->setNewData(allBalances, utxos);
|
||||
|
||||
// Add all the addresses into the inputs combo box
|
||||
auto lastFromAddr = ui->inputsCombo->currentText().split("(")[0].trimmed();
|
||||
|
||||
ui->inputsCombo->clear();
|
||||
auto i = allBalances->constBegin();
|
||||
while (i != allBalances->constEnd()) {
|
||||
QString item = i.key() % "(" % QString::number(i.value(), 'g', 8) % " " % Utils::getTokenName() % ")";
|
||||
ui->inputsCombo->addItem(item);
|
||||
if (item.startsWith(lastFromAddr)) ui->inputsCombo->setCurrentText(item);
|
||||
|
||||
++i;
|
||||
}
|
||||
};
|
||||
// 2. Get the UTXOs
|
||||
// First, create a new UTXO list, deleting the old one;
|
||||
delete utxos;
|
||||
utxos = new QList<UnspentOutput>();
|
||||
delete allBalances;
|
||||
allBalances = new QMap<QString, double>();
|
||||
|
||||
// Call the Transparent and Z unspent APIs serially and then, once they're done, update the UI
|
||||
getTransparentUnspent([=] (json reply) {
|
||||
|
||||
Reference in New Issue
Block a user