Added initial entry point for self statistics of credits.

This commit is contained in:
23rd 2025-06-05 17:14:28 +03:00
parent 759258bb39
commit 067dcbfbeb
6 changed files with 116 additions and 49 deletions

View file

@ -2780,6 +2780,8 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
"lng_credits_more_options" = "More Options"; "lng_credits_more_options" = "More Options";
"lng_credits_balance_me" = "your balance"; "lng_credits_balance_me" = "your balance";
"lng_credits_buy_button" = "Buy More Stars"; "lng_credits_buy_button" = "Buy More Stars";
"lng_credits_buy_button_short" = "Top Up";
"lng_credits_stats_button_short" = "Stats";
"lng_credits_gift_button" = "Gift Stars to Friends"; "lng_credits_gift_button" = "Gift Stars to Friends";
"lng_credits_box_out_title" = "Confirm Your Purchase"; "lng_credits_box_out_title" = "Confirm Your Purchase";
"lng_credits_box_out_sure#one" = "Do you want to buy **\"{text}\"** in **{bot}** for **{count} Star**?"; "lng_credits_box_out_sure#one" = "Do you want to buy **\"{text}\"** in **{bot}** for **{count} Star**?";
@ -6431,6 +6433,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
"lng_bot_earn_balance_button_locked" = "Withdraw"; "lng_bot_earn_balance_button_locked" = "Withdraw";
"lng_bot_earn_balance_button_buy_ads" = "Buy Ads"; "lng_bot_earn_balance_button_buy_ads" = "Buy Ads";
"lng_bot_earn_learn_credits_out_about" = "You can withdraw Stars using Fragment, or use Stars to advertise your bot. {link}"; "lng_bot_earn_learn_credits_out_about" = "You can withdraw Stars using Fragment, or use Stars to advertise your bot. {link}";
"lng_self_earn_learn_credits_out_about" = "You can withdraw from 10 Stars using Fragment. {link}";
"lng_bot_earn_out_ph" = "Enter amount to withdraw"; "lng_bot_earn_out_ph" = "Enter amount to withdraw";
"lng_bot_earn_balance_password_title" = "Two-step verification"; "lng_bot_earn_balance_password_title" = "Two-step verification";
"lng_bot_earn_balance_password_description" = "Please enter your password to collect."; "lng_bot_earn_balance_password_description" = "Please enter your password to collect.";

View file

