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:
parent
3b1c7dc5e1
commit
9765319027
@ -3560,7 +3560,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
|
||||
"lng_gift_buy_resale_title" = "Buy {name}";
|
||||
"lng_gift_buy_resale_button" = "Buy for {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_ton" = "Pay in TON";
|
||||
"lng_gift_buy_resale_confirm" = "Do you want to buy {name} for {price} and gift it to {user}?";
|
||||
|
@ -23,6 +23,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
|
||||
#include "main/main_session.h"
|
||||
#include "payments/payments_checkout_process.h"
|
||||
#include "ui/boxes/confirm_box.h"
|
||||
#include "ui/controls/sub_tabs.h"
|
||||
#include "ui/controls/ton_common.h"
|
||||
#include "ui/layers/generic_box.h"
|
||||
#include "ui/text/text_utilities.h"
|
||||
@ -678,19 +679,59 @@ void ShowBuyResaleGiftBox(
|
||||
not_null<PeerData*> to,
|
||||
Fn<void()> closeParentBox) {
|
||||
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 {
|
||||
rpl::variable<bool> ton;
|
||||
bool sent = false;
|
||||
};
|
||||
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) {
|
||||
if (state->sent) {
|
||||
return;
|
||||
@ -704,48 +745,41 @@ void ShowBuyResaleGiftBox(
|
||||
} else if (result != Payments::CheckoutResult::Paid) {
|
||||
state->sent = false;
|
||||
} else {
|
||||
show->showToast(u"done!"_q);
|
||||
closeParentBox();
|
||||
close();
|
||||
}
|
||||
};
|
||||
const auto type = gift->onlyAcceptTon
|
||||
const auto type = state->ton.current()
|
||||
? CreditsType::Ton
|
||||
: CreditsType::Stars;
|
||||
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, {
|
||||
.text = to->isSelf()
|
||||
? tr::lng_gift_buy_resale_confirm_self(
|
||||
lt_name,
|
||||
rpl::single(Ui::Text::Bold(UniqueGiftName(*gift))),
|
||||
lt_price,
|
||||
(gift->onlyAcceptTon
|
||||
? 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)),
|
||||
std::move(price),
|
||||
Ui::Text::WithEntities)
|
||||
: tr::lng_gift_buy_resale_confirm(
|
||||
lt_name,
|
||||
rpl::single(Ui::Text::Bold(UniqueGiftName(*gift))),
|
||||
lt_price,
|
||||
(gift->onlyAcceptTon
|
||||
? 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)),
|
||||
std::move(price),
|
||||
lt_user,
|
||||
rpl::single(Ui::Text::Bold(to->shortName())),
|
||||
Ui::Text::WithEntities),
|
||||
|
@ -2114,8 +2114,8 @@ void GenericCreditsEntryBox(
|
||||
lt_cost,
|
||||
rpl::single(Data::FormatGiftResaleStars(*uniqueGift)),
|
||||
Ui::Text::WithEntities),
|
||||
st::giftResaleButtonTitle,
|
||||
st::giftResaleButtonSubtitle);
|
||||
st::resaleButtonTitle,
|
||||
st::resaleButtonSubtitle);
|
||||
} else {
|
||||
button->setText(tr::lng_gift_buy_resale_button(
|
||||
lt_cost,
|
||||
|
@ -323,13 +323,18 @@ creditsHistoryRowRightMinorTop: 18px;
|
||||
creditsHistoryRowRightStyle: TextStyle(defaultTextStyle) {
|
||||
font: font(fsize);
|
||||
}
|
||||
giftResaleButtonTitle: FlatLabel(defaultFlatLabel) {
|
||||
resaleButtonTitle: FlatLabel(defaultFlatLabel) {
|
||||
style: semiboldTextStyle;
|
||||
textFg: activeButtonFg;
|
||||
}
|
||||
giftResaleButtonSubtitle: FlatLabel(defaultFlatLabel) {
|
||||
resaleButtonSubtitle: FlatLabel(defaultFlatLabel) {
|
||||
style: TextStyle(defaultTextStyle) {
|
||||
font: font(12px semibold);
|
||||
}
|
||||
textFg: activeButtonFg;
|
||||
}
|
||||
|
||||
resaleConfirmTonOnly: FlatLabel(boxLabel) {
|
||||
textFg: windowSubTextFg;
|
||||
}
|
||||
resaleConfirmTonOnlyMargin: margins(0px, 12px, 0px, 12px);
|
||||
|
Loading…
x
Reference in New Issue
Block a user