Send: resolve alias don't hang UI

This commit is contained in:
tobtoht 2021-10-23 00:14:34 +02:00
parent ab32e0b2a3
commit 779ae278f9
No known key found for this signature in database
GPG key ID: 1CADD27F41F45C3C
6 changed files with 39 additions and 59 deletions

View file

@ -31,8 +31,8 @@ SendWidget::SendWidget(QSharedPointer<AppContext> ctx, QWidget *parent)
connect(m_ctx.get(), &AppContext::initiateTransaction, this, &SendWidget::onInitiateTransaction);
connect(m_ctx.get(), &AppContext::endTransaction, this, &SendWidget::onEndTransaction);
connect(m_ctx.get(), &AppContext::openAliasResolved, this, &SendWidget::onOpenAliasResolved);
connect(m_ctx.get(), &AppContext::openAliasResolveError, this, &SendWidget::onOpenAliasResolveError);
connect(WalletManager::instance(), &WalletManager::openAliasResolved, this, &SendWidget::onOpenAliasResolved);
connect(ui->btnScan, &QPushButton::clicked, this, &SendWidget::scanClicked);
connect(ui->btnSend, &QPushButton::clicked, this, &SendWidget::sendClicked);
@ -139,8 +139,8 @@ void SendWidget::sendClicked() {
QString currency = ui->comboCurrencySelection->currentText();
QString recipient = ui->lineAddress->text().simplified().remove(' ');
QString description = ui->lineDescription->text();
if(recipient.isEmpty()) {
QMessageBox::warning(this, "Malformed recipient", "The recipient address was not correct");
if (recipient.isEmpty()) {
QMessageBox::warning(this, "Malformed recipient", "No destination address was entered.");
return;
}
@ -178,7 +178,7 @@ void SendWidget::sendClicked() {
amount = this->amount();
bool sendAll = (ui->lineAmount->text() == "all");
if (amount == 0 && !sendAll) {
QMessageBox::warning(this, "Amount error", "Invalid amount specified.");
QMessageBox::warning(this, "Amount error", "No amount was entered.");
return;
}
m_ctx->onCreateTransaction(recipient, amount, description, sendAll);
@ -193,8 +193,8 @@ void SendWidget::sendClicked() {
}
void SendWidget::aliasClicked() {
auto address = ui->lineAddress->text();
m_ctx->onOpenAliasResolve(address);
auto alias = ui->lineAddress->text();
WalletManager::instance()->resolveOpenAliasAsync(alias);
}
void SendWidget::clearClicked() {
@ -254,7 +254,24 @@ double SendWidget::amountDouble() {
return amount / constants::cdiv;
}
void SendWidget::onOpenAliasResolved(const QString &address, const QString &openAlias) {
void SendWidget::onOpenAliasResolved(const QString &openAlias, const QString &address, bool dnssecValid) {
if (address.isEmpty()) {
this->onOpenAliasResolveError("Could not resolve OpenAlias.");
return;
}
if (!dnssecValid) {
this->onOpenAliasResolveError("Address found, but the DNSSEC signatures could not be verified, so this address may be spoofed.");
return;
}
bool valid = WalletManager::addressValid(address, constants::networkType);
if (!valid) {
this->onOpenAliasResolveError(QString("Address validation error. Perhaps it is of the wrong network type.\n\n"
"OpenAlias: %1\nAddress: %2").arg(openAlias, address));
return;
}
this->fill(address, openAlias);
ui->btn_openAlias->hide();
}

View file

@ -38,7 +38,7 @@ public slots:
void fillAddress(const QString &address);
void updateConversionLabel();
void onOpenAliasResolveError(const QString &err);
void onOpenAliasResolved(const QString &address, const QString &openAlias);
void onOpenAliasResolved(const QString &openAlias, const QString &address, bool dnssecValid);
void onPreferredFiatCurrencyChanged();
void onInitiateTransaction();

View file

@ -210,48 +210,6 @@ void AppContext::onSetRestoreHeight(quint64 height){
emit customRestoreHeightSet(height);
}
void AppContext::onOpenAliasResolve(const QString &openAlias) {
// @TODO: calling this freezes for about 1-2 seconds :/
const auto result = WalletManager::instance()->resolveOpenAlias(openAlias);; // TODO: async call
const auto spl = result.split("|");
auto msg = QString("");
if(spl.count() != 2) {
msg = "Internal error";
emit openAliasResolveError(msg);
return;
}
const auto &status = spl.at(0);
const auto &address = spl.at(1);
const auto valid = WalletManager::addressValid(address, constants::networkType);
if(status == "false"){
if(valid){
msg = "Address found, but the DNSSEC signatures could not be verified, so this address may be spoofed";
emit openAliasResolveError(msg);
return;
} else {
msg = "No valid address found at this OpenAlias address, but the DNSSEC signatures could not be verified, so this may be spoofed";
emit openAliasResolveError(msg);
return;
}
} else if(status != "true") {
msg = "Internal error";
emit openAliasResolveError(msg);
return;
}
if(valid){
emit openAliasResolved(address, openAlias);
return;
}
msg = QString("Address validation error.");
if(!address.isEmpty())
msg += QString(" Perhaps it is of the wrong network type."
"\n\nOpenAlias: %1\nAddress: %2").arg(openAlias).arg(address);
emit openAliasResolveError(msg);
}
void AppContext::stopTimers() {
m_storeTimer.stop();
}

View file

@ -55,7 +55,6 @@ public slots:
void onCancelTransaction(PendingTransaction *tx, const QVector<QString> &address);
void onSweepOutputs(const QVector<QString> &keyImages, QString address, bool churn, int outputs);
void onCreateTransactionError(const QString &msg);
void onOpenAliasResolve(const QString &openAlias);
void onSetRestoreHeight(quint64 height);
void onMultiBroadcast(PendingTransaction *tx);
void onDeviceButtonRequest(quint64 code);
@ -86,8 +85,6 @@ signals:
void createTransactionError(QString message);
void createTransactionCancelled(const QVector<QString> &address, quint64 amount);
void createTransactionSuccess(PendingTransaction *tx, const QVector<QString> &address);
void openAliasResolveError(const QString &msg);
void openAliasResolved(const QString &address, const QString &openAlias);
void setRestoreHeightError(const QString &msg);
void customRestoreHeightSet(int height);
void initiateTransaction();

View file

@ -297,14 +297,20 @@ bool WalletManager::isDaemonLocal(const QString &daemon_address) const
return daemon_address.isEmpty() ? false : Monero::Utils::isAddressLocal(daemon_address.toStdString());
}
QString WalletManager::resolveOpenAlias(const QString &address) const
QString WalletManager::resolveOpenAlias(const QString &address, bool &dnssecValid) const
{
bool dnssec_valid = false;
std::string res = m_pimpl->resolveOpenAlias(address.toStdString(), dnssec_valid);
res = std::string(dnssec_valid ? "true" : "false") + "|" + res;
std::string res = m_pimpl->resolveOpenAlias(address.toStdString(), dnssecValid);
return QString::fromStdString(res);
}
void WalletManager::resolveOpenAliasAsync(const QString &alias) {
m_scheduler.run([this, alias] {
bool dnssecValid;
QString address = this->resolveOpenAlias(alias, dnssecValid);
emit openAliasResolved(alias, address, dnssecValid);
});
}
void WalletManager::setLogLevel(int logLevel)
{
Monero::WalletManagerFactory::setLogLevel(logLevel);

View file

@ -142,7 +142,8 @@ public:
Q_INVOKABLE qint64 addi(qint64 x, qint64 y) const { return x + y; }
Q_INVOKABLE qint64 subi(qint64 x, qint64 y) const { return x - y; }
Q_INVOKABLE QString resolveOpenAlias(const QString &address) const;
QString resolveOpenAlias(const QString &address, bool &dnssecValid) const;
void resolveOpenAliasAsync(const QString &address);
// clear/rename wallet cache
Q_INVOKABLE static bool clearWalletCache(const QString &fileName);
@ -162,6 +163,7 @@ signals:
void deviceError(const QString &message);
void miningStatus(bool isMining) const;
void proxyAddressChanged() const;
void openAliasResolved(const QString &alias, const QString &address, bool dnssecValid);
public slots:
private: