From 96951576c179b5d19e2eabd9a6591a6941ebb21a Mon Sep 17 00:00:00 2001 From: 23rd <23rd@vivaldi.net> Date: Mon, 30 Jun 2025 11:57:16 +0300 Subject: [PATCH] Fixed credits display in statistic charts. --- Telegram/SourceFiles/api/api_statistics.cpp | 1 - Telegram/SourceFiles/data/components/credits.cpp | 2 +- Telegram/SourceFiles/data/data_channel.cpp | 4 +++- Telegram/SourceFiles/data/data_user.cpp | 4 +++- .../earn/info_channel_earn_list.cpp | 4 +--- .../info/profile/info_profile_actions.cpp | 4 +++- .../statistics/info_statistics_list_controllers.cpp | 1 - .../statistics/view/chart_rulers_view.cpp | 13 +++++++++---- .../statistics/widgets/point_details_widget.cpp | 5 ++--- 9 files changed, 22 insertions(+), 16 deletions(-) diff --git a/Telegram/SourceFiles/api/api_statistics.cpp b/Telegram/SourceFiles/api/api_statistics.cpp index 010d55d725..8a0e733390 100644 --- a/Telegram/SourceFiles/api/api_statistics.cpp +++ b/Telegram/SourceFiles/api/api_statistics.cpp @@ -765,7 +765,6 @@ void EarnStatistics::requestHistory( _requestId = 0; const auto nextToken = result.data().vnext_offset().value_or_empty(); - qDebug() << "next" << nextToken; const auto &tlTransactions = result.data().vhistory().value_or_empty(); diff --git a/Telegram/SourceFiles/data/components/credits.cpp b/Telegram/SourceFiles/data/components/credits.cpp index 147999dd73..0bca68827f 100644 --- a/Telegram/SourceFiles/data/components/credits.cpp +++ b/Telegram/SourceFiles/data/components/credits.cpp @@ -93,7 +93,7 @@ CreditsAmount Credits::balanceCurrency(PeerId peerId) const { const auto it = _cachedPeerCurrencyBalances.find(peerId); return (it != _cachedPeerCurrencyBalances.end()) ? it->second - : CreditsAmount(); + : CreditsAmount(0, 0, CreditsType::Ton); } rpl::producer Credits::balanceValue() const { diff --git a/Telegram/SourceFiles/data/data_channel.cpp b/Telegram/SourceFiles/data/data_channel.cpp index b067d4a5a3..dc67580df9 100644 --- a/Telegram/SourceFiles/data/data_channel.cpp +++ b/Telegram/SourceFiles/data/data_channel.cpp @@ -1475,7 +1475,9 @@ void ApplyChannelUpdate( currencyLoadLifetime->destroy(); }; currencyLoad->request() | rpl::start_with_error_done( - [=](const QString &error) { apply({}); }, + [=](const QString &error) { + apply(CreditsAmount(0, CreditsType::Ton)); + }, [=] { apply(currencyLoad->data().currentBalance); }, *currencyLoadLifetime); base::timer_once(kTimeout) | rpl::start_with_next([=] { diff --git a/Telegram/SourceFiles/data/data_user.cpp b/Telegram/SourceFiles/data/data_user.cpp index 5706b1c519..7d4f70a433 100644 --- a/Telegram/SourceFiles/data/data_user.cpp +++ b/Telegram/SourceFiles/data/data_user.cpp @@ -797,7 +797,9 @@ void ApplyUserUpdate(not_null user, const MTPDuserFull &update) { currencyLoadLifetime->destroy(); }; currencyLoad->request() | rpl::start_with_error_done( - [=](const QString &error) { apply({}); }, + [=](const QString &error) { + apply(CreditsAmount(0, CreditsType::Ton)); + }, [=] { apply(currencyLoad->data().currentBalance); }, *currencyLoadLifetime); base::timer_once(kTimeout) | rpl::start_with_next([=] { diff --git a/Telegram/SourceFiles/info/channel_statistics/earn/info_channel_earn_list.cpp b/Telegram/SourceFiles/info/channel_statistics/earn/info_channel_earn_list.cpp index b15bfc4195..5bb06e790b 100644 --- a/Telegram/SourceFiles/info/channel_statistics/earn/info_channel_earn_list.cpp +++ b/Telegram/SourceFiles/info/channel_statistics/earn/info_channel_earn_list.cpp @@ -436,9 +436,7 @@ void InnerWidget::fill() { value ) | rpl::start_with_next([=](CreditsAmount v) { label->setMarkedText( - base::duplicate(prepended) - .append(icon) - .append(QString::number(v.whole())), + base::duplicate(prepended).append(icon).append(MajorPart(v)), Core::TextContext({ .session = session })); }, label->lifetime()); }; diff --git a/Telegram/SourceFiles/info/profile/info_profile_actions.cpp b/Telegram/SourceFiles/info/profile/info_profile_actions.cpp index 9ad819c339..b9efd1b104 100644 --- a/Telegram/SourceFiles/info/profile/info_profile_actions.cpp +++ b/Telegram/SourceFiles/info/profile/info_profile_actions.cpp @@ -897,7 +897,9 @@ rpl::producer AddCurrencyAction( } }; currencyLoad->request() | rpl::start_with_error_done( - [=](const QString &error) { done({}); }, + [=](const QString &error) { + done(CreditsAmount(0, CreditsType::Ton)); + }, [=] { done(currencyLoad->data().currentBalance); }, *currencyLoadLifetime); } diff --git a/Telegram/SourceFiles/info/statistics/info_statistics_list_controllers.cpp b/Telegram/SourceFiles/info/statistics/info_statistics_list_controllers.cpp index 8bed42de68..a956b763ea 100644 --- a/Telegram/SourceFiles/info/statistics/info_statistics_list_controllers.cpp +++ b/Telegram/SourceFiles/info/statistics/info_statistics_list_controllers.cpp @@ -11,7 +11,6 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL #include "api/api_statistics.h" #include "boxes/peer_list_controllers.h" #include "boxes/peer_list_widgets.h" -#include "info/channel_statistics/earn/earn_format.h" #include "info/channel_statistics/earn/earn_icons.h" #include "info/channel_statistics/earn/earn_format.h" #include "chat_helpers/stickers_gift_box_pack.h" diff --git a/Telegram/SourceFiles/statistics/view/chart_rulers_view.cpp b/Telegram/SourceFiles/statistics/view/chart_rulers_view.cpp index fc8d98a653..0e4451f27f 100644 --- a/Telegram/SourceFiles/statistics/view/chart_rulers_view.cpp +++ b/Telegram/SourceFiles/statistics/view/chart_rulers_view.cpp @@ -7,7 +7,6 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL */ #include "statistics/view/chart_rulers_view.h" -#include "data/data_channel_earn.h" // Data::kEarnMultiplier. #include "info/channel_statistics/earn/earn_format.h" #include "lang/lang_keys.h" #include "statistics/chart_lines_filter_controller.h" @@ -42,9 +41,15 @@ void ChartRulersView::setChartData( || chartData.currencyRate; if (chartData.currencyRate) { _currencyIcon = ChartCurrencyIcon(chartData, {}); - _leftCustomCaption = [=](float64 value) { - return FormatF(value / float64(Data::kEarnMultiplier)); - }; + if (chartData.currency == Data::StatisticalCurrency::Ton) { + _leftCustomCaption = [=](float64 value) { + return FormatF(value / float64(kOneStarInNano)); + }; + } else { + _leftCustomCaption = [=](float64 value) { + return FormatF(value); + }; + } _rightCustomCaption = [=, rate = chartData.currencyRate](float64 v) { return Info::ChannelEarn::ToUsd(v, rate, 0); }; diff --git a/Telegram/SourceFiles/statistics/widgets/point_details_widget.cpp b/Telegram/SourceFiles/statistics/widgets/point_details_widget.cpp index 44f2496baa..d3f0afbdad 100644 --- a/Telegram/SourceFiles/statistics/widgets/point_details_widget.cpp +++ b/Telegram/SourceFiles/statistics/widgets/point_details_widget.cpp @@ -7,7 +7,6 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL */ #include "statistics/widgets/point_details_widget.h" -#include "data/data_channel_earn.h" // Data::kEarnMultiplier. #include "info/channel_statistics/earn/earn_format.h" #include "lang/lang_keys.h" #include "statistics/statistics_common.h" @@ -179,7 +178,7 @@ PointDetailsWidget::PointDetailsWidget( const auto maxValueTextWidth = [&] { if (hasUsdLine) { auto maxValueWidth = 0; - const auto multiplier = float64(Data::kEarnMultiplier); + const auto multiplier = float64(kOneStarInNano); for (const auto &value : _chartData.lines.front().y) { const auto valueText = Ui::Text::String( _textStyle, @@ -325,7 +324,7 @@ void PointDetailsWidget::setXIndex(int xIndex) { nullptr, { float64(xIndex), float64(xIndex) }).parts : std::vector(); - const auto multiplier = float64(Data::kEarnMultiplier); + const auto multiplier = float64(kOneStarInNano); const auto isCredits = _chartData.currency == Data::StatisticalCurrency::Credits; for (auto i = 0; i < _chartData.lines.size(); i++) {