forked from domob1812/namecoin-core
-
Notifications
You must be signed in to change notification settings - Fork 149
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Namecoin / Qt: Add name_firstupdate GUI
- Loading branch information
1 parent
7c055a2
commit f67a48f
Showing
10 changed files
with
349 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,115 @@ | ||
#include <qt/buynamespage.h> | ||
#include <qt/forms/ui_buynamespage.h> | ||
|
||
#include <interfaces/node.h> | ||
#include <qt/configurenamedialog.h> | ||
#include <qt/guiutil.h> | ||
#include <qt/platformstyle.h> | ||
#include <qt/walletmodel.h> | ||
|
||
#include <QMessageBox> | ||
#include <QMenu> | ||
|
||
#include <optional> | ||
|
||
BuyNamesPage::BuyNamesPage(const PlatformStyle *platformStyle, QWidget *parent) : | ||
QWidget(parent), | ||
platformStyle(platformStyle), | ||
ui(new Ui::BuyNamesPage), | ||
walletModel(nullptr) | ||
{ | ||
ui->setupUi(this); | ||
|
||
connect(ui->registerNameButton, &QPushButton::clicked, this, &BuyNamesPage::onRegisterNameAction); | ||
|
||
ui->registerName->installEventFilter(this); | ||
} | ||
|
||
BuyNamesPage::~BuyNamesPage() | ||
{ | ||
delete ui; | ||
} | ||
|
||
void BuyNamesPage::setModel(WalletModel *walletModel) | ||
{ | ||
this->walletModel = walletModel; | ||
} | ||
|
||
bool BuyNamesPage::eventFilter(QObject *object, QEvent *event) | ||
{ | ||
if (event->type() == QEvent::FocusIn) | ||
{ | ||
if (object == ui->registerName) | ||
{ | ||
ui->registerNameButton->setDefault(true); | ||
} | ||
} | ||
return QWidget::eventFilter(object, event); | ||
} | ||
|
||
void BuyNamesPage::onRegisterNameAction() | ||
{ | ||
if (!walletModel) | ||
return; | ||
|
||
QString name = ui->registerName->text(); | ||
|
||
WalletModel::UnlockContext ctx(walletModel->requestUnlock()); | ||
if (!ctx.isValid()) | ||
return; | ||
|
||
ConfigureNameDialog dlg(platformStyle, name, "", this); | ||
dlg.setModel(walletModel); | ||
|
||
if (dlg.exec() != QDialog::Accepted) | ||
return; | ||
|
||
const QString &newValue = dlg.getReturnData(); | ||
const std::optional<QString> transferToAddress = dlg.getTransferTo(); | ||
|
||
const QString err_msg = this->firstupdate(name, newValue, transferToAddress); | ||
if (!err_msg.isEmpty() && err_msg != "ABORTED") | ||
{ | ||
QMessageBox::critical(this, tr("Name registration error"), err_msg); | ||
return; | ||
} | ||
|
||
// reset UI text | ||
ui->registerName->setText("d/"); | ||
ui->registerNameButton->setDefault(true); | ||
} | ||
|
||
QString BuyNamesPage::firstupdate(const QString &name, const std::optional<QString> &value, const std::optional<QString> &transferTo) const | ||
{ | ||
std::string strName = name.toStdString(); | ||
LogPrintf ("wallet attempting name_firstupdate: name=%s\n", strName); | ||
|
||
UniValue params(UniValue::VOBJ); | ||
params.pushKV ("name", strName); | ||
|
||
if (value) | ||
{ | ||
params.pushKV ("value", value.value().toStdString()); | ||
} | ||
|
||
if (transferTo) | ||
{ | ||
UniValue options(UniValue::VOBJ); | ||
options.pushKV ("destAddress", transferTo.value().toStdString()); | ||
params.pushKV ("options", options); | ||
} | ||
|
||
std::string walletURI = "/wallet/" + walletModel->getWalletName().toStdString(); | ||
|
||
UniValue res; | ||
try { | ||
res = walletModel->node().executeRpc("name_firstupdate", params, walletURI); | ||
} | ||
catch (const UniValue& e) { | ||
UniValue message = find_value(e, "message"); | ||
std::string errorStr = message.get_str(); | ||
LogPrintf ("name_firstupdate error: %s\n", errorStr); | ||
return QString::fromStdString(errorStr); | ||
} | ||
return tr (""); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
#ifndef BUYNAMESPAGE_H | ||
#define BUYNAMESPAGE_H | ||
|
||
#include <qt/platformstyle.h> | ||
|
||
#include <QWidget> | ||
|
||
class WalletModel; | ||
|
||
namespace Ui { | ||
class BuyNamesPage; | ||
} | ||
|
||
QT_BEGIN_NAMESPACE | ||
QT_END_NAMESPACE | ||
|
||
/** Page for buying names */ | ||
class BuyNamesPage : public QWidget | ||
{ | ||
Q_OBJECT | ||
|
||
public: | ||
explicit BuyNamesPage(const PlatformStyle *platformStyle, QWidget *parent = nullptr); | ||
~BuyNamesPage(); | ||
|
||
void setModel(WalletModel *walletModel); | ||
|
||
private: | ||
const PlatformStyle *platformStyle; | ||
Ui::BuyNamesPage *ui; | ||
WalletModel *walletModel; | ||
|
||
QString firstupdate(const QString &name, const std::optional<QString> &value, const std::optional<QString> &transferTo) const; | ||
|
||
private Q_SLOTS: | ||
// TODO: clean up this list | ||
bool eventFilter(QObject *object, QEvent *event); | ||
|
||
void onRegisterNameAction(); | ||
}; | ||
|
||
#endif // BUYNAMESPAGE_H |
Oops, something went wrong.