mirror of
https://github.com/AyuGram/AyuGramDesktop.git
synced 2025-06-05 06:33:57 +02:00
Fixed discount calculation for gifts options with different currencies.
This commit is contained in:
parent
f4c739ab92
commit
51dc5d6e37
2 changed files with 17 additions and 6 deletions
|
@ -26,7 +26,7 @@ Data::PremiumSubscriptionOption CreateSubscriptionOption(
|
||||||
}();
|
}();
|
||||||
return {
|
return {
|
||||||
.duration = Ui::FormatTTL(months * 86400 * 31),
|
.duration = Ui::FormatTTL(months * 86400 * 31),
|
||||||
.discount = discount
|
.discount = (discount > 0)
|
||||||
? QString::fromUtf8("\xe2\x88\x92%1%").arg(discount)
|
? QString::fromUtf8("\xe2\x88\x92%1%").arg(discount)
|
||||||
: QString(),
|
: QString(),
|
||||||
.costPerMonth = Ui::FillAmountAndCurrency(
|
.costPerMonth = Ui::FillAmountAndCurrency(
|
||||||
|
|
|
@ -24,15 +24,26 @@ template<typename Option>
|
||||||
if (tlOpts.isEmpty()) {
|
if (tlOpts.isEmpty()) {
|
||||||
return {};
|
return {};
|
||||||
}
|
}
|
||||||
|
auto monthlyAmountPerCurrency = base::flat_map<QString, int>();
|
||||||
auto result = Data::PremiumSubscriptionOptions();
|
auto result = Data::PremiumSubscriptionOptions();
|
||||||
const auto monthlyAmount = [&] {
|
const auto monthlyAmount = [&](const QString ¤cy) -> int {
|
||||||
|
const auto it = monthlyAmountPerCurrency.find(currency);
|
||||||
|
if (it != end(monthlyAmountPerCurrency)) {
|
||||||
|
return it->second;
|
||||||
|
}
|
||||||
const auto &min = ranges::min_element(
|
const auto &min = ranges::min_element(
|
||||||
tlOpts,
|
tlOpts,
|
||||||
ranges::less(),
|
ranges::less(),
|
||||||
[](const Option &o) { return o.data().vamount().v; }
|
[&](const Option &o) {
|
||||||
|
return currency == qs(o.data().vcurrency())
|
||||||
|
? o.data().vamount().v
|
||||||
|
: std::numeric_limits<int64_t>::max();
|
||||||
|
}
|
||||||
)->data();
|
)->data();
|
||||||
return min.vamount().v / float64(min.vmonths().v);
|
const auto monthly = min.vamount().v / float64(min.vmonths().v);
|
||||||
}();
|
monthlyAmountPerCurrency.emplace(currency, monthly);
|
||||||
|
return monthly;
|
||||||
|
};
|
||||||
result.reserve(tlOpts.size());
|
result.reserve(tlOpts.size());
|
||||||
for (const auto &tlOption : tlOpts) {
|
for (const auto &tlOption : tlOpts) {
|
||||||
const auto &option = tlOption.data();
|
const auto &option = tlOption.data();
|
||||||
|
@ -45,7 +56,7 @@ template<typename Option>
|
||||||
const auto currency = qs(option.vcurrency());
|
const auto currency = qs(option.vcurrency());
|
||||||
result.push_back(CreateSubscriptionOption(
|
result.push_back(CreateSubscriptionOption(
|
||||||
months,
|
months,
|
||||||
monthlyAmount,
|
monthlyAmount(currency),
|
||||||
amount,
|
amount,
|
||||||
currency,
|
currency,
|
||||||
botUrl));
|
botUrl));
|
||||||
|
|
Loading…
Add table
Reference in a new issue