@ -128,6 +128,13 @@ void InnerWidget::fill() {
return _state.availableBalance; return _state.availableBalance;
}) })
); );
auto overallBalanceValue = rpl::single(
data.overallRevenue
) | rpl::then(
_stateUpdated.events() | rpl::map([=] {
return _state.overallRevenue;
})
);
auto valueToString = [](StarsAmount v) { auto valueToString = [](StarsAmount v) {
return Lang::FormatStarsAmountDecimal(v); return Lang::FormatStarsAmountDecimal(v);
}; };
@ -211,13 +218,7 @@ void InnerWidget::fill() {
Ui::AddSkip(container); Ui::AddSkip(container);
Ui::AddSkip(container); Ui::AddSkip(container);
addOverview( addOverview(
rpl::single( rpl::duplicate(overallBalanceValue),
data.overallRevenue
) | rpl::then(
_stateUpdated.events() | rpl::map([=] {
return _state.overallRevenue;
})
),
tr::lng_bot_earn_total); tr::lng_bot_earn_total);
Ui::AddSkip(container); Ui::AddSkip(container);
Ui::AddSkip(container); Ui::AddSkip(container);
@ -245,17 +246,20 @@ void InnerWidget::fill() {
return _state.buyAdsUrl; return _state.buyAdsUrl;
}) })
), ),
rpl::duplicate(availableBalanceValue), peer()->isSelf()
? rpl::duplicate(overallBalanceValue)
: rpl::duplicate(availableBalanceValue),
rpl::duplicate(dateValue), rpl::duplicate(dateValue),
_state.isWithdrawalEnabled, _state.isWithdrawalEnabled,
rpl::duplicate( (peer()->isSelf()
availableBalanceValue ? rpl::duplicate(overallBalanceValue)
: rpl::duplicate(availableBalanceValue)
) | rpl::map([=](StarsAmount v) { ) | rpl::map([=](StarsAmount v) {
return v ? ToUsd(v, multiplier, kMinorLength) : QString(); return v ? ToUsd(v, multiplier, kMinorLength) : QString();
})); }));
container->resizeToWidth(container->width()); container->resizeToWidth(container->width());
} }
if (BotStarRef::Join::Allowed(peer())) { if (BotStarRef::Join::Allowed(peer()) && !peer()->isSelf()) {
const auto button = BotStarRef::AddViewListButton( const auto button = BotStarRef::AddViewListButton(
container, container,
tr::lng_credits_summary_earn_title(), tr::lng_credits_summary_earn_title(),
@ -267,7 +271,9 @@ void InnerWidget::fill() {
Ui::AddSkip(container); Ui::AddSkip(container);
Ui::AddDivider(container); Ui::AddDivider(container);
} }
fillHistory(); if (!peer()->isSelf()) {
fillHistory();
}
} }
void InnerWidget::fillHistory() { void InnerWidget::fillHistory() {

View file

@ -696,3 +696,12 @@ settingsGiftIconEmoji: IconEmoji {
icon: icon{{ "settings/mini_gift", windowFg }}; icon: icon{{ "settings/mini_gift", windowFg }};
padding: margins(1px, 2px, 1px, 0px); padding: margins(1px, 2px, 1px, 0px);
} }
settingsCreditsButtonBuy: RoundButton(inviteLinkCopy) {
icon: icon {{ "settings/add", activeButtonFg, point(0px, 7px) }};
iconOver: icon {{ "settings/add", activeButtonFgOver, point(0px, 7px) }};
}
settingsCreditsButtonStats: RoundButton(inviteLinkCopy) {
icon: icon {{ "info/edit/links_share", activeButtonFg }};
iconOver: icon {{ "info/edit/links_share", activeButtonFgOver }};
}

View file

@ -123,7 +123,11 @@ not_null<Button*> AddButtonWithIcon(
const style::SettingsButton &st, const style::SettingsButton &st,
IconDescriptor &&descriptor) { IconDescriptor &&descriptor) {
return container->add( return container->add(
CreateButtonWithIcon(container, std::move(text), st, std::move(descriptor))); CreateButtonWithIcon(
container,
std::move(text),
st,
std::move(descriptor)));
} }
void CreateRightLabel( void CreateRightLabel(

View file

@ -18,6 +18,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
#include "data/data_photo_media.h" #include "data/data_photo_media.h"
#include "data/data_session.h" #include "data/data_session.h"
#include "data/data_user.h" #include "data/data_user.h"
#include "info/bot/earn/info_bot_earn_widget.h"
#include "info/bot/starref/info_bot_starref_common.h" #include "info/bot/starref/info_bot_starref_common.h"
#include "info/bot/starref/info_bot_starref_join_widget.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/boosts/giveaway/boost_badge.h" // InfiniteRadialAnimationWidget.
@ -433,32 +434,74 @@ void Credits::setupContent() {
}; };
const auto state = content->lifetime().make_state<State>(); const auto state = content->lifetime().make_state<State>();
const auto button = content->add(
object_ptr<Ui::RoundButton>(
content,
rpl::conditional(
state->buyStars.loadingValue(),
rpl::single(QString()),
tr::lng_credits_buy_button()),
st::creditsSettingsBigBalanceButton),
st::boxRowPadding);
button->setTextTransform(Ui::RoundButton::TextTransform::NoTransform);
const auto show = _controller->uiShow();
button->setClickedCallback(state->buyStars.handler(show, paid));
{
using namespace Info::Statistics;
const auto loadingAnimation = InfiniteRadialAnimationWidget(
button,
button->height() / 2);
AddChildToWidgetCenter(button, loadingAnimation);
loadingAnimation->showOn(state->buyStars.loadingValue());
}
const auto paddings = rect::m::sum::h(st::boxRowPadding); const auto paddings = rect::m::sum::h(st::boxRowPadding);
button->widthValue() | rpl::filter([=] { if (!_controller->session().credits().statsEnabled()) {
return (button->widthNoMargins() != (content->width() - paddings)); const auto button = content->add(
}) | rpl::start_with_next([=] { object_ptr<Ui::RoundButton>(
button->resizeToWidth(content->width() - paddings); content,
}, button->lifetime()); rpl::conditional(
state->buyStars.loadingValue(),
rpl::single(QString()),
tr::lng_credits_buy_button()),
st::creditsSettingsBigBalanceButton),
st::boxRowPadding);
button->setTextTransform(Ui::RoundButton::TextTransform::NoTransform);
const auto show = _controller->uiShow();
button->setClickedCallback(state->buyStars.handler(show, paid));
{
using namespace Info::Statistics;
const auto loadingAnimation = InfiniteRadialAnimationWidget(
button,
button->height() / 2);
AddChildToWidgetCenter(button, loadingAnimation);
loadingAnimation->showOn(state->buyStars.loadingValue());
}
button->widthValue() | rpl::filter([=] {
return button->widthNoMargins() != (content->width() - paddings);
}) | rpl::start_with_next([=] {
button->resizeToWidth(content->width() - paddings);
}, button->lifetime());
} else {
const auto wrap = content->add(
object_ptr<Ui::FixedHeightWidget>(
content,
st::inviteLinkButton.height),
st::boxRowPadding);
const auto buy = Ui::CreateChild<Ui::RoundButton>(
wrap,
tr::lng_credits_buy_button_short(),
st::settingsCreditsButtonBuy);
buy->setTextTransform(Ui::RoundButton::TextTransform::NoTransform);
const auto show = _controller->uiShow();
buy->setClickedCallback(state->buyStars.handler(show, paid));
{
using namespace Info::Statistics;
const auto loadingAnimation = InfiniteRadialAnimationWidget(
buy,
buy->height() / 2);
AddChildToWidgetCenter(buy, loadingAnimation);
loadingAnimation->showOn(state->buyStars.loadingValue());
}
const auto stats = Ui::CreateChild<Ui::RoundButton>(
wrap,
tr::lng_credits_stats_button_short(),
st::settingsCreditsButtonStats);
stats->setTextTransform(Ui::RoundButton::TextTransform::NoTransform);
const auto self = _controller->session().user();
const auto controller = _controller->parentController();
stats->setClickedCallback([=] {
controller->showSection(Info::BotEarn::Make(self));
});
wrap->widthValue(
) | rpl::start_with_next([=](int width) {
const auto buttonWidth = (width - st::inviteLinkButtonsSkip) / 2;
buy->setFullWidth(buttonWidth);
stats->setFullWidth(buttonWidth);
buy->moveToLeft(0, 0, width);
stats->moveToRight(0, 0, width);
}, wrap->lifetime());
}
Ui::AddSkip(content); Ui::AddSkip(content);

View file

@ -2789,17 +2789,19 @@ void AddWithdrawalWidget(
const auto arrow = Ui::Text::IconEmoji(&st::textMoreIconEmoji); const auto arrow = Ui::Text::IconEmoji(&st::textMoreIconEmoji);
auto about = Ui::CreateLabelWithCustomEmoji( auto about = Ui::CreateLabelWithCustomEmoji(
container, container,
tr::lng_bot_earn_learn_credits_out_about( (peer->isSelf()
lt_link, ? tr::lng_self_earn_learn_credits_out_about
tr::lng_channel_earn_about_link( : tr::lng_bot_earn_learn_credits_out_about)(
lt_emoji, lt_link,
rpl::single(arrow), tr::lng_channel_earn_about_link(
Ui::Text::RichLangValue lt_emoji,
) | rpl::map([](TextWithEntities text) { rpl::single(arrow),
return Ui::Text::Link( Ui::Text::RichLangValue
std::move(text), ) | rpl::map([](TextWithEntities text) {
tr::lng_bot_earn_balance_about_url(tr::now)); return Ui::Text::Link(
}), std::move(text),
tr::lng_bot_earn_balance_about_url(tr::now));
}),
Ui::Text::RichLangValue), Ui::Text::RichLangValue),
Core::TextContext({ .session = session }), Core::TextContext({ .session = session }),
st::boxDividerLabel); st::boxDividerLabel);