Add null checks
This commit is contained in:
@@ -39,7 +39,8 @@ MainWindow::MainWindow(QWidget *parent) :
|
|||||||
|
|
||||||
// Set up check for updates action
|
// Set up check for updates action
|
||||||
QObject::connect(ui->actionCheck_for_Updates, &QAction::triggered, [=] () {
|
QObject::connect(ui->actionCheck_for_Updates, &QAction::triggered, [=] () {
|
||||||
QDesktopServices::openUrl(QUrl("https://github.com/ZcashFoundation/zec-qt-wallet/releases"));
|
// Silent is false, so show notification even if no update was found
|
||||||
|
rpc->checkForUpdate(false);
|
||||||
});
|
});
|
||||||
|
|
||||||
// Pay zcash URI
|
// Pay zcash URI
|
||||||
@@ -659,21 +660,16 @@ void MainWindow::doImport(QList<QString>* keys) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void MainWindow::payZcashURIError(QString errorDetail) {
|
|
||||||
QMessageBox::critical(this, tr("Error paying zcash URI"),
|
|
||||||
tr("URI should be of the form 'zcash:<addr>?amt=x&memo=y") + "\n" + errorDetail);
|
|
||||||
}
|
|
||||||
|
|
||||||
void MainWindow::payZcashURI() {
|
void MainWindow::payZcashURI() {
|
||||||
|
// Error to display if something goes wrong.
|
||||||
|
auto payZcashURIError = [=] (QString errorDetail = "") {
|
||||||
|
QMessageBox::critical(this, tr("Error paying zcash URI"),
|
||||||
|
tr("URI should be of the form 'zcash:<addr>?amt=x&memo=y") + "\n" + errorDetail);
|
||||||
|
};
|
||||||
|
|
||||||
// Read a zcash URI and pay it
|
// Read a zcash URI and pay it
|
||||||
QInputDialog uriDialog(this);
|
QString uri = QInputDialog::getText(this, tr("Paste zcash URI"),
|
||||||
uriDialog.setInputMode(QInputDialog::TextInput);
|
"zcash://" + QString(" ").repeated(180));
|
||||||
uriDialog.setWindowTitle(tr("Paste zcash URI"));
|
|
||||||
uriDialog.setLabelText("zcash://" + QString(" ").repeated(180)); // Hack to adjust the width of the dialog
|
|
||||||
if (uriDialog.exec() != QDialog::Accepted) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
QString uri = uriDialog.textValue();
|
|
||||||
|
|
||||||
// URI should be of the form zcash://address?amt=x&memo=y
|
// URI should be of the form zcash://address?amt=x&memo=y
|
||||||
if (!uri.startsWith("zcash:")) {
|
if (!uri.startsWith("zcash:")) {
|
||||||
@@ -707,6 +703,11 @@ void MainWindow::payZcashURI() {
|
|||||||
QStringList args = uri.split("&");
|
QStringList args = uri.split("&");
|
||||||
for (QString arg: args) {
|
for (QString arg: args) {
|
||||||
QStringList kv = arg.split("=");
|
QStringList kv = arg.split("=");
|
||||||
|
if (kv.length() != 2) {
|
||||||
|
payZcashURIError();
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
if (kv[0].toLower() == "amt" || kv[0].toLower() == "amount") {
|
if (kv[0].toLower() == "amt" || kv[0].toLower() == "amount") {
|
||||||
amount = kv[1].toDouble();
|
amount = kv[1].toDouble();
|
||||||
} else if (kv[0].toLower() == "memo") {
|
} else if (kv[0].toLower() == "memo") {
|
||||||
|
|||||||
@@ -89,7 +89,6 @@ private:
|
|||||||
|
|
||||||
void donate();
|
void donate();
|
||||||
void addressBook();
|
void addressBook();
|
||||||
void payZcashURIError(QString errorDetail = "");
|
|
||||||
void payZcashURI();
|
void payZcashURI();
|
||||||
void postToZBoard();
|
void postToZBoard();
|
||||||
void importPrivKey();
|
void importPrivKey();
|
||||||
|
|||||||
@@ -1111,7 +1111,7 @@
|
|||||||
</action>
|
</action>
|
||||||
<action name="actionPay_URI">
|
<action name="actionPay_URI">
|
||||||
<property name="text">
|
<property name="text">
|
||||||
<string>Pay zcash URI...</string>
|
<string>Pay zcash &URI...</string>
|
||||||
</property>
|
</property>
|
||||||
</action>
|
</action>
|
||||||
</widget>
|
</widget>
|
||||||
|
|||||||
19
src/rpc.cpp
19
src/rpc.cpp
@@ -905,7 +905,7 @@ void RPC::watchTxStatus() {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
void RPC::checkForUpdate() {
|
void RPC::checkForUpdate(bool silent) {
|
||||||
if (conn == nullptr)
|
if (conn == nullptr)
|
||||||
return noConnection();
|
return noConnection();
|
||||||
|
|
||||||
@@ -926,13 +926,18 @@ void RPC::checkForUpdate() {
|
|||||||
QVersionNumber maxVersion(0, 0, 0);
|
QVersionNumber maxVersion(0, 0, 0);
|
||||||
|
|
||||||
for (QJsonValue rel : releases) {
|
for (QJsonValue rel : releases) {
|
||||||
|
if (!rel.toObject().contains("tag_name"))
|
||||||
|
continue;
|
||||||
|
|
||||||
QString tag = rel.toObject()["tag_name"].toString();
|
QString tag = rel.toObject()["tag_name"].toString();
|
||||||
if (tag.startsWith("v"))
|
if (tag.startsWith("v"))
|
||||||
tag = tag.right(tag.length() - 1);
|
tag = tag.right(tag.length() - 1);
|
||||||
|
|
||||||
auto v = QVersionNumber::fromString(tag);
|
if (!tag.isEmpty()) {
|
||||||
if (v > maxVersion)
|
auto v = QVersionNumber::fromString(tag);
|
||||||
maxVersion = v;
|
if (v > maxVersion)
|
||||||
|
maxVersion = v;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
auto currentVersion = QVersionNumber::fromString(APP_VERSION);
|
auto currentVersion = QVersionNumber::fromString(APP_VERSION);
|
||||||
@@ -946,6 +951,12 @@ void RPC::checkForUpdate() {
|
|||||||
if (ans == QMessageBox::Yes) {
|
if (ans == QMessageBox::Yes) {
|
||||||
QDesktopServices::openUrl(QUrl("https://github.com/ZcashFoundation/zec-qt-wallet/releases"));
|
QDesktopServices::openUrl(QUrl("https://github.com/ZcashFoundation/zec-qt-wallet/releases"));
|
||||||
}
|
}
|
||||||
|
} else {
|
||||||
|
if (!silent) {
|
||||||
|
QMessageBox::information(main, QObject::tr("No updates available"),
|
||||||
|
QObject::tr("You already have the latest release v%1")
|
||||||
|
.arg(currentVersion.toString()));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -38,7 +38,7 @@ public:
|
|||||||
|
|
||||||
void refreshAddresses();
|
void refreshAddresses();
|
||||||
|
|
||||||
void checkForUpdate();
|
void checkForUpdate(bool silent = true);
|
||||||
void refreshZECPrice();
|
void refreshZECPrice();
|
||||||
void getZboardTopics(std::function<void(QMap<QString, QString>)> cb);
|
void getZboardTopics(std::function<void(QMap<QString, QString>)> cb);
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user