Browse Source

fix Balance render problems

pull/170/head
DenioD 4 years ago
parent
commit
3edf50f39f
  1. 1
      silentdragon-lite.pro
  2. 36
      src/controller.cpp
  3. 118
      src/mainwindow.cpp
  4. 8
      src/mainwindow.ui
  5. 168
      src/seedrestore.ui

1
silentdragon-lite.pro

@ -131,6 +131,7 @@ FORMS += \
src/newwallet.ui \ src/newwallet.ui \
src/recurringpayments.ui \ src/recurringpayments.ui \
src/restoreseed.ui \ src/restoreseed.ui \
src/seedrestore.ui \
src/sendHushTransactionChat.ui \ src/sendHushTransactionChat.ui \
src/settings.ui \ src/settings.ui \
src/about.ui \ src/about.ui \

36
src/controller.cpp

@ -638,7 +638,7 @@ void Controller::getInfoThenRefresh(bool force)
refreshAddresses(); // This calls refreshZSentTransactions() and refreshReceivedZTrans() refreshAddresses(); // This calls refreshZSentTransactions() and refreshReceivedZTrans()
refreshTransactions(); refreshTransactions();
} }
refreshBalances();
int lag = longestchain - notarized ; int lag = longestchain - notarized ;
this->setLag(lag); this->setLag(lag);
}, [=](QString err) { }, [=](QString err) {
@ -730,7 +730,7 @@ void Controller::processUnspent(const QJsonValue& reply, QMap<QString, CAmount>*
QString qsAddr = it["address"].toString(); QString qsAddr = it["address"].toString();
int block = it["created_in_block"].toInt(); int block = it["created_in_block"].toInt();
QString txid = it["created_in_txid"].toString(); QString txid = it["created_in_txid"].toString();
CAmount amount = CAmount::fromqint64(it["value"].toInt()); CAmount amount = CAmount::fromqint64(it["value"].toDouble());
bool spendable = it["unconfirmed_spent"].isNull() && it["spent"].isNull(); // TODO: Wait for 1 confirmations bool spendable = it["unconfirmed_spent"].isNull() && it["spent"].isNull(); // TODO: Wait for 1 confirmations
bool pending = !it["unconfirmed_spent"].isNull(); bool pending = !it["unconfirmed_spent"].isNull();
@ -741,7 +741,7 @@ void Controller::processUnspent(const QJsonValue& reply, QMap<QString, CAmount>*
if (spendable) if (spendable)
{ {
(*balancesMap)[qsAddr] = (*balancesMap)[qsAddr] + (*balancesMap)[qsAddr] = (*balancesMap)[qsAddr] +
CAmount::fromqint64(it["value"].toInt()); CAmount::fromqint64(it["value"].toDouble());
} }
} }
}; };
@ -906,9 +906,9 @@ void Controller::refreshBalances()
// 1. Get the Balances // 1. Get the Balances
zrpc->fetchBalance([=] (QJsonValue reply) { zrpc->fetchBalance([=] (QJsonValue reply) {
CAmount balT = CAmount::fromqint64(reply["tbalance"].toInt()); CAmount balT = CAmount::fromqint64(reply["tbalance"].toDouble());
CAmount balZ = CAmount::fromqint64(reply["zbalance"].toInt()); CAmount balZ = CAmount::fromqint64(reply["zbalance"].toDouble());
CAmount balVerified = CAmount::fromqint64(reply["verified_zbalance"].toInt()); CAmount balVerified = CAmount::fromqint64(reply["verified_zbalance"].toDouble());
model->setBalT(balT); model->setBalT(balT);
model->setBalZ(balZ); model->setBalZ(balZ);
@ -985,7 +985,7 @@ void Controller::refreshTransactions() {
address = o.toObject()["address"].toString(); address = o.toObject()["address"].toString();
// Sent items are -ve // Sent items are -ve
CAmount amount = CAmount::fromqint64(-1* o.toObject()["value"].toInt()); CAmount amount = CAmount::fromqint64(-1* o.toObject()["value"].toDouble());
// Check for Memos // Check for Memos
@ -1169,7 +1169,7 @@ void Controller::refreshTransactions() {
); );
DataStore::getChatDataStore()->setData(ChatIDGenerator::getInstance()->generateID(item), item); DataStore::getChatDataStore()->setData(ChatIDGenerator::getInstance()->generateID(item), item);
updateUIBalances(); // updateUIBalances();
} }
} }
@ -1194,18 +1194,18 @@ void Controller::refreshTransactions() {
} }
else else
{ {
// Incoming Transaction
{ // Incoming Transaction
address = (it.toObject()["address"].isNull() ? "" : it.toObject()["address"].toString()); address = (it.toObject()["address"].isNull() ? "" : it.toObject()["address"].toString());
model->markAddressUsed(address); model->markAddressUsed(address);
QString memo; QString memo;
if (!it.toObject()["memo"].isNull()) { if (!it.toObject()["memo"].isNull())
memo = it.toObject()["memo"].toString(); memo = it.toObject()["memo"].toString();
}
items.push_back(TransactionItemDetail{ items.push_back(TransactionItemDetail{
address, address,
CAmount::fromqint64(it.toObject()["amount"].toInt()), CAmount::fromqint64(it.toObject()["amount"].toDouble()),
memo memo
}); });
@ -1214,7 +1214,14 @@ void Controller::refreshTransactions() {
}; };
txdata.push_back(tx); txdata.push_back(tx);
}
address = (it.toObject()["address"].isNull() ? "" : it.toObject()["address"].toString());
model->markAddressUsed(address);
QString memo;
if (!it.toObject()["memo"].isNull())
memo = it.toObject()["memo"].toString();
QString type; QString type;
QString publickey; QString publickey;
QString headerbytes; QString headerbytes;
@ -1470,8 +1477,9 @@ void Controller::refreshTransactions() {
chat->renderChatBox(ui, ui->listChat,ui->memoSizeChat); chat->renderChatBox(ui, ui->listChat,ui->memoSizeChat);
ui->listChat->verticalScrollBar()->setValue( ui->listChat->verticalScrollBar()->setValue(
ui->listChat->verticalScrollBar()->maximum()); ui->listChat->verticalScrollBar()->maximum());
}); });
} }
void Controller::refreshChat(QListView *listWidget, QLabel *label) void Controller::refreshChat(QListView *listWidget, QLabel *label)

