Skip to content

Commit

Permalink
Merge #443: Add name_firstupdate GUI
Browse files Browse the repository at this point in the history
befa241 Namecoin / Qt: Add name_firstupdate GUI (Jeremy Rand)

Pull request description:

  This PR adds a GUI for `name_firstupdate`, based on Brandon's port of Mikhail's GUI.  AFAICT, once #436 is merged, patching this GUI to use `name_autoregister` instead should be roughly a one-liner.  Until then, it's still a UX improvement over the status quo, even though the user needs to run `name_new` themselves.

  Refs #187

ACKs for top commit:
  domob1812:
    ACK befa241.

Tree-SHA512: 044e2daf0b67992013703fe3e4e6fe255585fa0268b5b084a92c6eff0027f662891adb9633b1a4c1fef7a39de2e796b8aa713b0f901558ce016a00318e5b602a
  • Loading branch information
domob1812 committed Sep 1, 2021
2 parents e5707b0 + befa241 commit 53551bd
Show file tree
Hide file tree
Showing 10 changed files with 347 additions and 1 deletion.
4 changes: 4 additions & 0 deletions src/Makefile.qt.include
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ QT_FORMS_UI = \
qt/forms/debugwindow.ui \
qt/forms/sendcoinsdialog.ui \
qt/forms/sendcoinsentry.ui \
qt/forms/buynamespage.ui \
qt/forms/managenamespage.ui \
qt/forms/configurenamedialog.ui \
qt/forms/signverifymessagedialog.ui \
Expand All @@ -47,6 +48,7 @@ QT_MOC_CPP = \
qt/moc_bitcoinamountfield.cpp \
qt/moc_bitcoingui.cpp \
qt/moc_bitcoinunits.cpp \
qt/moc_buynamespage.cpp \
qt/moc_clientmodel.cpp \
qt/moc_coincontroldialog.cpp \
qt/moc_coincontroltreewidget.cpp \
Expand Down Expand Up @@ -120,6 +122,7 @@ BITCOIN_QT_H = \
qt/bitcoinamountfield.h \
qt/bitcoingui.h \
qt/bitcoinunits.h \
qt/buynamespage.h \
qt/clientmodel.h \
qt/coincontroldialog.h \
qt/coincontroltreewidget.h \
Expand Down Expand Up @@ -260,6 +263,7 @@ BITCOIN_QT_WALLET_CPP = \
qt/addressbookpage.cpp \
qt/addresstablemodel.cpp \
qt/askpassphrasedialog.cpp \
qt/buynamespage.cpp \
qt/coincontroldialog.cpp \
qt/coincontroltreewidget.cpp \
qt/configurenamedialog.cpp \
Expand Down
25 changes: 24 additions & 1 deletion src/qt/bitcoingui.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
#include <qt/bitcoingui.h>

#include <qt/bitcoinunits.h>
#include <qt/buynamespage.h>
#include <qt/clientmodel.h>
#include <qt/createwalletdialog.h>
#include <qt/guiconstants.h>
Expand Down Expand Up @@ -283,11 +284,22 @@ void BitcoinGUI::createActions()
historyAction->setShortcut(QKeySequence(Qt::ALT + Qt::Key_4));
tabGroup->addAction(historyAction);

buyNamesAction = new QAction(platformStyle->SingleColorIcon(":/icons/bitcoin_transparent_letter"), tr("&Buy Names"), this);
buyNamesAction->setStatusTip(tr("Register new names"));
buyNamesAction->setToolTip(buyNamesAction->statusTip());
buyNamesAction->setCheckable(true);
buyNamesAction->setShortcut(QKeySequence(Qt::ALT + Qt::Key_5));
tabGroup->addAction(buyNamesAction);

buyNamesMenuAction = new QAction(buyNamesAction->text(), this);
buyNamesMenuAction->setStatusTip(buyNamesAction->statusTip());
buyNamesMenuAction->setToolTip(buyNamesMenuAction->statusTip());

manageNamesAction = new QAction(platformStyle->SingleColorIcon(":/icons/bitcoin_transparent_letter"), tr("&Manage Names"), this);
manageNamesAction->setStatusTip(tr("Manage registered names"));
manageNamesAction->setToolTip(manageNamesAction->statusTip());
manageNamesAction->setCheckable(true);
manageNamesAction->setShortcut(QKeySequence(Qt::ALT + Qt::Key_5));
manageNamesAction->setShortcut(QKeySequence(Qt::ALT + Qt::Key_6));
tabGroup->addAction(manageNamesAction);

