2
0
mirror of https://github.com/telegramdesktop/tdesktop synced 2025-08-22 10:17:10 +00:00

Allow choosing Stars/TON payment.

This commit is contained in:
John Preston 2025-07-30 10:37:03 +04:00
parent 3b1c7dc5e1
commit 9765319027
4 changed files with 75 additions and 36 deletions

View File

@ -3560,7 +3560,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
"lng_gift_buy_resale_title" = "Buy {name}"; "lng_gift_buy_resale_title" = "Buy {name}";
"lng_gift_buy_resale_button" = "Buy for {cost}"; "lng_gift_buy_resale_button" = "Buy for {cost}";
"lng_gift_buy_resale_equals" = "Equals to {cost}"; "lng_gift_buy_resale_equals" = "Equals to {cost}";
"lng_gift_buy_resale_only_ton" = "The seller only accepts TON as payment"; "lng_gift_buy_resale_only_ton" = "The seller only accepts TON as payment.";
"lng_gift_buy_resale_pay_stars" = "Pay in Stars"; "lng_gift_buy_resale_pay_stars" = "Pay in Stars";
"lng_gift_buy_resale_pay_ton" = "Pay in TON"; "lng_gift_buy_resale_pay_ton" = "Pay in TON";
"lng_gift_buy_resale_confirm" = "Do you want to buy {name} for {price} and gift it to {user}?"; "lng_gift_buy_resale_confirm" = "Do you want to buy {name} for {price} and gift it to {user}?";

View File

