mirror of
https://github.com/AyuGram/AyuGramDesktop.git
synced 2025-06-07 23:53:58 +02:00
Fixed button for currency withdrawal from bots.
This commit is contained in:
parent
d4056ac10a
commit
54825dc66f
3 changed files with 25 additions and 19 deletions
|
@ -46,11 +46,15 @@ void HandleWithdrawalButton(
|
||||||
bool loading = false;
|
bool loading = false;
|
||||||
};
|
};
|
||||||
|
|
||||||
const auto channel = receiver.currencyReceiver;
|
const auto currencyReceiver = receiver.currencyReceiver;
|
||||||
const auto peer = receiver.creditsReceiver;
|
const auto creditsReceiver = receiver.creditsReceiver;
|
||||||
|
const auto isChannel = receiver.currencyReceiver
|
||||||
|
&& receiver.currencyReceiver->isChannel();
|
||||||
|
|
||||||
const auto state = button->lifetime().make_state<State>();
|
const auto state = button->lifetime().make_state<State>();
|
||||||
const auto session = (channel ? &channel->session() : &peer->session());
|
const auto session = (currencyReceiver
|
||||||
|
? ¤cyReceiver->session()
|
||||||
|
: &creditsReceiver->session());
|
||||||
|
|
||||||
using ChannelOutUrl = MTPstats_BroadcastRevenueWithdrawalUrl;
|
using ChannelOutUrl = MTPstats_BroadcastRevenueWithdrawalUrl;
|
||||||
using CreditsOutUrl = MTPpayments_StarsRevenueWithdrawalUrl;
|
using CreditsOutUrl = MTPpayments_StarsRevenueWithdrawalUrl;
|
||||||
|
@ -59,7 +63,7 @@ void HandleWithdrawalButton(
|
||||||
const auto processOut = [=] {
|
const auto processOut = [=] {
|
||||||
if (state->loading) {
|
if (state->loading) {
|
||||||
return;
|
return;
|
||||||
} else if (peer && !receiver.creditsAmount()) {
|
} else if (creditsReceiver && !receiver.creditsAmount()) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
state->loading = true;
|
state->loading = true;
|
||||||
|
@ -70,10 +74,10 @@ void HandleWithdrawalButton(
|
||||||
state->loading = false;
|
state->loading = false;
|
||||||
|
|
||||||
auto fields = PasscodeBox::CloudFields::From(pass);
|
auto fields = PasscodeBox::CloudFields::From(pass);
|
||||||
fields.customTitle = channel
|
fields.customTitle = isChannel
|
||||||
? tr::lng_channel_earn_balance_password_title()
|
? tr::lng_channel_earn_balance_password_title()
|
||||||
: tr::lng_bot_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_channel_earn_balance_password_description(tr::now)
|
||||||
: tr::lng_bot_earn_balance_password_description(tr::now);
|
: tr::lng_bot_earn_balance_password_description(tr::now);
|
||||||
fields.customSubmitButton = tr::lng_passcode_submit();
|
fields.customSubmitButton = tr::lng_passcode_submit();
|
||||||
|
@ -94,18 +98,18 @@ void HandleWithdrawalButton(
|
||||||
show->showToast(message);
|
show->showToast(message);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
if (channel) {
|
if (currencyReceiver) {
|
||||||
session->api().request(
|
session->api().request(
|
||||||
MTPstats_GetBroadcastRevenueWithdrawalUrl(
|
MTPstats_GetBroadcastRevenueWithdrawalUrl(
|
||||||
channel->input,
|
currencyReceiver->input,
|
||||||
result.result
|
result.result
|
||||||
)).done([=](const ChannelOutUrl &r) {
|
)).done([=](const ChannelOutUrl &r) {
|
||||||
done(qs(r.data().vurl()));
|
done(qs(r.data().vurl()));
|
||||||
}).fail(fail).send();
|
}).fail(fail).send();
|
||||||
} else if (peer) {
|
} else if (creditsReceiver) {
|
||||||
session->api().request(
|
session->api().request(
|
||||||
MTPpayments_GetStarsRevenueWithdrawalUrl(
|
MTPpayments_GetStarsRevenueWithdrawalUrl(
|
||||||
peer->input,
|
creditsReceiver->input,
|
||||||
MTP_long(receiver.creditsAmount()),
|
MTP_long(receiver.creditsAmount()),
|
||||||
result.result
|
result.result
|
||||||
)).done([=](const CreditsOutUrl &r) {
|
)).done([=](const CreditsOutUrl &r) {
|
||||||
|
@ -134,17 +138,17 @@ void HandleWithdrawalButton(
|
||||||
processOut();
|
processOut();
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
if (channel) {
|
if (currencyReceiver) {
|
||||||
session->api().request(
|
session->api().request(
|
||||||
MTPstats_GetBroadcastRevenueWithdrawalUrl(
|
MTPstats_GetBroadcastRevenueWithdrawalUrl(
|
||||||
channel->input,
|
currencyReceiver->input,
|
||||||
MTP_inputCheckPasswordEmpty()
|
MTP_inputCheckPasswordEmpty()
|
||||||
)).fail(fail).send();
|
)).fail(fail).send();
|
||||||
} else if (peer) {
|
} else if (creditsReceiver) {
|
||||||
session->api().request(
|
session->api().request(
|
||||||
MTPpayments_GetStarsRevenueWithdrawalUrl(
|
MTPpayments_GetStarsRevenueWithdrawalUrl(
|
||||||
peer->input,
|
creditsReceiver->input,
|
||||||
MTP_long(std::numeric_limits<int64_t>::max()),
|
MTP_long(receiver.creditsAmount()),
|
||||||
MTP_inputCheckPasswordEmpty()
|
MTP_inputCheckPasswordEmpty()
|
||||||
)).fail(fail).send();
|
)).fail(fail).send();
|
||||||
}
|
}
|
||||||
|
|
|
@ -22,7 +22,7 @@ void RestrictSponsored(
|
||||||
Fn<void(QString)> failed);
|
Fn<void(QString)> failed);
|
||||||
|
|
||||||
struct RewardReceiver final {
|
struct RewardReceiver final {
|
||||||
ChannelData *currencyReceiver = nullptr;
|
PeerData *currencyReceiver = nullptr;
|
||||||
PeerData *creditsReceiver = nullptr;
|
PeerData *creditsReceiver = nullptr;
|
||||||
Fn<uint64()> creditsAmount;
|
Fn<uint64()> creditsAmount;
|
||||||
};
|
};
|
||||||
|
|
|
@ -850,7 +850,7 @@ void InnerWidget::fill() {
|
||||||
Ui::AddSkip(container);
|
Ui::AddSkip(container);
|
||||||
Ui::AddDivider(container);
|
Ui::AddDivider(container);
|
||||||
Ui::AddSkip(container);
|
Ui::AddSkip(container);
|
||||||
if (channel && data.availableBalance) {
|
if (data.availableBalance) {
|
||||||
const auto value = data.availableBalance;
|
const auto value = data.availableBalance;
|
||||||
AddHeader(container, tr::lng_channel_earn_balance_title);
|
AddHeader(container, tr::lng_channel_earn_balance_title);
|
||||||
Ui::AddSkip(container);
|
Ui::AddSkip(container);
|
||||||
|
@ -938,7 +938,7 @@ void InnerWidget::fill() {
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
Api::HandleWithdrawalButton(
|
Api::HandleWithdrawalButton(
|
||||||
{ .currencyReceiver = channel },
|
{ .currencyReceiver = _peer },
|
||||||
button,
|
button,
|
||||||
_controller->uiShow());
|
_controller->uiShow());
|
||||||
Ui::ToggleChildrenVisibility(button, true);
|
Ui::ToggleChildrenVisibility(button, true);
|
||||||
|
@ -1006,7 +1006,9 @@ void InnerWidget::fill() {
|
||||||
not_null<Ui::VerticalLayout*> historyDividerContainer) {
|
not_null<Ui::VerticalLayout*> historyDividerContainer) {
|
||||||
const auto hasCurrencyTab
|
const auto hasCurrencyTab
|
||||||
= !data.currencyEarn.firstHistorySlice.list.empty();
|
= !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)
|
const auto hasOneTab = (hasCurrencyTab || hasCreditsTab)
|
||||||
&& (hasCurrencyTab != hasCreditsTab);
|
&& (hasCurrencyTab != hasCreditsTab);
|
||||||
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue