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

Add name_firstupdate GUI #443

Merged
merged 1 commit into from
Sep 1, 2021
Merged
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
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 @@ -282,11 +283,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 @@ -308,6 +320,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 @@ -567,6 +581,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