mirror of
https://github.com/AyuGram/AyuGramDesktop.git
synced 2025-06-08 16:13:56 +02:00
Show transfer price if transfer from resale.
This commit is contained in:
parent
bc3efe2f4c
commit
833341dea7
1 changed files with 95 additions and 42 deletions
|
@ -1963,6 +1963,61 @@ void SendStarsFormRequest(
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void SubmitStarsForm(
|
||||||
|
std::shared_ptr<Main::SessionShow> show,
|
||||||
|
MTPInputInvoice invoice,
|
||||||
|
uint64 formId,
|
||||||
|
uint64 price,
|
||||||
|
Fn<void(Payments::CheckoutResult, const MTPUpdates *)> done) {
|
||||||
|
const auto ready = [=](Settings::SmallBalanceResult result) {
|
||||||
|
SendStarsFormRequest(show, result, formId, invoice, done);
|
||||||
|
};
|
||||||
|
Settings::MaybeRequestBalanceIncrease(
|
||||||
|
show,
|
||||||
|
price,
|
||||||
|
Settings::SmallBalanceDeepLink{},
|
||||||
|
ready);
|
||||||
|
}
|
||||||
|
|
||||||
|
void RequestStarsForm(
|
||||||
|
std::shared_ptr<Main::SessionShow> show,
|
||||||
|
MTPInputInvoice invoice,
|
||||||
|
Fn<void(
|
||||||
|
uint64 formId,
|
||||||
|
uint64 price,
|
||||||
|
std::optional<Payments::CheckoutResult> failure)> done) {
|
||||||
|
const auto fail = [=](Payments::CheckoutResult failure) {
|
||||||
|
done(0, 0, failure);
|
||||||
|
};
|
||||||
|
show->session().api().request(MTPpayments_GetPaymentForm(
|
||||||
|
MTP_flags(0),
|
||||||
|
invoice,
|
||||||
|
MTPDataJSON() // theme_params
|
||||||
|
)).done([=](const MTPpayments_PaymentForm &result) {
|
||||||
|
result.match([&](const MTPDpayments_paymentFormStarGift &data) {
|
||||||
|
const auto prices = data.vinvoice().data().vprices().v;
|
||||||
|
if (show->valid() && !prices.isEmpty()) {
|
||||||
|
const auto price = prices.front().data().vamount().v;
|
||||||
|
done(data.vform_id().v, price, std::nullopt);
|
||||||
|
} else {
|
||||||
|
fail(Payments::CheckoutResult::Failed);
|
||||||
|
}
|
||||||
|
}, [&](const auto &) {
|
||||||
|
fail(Payments::CheckoutResult::Failed);
|
||||||
|
});
|
||||||
|
}).fail([=](const MTP::Error &error) {
|
||||||
|
const auto type = error.type();
|
||||||
|
if (type == u"STARGIFT_EXPORT_IN_PROGRESS"_q) {
|
||||||
|
fail(Payments::CheckoutResult::Cancelled);
|
||||||
|
} else if (type == u"NO_PAYMENT_NEEDED"_q) {
|
||||||
|
fail(Payments::CheckoutResult::Free);
|
||||||
|
} else {
|
||||||
|
show->showToast(type);
|
||||||
|
fail(Payments::CheckoutResult::Failed);
|
||||||
|
}
|
||||||
|
}).send();
|
||||||
|
}
|
||||||
|
|
||||||
void UpgradeGift(
|
void UpgradeGift(
|
||||||
not_null<Window::SessionController*> window,
|
not_null<Window::SessionController*> window,
|
||||||
Data::SavedStarGiftId savedId,
|
Data::SavedStarGiftId savedId,
|
||||||
|
@ -2564,6 +2619,7 @@ void SendGiftBox(
|
||||||
std::vector<GiftDescriptor> list;
|
std::vector<GiftDescriptor> list;
|
||||||
std::vector<std::unique_ptr<GiftButton>> buttons;
|
std::vector<std::unique_ptr<GiftButton>> buttons;
|
||||||
std::shared_ptr<Api::PremiumGiftCodeOptions> api;
|
std::shared_ptr<Api::PremiumGiftCodeOptions> api;
|
||||||
|
std::shared_ptr<Data::UniqueGift> transferRequested;
|
||||||
rpl::variable<VisibleRange> visibleRange;
|
rpl::variable<VisibleRange> visibleRange;
|
||||||
uint64 resaleRequestingId = 0;
|
uint64 resaleRequestingId = 0;
|
||||||
rpl::lifetime resaleLifetime;
|
rpl::lifetime resaleLifetime;
|
||||||
|
@ -2647,20 +2703,41 @@ void SendGiftBox(
|
||||||
button->setDescriptor(descriptor, GiftButton::Mode::Full);
|
button->setDescriptor(descriptor, GiftButton::Mode::Full);
|
||||||
button->setClickedCallback([=] {
|
button->setClickedCallback([=] {
|
||||||
const auto star = std::get_if<GiftTypeStars>(&descriptor);
|
const auto star = std::get_if<GiftTypeStars>(&descriptor);
|
||||||
if (star
|
const auto unique = star ? star->info.unique : nullptr;
|
||||||
&& star->info.unique
|
if (unique && star->mine && !peer->isSelf()) {
|
||||||
&& star->mine
|
|
||||||
&& !peer->isSelf()) {
|
|
||||||
const auto done = [=] {
|
const auto done = [=] {
|
||||||
window->session().credits().load(true);
|
window->session().credits().load(true);
|
||||||
window->showPeerHistory(peer);
|
window->showPeerHistory(peer);
|
||||||
};
|
};
|
||||||
|
if (state->transferRequested == unique) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
state->transferRequested = unique;
|
||||||
|
const auto savedId = star->transferId;
|
||||||
|
using Payments::CheckoutResult;
|
||||||
|
const auto formReady = [=](
|
||||||
|
uint64 formId,
|
||||||
|
uint64 price,
|
||||||
|
std::optional<CheckoutResult> failure) {
|
||||||
|
state->transferRequested = nullptr;
|
||||||
|
if (!failure || *failure == CheckoutResult::Free) {
|
||||||
|
unique->starsForTransfer = price;
|
||||||
ShowTransferToBox(
|
ShowTransferToBox(
|
||||||
window,
|
window,
|
||||||
peer,
|
peer,
|
||||||
star->info.unique,
|
unique,
|
||||||
star->transferId,
|
savedId,
|
||||||
done);
|
done);
|
||||||
|
} else if (*failure == CheckoutResult::Cancelled) {
|
||||||
|
done();
|
||||||
|
}
|
||||||
|
};
|
||||||
|
RequestStarsForm(
|
||||||
|
window->uiShow(),
|
||||||
|
MTP_inputInvoiceStarGiftTransfer(
|
||||||
|
Api::InputSavedStarGiftId(savedId, unique),
|
||||||
|
peer->input),
|
||||||
|
formReady);
|
||||||
} else if (star && star->info.unique && star->resale) {
|
} else if (star && star->info.unique && star->resale) {
|
||||||
window->show(Box(
|
window->show(Box(
|
||||||
Settings::GlobalStarGiftBox,
|
Settings::GlobalStarGiftBox,
|
||||||
|
@ -4808,40 +4885,16 @@ void RequestStarsFormAndSubmit(
|
||||||
std::shared_ptr<Main::SessionShow> show,
|
std::shared_ptr<Main::SessionShow> show,
|
||||||
MTPInputInvoice invoice,
|
MTPInputInvoice invoice,
|
||||||
Fn<void(Payments::CheckoutResult, const MTPUpdates *)> done) {
|
Fn<void(Payments::CheckoutResult, const MTPUpdates *)> done) {
|
||||||
show->session().api().request(MTPpayments_GetPaymentForm(
|
RequestStarsForm(show, invoice, [=](
|
||||||
MTP_flags(0),
|
uint64 formId,
|
||||||
invoice,
|
uint64 price,
|
||||||
MTPDataJSON() // theme_params
|
std::optional<Payments::CheckoutResult> failure) {
|
||||||
)).done([=](const MTPpayments_PaymentForm &result) {
|
if (!failure) {
|
||||||
result.match([&](const MTPDpayments_paymentFormStarGift &data) {
|
SubmitStarsForm(show, invoice, formId, price, done);
|
||||||
const auto formId = data.vform_id().v;
|
|
||||||
const auto prices = data.vinvoice().data().vprices().v;
|
|
||||||
if (!show->valid()) {
|
|
||||||
done(Payments::CheckoutResult::Failed, nullptr);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
const auto ready = [=](Settings::SmallBalanceResult result) {
|
|
||||||
SendStarsFormRequest(show, result, formId, invoice, done);
|
|
||||||
};
|
|
||||||
Settings::MaybeRequestBalanceIncrease(
|
|
||||||
show,
|
|
||||||
prices.front().data().vamount().v,
|
|
||||||
Settings::SmallBalanceDeepLink{},
|
|
||||||
ready);
|
|
||||||
}, [&](const auto &) {
|
|
||||||
done(Payments::CheckoutResult::Failed, nullptr);
|
|
||||||
});
|
|
||||||
}).fail([=](const MTP::Error &error) {
|
|
||||||
const auto type = error.type();
|
|
||||||
if (type == u"STARGIFT_EXPORT_IN_PROGRESS"_q) {
|
|
||||||
done(Payments::CheckoutResult::Cancelled, nullptr);
|
|
||||||
} else if (type == u"NO_PAYMENT_NEEDED"_q) {
|
|
||||||
done(Payments::CheckoutResult::Free, nullptr);
|
|
||||||
} else {
|
} else {
|
||||||
show->showToast(type);
|
done(*failure, nullptr);
|
||||||
done(Payments::CheckoutResult::Failed, nullptr);
|
|
||||||
}
|
}
|
||||||
}).send();
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
void ShowGiftTransferredToast(
|
void ShowGiftTransferredToast(
|
||||||
|
|
Loading…
Add table
Reference in a new issue