mirror of
https://github.com/AyuGram/AyuGramDesktop.git
synced 2026-07-25 06:54:43 +00:00
Improve giveaway prices display.
This commit is contained in:
@@ -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 ¤cy,
|
||||
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 ¤cy,
|
||||
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 ¤cy) -> int {
|
||||
const auto monthlyAmount = [&](const QString ¤cy) -> float64 {
|
||||
const auto it = monthlyAmountPerCurrency.find(currency);
|
||||
if (it != end(monthlyAmountPerCurrency)) {
|
||||
return it->second;
|
||||
|
||||
Reference in New Issue
Block a user