diff --git a/Telegram/Resources/langs/lang.strings b/Telegram/Resources/langs/lang.strings index 924481f4b..02a263f42 100644 --- a/Telegram/Resources/langs/lang.strings +++ b/Telegram/Resources/langs/lang.strings @@ -5201,6 +5201,8 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL "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_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_send_message" = "message"; diff --git a/Telegram/SourceFiles/api/api_earn.cpp b/Telegram/SourceFiles/api/api_earn.cpp index d6425ef69..724fbc28c 100644 --- a/Telegram/SourceFiles/api/api_earn.cpp +++ b/Telegram/SourceFiles/api/api_earn.cpp @@ -34,16 +34,21 @@ void RestrictSponsored( } void HandleWithdrawalButton( - not_null channel, + RewardReceiver receiver, not_null button, std::shared_ptr show) { + Expects(receiver.currencyReceiver + || (receiver.creditsReceiver && receiver.creditsAmount)); struct State { rpl::lifetime lifetime; bool loading = false; }; + const auto channel = receiver.currencyReceiver; + const auto peer = receiver.creditsReceiver; + const auto state = button->lifetime().make_state(); - const auto session = &channel->session(); + const auto session = (channel ? &channel->session() : &peer->session()); session->api().cloudPassword().reload(); button->setClickedCallback([=] { @@ -58,10 +63,12 @@ void HandleWithdrawalButton( state->loading = false; auto fields = PasscodeBox::CloudFields::From(pass); - fields.customTitle - = tr::lng_channel_earn_balance_password_title(); - fields.customDescription - = tr::lng_channel_earn_balance_password_description(tr::now); + fields.customTitle = channel + ? tr::lng_channel_earn_balance_password_title() + : tr::lng_bot_earn_balance_password_title(); + 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.customCheckCallback = crl::guard(button, [=]( const Core::CloudPasswordResult &result, @@ -77,15 +84,30 @@ void HandleWithdrawalButton( const auto fail = [=](const QString &error) { show->showToast(error); }; - session->api().request( - MTPstats_GetBroadcastRevenueWithdrawalUrl( - channel->inputChannel, - result.result - )).done([=](const MTPstats_BroadcastRevenueWithdrawalUrl &r) { - done(qs(r.data().vurl())); - }).fail([=](const MTP::Error &error) { - fail(error.type()); - }).send(); + if (channel) { + session->api().request( + MTPstats_GetBroadcastRevenueWithdrawalUrl( + channel->inputChannel, + result.result + )).done([=]( + const MTPstats_BroadcastRevenueWithdrawalUrl &r) { + done(qs(r.data().vurl())); + }).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(session, fields)); }); diff --git a/Telegram/SourceFiles/api/api_earn.h b/Telegram/SourceFiles/api/api_earn.h index 93f2bf6eb..cbee5d25a 100644 --- a/Telegram/SourceFiles/api/api_earn.h +++ b/Telegram/SourceFiles/api/api_earn.h @@ -21,8 +21,14 @@ void RestrictSponsored( bool restricted, Fn failed); +struct RewardReceiver final { + ChannelData *currencyReceiver = nullptr; + PeerData *creditsReceiver = nullptr; + Fn creditsAmount; +}; + void HandleWithdrawalButton( - not_null channel, + RewardReceiver receiver, not_null button, std::shared_ptr show); diff --git a/Telegram/SourceFiles/info/channel_statistics/earn/info_earn_inner_widget.cpp b/Telegram/SourceFiles/info/channel_statistics/earn/info_earn_inner_widget.cpp index f33f93ea3..4516135ae 100644 --- a/Telegram/SourceFiles/info/channel_statistics/earn/info_earn_inner_widget.cpp +++ b/Telegram/SourceFiles/info/channel_statistics/earn/info_earn_inner_widget.cpp @@ -714,7 +714,10 @@ void InnerWidget::fill() { !withdrawalEnabled); #endif - Api::HandleWithdrawalButton(channel, button, _controller->uiShow()); + Api::HandleWithdrawalButton( + { .currencyReceiver = channel }, + button, + _controller->uiShow()); Ui::ToggleChildrenVisibility(button, true); Ui::AddSkip(container);