118
src/mainwindow.cpp

@ -26,6 +26,7 @@
#include "requestdialog.h" #include "requestdialog.h"
#include "ui_startupencryption.h" #include "ui_startupencryption.h"
#include "ui_removeencryption.h" #include "ui_removeencryption.h"
#include "ui_seedrestore.h"
#include "websockets.h" #include "websockets.h"
#include "sodium.h" #include "sodium.h"
#include "sodium/crypto_generichash_blake2b.h" #include "sodium/crypto_generichash_blake2b.h"
@ -162,17 +163,124 @@ MainWindow::MainWindow(QWidget *parent) :
// Rescan // Rescan
QObject::connect(ui->actionRescan, &QAction::triggered, [=]() { QObject::connect(ui->actionRescan, &QAction::triggered, [=]() {
// To rescan, we clear the wallet state, and then reload the connection
QFile file(dirwalletenc);
QFile file1(dirwallet);
if(fileExists(dirwalletenc))
{
file.remove();
file1.remove();
}
Ui_Restore restoreSeed;
QDialog dialog(this);
restoreSeed.setupUi(&dialog);
Settings::saveRestore(&dialog);
rpc->fetchSeed([&](QJsonValue reply) {
if (isJsonError(reply)) {
return;
}
restoreSeed.seed->setReadOnly(true);
restoreSeed.seed->setLineWrapMode(QPlainTextEdit::LineWrapMode::NoWrap);
QString seedJson = QLatin1String(QJsonDocument(reply.toObject()).toJson(QJsonDocument::Compact));
int startPos = seedJson.indexOf("seed") +7;
int endPos = seedJson.indexOf("}") -1;
int length = endPos - startPos;
QString seed = seedJson.mid(startPos, length);
restoreSeed.seed->setPlainText(seed);
int startPosB = seedJson.indexOf("birthday") +10;
int endPosB = seedJson.indexOf("seed") -2;
int lengthB = endPosB - startPosB;
QString birthday = seedJson.mid(startPosB, lengthB);
restoreSeed.birthday->setPlainText(birthday);
});
QObject::connect(restoreSeed.restore, &QPushButton::clicked, [&](){
QString seed = restoreSeed.seed->toPlainText();
if (seed.trimmed().split(" ").length() != 24) {
QMessageBox::warning(this, tr("Failed to restore wallet"),
tr("SilentDragonLite needs 24 words to restore wallet"),
QMessageBox::Ok);
return false;
}
// 2. Validate birthday
QString birthday_str = restoreSeed.birthday->toPlainText();
bool ok;
qint64 birthday = birthday_str.toUInt(&ok);
if (!ok) {
QMessageBox::warning(this, tr("Failed to parse wallet birthday"),
tr("Couldn't understand wallet birthday. This should be a block height from where to rescan the wallet. You can leave it as '0' if you don't know what it should be."),
QMessageBox::Ok);
return false;
}
QString number_str = restoreSeed.quantity->text();
qint64 number = number_str.toUInt();
auto config = std::shared_ptr<ConnectionConfig>(new ConnectionConfig());
config->server = Settings::getInstance()->getSettings().server;
// 3. Attempt to restore wallet with the seed phrase
{
char* resp = litelib_initialize_new_from_phrase(config->server.toStdString().c_str(),
seed.toStdString().c_str(), birthday, number);
QString reply = litelib_process_response(resp);
if (reply.toUpper().trimmed() != "OK") {
QMessageBox::warning(this, tr("Failed to restore wallet"),
tr("Couldn't restore the wallet") + "\n" + reply,
QMessageBox::Ok);
}
}
// 4. Finally attempt to save the wallet
{
char* resp = litelib_execute("save", "");
QString reply = litelib_process_response(resp);
QByteArray ba_reply = reply.toUtf8();
QJsonDocument jd_reply = QJsonDocument::fromJson(ba_reply);
QJsonObject parsed = jd_reply.object();
if (parsed.isEmpty() || parsed["result"].isNull()) {
QMessageBox::warning(this, tr("Failed to save wallet"),
tr("Couldn't save the wallet") + "\n" + reply,
QMessageBox::Ok);
} else {}
dialog.close();
// To rescan, we clear the wallet state, and then reload the connection
// This will start a sync, and show the scanning status. // This will start a sync, and show the scanning status.
this->getRPC()->clearWallet([=] (auto) { this->getRPC()->clearWallet([=] (auto) {
// Save the wallet // Save the wallet
this->getRPC()->saveWallet([=] (auto) { this->getRPC()->saveWallet([=] (auto) {
// Then reload the connection. The ConnectionLoader deletes itself. // Then reload the connection. The ConnectionLoader deletes itself.
auto cl = new ConnectionLoader(this, rpc); auto cl = new ConnectionLoader(this, rpc);
cl->loadConnection(); cl->loadConnection();
}); });
}); });
});
}
});
// });
dialog.exec();
});
// Address Book // Address Book
QObject::connect(ui->action_Address_Book, &QAction::triggered, this, &MainWindow::addressBook); QObject::connect(ui->action_Address_Book, &QAction::triggered, this, &MainWindow::addressBook);

8
src/mainwindow.ui

@ -6,7 +6,7 @@
<rect> <rect>
<x>0</x> <x>0</x>
<y>0</y> <y>0</y>
<width>1282</width> <width>1308</width>
<height>779</height> <height>779</height>
</rect> </rect>
</property> </property>
@ -59,7 +59,7 @@
<item row="0" column="0" colspan="2"> <item row="0" column="0" colspan="2">
<widget class="QTabWidget" name="tabWidget"> <widget class="QTabWidget" name="tabWidget">
<property name="currentIndex"> <property name="currentIndex">
<number>5</number> <number>0</number>
</property> </property>
<widget class="QWidget" name="tab"> <widget class="QWidget" name="tab">
<attribute name="title"> <attribute name="title">
@ -428,7 +428,7 @@
<rect> <rect>
<x>0</x> <x>0</x>
<y>0</y> <y>0</y>
<width>1234</width> <width>1260</width>
<height>509</height> <height>509</height>
</rect> </rect>
</property> </property>
@ -1834,7 +1834,7 @@
<rect> <rect>
<x>0</x> <x>0</x>
<y>0</y> <y>0</y>
<width>1282</width> <width>1308</width>
<height>22</height> <height>22</height>
</rect> </rect>
</property> </property>

168
src/seedrestore.ui

