mirror of
https://github.com/feather-wallet/feather.git
synced 2025-01-09 12:29:44 +00:00
Wizard: detect local node
This commit is contained in:
parent
2d1c8d722a
commit
deb0087019
5 changed files with 104 additions and 8 deletions
|
@ -10,12 +10,13 @@
|
||||||
#include <QtWidgets/QStyle>
|
#include <QtWidgets/QStyle>
|
||||||
#include <QPushButton>
|
#include <QPushButton>
|
||||||
|
|
||||||
|
#include "constants.h"
|
||||||
|
#include "networktype.h"
|
||||||
#include "utils.h"
|
#include "utils.h"
|
||||||
|
#include "utils/ColorScheme.h"
|
||||||
#include "utils/config.h"
|
#include "utils/config.h"
|
||||||
#include "utils/os/tails.h"
|
#include "utils/os/tails.h"
|
||||||
#include "utils/os/whonix.h"
|
#include "utils/os/whonix.h"
|
||||||
#include "utils/ColorScheme.h"
|
|
||||||
#include "constants.h"
|
|
||||||
|
|
||||||
QByteArray Utils::fileGetContents(const QString &path)
|
QByteArray Utils::fileGetContents(const QString &path)
|
||||||
{
|
{
|
||||||
|
@ -507,3 +508,15 @@ QString Utils::defaultWalletDir() {
|
||||||
return QStandardPaths::writableLocation(QStandardPaths::DocumentsLocation) + "/Monero/wallets";
|
return QStandardPaths::writableLocation(QStandardPaths::DocumentsLocation) + "/Monero/wallets";
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
|
quint16 Utils::getDefaultRpcPort(NetworkType::Type type) {
|
||||||
|
switch (type) {
|
||||||
|
case NetworkType::Type::MAINNET:
|
||||||
|
return 18081;
|
||||||
|
case NetworkType::Type::TESTNET:
|
||||||
|
return 28081;
|
||||||
|
case NetworkType::Type::STAGENET:
|
||||||
|
return 38081;
|
||||||
|
}
|
||||||
|
return 18081;
|
||||||
|
}
|
|
@ -78,6 +78,7 @@ public:
|
||||||
static QTextCharFormat addressTextFormat(const SubaddressIndex &index, quint64 amount);
|
static QTextCharFormat addressTextFormat(const SubaddressIndex &index, quint64 amount);
|
||||||
static bool isTorsocks();
|
static bool isTorsocks();
|
||||||
static QString defaultWalletDir();
|
static QString defaultWalletDir();
|
||||||
|
static quint16 getDefaultRpcPort(NetworkType::Type type);
|
||||||
|
|
||||||
template<typename QEnum>
|
template<typename QEnum>
|
||||||
static QString QtEnumToString (const QEnum value)
|
static QString QtEnumToString (const QEnum value)
|
||||||
|
|
|
@ -3,27 +3,55 @@
|
||||||
|
|
||||||
#include "PageNetwork.h"
|
#include "PageNetwork.h"
|
||||||
#include "ui_PageNetwork.h"
|
#include "ui_PageNetwork.h"
|
||||||
#include "WalletWizard.h"
|
|
||||||
|
#include <QtConcurrent/QtConcurrent>
|
||||||
|
|
||||||
#include "constants.h"
|
#include "constants.h"
|
||||||
|
#include "utils.h"
|
||||||
|
#include "WalletWizard.h"
|
||||||
|
|
||||||
PageNetwork::PageNetwork(QWidget *parent)
|
PageNetwork::PageNetwork(QWidget *parent)
|
||||||
: QWizardPage(parent)
|
: QWizardPage(parent)
|
||||||
, ui(new Ui::PageNetwork)
|
, ui(new Ui::PageNetwork)
|
||||||
|
, m_portOpenWatcher(new QFutureWatcher<QPair<bool, QString>>(this))
|
||||||
{
|
{
|
||||||
ui->setupUi(this);
|
ui->setupUi(this);
|
||||||
this->setTitle("Welcome to Feather");
|
this->setTitle("Welcome to Feather");
|
||||||
|
|
||||||
|
ui->frame_nodeDetected->hide();
|
||||||
ui->frame_customNode->hide();
|
ui->frame_customNode->hide();
|
||||||
|
|
||||||
ui->btnGroup_network->setId(ui->radio_autoConnect, 0);
|
ui->btnGroup_network->setId(ui->radio_autoConnect, Button::AUTO);
|
||||||
ui->btnGroup_network->setId(ui->radio_custom, 1);
|
ui->btnGroup_network->setId(ui->radio_custom, Button::CUSTOM);
|
||||||
|
|
||||||
|
QPixmap infoIcon = QPixmap(":/assets/images/info2.svg");
|
||||||
|
ui->infoIcon->setPixmap(infoIcon.scaledToWidth(32, Qt::SmoothTransformation));
|
||||||
|
|
||||||
connect(ui->btnGroup_network, &QButtonGroup::idClicked, [this](int id) {
|
connect(ui->btnGroup_network, &QButtonGroup::idClicked, [this](int id) {
|
||||||
ui->frame_customNode->setVisible(id == 1);
|
ui->frame_customNode->setVisible(id == Button::CUSTOM);
|
||||||
});
|
});
|
||||||
connect(ui->line_customNode, &QLineEdit::textEdited, [this]{
|
connect(ui->line_customNode, &QLineEdit::textEdited, [this]{
|
||||||
this->completeChanged();
|
this->completeChanged();
|
||||||
});
|
});
|
||||||
|
|
||||||
|
connect(m_portOpenWatcher, &QFutureWatcher<QPair<bool, QString>>::finished, [this](){
|
||||||
|
auto res = m_portOpenWatcher->result();
|
||||||
|
bool nodeFound = res.first;
|
||||||
|
if (nodeFound) {
|
||||||
|
ui->frame_nodeDetected->show();
|
||||||
|
ui->label_nodeDetected->setText(QString("Feather detected a local node on %1").arg(res.second));
|
||||||
|
|
||||||
|
ui->btnGroup_network->button(Button::CUSTOM)->click();
|
||||||
|
ui->line_customNode->setText(res.second);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
QFuture<QPair<bool, QString>> portOpen = QtConcurrent::run([]{
|
||||||
|
QString localhost = "127.0.0.1";
|
||||||
|
quint16 port = Utils::getDefaultRpcPort(constants::networkType);
|
||||||
|
return QPair<bool, QString>{Utils::portOpen(localhost, port), QString("%1:%2").arg(localhost, QString::number(port))};
|
||||||
|
});
|
||||||
|
m_portOpenWatcher->setFuture(portOpen);
|
||||||
}
|
}
|
||||||
|
|
||||||
int PageNetwork::nextId() const {
|
int PageNetwork::nextId() const {
|
||||||
|
@ -34,7 +62,7 @@ bool PageNetwork::validatePage() {
|
||||||
int id = ui->btnGroup_network->checkedId();
|
int id = ui->btnGroup_network->checkedId();
|
||||||
config()->set(Config::nodeSource, id);
|
config()->set(Config::nodeSource, id);
|
||||||
|
|
||||||
if (id == 1) {
|
if (id == Button::CUSTOM) {
|
||||||
NodeList nodeList;
|
NodeList nodeList;
|
||||||
nodeList.addNode(ui->line_customNode->text(), constants::networkType, NodeList::Type::custom);
|
nodeList.addNode(ui->line_customNode->text(), constants::networkType, NodeList::Type::custom);
|
||||||
}
|
}
|
||||||
|
@ -43,7 +71,7 @@ bool PageNetwork::validatePage() {
|
||||||
}
|
}
|
||||||
|
|
||||||
bool PageNetwork::isComplete() const {
|
bool PageNetwork::isComplete() const {
|
||||||
if (ui->btnGroup_network->checkedId() == 0) {
|
if (ui->btnGroup_network->checkedId() == Button::AUTO) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -26,7 +26,13 @@ public:
|
||||||
bool isComplete() const override;
|
bool isComplete() const override;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
enum Button {
|
||||||
|
AUTO=0,
|
||||||
|
CUSTOM
|
||||||
|
};
|
||||||
|
|
||||||
Ui::PageNetwork *ui;
|
Ui::PageNetwork *ui;
|
||||||
|
QFutureWatcher<QPair<bool, QString>> *m_portOpenWatcher;
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif //FEATHER_WIZARDNETWORK_H
|
#endif //FEATHER_WIZARDNETWORK_H
|
||||||
|
|
|
@ -70,6 +70,54 @@
|
||||||
</item>
|
</item>
|
||||||
</layout>
|
</layout>
|
||||||
</item>
|
</item>
|
||||||
|
<item>
|
||||||
|
<widget class="QFrame" name="frame_nodeDetected">
|
||||||
|
<property name="frameShape">
|
||||||
|
<enum>QFrame::StyledPanel</enum>
|
||||||
|
</property>
|
||||||
|
<property name="frameShadow">
|
||||||
|
<enum>QFrame::Raised</enum>
|
||||||
|
</property>
|
||||||
|
<layout class="QHBoxLayout" name="horizontalLayout">
|
||||||
|
<item>
|
||||||
|
<widget class="QLabel" name="infoIcon">
|
||||||
|
<property name="sizePolicy">
|
||||||
|
<sizepolicy hsizetype="Maximum" vsizetype="Preferred">
|
||||||
|
<horstretch>0</horstretch>
|
||||||
|
<verstretch>0</verstretch>
|
||||||
|
</sizepolicy>
|
||||||
|
</property>
|
||||||
|
<property name="text">
|
||||||
|
<string>icon</string>
|
||||||
|
</property>
|
||||||
|
</widget>
|
||||||
|
</item>
|
||||||
|
<item>
|
||||||
|
<spacer name="horizontalSpacer">
|
||||||
|
<property name="orientation">
|
||||||
|
<enum>Qt::Horizontal</enum>
|
||||||
|
</property>
|
||||||
|
<property name="sizeType">
|
||||||
|
<enum>QSizePolicy::Fixed</enum>
|
||||||
|
</property>
|
||||||
|
<property name="sizeHint" stdset="0">
|
||||||
|
<size>
|
||||||
|
<width>5</width>
|
||||||
|
<height>0</height>
|
||||||
|
</size>
|
||||||
|
</property>
|
||||||
|
</spacer>
|
||||||
|
</item>
|
||||||
|
<item>
|
||||||
|
<widget class="QLabel" name="label_nodeDetected">
|
||||||
|
<property name="text">
|
||||||
|
<string>Feather detected a local node on port 18081.</string>
|
||||||
|
</property>
|
||||||
|
</widget>
|
||||||
|
</item>
|
||||||
|
</layout>
|
||||||
|
</widget>
|
||||||
|
</item>
|
||||||
<item>
|
<item>
|
||||||
<layout class="QVBoxLayout" name="verticalLayout_2">
|
<layout class="QVBoxLayout" name="verticalLayout_2">
|
||||||
<item>
|
<item>
|
||||||
|
|
Loading…
Reference in a new issue