From 9db7b9c953a0bd7ac15221c6c3f329d5a0440f2e Mon Sep 17 00:00:00 2001 From: Jeremy Rand Date: Thu, 5 Jan 2023 12:33:10 +0000 Subject: [PATCH] (WIP) Namecoin / Qt: Add Pre-Register GUI TODO: Handle name encoding properly. --- src/qt/buynamespage.cpp | 49 +++++++++++++++++ src/qt/buynamespage.h | 2 + src/qt/forms/buynamespage.ui | 100 +++++++++++++++++++++++++---------- 3 files changed, 124 insertions(+), 27 deletions(-) diff --git a/src/qt/buynamespage.cpp b/src/qt/buynamespage.cpp index d24627beb5..0297c68e44 100644 --- a/src/qt/buynamespage.cpp +++ b/src/qt/buynamespage.cpp @@ -23,9 +23,11 @@ BuyNamesPage::BuyNamesPage(const PlatformStyle *platformStyle, QWidget *parent) { ui->setupUi(this); + ui->preRegisterNameButton->hide(); ui->registerNameButton->hide(); connect(ui->registerName, &QLineEdit::textEdited, this, &BuyNamesPage::onNameEdited); + connect(ui->preRegisterNameButton, &QPushButton::clicked, this, &BuyNamesPage::onPreRegisterNameAction); connect(ui->registerNameButton, &QPushButton::clicked, this, &BuyNamesPage::onRegisterNameAction); ui->registerName->installEventFilter(this); @@ -63,15 +65,40 @@ void BuyNamesPage::onNameEdited(const QString &name) if (availableError == "") { ui->statusLabel->setText(tr("%1 is available to register!").arg(name)); + ui->preRegisterNameButton->show(); ui->registerNameButton->show(); } else { ui->statusLabel->setText(availableError); + ui->preRegisterNameButton->hide(); ui->registerNameButton->hide(); } } +void BuyNamesPage::onPreRegisterNameAction() +{ + if (!walletModel) + return; + + QString name = ui->registerName->text(); + + WalletModel::UnlockContext ctx(walletModel->requestUnlock()); + if (!ctx.isValid()) + return; + + const QString err_msg = this->name_new(name); + if (!err_msg.isEmpty() && err_msg != "ABORTED") + { + QMessageBox::critical(this, tr("Name pre-registration error"), err_msg); + return; + } + + // reset UI text + ui->registerName->setText("d/"); + ui->registerNameButton->setDefault(true); +} + void BuyNamesPage::onRegisterNameAction() { if (!walletModel) @@ -139,6 +166,28 @@ QString BuyNamesPage::name_available(const QString &name) const return tr("%1 is already registered, sorry!").arg(name); } +QString BuyNamesPage::name_new(const QString &name) const +{ + const std::string strName = name.toStdString(); + LogPrint(BCLog::QT, "wallet attempting name_new: name=%s\n", strName); + + UniValue params(UniValue::VOBJ); + params.pushKV ("name", strName); + + const std::string walletURI = "/wallet/" + walletModel->getWalletName().toStdString(); + + try { + walletModel->node().executeRpc("name_new", params, walletURI); + } + catch (const UniValue& e) { + const UniValue message = find_value(e, "message"); + const std::string errorStr = message.get_str(); + LogPrint(BCLog::QT, "name_new error: %s\n", errorStr); + return QString::fromStdString(errorStr); + } + return tr (""); +} + QString BuyNamesPage::firstupdate(const QString &name, const std::optional &value, const std::optional &transferTo) const { const std::string strName = name.toStdString(); diff --git a/src/qt/buynamespage.h b/src/qt/buynamespage.h index 0418482134..10a654c5a9 100644 --- a/src/qt/buynamespage.h +++ b/src/qt/buynamespage.h @@ -31,12 +31,14 @@ class BuyNamesPage : public QWidget WalletModel *walletModel; QString name_available(const QString &name) const; + QString name_new(const QString &name) const; QString firstupdate(const QString &name, const std::optional &value, const std::optional &transferTo) const; private Q_SLOTS: bool eventFilter(QObject *object, QEvent *event); void onNameEdited(const QString &name); + void onPreRegisterNameAction(); void onRegisterNameAction(); }; diff --git a/src/qt/forms/buynamespage.ui b/src/qt/forms/buynamespage.ui index 82d6a82802..43633d9a8e 100644 --- a/src/qt/forms/buynamespage.ui +++ b/src/qt/forms/buynamespage.ui @@ -97,33 +97,79 @@ - - - - 0 - 0 - - - - - 150 - 0 - - - - Register the name. You must have already pre-registered it. - - - &Register Name… - - - - :/icons/send:/icons/send - - - true - - + + + + + + 0 + 0 + + + + + 150 + 0 + + + + Pre-Register the name. You must do this before registering it. + + + &Pre-Register Name… + + + + :/icons/send:/icons/send + + + false + + + + + + + + 0 + 0 + + + + + 150 + 0 + + + + Register the name. You must have already pre-registered it. + + + &Register Name… + + + + :/icons/send:/icons/send + + + true + + + + + + + Qt::Horizontal + + + + 20 + 40 + + + + +