mirror of
https://github.com/feather-wallet/feather.git
synced 2025-04-23 20:58:13 +00:00
PaymentRequest: add fiat conversion
This commit is contained in:
parent
e7a6e4f16a
commit
8f3205d632
3 changed files with 129 additions and 15 deletions
|
@ -10,6 +10,8 @@
|
|||
#include <QRegularExpressionValidator>
|
||||
|
||||
#include "WalletManager.h"
|
||||
#include "utils/AppData.h"
|
||||
#include "utils/config.h"
|
||||
#include "utils/Utils.h"
|
||||
|
||||
PaymentRequestDialog::PaymentRequestDialog(QWidget *parent, Wallet *wallet, QString address)
|
||||
|
@ -24,9 +26,17 @@ PaymentRequestDialog::PaymentRequestDialog(QWidget *parent, Wallet *wallet, QStr
|
|||
QRegularExpression rx;
|
||||
rx.setPattern(amount_rx);
|
||||
QValidator *validator = new QRegularExpressionValidator(rx, this);
|
||||
ui->line_amountXMR->setValidator(validator);
|
||||
ui->line_amount->setValidator(validator);
|
||||
|
||||
connect(ui->line_amount, &QLineEdit::textEdited, [this] (const QString &text){
|
||||
this->calculateFiat();
|
||||
this->updatePaymentRequest();
|
||||
});
|
||||
connect(ui->line_amountFiat, &QLineEdit::textEdited, [this](const QString &text) {
|
||||
this->calculateCrypto();
|
||||
this->updatePaymentRequest();
|
||||
});
|
||||
|
||||
connect(ui->line_amountXMR, &QLineEdit::textChanged, this, &PaymentRequestDialog::updatePaymentRequest);
|
||||
connect(ui->line_description, &QLineEdit::textChanged, this, &PaymentRequestDialog::updatePaymentRequest);
|
||||
connect(ui->line_recipient, &QLineEdit::textChanged, this, &PaymentRequestDialog::updatePaymentRequest);
|
||||
|
||||
|
@ -34,9 +44,26 @@ PaymentRequestDialog::PaymentRequestDialog(QWidget *parent, Wallet *wallet, QStr
|
|||
connect(ui->btn_copyImage, &QPushButton::clicked, this, &PaymentRequestDialog::copyImage);
|
||||
connect(ui->btn_saveImage, &QPushButton::clicked, this, &PaymentRequestDialog::saveImage);
|
||||
|
||||
QString preferredFiatCurrency = conf()->get(Config::preferredFiatCurrency).toString();
|
||||
QStringList fiatSymbols = conf()->get(Config::fiatSymbols).toStringList();
|
||||
if (fiatSymbols.contains(preferredFiatCurrency)) {
|
||||
fiatSymbols.removeAll(preferredFiatCurrency);
|
||||
}
|
||||
|
||||
ui->comboCurrency->addItem(preferredFiatCurrency);
|
||||
ui->comboCurrency->addItems(fiatSymbols);
|
||||
ui->comboCurrency->setCurrentIndex(0);
|
||||
connect(ui->comboCurrency, &QComboBox::currentIndexChanged, [this] (int index){
|
||||
calculateFiat();
|
||||
});
|
||||
|
||||
if (conf()->get(Config::disableWebsocket).toBool()) {
|
||||
ui->frame_fiat->hide();
|
||||
}
|
||||
|
||||
this->updatePaymentRequest();
|
||||
|
||||
ui->line_amountXMR->setFocus();
|
||||
ui->line_amount->setFocus();
|
||||
|
||||
this->adjustSize();
|
||||
}
|
||||
|
@ -44,7 +71,7 @@ PaymentRequestDialog::PaymentRequestDialog(QWidget *parent, Wallet *wallet, QStr
|
|||
void PaymentRequestDialog::updatePaymentRequest() {
|
||||
QString description = ui->line_description->text();
|
||||
QString recipient = ui->line_recipient->text();
|
||||
quint64 amount = WalletManager::amountFromString(ui->line_amountXMR->text());
|
||||
quint64 amount = WalletManager::amountFromString(ui->line_amount->text());
|
||||
|
||||
QString uri = m_wallet->make_uri(m_address, amount, description, recipient);
|
||||
|
||||
|
@ -58,6 +85,22 @@ void PaymentRequestDialog::updatePaymentRequest() {
|
|||
}
|
||||
}
|
||||
|
||||
void PaymentRequestDialog::calculateCrypto() {
|
||||
QString fiatCurrency = ui->comboCurrency->currentText();
|
||||
QString fiatAmount = ui->line_amountFiat->text();
|
||||
|
||||
double cryptoAmount = appData()->prices.convert(fiatCurrency, "XMR", fiatAmount.toDouble());
|
||||
ui->line_amount->setText(QString::number(cryptoAmount, 'f', 10));
|
||||
}
|
||||
|
||||
void PaymentRequestDialog::calculateFiat() {
|
||||
QString fiatCurrency = ui->comboCurrency->currentText();
|
||||
QString cryptoAmount = ui->line_amount->text();
|
||||
|
||||
double fiatAmount = appData()->prices.convert("XMR", fiatCurrency, cryptoAmount.toDouble());
|
||||
ui->line_amountFiat->setText(QString::number(fiatAmount, 'f', 2));
|
||||
}
|
||||
|
||||
void PaymentRequestDialog::copyLink() {
|
||||
Utils::copyToClipboard(ui->line_paymentRequestUri->text());
|
||||
QMessageBox::information(this, "Information", "Payment request link copied to clipboard.");
|
||||
|
@ -80,4 +123,4 @@ void PaymentRequestDialog::saveImage() {
|
|||
QMessageBox::information(this, "Information", "QR code saved to file");
|
||||
}
|
||||
|
||||
PaymentRequestDialog::~PaymentRequestDialog() = default;
|
||||
PaymentRequestDialog::~PaymentRequestDialog() = default;
|
||||
|
|
|
@ -28,6 +28,9 @@ private slots:
|
|||
void copyImage();
|
||||
void saveImage();
|
||||
|
||||
void calculateCrypto();
|
||||
void calculateFiat();
|
||||
|
||||
private:
|
||||
QScopedPointer<Ui::PaymentRequestDialog> ui;
|
||||
Wallet *m_wallet;
|
||||
|
|
|
@ -34,7 +34,7 @@
|
|||
<item>
|
||||
<widget class="Line" name="line">
|
||||
<property name="orientation">
|
||||
<enum>Qt::Horizontal</enum>
|
||||
<enum>Qt::Orientation::Horizontal</enum>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
|
@ -52,7 +52,7 @@
|
|||
<item>
|
||||
<layout class="QHBoxLayout" name="horizontalLayout_3">
|
||||
<item>
|
||||
<widget class="QLineEdit" name="line_amountXMR">
|
||||
<widget class="QLineEdit" name="line_amount">
|
||||
<property name="sizePolicy">
|
||||
<sizepolicy hsizetype="Maximum" vsizetype="Fixed">
|
||||
<horstretch>0</horstretch>
|
||||
|
@ -71,7 +71,7 @@
|
|||
<item>
|
||||
<spacer name="horizontalSpacer_2">
|
||||
<property name="orientation">
|
||||
<enum>Qt::Horizontal</enum>
|
||||
<enum>Qt::Orientation::Horizontal</enum>
|
||||
</property>
|
||||
<property name="sizeHint" stdset="0">
|
||||
<size>
|
||||
|
@ -85,26 +85,94 @@
|
|||
</item>
|
||||
</layout>
|
||||
</item>
|
||||
<item row="1" column="0">
|
||||
<item row="2" column="0">
|
||||
<widget class="QLabel" name="label_2">
|
||||
<property name="text">
|
||||
<string>Description:</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="1" column="1">
|
||||
<item row="2" column="1">
|
||||
<widget class="QLineEdit" name="line_description"/>
|
||||
</item>
|
||||
<item row="2" column="0">
|
||||
<item row="3" column="0">
|
||||
<widget class="QLabel" name="label_3">
|
||||
<property name="text">
|
||||
<string>Your name:</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="2" column="1">
|
||||
<item row="3" column="1">
|
||||
<widget class="QLineEdit" name="line_recipient"/>
|
||||
</item>
|
||||
<item row="1" column="0">
|
||||
<widget class="QLabel" name="label_5">
|
||||
<property name="text">
|
||||
<string/>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="1" column="1">
|
||||
<layout class="QHBoxLayout" name="horizontalLayout_2">
|
||||
<item>
|
||||
<widget class="QFrame" name="frame_fiat">
|
||||
<property name="frameShape">
|
||||
<enum>QFrame::Shape::NoFrame</enum>
|
||||
</property>
|
||||
<property name="frameShadow">
|
||||
<enum>QFrame::Shadow::Sunken</enum>
|
||||
</property>
|
||||
<layout class="QHBoxLayout" name="horizontalLayout_4">
|
||||
<property name="leftMargin">
|
||||
<number>0</number>
|
||||
</property>
|
||||
<property name="topMargin">
|
||||
<number>0</number>
|
||||
</property>
|
||||
<property name="rightMargin">
|
||||
<number>0</number>
|
||||
</property>
|
||||
<property name="bottomMargin">
|
||||
<number>0</number>
|
||||
</property>
|
||||
<item>
|
||||
<widget class="QLineEdit" name="line_amountFiat">
|
||||
<property name="sizePolicy">
|
||||
<sizepolicy hsizetype="Maximum" vsizetype="Fixed">
|
||||
<horstretch>0</horstretch>
|
||||
<verstretch>0</verstretch>
|
||||
</sizepolicy>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QComboBox" name="comboCurrency">
|
||||
<property name="sizePolicy">
|
||||
<sizepolicy hsizetype="Maximum" vsizetype="Fixed">
|
||||
<horstretch>0</horstretch>
|
||||
<verstretch>0</verstretch>
|
||||
</sizepolicy>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
</layout>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<spacer name="horizontalSpacer">
|
||||
<property name="orientation">
|
||||
<enum>Qt::Orientation::Horizontal</enum>
|
||||
</property>
|
||||
<property name="sizeHint" stdset="0">
|
||||
<size>
|
||||
<width>40</width>
|
||||
<height>20</height>
|
||||
</size>
|
||||
</property>
|
||||
</spacer>
|
||||
</item>
|
||||
</layout>
|
||||
</item>
|
||||
</layout>
|
||||
</item>
|
||||
<item>
|
||||
|
@ -133,7 +201,7 @@
|
|||
<item>
|
||||
<spacer name="horizontalSpacer_3">
|
||||
<property name="orientation">
|
||||
<enum>Qt::Horizontal</enum>
|
||||
<enum>Qt::Orientation::Horizontal</enum>
|
||||
</property>
|
||||
<property name="sizeHint" stdset="0">
|
||||
<size>
|
||||
|
@ -146,10 +214,10 @@
|
|||
<item>
|
||||
<widget class="QDialogButtonBox" name="buttonBox">
|
||||
<property name="orientation">
|
||||
<enum>Qt::Horizontal</enum>
|
||||
<enum>Qt::Orientation::Horizontal</enum>
|
||||
</property>
|
||||
<property name="standardButtons">
|
||||
<set>QDialogButtonBox::Close</set>
|
||||
<set>QDialogButtonBox::StandardButton::Close</set>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
|
|
Loading…
Reference in a new issue