Respected accessibility of premium for credits purchasing.

This commit is contained in:
23rd 2024-05-28 16:28:35 +03:00 committed by John Preston
parent 9a5923676a
commit cd7507fb23
3 changed files with 23 additions and 6 deletions

View File

@ -2328,6 +2328,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
"lng_credits_small_balance_title#one" = "{count} Star Needed";
"lng_credits_small_balance_title#other" = "{count} Stars Needed";
"lng_credits_small_balance_about" = "Buy **Stars** and use them on **{bot}** and other miniapps.";
"lng_credits_purchase_blocked" = "Sorry, you can't purchase this item with Telegram Stars.";
"lng_location_title" = "Location";
"lng_location_about" = "Display the location of your business on your account.";

View File

@ -15,6 +15,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
#include "data/data_user.h"
#include "history/history_item.h"
#include "history/history_item_components.h"
#include "lang/lang_keys.h"
#include "main/main_session.h"
#include "mainwidget.h"
#include "payments/payments_checkout_process.h" // NonPanelPaymentForm.
@ -80,13 +81,19 @@ Fn<void(NonPanelPaymentForm)> ProcessNonPanelPaymentFormFactory(
- int64(slice.balance);
if (creditsNeeded <= 0) {
sendBox();
} else {
} else if (strong->session().premiumPossible()) {
strong->uiShow()->show(Box(
Settings::SmallBalanceBox,
strong,
creditsNeeded,
form->botId,
sendBox));
} else {
strong->uiShow()->showToast(
tr::lng_credits_purchase_blocked(tr::now));
if (maybeReturnToBot) {
maybeReturnToBot(CheckoutResult::Failed);
}
}
}
lifetime->destroy();

View File

@ -286,11 +286,20 @@ void FillCreditOptions(
const auto apiCredits = content->lifetime().make_state<ApiOptions>(
controller->session().user());
apiCredits->request(
) | rpl::start_with_error_done([=](const QString &error) {
controller->showToast(error);
}, [=] {
fill(apiCredits->options());
if (controller->session().premiumPossible()) {
apiCredits->request(
) | rpl::start_with_error_done([=](const QString &error) {
controller->showToast(error);
}, [=] {
fill(apiCredits->options());
}, content->lifetime());
}
controller->session().premiumPossibleValue(
) | rpl::start_with_next([=](bool premiumPossible) {
if (!premiumPossible) {
fill({});
}
}, content->lifetime());
}