Custom SuchWow donation tip amount

This commit is contained in:
dsc 2021-05-14 03:36:33 +02:00
parent 0d502f0e45
commit 624f13b2d9
7 changed files with 63 additions and 20 deletions

View file

@ -274,6 +274,7 @@ MainWindow::MainWindow(AppContext *ctx, QWidget *parent) :
// settings connects
connect(m_windowSettings, &Settings::preferredFiatCurrencyChanged, this, &MainWindow::onUpdateFiatBalanceWidget);
connect(m_windowSettings, &Settings::preferredFiatCurrencyChanged, m_ctx, &AppContext::onPreferredFiatCurrencyChanged);
connect(m_windowSettings, &Settings::preferredFiatCurrencyChanged, ui->suchWowWidget, &SuchWowWidget::onPreferredFiatCurrencyChanged);
connect(m_windowSettings, &Settings::preferredFiatCurrencyChanged, ui->sendWidget, QOverload<>::of(&SendWidget::onPreferredFiatCurrencyChanged));
// Skin
@ -1078,7 +1079,9 @@ void MainWindow::showSendScreen(const CCSEntry &entry) {
}
void MainWindow::suchDonate(const QString address) {
double donation = AppContext::prices->convert("EUR", "WOW", 2);
double tipAmount = config()->get(Config::suchWowTipAmount).toDouble();
QString preferredCurrency = config()->get(Config::preferredFiatCurrency).toString();
double donation = AppContext::prices->convert(preferredCurrency, "WOW", tipAmount);
ui->sendWidget->fill(address, "SuchWow contribution :-)", donation);
ui->tabWidget->setCurrentIndex(Tabs::SEND);
}

View file

@ -64,8 +64,6 @@ void SendWidget::addressEdited() {
if (outputs.size() > 0) {
ui->lineAmount->setText(WalletManager::displayAmount(ui->lineAddress->getTotal()));
ui->comboCurrencySelection->setCurrentIndex(0);
} else {
ui->lineAmount->setText("");
}
ui->btn_openAlias->setVisible(ui->lineAddress->isOpenAlias());

View file

@ -48,8 +48,9 @@ static const QHash<Config::ConfigKey, ConfigDirective> configStrings = {
{Config::hideBalance, {QS("hideBalance"), false}},
{Config::hideFiatBalance, {QS("hideFiatBalance"), false}},
{Config::redditFrontend, {QS("redditFrontend"), "old.reddit.com"}},
{Config::showHistorySyncNotice, {QS("showHistorySyncNotice"), true}},
{Config::ignoreUpdateWarning, {QS("ignoreUpdateWarning"), ""}},
{Config::showHistorySyncNotice, {QS("showHistorySyncNotice"), true}}
{Config::suchWowTipAmount, {QS("suchWowTipAmount"), 0.75}}
};

View file

@ -51,7 +51,8 @@ public:
hideFiatBalance,
redditFrontend,
showHistorySyncNotice,
ignoreUpdateWarning
ignoreUpdateWarning,
suchWowTipAmount
};
~Config() override;

View file

@ -47,6 +47,16 @@ SuchWowWidget::SuchWowWidget(QWidget *parent) :
m_contextMenu->addAction("Donate", this, &SuchWowWidget::suchDonate);
connect(ui->listWidget, &QListWidget::customContextMenuRequested, this, &SuchWowWidget::showContextMenu);
// tip amount slider
ui->slider_tipAmount->setMinimum(1);
ui->slider_tipAmount->setMaximum(60);
ui->slider_tipAmount->setTickInterval(1);
ui->slider_tipAmount->setSingleStep(1);
double tipAmount = config()->get(Config::suchWowTipAmount).toDouble();
ui->slider_tipAmount->setValue((int)(tipAmount * 10));
connect(ui->slider_tipAmount, &QSlider::valueChanged, this, &SuchWowWidget::onTipSliderChanged);
this->setTipAmountLabel();
}
void SuchWowWidget::setupTable() {
@ -136,6 +146,24 @@ SuchWowPost *SuchWowWidget::itemToPost() {
return nullptr;
}
void SuchWowWidget::setTipAmountLabel(double tipAmount) {
if(tipAmount == 0.0)
tipAmount = config()->get(Config::suchWowTipAmount).toDouble();
QString amount_fmt = Utils::amountToCurrencyString(tipAmount, config()->get(Config::preferredFiatCurrency).toString());
ui->label_tipAmount->setText(QString("Default tip amount (%1)").arg(amount_fmt));
}
void SuchWowWidget::onTipSliderChanged(int value) {
double amount = (double)value / 10;
config()->set(Config::suchWowTipAmount, amount);
setTipAmountLabel(amount);
}
void SuchWowWidget::onPreferredFiatCurrencyChanged(const QString &symbol) {
this->setTipAmountLabel();
}
SuchWowWidget::~SuchWowWidget() {
delete ui;
}

View file

@ -76,10 +76,12 @@ public:
public slots:
void onWS(QJsonArray such_data);
void onPreferredFiatCurrencyChanged(const QString &symbol);
private slots:
void addThumb(SuchWowPost *post);
void showImage(SuchWowPost *post);
void onTipSliderChanged(int value);
signals:
void donate(QString donate);
@ -89,6 +91,7 @@ private:
void setupTable();
void suchDonate();
void suchImage();
void setTipAmountLabel(double tipAmount = 0.0);
SuchWowPost* itemToPost();
void showContextMenu(const QPoint &pos);

View file

@ -14,24 +14,33 @@
<string>Form</string>
</property>
<layout class="QVBoxLayout" name="verticalLayout">
<property name="spacing">
<number>4</number>
</property>
<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="QListWidget" name="listWidget"/>
</item>
<item>
<layout class="QFormLayout" name="formLayout">
<item row="0" column="0">
<widget class="QLabel" name="label_tipAmount">
<property name="text">
<string>Default tip amount</string>
</property>
</widget>
</item>
<item row="0" column="1">
<widget class="QSlider" name="slider_tipAmount">
<property name="maximumSize">
<size>
<width>280</width>
<height>16777215</height>
</size>
</property>
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
</widget>
</item>
</layout>
</item>
</layout>
</widget>
<resources/>