@ -23,6 +23,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
#include "main/main_session.h" #include "main/main_session.h"
#include "payments/payments_checkout_process.h" #include "payments/payments_checkout_process.h"
#include "ui/boxes/confirm_box.h" #include "ui/boxes/confirm_box.h"
#include "ui/controls/sub_tabs.h"
#include "ui/controls/ton_common.h" #include "ui/controls/ton_common.h"
#include "ui/layers/generic_box.h" #include "ui/layers/generic_box.h"
#include "ui/text/text_utilities.h" #include "ui/text/text_utilities.h"
@ -678,19 +679,59 @@ void ShowBuyResaleGiftBox(
not_null<PeerData*> to, not_null<PeerData*> to,
Fn<void()> closeParentBox) { Fn<void()> closeParentBox) {
show->show(Box([=](not_null<Ui::GenericBox*> box) { show->show(Box([=](not_null<Ui::GenericBox*> box) {
box->setTitle(tr::lng_gift_buy_resale_title(
lt_name,
rpl::single(UniqueGiftName(*gift))));
auto transfer = tr::lng_gift_buy_resale_button(
lt_cost,
rpl::single(Data::FormatGiftResaleAsked(*gift)),
Ui::Text::WithEntities);
struct State { struct State {
rpl::variable<bool> ton;
bool sent = false; bool sent = false;
}; };
const auto state = std::make_shared<State>(); const auto state = std::make_shared<State>();
state->ton = gift->onlyAcceptTon;
if (gift->onlyAcceptTon) {
box->addRow(
object_ptr<Ui::FlatLabel>(
box,
tr::lng_gift_buy_resale_only_ton(
Ui::Text::RichLangValue),
st::resaleConfirmTonOnly),
st::boxRowPadding + st::resaleConfirmTonOnlyMargin);
} else {
const auto tabs = box->addRow(
object_ptr<Ui::SubTabs>(
box,
Ui::SubTabsOptions{
.selected = u"stars"_q,
.centered = true,
},
std::vector<Ui::SubTabsTab>{
{
u"stars"_q,
tr::lng_gift_buy_resale_pay_stars(
tr::now,
Ui::Text::WithEntities),
},
{
u"ton"_q,
tr::lng_gift_buy_resale_pay_ton(
tr::now,
Ui::Text::WithEntities),
},
}),
st::boxRowPadding + st::resaleConfirmTonOnlyMargin);
tabs->activated() | rpl::start_with_next([=](QString id) {
tabs->setActiveTab(id);
state->ton = (id == u"ton"_q);
}, tabs->lifetime());
}
auto transfer = state->ton.value() | rpl::map([=](bool ton) {
return tr::lng_gift_buy_resale_button(
lt_cost,
rpl::single(ton
? Data::FormatGiftResaleTon(*gift)
: Data::FormatGiftResaleStars(*gift)),
Ui::Text::WithEntities);
}) | rpl::flatten_latest();
auto callback = [=](Fn<void()> close) { auto callback = [=](Fn<void()> close) {
if (state->sent) { if (state->sent) {
return; return;
@ -704,48 +745,41 @@ void ShowBuyResaleGiftBox(
} else if (result != Payments::CheckoutResult::Paid) { } else if (result != Payments::CheckoutResult::Paid) {
state->sent = false; state->sent = false;
} else { } else {
show->showToast(u"done!"_q);
closeParentBox(); closeParentBox();
close(); close();
} }
}; };
const auto type = gift->onlyAcceptTon const auto type = state->ton.current()
? CreditsType::Ton ? CreditsType::Ton
: CreditsType::Stars; : CreditsType::Stars;
BuyResaleGift(show, to, gift, type, done); BuyResaleGift(show, to, gift, type, done);
}; };
auto price = state->ton.value() | rpl::map([=](bool ton) {
return ton
? tr::lng_action_gift_for_ton(
lt_count_decimal,
rpl::single(gift->nanoTonForResale
/ float64(Ui::kNanosInOne)),
Ui::Text::Bold)
: tr::lng_action_gift_for_stars(
lt_count_decimal,
rpl::single(gift->starsForResale * 1.),
Ui::Text::Bold);
}) | rpl::flatten_latest();
Ui::ConfirmBox(box, { Ui::ConfirmBox(box, {
.text = to->isSelf() .text = to->isSelf()
? tr::lng_gift_buy_resale_confirm_self( ? tr::lng_gift_buy_resale_confirm_self(
lt_name, lt_name,
rpl::single(Ui::Text::Bold(UniqueGiftName(*gift))), rpl::single(Ui::Text::Bold(UniqueGiftName(*gift))),
lt_price, lt_price,
(gift->onlyAcceptTon std::move(price),
? tr::lng_action_gift_for_ton(
lt_count,
rpl::single(gift->nanoTonForResale
/ float64(Ui::kNanosInOne)),
Ui::Text::Bold)
: tr::lng_action_gift_for_stars(
lt_count_decimal,
rpl::single(gift->starsForResale * 1.),
Ui::Text::Bold)),
Ui::Text::WithEntities) Ui::Text::WithEntities)
: tr::lng_gift_buy_resale_confirm( : tr::lng_gift_buy_resale_confirm(
lt_name, lt_name,
rpl::single(Ui::Text::Bold(UniqueGiftName(*gift))), rpl::single(Ui::Text::Bold(UniqueGiftName(*gift))),
lt_price, lt_price,
(gift->onlyAcceptTon std::move(price),
? tr::lng_action_gift_for_ton(
lt_count,
rpl::single(gift->nanoTonForResale
/ float64(Ui::kNanosInOne)),
Ui::Text::Bold)
: tr::lng_action_gift_for_stars(
lt_count_decimal,
rpl::single(gift->starsForResale * 1.),
Ui::Text::Bold)),
lt_user, lt_user,
rpl::single(Ui::Text::Bold(to->shortName())), rpl::single(Ui::Text::Bold(to->shortName())),
Ui::Text::WithEntities), Ui::Text::WithEntities),

View File

@ -2114,8 +2114,8 @@ void GenericCreditsEntryBox(
lt_cost, lt_cost,
rpl::single(Data::FormatGiftResaleStars(*uniqueGift)), rpl::single(Data::FormatGiftResaleStars(*uniqueGift)),
Ui::Text::WithEntities), Ui::Text::WithEntities),
st::giftResaleButtonTitle, st::resaleButtonTitle,
st::giftResaleButtonSubtitle); st::resaleButtonSubtitle);
} else { } else {
button->setText(tr::lng_gift_buy_resale_button( button->setText(tr::lng_gift_buy_resale_button(
lt_cost, lt_cost,

View File

@ -323,13 +323,18 @@ creditsHistoryRowRightMinorTop: 18px;
creditsHistoryRowRightStyle: TextStyle(defaultTextStyle) { creditsHistoryRowRightStyle: TextStyle(defaultTextStyle) {
font: font(fsize); font: font(fsize);
} }
giftResaleButtonTitle: FlatLabel(defaultFlatLabel) { resaleButtonTitle: FlatLabel(defaultFlatLabel) {
style: semiboldTextStyle; style: semiboldTextStyle;
textFg: activeButtonFg; textFg: activeButtonFg;
} }
giftResaleButtonSubtitle: FlatLabel(defaultFlatLabel) { resaleButtonSubtitle: FlatLabel(defaultFlatLabel) {
style: TextStyle(defaultTextStyle) { style: TextStyle(defaultTextStyle) {
font: font(12px semibold); font: font(12px semibold);
} }
textFg: activeButtonFg; textFg: activeButtonFg;
} }
resaleConfirmTonOnly: FlatLabel(boxLabel) {
textFg: windowSubTextFg;
}
resaleConfirmTonOnlyMargin: margins(0px, 12px, 0px, 12px);