Fixed button for currency withdrawal from bots.

This commit is contained in:
23rd 2025-05-07 10:28:54 +03:00
parent d4056ac10a
commit 54825dc66f
3 changed files with 25 additions and 19 deletions

View file

@ -46,11 +46,15 @@ void HandleWithdrawalButton(
bool loading = false;
};
const auto channel = receiver.currencyReceiver;
const auto peer = receiver.creditsReceiver;
const auto currencyReceiver = receiver.currencyReceiver;
const auto creditsReceiver = receiver.creditsReceiver;
const auto isChannel = receiver.currencyReceiver
&& receiver.currencyReceiver->isChannel();
const auto state = button->lifetime().make_state<State>();
const auto session = (channel ? &channel->session() : &peer->session());
const auto session = (currencyReceiver
? &currencyReceiver->session()
: &creditsReceiver->session());
using ChannelOutUrl = MTPstats_BroadcastRevenueWithdrawalUrl;
using CreditsOutUrl = MTPpayments_StarsRevenueWithdrawalUrl;
@ -59,7 +63,7 @@ void HandleWithdrawalButton(
const auto processOut = [=] {
if (state->loading) {
return;
} else if (peer && !receiver.creditsAmount()) {
} else if (creditsReceiver && !receiver.creditsAmount()) {
return;
}
state->loading = true;
@ -70,10 +74,10 @@ void HandleWithdrawalButton(
state->loading = false;
auto fields = PasscodeBox::CloudFields::From(pass);
fields.customTitle = channel
fields.customTitle = isChannel
? tr::lng_channel_earn_balance_password_title()
: tr::lng_bot_earn_balance_password_title();
fields.customDescription = channel
fields.customDescription = isChannel
? tr::lng_channel_earn_balance_password_description(tr::now)
: tr::lng_bot_earn_balance_password_description(tr::now);
fields.customSubmitButton = tr::lng_passcode_submit();
@ -94,18 +98,18 @@ void HandleWithdrawalButton(
show->showToast(message);
}
};
if (channel) {
if (currencyReceiver) {
session->api().request(
MTPstats_GetBroadcastRevenueWithdrawalUrl(
channel->input,
currencyReceiver->input,
result.result
)).done([=](const ChannelOutUrl &r) {
done(qs(r.data().vurl()));
}).fail(fail).send();
} else if (peer) {
} else if (creditsReceiver) {
session->api().request(
MTPpayments_GetStarsRevenueWithdrawalUrl(
peer->input,
creditsReceiver->input,
MTP_long(receiver.creditsAmount()),
result.result
)).done([=](const CreditsOutUrl &r) {
@ -134,17 +138,17 @@ void HandleWithdrawalButton(
processOut();
}
};
if (channel) {
if (currencyReceiver) {
session->api().request(
MTPstats_GetBroadcastRevenueWithdrawalUrl(
channel->input,
currencyReceiver->input,
MTP_inputCheckPasswordEmpty()
)).fail(fail).send();
} else if (peer) {
} else if (creditsReceiver) {
session->api().request(
MTPpayments_GetStarsRevenueWithdrawalUrl(
peer->input,
MTP_long(std::numeric_limits<int64_t>::max()),
creditsReceiver->input,
MTP_long(receiver.creditsAmount()),
MTP_inputCheckPasswordEmpty()
)).fail(fail).send();
}

View file

@ -22,7 +22,7 @@ void RestrictSponsored(
Fn<void(QString)> failed);
struct RewardReceiver final {
ChannelData *currencyReceiver = nullptr;
PeerData *currencyReceiver = nullptr;
PeerData *creditsReceiver = nullptr;
Fn<uint64()> creditsAmount;
};

View file

@ -850,7 +850,7 @@ void InnerWidget::fill() {
Ui::AddSkip(container);
Ui::AddDivider(container);
Ui::AddSkip(container);
if (channel && data.availableBalance) {
if (data.availableBalance) {
const auto value = data.availableBalance;
AddHeader(container, tr::lng_channel_earn_balance_title);
Ui::AddSkip(container);
@ -938,7 +938,7 @@ void InnerWidget::fill() {
#endif
Api::HandleWithdrawalButton(
{ .currencyReceiver = channel },
{ .currencyReceiver = _peer },
button,
_controller->uiShow());
Ui::ToggleChildrenVisibility(button, true);
@ -1006,7 +1006,9 @@ void InnerWidget::fill() {
not_null<Ui::VerticalLayout*> historyDividerContainer) {
const auto hasCurrencyTab
= !data.currencyEarn.firstHistorySlice.list.empty();
const auto hasCreditsTab = !data.creditsStatusSlice.list.empty();
// Credits stats for bots are available in info_bot_earn_list.
const auto hasCreditsTab = !bot
&& !data.creditsStatusSlice.list.empty();
const auto hasOneTab = (hasCurrencyTab || hasCreditsTab)
&& (hasCurrencyTab != hasCreditsTab);