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) Overhauled the Buy Names Page with the Electrum-NMC version #558

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
13 changes: 13 additions & 0 deletions src/names/applications.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -217,3 +217,16 @@ GetMinimalJSON (const std::string& text){

return v.write(0,0);
}

std::string
ConvertDomainForms (const std::string& domain){
if(domain.ends_with(".bit")){
return domain.substr(0, domain.size()-4);
} else if (domain.starts_with("0x")) {
std::string cutdomain = domain.substr(2, domain.size());
int hexval = std::stoi(cutdomain, 0, 16);
return std::to_string(hexval);
} else {
return domain;
}
}
2 changes: 2 additions & 0 deletions src/names/applications.h
Original file line number Diff line number Diff line change
Expand Up @@ -29,4 +29,6 @@ bool IsMinimalJSONOrEmptyString (const std::string& text);

std::string GetMinimalJSON (const std::string& text);

std::string ConvertDomainForms (const std::string& domain);

#endif // H_BITCOIN_NAMES_APPLICATIONS
141 changes: 133 additions & 8 deletions src/qt/buynamespage.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,18 @@
#include <qt/platformstyle.h>
#include <qt/walletmodel.h>
#include <rpc/protocol.h>
#include <names/applications.h>

#include <univalue.h>

#include <string>
#include <algorithm>

#include <QMessageBox>

//ascii -> old domain system
//domain -> domain from scratch (without .bit)
//hex -> hex
BuyNamesPage::BuyNamesPage(const PlatformStyle *platformStyle, QWidget *parent) :
QWidget(parent),
platformStyle(platformStyle),
Expand All @@ -22,11 +29,13 @@ BuyNamesPage::BuyNamesPage(const PlatformStyle *platformStyle, QWidget *parent)
ui->setupUi(this);

ui->registerNameButton->hide();

connect(ui->registerName, &QLineEdit::textEdited, this, &BuyNamesPage::onNameEdited);

connect(ui->registerNameDomain, &QLineEdit::textEdited, this, &BuyNamesPage::onDomainNameEdited);
connect(ui->registerNameAscii, &QLineEdit::textEdited, this, &BuyNamesPage::onAsciiNameEdited);
connect(ui->registerNameHex, &QLineEdit::textEdited, this, &BuyNamesPage::onHexNameEdited);
connect(ui->registerNameButton, &QPushButton::clicked, this, &BuyNamesPage::onRegisterNameAction);

ui->registerName->installEventFilter(this);
ui->registerNameDomain->installEventFilter(this);
}

BuyNamesPage::~BuyNamesPage()
Expand All @@ -43,23 +52,84 @@ bool BuyNamesPage::eventFilter(QObject *object, QEvent *event)
{
if (event->type() == QEvent::FocusIn)
{
if (object == ui->registerName)
if (object == ui->registerNameAscii)
{
ui->registerNameButton->setDefault(true);
}
}
return QWidget::eventFilter(object, event);
}

void BuyNamesPage::onNameEdited(const QString &name)
void BuyNamesPage::onAsciiNameEdited(const QString &name)
{
if (!walletModel)
return;

const QString availableError = name_available(name);
QString availableError = name_available(name);

if (availableError == "")
{
ui->statusLabel->setText(tr("%1 is available to register!").arg(name));
ui->registerNameButton->show();
}
else
{
ui->statusLabel->setText(availableError);
ui->registerNameButton->hide();
}
}

void BuyNamesPage::onHexNameEdited(const QString &name)
{

if (!walletModel)
return;

QString availableError;
//check if it's even a valid hexdomain
std::string hex = name.toStdString();
if(!std::all_of(hex.begin(), hex.end(), ::isxdigit))
{
ui->statusLabel->setText(tr("%1 is not a valid hexadecimal entry!").arg(name));
}
else
{
std::string domain = ConvertDomainForms("0x" + hex);
availableError = name_available(QString::fromStdString(domain));
}

if (availableError == "")
{
ui->statusLabel->setText(tr("%1 is available to register!").arg(name));
ui->registerNameButton->show();
}
else
{
ui->statusLabel->setText(availableError);
ui->registerNameButton->hide();
}
}

void BuyNamesPage::onDomainNameEdited(const QString &name){

if (!walletModel)
return;

QString availableError;
std::string domain = name.toStdString();
//check if it even ends with .bit
if(!name.toStdString().ends_with(".bit"))
{
ui->statusLabel->setText(tr("%1 does not end with .bit!").arg(name));
} else {
domain = ConvertDomainForms(domain);
availableError = name_available(QString::fromStdString(domain));
}

if (availableError == "")
{

const std::string domain = ConvertDomainForms(name.toStdString());
ui->statusLabel->setText(tr("%1 is available to register!").arg(name));
ui->registerNameButton->show();
}
Expand All @@ -75,7 +145,60 @@ void BuyNamesPage::onRegisterNameAction()
if (!walletModel)
return;

QString name = ui->registerName->text();
//check which tab we're on
int currentTab = ui->tabWidget->currentIndex();

QString input, name;
QMessageBox::StandardButton ErrorBox;

//just do the conversion here...
switch(currentTab) {
case 0:
{
//strip off .bit
input = ui->registerNameDomain->text();
std::string domain = input.toStdString();
if(!domain.ends_with(".bit")){
ErrorBox = QMessageBox::critical(this, tr("Invalid Namecoin Domain"),
tr("The inputted domain does not end with .bit."), QMessageBox::Cancel);
return;
} else {
name = QString::fromStdString(ConvertDomainForms(domain));
}
}

break;

case 1:
{
//no changes needed
input = ui->registerNameAscii->text();
name = input;
break;
}
case 2:
{
//check if valid hex
input = ui->registerNameHex->text();
std::string hex = input.toStdString();

if(!std::all_of(hex.begin(), hex.end(), ::isxdigit)){
ErrorBox = QMessageBox::critical(this, tr("Invalid Hex Value"),
tr("The inputted hex value is invalid."), QMessageBox::Cancel);

return;
} else {
std::string domain = ConvertDomainForms("0x" + input.toStdString());
name = QString::fromStdString(domain);
}
}

break;

default:
//how did we get here?
break;
}

WalletModel::UnlockContext ctx(walletModel->requestUnlock());
if (!ctx.isValid())
Expand All @@ -98,7 +221,9 @@ void BuyNamesPage::onRegisterNameAction()
}

// reset UI text
ui->registerName->setText("d/");
ui->registerNameDomain->setText("");
ui->registerNameAscii->setText("d/");
ui->registerNameHex->setText("642f");
ui->registerNameButton->setDefault(true);
}

Expand Down
5 changes: 4 additions & 1 deletion src/qt/buynamespage.h
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,10 @@ class BuyNamesPage : public QWidget
private Q_SLOTS:
bool eventFilter(QObject *object, QEvent *event);

void onNameEdited(const QString &name);
void onDomainNameEdited(const QString &name);
void onHexNameEdited(const QString &name);
void onAsciiNameEdited(const QString &name);

void onRegisterNameAction();
};

Expand Down
Loading
Loading