mirror of
https://github.com/AyuGram/AyuGramDesktop.git
synced 2025-06-05 06:33:57 +02:00
Made withdrawal button handler in earn sections more universal.
This commit is contained in:
parent
9eebd3b514
commit
989145726d
4 changed files with 50 additions and 17 deletions
|
@ -5201,6 +5201,8 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
|
||||||
"lng_bot_earn_balance_button_locked" = "Withdraw via Fragment";
|
"lng_bot_earn_balance_button_locked" = "Withdraw via Fragment";
|
||||||
"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_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_description" = "Please enter your password to collect.";
|
||||||
|
|
||||||
"lng_contact_add" = "Add";
|
"lng_contact_add" = "Add";
|
||||||
"lng_contact_send_message" = "message";
|
"lng_contact_send_message" = "message";
|
||||||
|
|
|
@ -34,16 +34,21 @@ void RestrictSponsored(
|
||||||
}
|
}
|
||||||
|
|
||||||
void HandleWithdrawalButton(
|
void HandleWithdrawalButton(
|
||||||
not_null<ChannelData*> channel,
|
RewardReceiver receiver,
|
||||||
not_null<Ui::RippleButton*> button,
|
not_null<Ui::RippleButton*> button,
|
||||||
std::shared_ptr<Ui::Show> show) {
|
std::shared_ptr<Ui::Show> show) {
|
||||||
|
Expects(receiver.currencyReceiver
|
||||||
|
|| (receiver.creditsReceiver && receiver.creditsAmount));
|
||||||
struct State {
|
struct State {
|
||||||
rpl::lifetime lifetime;
|
rpl::lifetime lifetime;
|
||||||
bool loading = false;
|
bool loading = false;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
const auto channel = receiver.currencyReceiver;
|
||||||
|
const auto peer = receiver.creditsReceiver;
|
||||||
|
|
||||||
const auto state = button->lifetime().make_state<State>();
|
const auto state = button->lifetime().make_state<State>();
|
||||||
const auto session = &channel->session();
|
const auto session = (channel ? &channel->session() : &peer->session());
|
||||||
|
|
||||||
session->api().cloudPassword().reload();
|
session->api().cloudPassword().reload();
|
||||||
button->setClickedCallback([=] {
|
button->setClickedCallback([=] {
|
||||||
|
@ -58,10 +63,12 @@ void HandleWithdrawalButton(
|
||||||
state->loading = false;
|
state->loading = false;
|
||||||
|
|
||||||
auto fields = PasscodeBox::CloudFields::From(pass);
|
auto fields = PasscodeBox::CloudFields::From(pass);
|
||||||
fields.customTitle
|
fields.customTitle = channel
|
||||||
= tr::lng_channel_earn_balance_password_title();
|
? tr::lng_channel_earn_balance_password_title()
|
||||||
fields.customDescription
|
: tr::lng_bot_earn_balance_password_title();
|
||||||
= tr::lng_channel_earn_balance_password_description(tr::now);
|
fields.customDescription = channel
|
||||||
|
? tr::lng_channel_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();
|
||||||
fields.customCheckCallback = crl::guard(button, [=](
|
fields.customCheckCallback = crl::guard(button, [=](
|
||||||
const Core::CloudPasswordResult &result,
|
const Core::CloudPasswordResult &result,
|
||||||
|
@ -77,15 +84,30 @@ void HandleWithdrawalButton(
|
||||||
const auto fail = [=](const QString &error) {
|
const auto fail = [=](const QString &error) {
|
||||||
show->showToast(error);
|
show->showToast(error);
|
||||||
};
|
};
|
||||||
session->api().request(
|
if (channel) {
|
||||||
MTPstats_GetBroadcastRevenueWithdrawalUrl(
|
session->api().request(
|
||||||
channel->inputChannel,
|
MTPstats_GetBroadcastRevenueWithdrawalUrl(
|
||||||
result.result
|
channel->inputChannel,
|
||||||
)).done([=](const MTPstats_BroadcastRevenueWithdrawalUrl &r) {
|
result.result
|
||||||
done(qs(r.data().vurl()));
|
)).done([=](
|
||||||
}).fail([=](const MTP::Error &error) {
|
const MTPstats_BroadcastRevenueWithdrawalUrl &r) {
|
||||||
fail(error.type());
|
done(qs(r.data().vurl()));
|
||||||
}).send();
|
}).fail([=](const MTP::Error &error) {
|
||||||
|
fail(error.type());
|
||||||
|
}).send();
|
||||||
|
} else if (peer) {
|
||||||
|
session->api().request(
|
||||||
|
MTPpayments_GetStarsRevenueWithdrawalUrl(
|
||||||
|
peer->input,
|
||||||
|
MTP_long(receiver.creditsAmount()),
|
||||||
|
result.result
|
||||||
|
)).done([=](
|
||||||
|
const MTPpayments_StarsRevenueWithdrawalUrl &r) {
|
||||||
|
done(qs(r.data().vurl()));
|
||||||
|
}).fail([=](const MTP::Error &error) {
|
||||||
|
fail(error.type());
|
||||||
|
}).send();
|
||||||
|
}
|
||||||
});
|
});
|
||||||
show->show(Box<PasscodeBox>(session, fields));
|
show->show(Box<PasscodeBox>(session, fields));
|
||||||
});
|
});
|
||||||
|
|
|
@ -21,8 +21,14 @@ void RestrictSponsored(
|
||||||
bool restricted,
|
bool restricted,
|
||||||
Fn<void(QString)> failed);
|
Fn<void(QString)> failed);
|
||||||
|
|
||||||
|
struct RewardReceiver final {
|
||||||
|
ChannelData *currencyReceiver = nullptr;
|
||||||
|
PeerData *creditsReceiver = nullptr;
|
||||||
|
Fn<uint64()> creditsAmount;
|
||||||
|
};
|
||||||
|
|
||||||
void HandleWithdrawalButton(
|
void HandleWithdrawalButton(
|
||||||
not_null<ChannelData*> channel,
|
RewardReceiver receiver,
|
||||||
not_null<Ui::RippleButton*> button,
|
not_null<Ui::RippleButton*> button,
|
||||||
std::shared_ptr<Ui::Show> show);
|
std::shared_ptr<Ui::Show> show);
|
||||||
|
|
||||||
|
|
|
@ -714,7 +714,10 @@ void InnerWidget::fill() {
|
||||||
!withdrawalEnabled);
|
!withdrawalEnabled);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
Api::HandleWithdrawalButton(channel, button, _controller->uiShow());
|
Api::HandleWithdrawalButton(
|
||||||
|
{ .currencyReceiver = channel },
|
||||||
|
button,
|
||||||
|
_controller->uiShow());
|
||||||
Ui::ToggleChildrenVisibility(button, true);
|
Ui::ToggleChildrenVisibility(button, true);
|
||||||
|
|
||||||
Ui::AddSkip(container);
|
Ui::AddSkip(container);
|
||||||
|
|
Loading…
Add table
Reference in a new issue