@ -1,72 +1,114 @@
<ui version="4.0" > <?xml version="1.0" encoding="UTF-8"?>
<author></author> <ui version="4.0">
<comment></comment> <class>Restore</class>
<exportmacro></exportmacro> <widget class="QDialog" name="Restore">
<class>Dialog</class> <property name="geometry">
<widget class="QDialog" name="Dialog" >
<property name="geometry" >
<rect> <rect>
<x>0</x> <x>0</x>
<y>0</y> <y>0</y>
<width>400</width> <width>637</width>
<height>300</height> <height>429</height>
</rect> </rect>
</property> </property>
<property name="windowTitle" > <property name="windowTitle">
<string>Dialog</string> <string>Restore your Wallet</string>
</property> </property>
<widget class="QDialogButtonBox" name="buttonBox" > <layout class="QGridLayout" name="gridLayout">
<property name="geometry" > <item row="0" column="0" colspan="3">
<rect> <widget class="QPlainTextEdit" name="seed">
<x>30</x> <property name="minimumSize">
<y>240</y> <size>
<width>341</width> <width>0</width>
<height>32</height> <height>284</height>
</rect> </size>
</property> </property>
<property name="orientation" > </widget>
<enum>Qt::Horizontal</enum> </item>
</property> <item row="1" column="0">
<property name="standardButtons" > <layout class="QVBoxLayout" name="verticalLayout">
<set>QDialogButtonBox::Cancel|QDialogButtonBox::Ok</set> <item>
</property> <widget class="QLabel" name="label">
</widget> <property name="text">
<string>Birthday :</string>
</property>
</widget>
</item>
<item>
<widget class="QLabel" name="label_2">
<property name="text">
<string>Quantity :</string>
</property>
</widget>
</item>
</layout>
</item>
<item row="1" column="1" colspan="2">
<layout class="QVBoxLayout" name="verticalLayout_2">
<item>
<widget class="QPlainTextEdit" name="birthday">
<property name="minimumSize">
<size>
<width>529</width>
<height>0</height>
</size>
</property>
<property name="maximumSize">
<size>
<width>16777215</width>
<height>25</height>
</size>
</property>
<property name="verticalScrollBarPolicy">
<enum>Qt::ScrollBarAlwaysOff</enum>
</property>
<property name="horizontalScrollBarPolicy">
<enum>Qt::ScrollBarAlwaysOff</enum>
</property>
</widget>
</item>
<item>
<widget class="QLineEdit" name="quantity">
<property name="minimumSize">
<size>
<width>529</width>
<height>0</height>
</size>
</property>
<property name="text">
<string/>
</property>
</widget>
</item>
</layout>
</item>
<item row="2" column="0" colspan="2">
<spacer name="horizontalSpacer">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>521</width>
<height>20</height>
</size>
</property>
</spacer>
</item>
<item row="2" column="2">
<widget class="QPushButton" name="restore">
<property name="maximumSize">
<size>
<width>89</width>
<height>16777215</height>
</size>
</property>
<property name="text">
<string>Restore</string>
</property>
</widget>
</item>
</layout>
</widget> </widget>
<pixmapfunction></pixmapfunction>
<resources/> <resources/>
<connections> <connections/>
<connection>
<sender>buttonBox</sender>
<signal>accepted()</signal>
<receiver>Dialog</receiver>
<slot>accept()</slot>
<hints>
<hint type="sourcelabel" >
<x>248</x>
<y>254</y>
</hint>
<hint type="destinationlabel" >
<x>157</x>
<y>274</y>
</hint>
</hints>
</connection>
<connection>
<sender>buttonBox</sender>
<signal>rejected()</signal>
<receiver>Dialog</receiver>
<slot>reject()</slot>
<hints>
<hint type="sourcelabel" >
<x>316</x>
<y>260</y>
</hint>
<hint type="destinationlabel" >
<x>286</x>
<y>274</y>
</hint>
</hints>
</connection>
</connections>
</ui> </ui>

Loading…
Cancel
Save