manageNamesMenuAction = new QAction(manageNamesAction->text(), this);
Expand All @@ -309,6 +321,8 @@ void BitcoinGUI::createActions()
connect(receiveCoinsMenuAction, &QAction::triggered, this, &BitcoinGUI::gotoReceiveCoinsPage);
connect(historyAction, &QAction::triggered, [this]{ showNormalIfMinimized(); });
connect(historyAction, &QAction::triggered, this, &BitcoinGUI::gotoHistoryPage);
connect(buyNamesAction, &QAction::triggered, [this]{ showNormalIfMinimized(); });
connect(buyNamesAction, &QAction::triggered, this, &BitcoinGUI::gotoBuyNamesPage);
connect(manageNamesAction, &QAction::triggered, [this]{ showNormalIfMinimized(); });
connect(manageNamesAction, &QAction::triggered, this, &BitcoinGUI::gotoManageNamesPage);
#endif // ENABLE_WALLET
Expand Down Expand Up @@ -568,6 +582,7 @@ void BitcoinGUI::createToolBars()
toolbar->addAction(sendCoinsAction);
toolbar->addAction(receiveCoinsAction);
toolbar->addAction(historyAction);
toolbar->addAction(buyNamesAction);
toolbar->addAction(manageNamesAction);
overviewAction->setChecked(true);

Expand Down Expand Up @@ -773,6 +788,7 @@ void BitcoinGUI::setWalletActionsEnabled(bool enabled)
receiveCoinsAction->setEnabled(enabled);
receiveCoinsMenuAction->setEnabled(enabled);
historyAction->setEnabled(enabled);
buyNamesAction->setEnabled(enabled);
manageNamesAction->setEnabled(enabled);
encryptWalletAction->setEnabled(enabled);
backupWalletAction->setEnabled(enabled);
Expand Down Expand Up @@ -824,6 +840,7 @@ void BitcoinGUI::createTrayIconMenu()
if (enableWallet) {
trayIconMenu->addAction(sendCoinsMenuAction);
trayIconMenu->addAction(receiveCoinsMenuAction);
trayIconMenu->addAction(buyNamesMenuAction);
trayIconMenu->addAction(manageNamesMenuAction);
trayIconMenu->addSeparator();
trayIconMenu->addAction(signMessageAction);
Expand Down Expand Up @@ -920,6 +937,12 @@ void BitcoinGUI::gotoSendCoinsPage(QString addr)
if (walletFrame) walletFrame->gotoSendCoinsPage(addr);
}

void BitcoinGUI::gotoBuyNamesPage()
{
buyNamesAction->setChecked(true);
if (walletFrame) walletFrame->gotoBuyNamesPage();
}

void BitcoinGUI::gotoManageNamesPage()
{
manageNamesAction->setChecked(true);
Expand Down
4 changes: 4 additions & 0 deletions src/qt/bitcoingui.h
Original file line number Diff line number Diff line change
Expand Up @@ -140,6 +140,8 @@ class BitcoinGUI : public QMainWindow
QAction* sendCoinsMenuAction = nullptr;
QAction* usedSendingAddressesAction = nullptr;
QAction* usedReceivingAddressesAction = nullptr;
QAction* buyNamesAction = nullptr;
QAction* buyNamesMenuAction = nullptr;
QAction* manageNamesAction = nullptr;
QAction* manageNamesMenuAction = nullptr;
QAction* signMessageAction = nullptr;
Expand Down Expand Up @@ -282,6 +284,8 @@ public Q_SLOTS:
void gotoReceiveCoinsPage();
/** Switch to send coins page */
void gotoSendCoinsPage(QString addr = "");
/** Switch to buy names page */
void gotoBuyNamesPage();
/** Switch to manage names page */
void gotoManageNamesPage();

Expand Down
114 changes: 114 additions & 0 deletions src/qt/buynamespage.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,114 @@
#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 <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 ("");
}
41 changes: 41 additions & 0 deletions src/qt/buynamespage.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
#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:
bool eventFilter(QObject *object, QEvent *event);

void onRegisterNameAction();
};

#endif // BUYNAMESPAGE_H
Loading

0 comments on commit 53551bd

Please sign in to comment.