diff --git a/Telegram/Resources/langs/lang.strings b/Telegram/Resources/langs/lang.strings index 9737221623..7cc78f5377 100644 --- a/Telegram/Resources/langs/lang.strings +++ b/Telegram/Resources/langs/lang.strings @@ -2773,6 +2773,11 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL "lng_credits_summary_title" = "Telegram Stars"; "lng_credits_summary_about" = "Buy Stars to unlock content and services in miniapps on Telegram."; +"lng_credits_currency_summary_title" = "TON Balance"; +"lng_credits_currency_summary_about" = "Offer TON to submit post suggestions to channels on Telegram."; +"lng_credits_currency_summary_subtitle" = "You can withdraw your TON using Fragment."; +"lng_credits_currency_summary_in_button" = "Top-up via Fragment"; +"lng_credits_currency_summary_in_subtitle" = "You can top-up your TON balance via Fragment."; "lng_credits_summary_options_subtitle" = "Choose package"; "lng_credits_summary_options_credits#one" = "{count} Star"; "lng_credits_summary_options_credits#other" = "{count} Stars"; @@ -2857,6 +2862,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL "lng_credits_box_history_entry_gift_examples" = "Examples"; "lng_credits_box_history_entry_ads" = "Ads Platform"; "lng_credits_box_history_entry_premium_bot" = "Stars Top-Up"; +"lng_credits_box_history_entry_currency_in" = "TON Top-Up"; "lng_credits_box_history_entry_api" = "Paid Broadcast"; "lng_credits_box_history_entry_floodskip_about#one" = "{count} Message"; "lng_credits_box_history_entry_floodskip_about#other" = "{count} Messages"; diff --git a/Telegram/SourceFiles/settings/settings_credits.cpp b/Telegram/SourceFiles/settings/settings_credits.cpp index c275075265..688cca122e 100644 --- a/Telegram/SourceFiles/settings/settings_credits.cpp +++ b/Telegram/SourceFiles/settings/settings_credits.cpp @@ -22,6 +22,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL #include "info/bot/starref/info_bot_starref_common.h" #include "info/bot/starref/info_bot_starref_join_widget.h" #include "info/channel_statistics/boosts/giveaway/boost_badge.h" // InfiniteRadialAnimationWidget. +#include "info/channel_statistics/earn/earn_icons.h" #include "info/settings/info_settings_widget.h" // SectionCustomTopBarData. #include "info/statistics/info_statistics_list_controllers.h" #include "info/info_memento.h" @@ -46,6 +47,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL #include "ui/wrap/slide_wrap.h" #include "ui/wrap/vertical_layout.h" #include "window/window_session_controller.h" +#include "styles/style_chat.h" #include "styles/style_chat_helpers.h" #include "styles/style_credits.h" #include "styles/style_giveaway.h" @@ -63,7 +65,8 @@ class Credits : public Section { public: Credits( QWidget *parent, - not_null controller); + not_null controller, + CreditsType type); [[nodiscard]] rpl::producer title() override; @@ -83,6 +86,7 @@ private: void setupHistory(not_null container); void setupSubscriptions(not_null container); const not_null _controller; + const CreditsType _creditsType; QWidget *_parent = nullptr; @@ -103,11 +107,17 @@ private: Credits::Credits( QWidget *parent, - not_null controller) + not_null controller, + CreditsType type) : Section(parent) , _controller(controller) +, _creditsType(type) , _star(Ui::GenerateStars(st::creditsTopupButton.height, 1)) -, _balanceStar(Ui::GenerateStars(st::creditsBalanceStarHeight, 1)) { +, _balanceStar((_creditsType == CreditsType::Ton) + ? Ui::Earn::IconCurrencyColored( + st::tonFieldIconSize, + st::windowActiveTextFg->c) + : Ui::GenerateStars(st::creditsBalanceStarHeight, 1)) { setupContent(); _controller->session().premiumPossibleValue( @@ -119,6 +129,9 @@ Credits::Credits( } rpl::producer Credits::title() { + if (_creditsType == CreditsType::Ton) { + return tr::lng_credits_currency_summary_title(); + } return tr::lng_premium_summary_title(); } @@ -387,6 +400,7 @@ void Credits::setupHistory(not_null container) { void Credits::setupContent() { const auto content = Ui::CreateChild(this); + const auto isCurrency = _creditsType == CreditsType::Ton; const auto paid = [=] { if (_parent) { Ui::StartFireworks(_parent); @@ -436,13 +450,21 @@ void Credits::setupContent() { rpl::conditional( state->buyStars.loadingValue(), rpl::single(TextWithEntities()), - tr::lng_credits_topup_button( - lt_emoji, - rpl::single(Ui::Text::SingleCustomEmoji(u"+"_q)), - Ui::Text::WithEntities))); + isCurrency + ? tr::lng_credits_currency_summary_in_button( + Ui::Text::WithEntities) + : tr::lng_credits_topup_button( + lt_emoji, + rpl::single(Ui::Text::SingleCustomEmoji(u"+"_q)), + Ui::Text::WithEntities))); button->setTextTransform(Ui::RoundButton::TextTransform::NoTransform); const auto show = _controller->uiShow(); - button->setClickedCallback(state->buyStars.handler(show, paid)); + if (isCurrency) { + const auto url = tr::lng_suggest_low_ton_fragment_url(tr::now); + button->setClickedCallback([=] { UrlClickHandler::Open(url); }); + } else { + button->setClickedCallback(state->buyStars.handler(show, paid)); + } { using namespace Info::Statistics; const auto loadingAnimation = InfiniteRadialAnimationWidget( @@ -462,8 +484,16 @@ void Credits::setupContent() { const auto height = textSt.style.font->height; auto customEmojiFactory = [=](const auto &...) { return std::make_unique( - Ui::MakeCreditsIconEmoji(height, 1), - QPoint(-st::lineWidth, st::lineWidth)); + isCurrency + ? std::make_unique( + Ui::Earn::IconCurrencyColored( + st::tonFieldIconSize, + st::windowActiveTextFg->c), + u"currency_icon:%1"_q.arg(height)) + : Ui::MakeCreditsIconEmoji(height, 1), + isCurrency + ? QPoint(0, st::lineWidth * 2) + : QPoint(-st::lineWidth, st::lineWidth)); }; return { .customEmojiFactory = std::move(customEmojiFactory) }; }(); @@ -476,7 +506,9 @@ void Credits::setupContent() { lt_emoji, rpl::single(Ui::MakeCreditsIconEntity()), lt_amount, - _controller->session().credits().balanceValue( + (isCurrency + ? _controller->session().credits().tonBalanceValue() + : _controller->session().credits().balanceValue() ) | rpl::map( Lang::FormatCreditsAmountDecimal ) | rpl::map(Ui::Text::Bold), @@ -489,12 +521,18 @@ void Credits::setupContent() { Ui::AddSkip(content); Ui::AddSkip(content); - Ui::AddDivider(content); + if (isCurrency) { + Ui::AddDividerText( + content, + tr::lng_credits_currency_summary_in_subtitle()); + } else { + Ui::AddDivider(content); + } Ui::AddSkip(content, st::lineWidth * 4); const auto controller = _controller->parentController(); const auto self = _controller->session().user(); - { + if (!isCurrency) { const auto wrap = content->add( object_ptr>( content, @@ -511,15 +549,17 @@ void Credits::setupContent() { return _controller->session().credits().statsEnabled(); })); } - AddButtonWithIcon( - content, - tr::lng_credits_gift_button(), - st::settingsCreditsButton, - { &st::settingsButtonIconGift })->setClickedCallback([=] { - Ui::ShowGiftCreditsBox(controller, paid); - }); + if (!isCurrency) { + AddButtonWithIcon( + content, + tr::lng_credits_gift_button(), + st::settingsCreditsButton, + { &st::settingsButtonIconGift })->setClickedCallback([=] { + Ui::ShowGiftCreditsBox(controller, paid); + }); + } - if (Info::BotStarRef::Join::Allowed(self)) { + if (!isCurrency && Info::BotStarRef::Join::Allowed(self)) { AddButtonWithIcon( content, tr::lng_credits_earn_button(), @@ -529,10 +569,12 @@ void Credits::setupContent() { }); } - Ui::AddSkip(content, st::lineWidth * 4); - Ui::AddDivider(content); + if (!isCurrency) { + Ui::AddSkip(content, st::lineWidth * 4); + Ui::AddDivider(content); - setupSubscriptions(content); + setupSubscriptions(content); + } setupHistory(content); Ui::ResizeFitChild(this, content); @@ -541,6 +583,7 @@ void Credits::setupContent() { QPointer Credits::createPinnedToTop( not_null parent) { _parent = parent; + const auto isCurrency = _creditsType == CreditsType::Ton; const auto content = [&]() -> Ui::Premium::TopBarAbstract* { const auto weak = base::make_weak(_controller); @@ -555,10 +598,13 @@ QPointer Credits::createPinnedToTop( st::creditsPremiumCover, Ui::Premium::TopBarDescriptor{ .clickContextOther = clickContextOther, - .title = tr::lng_credits_summary_title(), - .about = tr::lng_credits_summary_about( - TextWithEntities::Simple), + .title = title(), + .about = (isCurrency + ? tr::lng_credits_currency_summary_about + : tr::lng_credits_summary_about)( + TextWithEntities::Simple), .light = true, + .logo = isCurrency ? u"diamond"_q : QString(), .gradientStops = Ui::Premium::CreditsIconGradientStops(), }); }(); @@ -589,7 +635,9 @@ QPointer Credits::createPinnedToTop( const auto balance = AddBalanceWidget( content, &_controller->session(), - _controller->session().credits().balanceValue(), + isCurrency + ? _controller->session().credits().tonBalanceValue() + : _controller->session().credits().balanceValue(), true, content->heightValue() | rpl::map([=](int height) { const auto ratio = float64(height - content->minimumHeight()) @@ -658,6 +706,9 @@ void Credits::showFinished() { _showFinished.fire({}); } +class Currency { +}; + } // namespace template <> @@ -668,7 +719,27 @@ struct SectionFactory : AbstractSectionFactory { not_null scroll, rpl::producer containerValue ) const final override { - return object_ptr(parent, controller); + return object_ptr(parent, controller, CreditsType::Stars); + } + bool hasCustomTopBar() const final override { + return true; + } + + [[nodiscard]] static const std::shared_ptr &Instance() { + static const auto result = std::make_shared(); + return result; + } +}; + +template <> +struct SectionFactory : AbstractSectionFactory { + object_ptr create( + not_null parent, + not_null controller, + not_null scroll, + rpl::producer containerValue + ) const final override { + return object_ptr(parent, controller, CreditsType::Ton); } bool hasCustomTopBar() const final override { return true; @@ -684,6 +755,10 @@ Type CreditsId() { return Credits::Id(); } +Type CurrencyId() { + return SectionFactory::Instance(); +} + BuyStarsHandler::BuyStarsHandler() = default; BuyStarsHandler::~BuyStarsHandler() = default; diff --git a/Telegram/SourceFiles/settings/settings_credits.h b/Telegram/SourceFiles/settings/settings_credits.h index 27692cd3d4..63ebae985f 100644 --- a/Telegram/SourceFiles/settings/settings_credits.h +++ b/Telegram/SourceFiles/settings/settings_credits.h @@ -20,6 +20,7 @@ class SessionShow; namespace Settings { [[nodiscard]] Type CreditsId(); +[[nodiscard]] Type CurrencyId(); class BuyStarsHandler final : public base::has_weak_ptr { public: