mirror of
https://github.com/AyuGram/AyuGramDesktop.git
synced 2025-04-15 21:57:10 +02:00
Fixed purchases of credits.
This commit is contained in:
parent
0e30e306ff
commit
174fb62c32
5 changed files with 19 additions and 51 deletions
|
@ -57,7 +57,7 @@ namespace {
|
|||
status.data().vhistory().v
|
||||
) | ranges::views::transform(HistoryFromTL) | ranges::to_vector,
|
||||
.balance = status.data().vbalance().v,
|
||||
.allLoaded = status.data().vnext_offset().has_value(),
|
||||
.allLoaded = !status.data().vnext_offset().has_value(),
|
||||
.token = qs(status.data().vnext_offset().value_or_empty()),
|
||||
};
|
||||
}
|
||||
|
@ -85,6 +85,7 @@ rpl::producer<rpl::no_value, QString> CreditsTopupOptions::request() {
|
|||
option.data().vstore_product().value_or_empty()),
|
||||
.currency = qs(option.data().vcurrency()),
|
||||
.amount = option.data().vamount().v,
|
||||
.extended = option.data().is_extended(),
|
||||
};
|
||||
}) | ranges::to_vector;
|
||||
consumer.put_done();
|
||||
|
@ -114,10 +115,6 @@ void CreditsStatus::request(
|
|||
_peer->isSelf() ? MTP_inputPeerSelf() : _peer->input
|
||||
)).done([=](const TLResult &result) {
|
||||
_requestId = 0;
|
||||
#if _DEBUG
|
||||
done({ .balance = uint64(base::RandomIndex(9999)) });
|
||||
return;
|
||||
#endif
|
||||
done(StatusFromTL(result, _peer));
|
||||
}).fail([=] {
|
||||
_requestId = 0;
|
||||
|
@ -127,9 +124,11 @@ void CreditsStatus::request(
|
|||
|
||||
CreditsHistory::CreditsHistory(not_null<PeerData*> peer, bool in, bool out)
|
||||
: _peer(peer)
|
||||
, _flags(HistoryTL::Flags(0)
|
||||
| (in ? HistoryTL::Flag::f_inbound : HistoryTL::Flags(0))
|
||||
| (out ? HistoryTL::Flag::f_outbound : HistoryTL::Flags(0)))
|
||||
, _flags((in == out)
|
||||
? HistoryTL::Flags(0)
|
||||
: HistoryTL::Flags(0)
|
||||
| (in ? HistoryTL::Flag::f_inbound : HistoryTL::Flags(0))
|
||||
| (out ? HistoryTL::Flag::f_outbound : HistoryTL::Flags(0)))
|
||||
, _api(&peer->session().api().instance()) {
|
||||
}
|
||||
|
||||
|
@ -145,46 +144,6 @@ void CreditsHistory::request(
|
|||
MTP_string(token)
|
||||
)).done([=](const MTPpayments_StarsStatus &result) {
|
||||
_requestId = 0;
|
||||
#if _DEBUG
|
||||
done({
|
||||
.list = [&] {
|
||||
auto a = std::vector<Data::CreditsHistoryEntry>();
|
||||
const auto isIn = _flags & HistoryTL::Flag::f_inbound;
|
||||
const auto isOut = _flags & HistoryTL::Flag::f_outbound;
|
||||
for (auto i = 0; i < base::RandomIndex(10) + 1; i++) {
|
||||
const auto type = (isIn && isOut)
|
||||
? base::RandomIndex(4)
|
||||
: isOut
|
||||
? 0
|
||||
: (base::RandomIndex(3) + 1);
|
||||
a.push_back(Data::CreditsHistoryEntry{
|
||||
.id = QString::number(base::RandomValue<uint64>()),
|
||||
.credits = uint64(
|
||||
std::max(base::RandomIndex(15000), 1)),
|
||||
.date = base::unixtime::parse(
|
||||
std::abs(base::RandomValue<TimeId>())),
|
||||
.peerType = ((type == 0)
|
||||
? Data::CreditsHistoryEntry::PeerType::Peer
|
||||
: (type == 1)
|
||||
? Data::CreditsHistoryEntry::PeerType::PlayMarket
|
||||
: (type == 2)
|
||||
? Data::CreditsHistoryEntry::PeerType::Fragment
|
||||
: Data::CreditsHistoryEntry::PeerType::AppStore),
|
||||
.peerId = (type == 0)
|
||||
? peerFromUser(5000233800)
|
||||
: PeerId(0),
|
||||
});
|
||||
}
|
||||
return a;
|
||||
}(),
|
||||
.balance = 47890,
|
||||
.allLoaded = !token.isEmpty(),
|
||||
.token = token.isEmpty()
|
||||
? QString::number(base::RandomValue<uint64>())
|
||||
: QString(),
|
||||
});
|
||||
return;
|
||||
#endif
|
||||
done(StatusFromTL(result, _peer));
|
||||
}).fail([=] {
|
||||
_requestId = 0;
|
||||
|
|
|
@ -14,6 +14,7 @@ struct CreditTopupOption final {
|
|||
QString product;
|
||||
QString currency;
|
||||
uint64 amount = 0;
|
||||
bool extended = false;
|
||||
};
|
||||
|
||||
using CreditTopupOptions = std::vector<CreditTopupOption>;
|
||||
|
|
|
@ -317,10 +317,16 @@ MTPInputInvoice Form::inputInvoice() const {
|
|||
} else if (const auto slug = std::get_if<InvoiceSlug>(&_id.value)) {
|
||||
return MTP_inputInvoiceSlug(MTP_string(slug->slug));
|
||||
} else if (const auto credits = std::get_if<InvoiceCredits>(&_id.value)) {
|
||||
using Flag = MTPDstarsTopupOption::Flag;
|
||||
const auto emptyFlag = MTPDstarsTopupOption::Flags(0);
|
||||
return MTP_inputInvoiceStars(MTP_starsTopupOption(
|
||||
credits->product.isEmpty()
|
||||
? MTP_flags(0)
|
||||
: MTP_flags(MTPDstarsTopupOption::Flag::f_store_product),
|
||||
MTP_flags(emptyFlag
|
||||
| (credits->product.isEmpty()
|
||||
? Flag::f_store_product
|
||||
: emptyFlag)
|
||||
| (credits->extended
|
||||
? Flag::f_extended
|
||||
: emptyFlag)),
|
||||
MTP_long(credits->credits),
|
||||
MTP_string(credits->product),
|
||||
MTP_string(credits->currency),
|
||||
|
|
|
@ -223,6 +223,7 @@ struct InvoiceCredits {
|
|||
QString product;
|
||||
QString currency;
|
||||
uint64 amount = 0;
|
||||
bool extended = false;
|
||||
};
|
||||
|
||||
struct InvoiceId {
|
||||
|
|
|
@ -297,6 +297,7 @@ void Credits::setupOptions(not_null<Ui::VerticalLayout*> container) {
|
|||
.product = option.product,
|
||||
.currency = option.currency,
|
||||
.amount = option.amount,
|
||||
.extended = option.extended,
|
||||
};
|
||||
|
||||
const auto weak = Ui::MakeWeak(button);
|
||||
|
|
Loading…
Add table
Reference in a new issue