Skip to content

Commit eddad6b

Browse files
committed
Show correct price per year in 2year premium.
Fixes #29961.
1 parent d02a8cb commit eddad6b

File tree

4 files changed

+23
-21
lines changed

4 files changed

+23
-21
lines changed

Telegram/SourceFiles/api/api_premium_option.cpp

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,9 @@ Data::PremiumSubscriptionOption CreateSubscriptionOption(
3636
.costNoDiscount = Ui::FillAmountAndCurrency(
3737
monthlyAmount * months,
3838
currency),
39-
.costTotal = Ui::FillAmountAndCurrency(amount, currency),
39+
.costPerYear = Ui::FillAmountAndCurrency(
40+
amount / float64(months / 12.),
41+
currency),
4042
.botUrl = botUrl,
4143
};
4244
}

Telegram/SourceFiles/data/data_premium_subscription_option.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ struct PremiumSubscriptionOption {
1515
QString discount;
1616
QString costPerMonth;
1717
QString costNoDiscount;
18-
QString costTotal;
18+
QString costPerYear;
1919
QString currency;
2020
QString total;
2121
QString botUrl;

Telegram/SourceFiles/settings/settings_premium.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -73,17 +73,17 @@ using SectionCustomTopBarData = Info::Settings::SectionCustomTopBarData;
7373
[[nodiscard]] Data::PremiumSubscriptionOptions SubscriptionOptionsForRows(
7474
Data::PremiumSubscriptionOptions result) {
7575
for (auto &option : result) {
76-
const auto total = option.costTotal;
76+
const auto perYear = option.costPerYear;
7777
const auto perMonth = option.costPerMonth;
7878

79-
option.costTotal = tr::lng_premium_gift_per(
79+
option.costPerYear = tr::lng_premium_gift_per(
8080
tr::now,
8181
lt_cost,
8282
perMonth);
8383
option.costPerMonth = tr::lng_premium_subscribe_total(
8484
tr::now,
8585
lt_cost,
86-
total);
86+
perYear);
8787

8888
if (option.duration == tr::lng_months(tr::now, lt_count, 1)) {
8989
option.costPerMonth = QString();

Telegram/SourceFiles/ui/effects/premium_graphics.cpp

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -934,7 +934,7 @@ void AddGiftOptions(
934934
return s.replace(kStar, QChar());
935935
};
936936
const auto &costPerMonthFont = st::shareBoxListItem.nameStyle.font;
937-
const auto &costTotalFont = st::normalFont;
937+
const auto &costPerYearFont = st::normalFont;
938938
const auto costPerMonthIcon = info.costPerMonth.startsWith(kStar)
939939
? GenerateStars(costPerMonthFont->height, 1)
940940
: QImage();
@@ -951,14 +951,14 @@ void AddGiftOptions(
951951
? info.costPerMonth
952952
: removedStar(info.costPerMonth)));
953953

954-
const auto costTotalEntry = [&] {
955-
if (!info.costTotal.startsWith(kStar)) {
954+
const auto costPerYearEntry = [&] {
955+
if (!info.costPerYear.startsWith(kStar)) {
956956
return QImage();
957957
}
958-
const auto text = removedStar(info.costTotal);
959-
const auto icon = GenerateStars(costTotalFont->height, 1);
958+
const auto text = removedStar(info.costPerYear);
959+
const auto icon = GenerateStars(costPerYearFont->height, 1);
960960
auto result = QImage(
961-
QSize(costTotalFont->spacew + costTotalFont->width(text), 0)
961+
QSize(costPerYearFont->spacew + costPerYearFont->width(text), 0)
962962
* style::DevicePixelRatio()
963963
+ icon.size(),
964964
QImage::Format_ARGB32_Premultiplied);
@@ -968,8 +968,8 @@ void AddGiftOptions(
968968
auto p = QPainter(&result);
969969
p.drawImage(0, 0, icon);
970970
p.setPen(st::windowSubTextFg);
971-
p.setFont(costTotalFont);
972-
auto copy = info.costTotal;
971+
p.setFont(costPerYearFont);
972+
auto copy = info.costPerYear;
973973
p.drawText(
974974
Rect(result.size() / style::DevicePixelRatio()),
975975
text,
@@ -1077,12 +1077,12 @@ void AddGiftOptions(
10771077
: (costPerMonthFont->spacew
10781078
+ costPerMonthIcon.width()
10791079
/ style::DevicePixelRatio());
1080-
const auto costTotalWidth = costTotalFont->width(
1081-
info.costTotal);
1080+
const auto costPerYearWidth = costPerYearFont->width(
1081+
info.costPerYear);
10821082
const auto pos = perRect.translated(left, 0).topLeft();
10831083
const auto availableWidth = row->width()
10841084
- pos.x()
1085-
- costTotalWidth;
1085+
- costPerYearWidth;
10861086
costPerMonthLabel->draw(p, {
10871087
.position = pos,
10881088
.outerWidth = availableWidth,
@@ -1094,16 +1094,16 @@ void AddGiftOptions(
10941094

10951095
const auto totalRect = row->rect()
10961096
- QMargins(0, 0, st.rowMargins.right(), 0);
1097-
if (costTotalEntry.isNull()) {
1098-
p.setFont(costTotalFont);
1099-
p.drawText(totalRect, info.costTotal, style::al_right);
1097+
if (costPerYearEntry.isNull()) {
1098+
p.setFont(costPerYearFont);
1099+
p.drawText(totalRect, info.costPerYear, style::al_right);
11001100
} else {
1101-
const auto size = costTotalEntry.size()
1101+
const auto size = costPerYearEntry.size()
11021102
/ style::DevicePixelRatio();
11031103
p.drawImage(
11041104
totalRect.width() - size.width(),
11051105
(row->height() - size.height()) / 2,
1106-
costTotalEntry);
1106+
costPerYearEntry);
11071107
}
11081108
}, row->lifetime());
11091109

0 commit comments

Comments
 (0)