Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

(WIP) Add Pre-Register GUI #528

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
49 changes: 49 additions & 0 deletions src/qt/buynamespage.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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<QString> &value, const std::optional<QString> &transferTo) const
{
const std::string strName = name.toStdString();
Expand Down
2 changes: 2 additions & 0 deletions src/qt/buynamespage.h
Original file line number Diff line number Diff line change
Expand Up @@ -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<QString> &value, const std::optional<QString> &transferTo) const;

private Q_SLOTS:
bool eventFilter(QObject *object, QEvent *event);

void onNameEdited(const QString &name);
void onPreRegisterNameAction();
void onRegisterNameAction();
};

Expand Down
100 changes: 73 additions & 27 deletions src/qt/forms/buynamespage.ui
Original file line number Diff line number Diff line change
Expand Up @@ -97,33 +97,79 @@
</widget>
</item>
<item>
<widget class="QPushButton" name="registerNameButton">
<property name="sizePolicy">
<sizepolicy hsizetype="Fixed" vsizetype="Fixed">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="minimumSize">
<size>
<width>150</width>
<height>0</height>
</size>
</property>
<property name="toolTip">
<string>Register the name. You must have already pre-registered it.</string>
</property>
<property name="text">
<string>&amp;Register Name&#8230;</string>
</property>
<property name="icon">
<iconset resource="../bitcoin.qrc">
<normaloff>:/icons/send</normaloff>:/icons/send</iconset>
</property>
<property name="default">
<bool>true</bool>
</property>
</widget>
<layout class="QHBoxLayout" name="availableHorizontalLayout">
<item>
<widget class="QPushButton" name="preRegisterNameButton">
<property name="sizePolicy">
<sizepolicy hsizetype="Fixed" vsizetype="Fixed">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="minimumSize">
<size>
<width>150</width>
<height>0</height>
</size>
</property>
<property name="toolTip">
<string>Pre-Register the name. You must do this before registering it.</string>
</property>
<property name="text">
<string>&amp;Pre-Register Name&#8230;</string>
</property>
<property name="icon">
<iconset resource="../bitcoin.qrc">
<normaloff>:/icons/send</normaloff>:/icons/send</iconset>
</property>
<property name="default">
<bool>false</bool>
</property>
</widget>
</item>
<item>
<widget class="QPushButton" name="registerNameButton">
<property name="sizePolicy">
<sizepolicy hsizetype="Fixed" vsizetype="Fixed">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="minimumSize">
<size>
<width>150</width>
<height>0</height>
</size>
</property>
<property name="toolTip">
<string>Register the name. You must have already pre-registered it.</string>
</property>
<property name="text">
<string>&amp;Register Name&#8230;</string>
</property>
<property name="icon">
<iconset resource="../bitcoin.qrc">
<normaloff>:/icons/send</normaloff>:/icons/send</iconset>
</property>
<property name="default">
<bool>true</bool>
</property>
</widget>
</item>
<item>
<spacer name="availableSpacer">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>20</width>
<height>40</height>
</size>
</property>
</spacer>
</item>
</layout>
</item>
<item>
<spacer name="verticalSpacer">
Expand Down