Improve giveaway prices display.

This commit is contained in:
John Preston
2026-03-16 15:59:50 +04:00
parent 994dd2e05c
commit 53a2d4704d
4 changed files with 37 additions and 25 deletions
+3
View File
@@ -56,6 +56,9 @@ namespace {
+ QChar(0x00D7)
+ ' '
+ QString::number(tlOption.vusers().v);
options[i].total = Ui::FillAmountAndCurrency(
tlOption.vamount().v,
currency);
options[i].currency = currency;
}
return options;
@@ -15,29 +15,33 @@ constexpr auto kDiscountDivider = 1.;
Data::PremiumSubscriptionOption CreateSubscriptionOption(
int months,
int monthlyAmount,
float64 monthlyAmount,
int64 amount,
const QString &currency,
const QString &botUrl) {
const auto baselineAmount = monthlyAmount * months;
const auto discount = [&] {
const auto percent = 1. - float64(amount) / (monthlyAmount * months);
return std::round(percent * 100. / kDiscountDivider)
const auto percent = 1. - float64(amount) / baselineAmount;
return base::SafeRound(percent * 100. / kDiscountDivider)
* kDiscountDivider;
}();
const auto hasDiscount = (discount > 0);
return {
.months = months,
.duration = Ui::FormatTTL(months * 86400 * 31),
.discount = (discount > 0)
.discount = hasDiscount
? QString::fromUtf8("\xe2\x88\x92%1%").arg(discount)
: QString(),
.costPerMonth = Ui::FillAmountAndCurrency(
amount / float64(months),
currency),
.costNoDiscount = Ui::FillAmountAndCurrency(
monthlyAmount * months,
int64(base::SafeRound(amount / float64(months))),
currency),
.costNoDiscount = hasDiscount
? Ui::FillAmountAndCurrency(
int64(base::SafeRound(baselineAmount)),
currency)
: QString(),
.costPerYear = Ui::FillAmountAndCurrency(
amount / float64(months / 12.),
int64(base::SafeRound(amount / float64(months / 12.))),
currency),
.botUrl = botUrl,
};
@@ -13,7 +13,7 @@ namespace Api {
[[nodiscard]] Data::PremiumSubscriptionOption CreateSubscriptionOption(
int months,
int monthlyAmount,
float64 monthlyAmount,
int64 amount,
const QString &currency,
const QString &botUrl);
@@ -24,9 +24,9 @@ template<typename Option>
if (tlOpts.isEmpty()) {
return {};
}
auto monthlyAmountPerCurrency = base::flat_map<QString, int>();
auto monthlyAmountPerCurrency = base::flat_map<QString, float64>();
auto result = Data::PremiumSubscriptionOptions();
const auto monthlyAmount = [&](const QString &currency) -> int {
const auto monthlyAmount = [&](const QString &currency) -> float64 {
const auto it = monthlyAmountPerCurrency.find(currency);
if (it != end(monthlyAmountPerCurrency)) {
return it->second;