Merge pull request 'Send: show fiat conversion when XMR is selected' (#75) from tobtoht/feather:send_fiat into master

Reviewed-on: https://git.wownero.com/feather/feather/pulls/75
This commit is contained in:
tobtoht 2020-10-15 02:20:44 +00:00
commit 61a135e1c2
4 changed files with 29 additions and 15 deletions

View file

@ -256,6 +256,7 @@ MainWindow::MainWindow(AppContext *ctx, QWidget *parent) :
connect(m_windowSettings, &Settings::preferredFiatCurrencyChanged, tickerWidget, &TickerWidget::init);
connect(m_windowSettings, &Settings::preferredFiatCurrencyChanged, m_balanceWidget, &TickerWidget::init);
connect(m_windowSettings, &Settings::preferredFiatCurrencyChanged, m_ctx, &AppContext::onPreferredFiatCurrencyChanged);
connect(m_windowSettings, &Settings::preferredFiatCurrencyChanged, ui->sendWidget, QOverload<>::of(&SendWidget::onPreferredFiatCurrencyChanged));
// CCS/Reddit widget
connect(m_windowSettings, &Settings::homeWidgetChanged, this, &MainWindow::homeWidgetChanged);

View file

@ -27,8 +27,8 @@ SendWidget::SendWidget(QWidget *parent) :
connect(ui->lineAmount, &QLineEdit::textEdited, this, &SendWidget::amountEdited);
connect(ui->lineAddress, &QLineEdit::textEdited, this, &SendWidget::addressEdited);
connect(ui->btn_openAlias, &QPushButton::clicked, this, &SendWidget::aliasClicked);
ui->label_xmrAmount->setText("");
ui->label_xmrAmount->hide();
ui->label_conversionAmount->setText("");
ui->label_conversionAmount->hide();
ui->btn_openAlias->hide();
}
@ -120,18 +120,26 @@ void SendWidget::btnMaxClicked() {
void SendWidget::updateConversionLabel() {
auto amount = this->amount();
if(amount == -1) return;
ui->label_xmrAmount->setText("");
ui->label_conversionAmount->setText("");
if(amount <= 0) {
ui->label_xmrAmount->hide();
ui->label_conversionAmount->hide();
return;
}
QString conversionAmountStr = [this]{
QString currency = ui->comboCurrencySelection->currentText();
if (currency != "XMR") {
QString xmr_str = QString("%1 XMR").arg(QString::number(this->conversionAmount()));
ui->label_xmrAmount->setText(xmr_str);
ui->label_xmrAmount->show();
}
return QString("~%1 XMR").arg(QString::number(this->conversionAmount(), 'f'));
} else {
auto preferredFiatCurrency = config()->get(Config::preferredFiatCurrency).toString();
double conversionAmount = AppContext::prices->convert("XMR", preferredFiatCurrency, this->amount());
return QString("~%1 %2").arg(QString::number(conversionAmount, 'f', 2), preferredFiatCurrency);
};
}();
ui->label_conversionAmount->setText(conversionAmountStr);
ui->label_conversionAmount->show();
}
double SendWidget::conversionAmount() {
@ -163,7 +171,7 @@ void SendWidget::clearFields() {
ui->lineAddress->clear();
ui->lineAmount->clear();
ui->lineDescription->clear();
ui->label_xmrAmount->clear();
ui->label_conversionAmount->clear();
}
void SendWidget::onWalletClosed() {
@ -178,6 +186,10 @@ void SendWidget::onEndTransaction() {
ui->btnSend->setEnabled(true);
}
void SendWidget::onPreferredFiatCurrencyChanged() {
this->updateConversionLabel();
}
SendWidget::~SendWidget() {
delete ui;
}

View file

@ -38,6 +38,7 @@ public slots:
void onOpenAliasResolveError(const QString &err);
void onOpenAliasResolved(const QString &address, const QString &openAlias);
void onWalletClosed();
void onPreferredFiatCurrencyChanged();
void onInitiateTransaction();
void onEndTransaction();

View file

@ -6,8 +6,8 @@
<rect>
<x>0</x>
<y>0</y>
<width>500</width>
<height>148</height>
<width>603</width>
<height>175</height>
</rect>
</property>
<property name="windowTitle">
@ -153,12 +153,12 @@
</widget>
</item>
<item>
<widget class="QLabel" name="label_xmrAmount">
<widget class="QLabel" name="label_conversionAmount">
<property name="enabled">
<bool>true</bool>
</property>
<property name="text">
<string>xmrAmount</string>
<string>conversionAmount</string>
</property>
</widget>
</item>