forked from domob1812/namecoin-core
-
Notifications
You must be signed in to change notification settings - Fork 149
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge #443: Add name_firstupdate GUI
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
Showing
10 changed files
with
347 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 (""); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
Oops, something went wrong.