AyuGramDesktop/Telegram/SourceFiles/payments/payments_non_panel_process.cpp

46 lines
1.4 KiB
C++

/*
This file is part of Telegram Desktop,
the official desktop application for the Telegram messaging service.
For license and copyright information please follow this link:
https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
*/
#include "payments/payments_non_panel_process.h"
#include "payments/payments_checkout_process.h" // NonPanelPaymentForm.
#include "payments/payments_form.h"
#include "history/history_item.h"
#include "ui/layers/generic_box.h"
#include "window/window_session_controller.h"
#include "boxes/send_credits_box.h"
namespace Payments {
namespace {
bool IsCreditsInvoice(not_null<HistoryItem*> item) {
const auto media = item->media();
const auto invoice = media ? media->invoice() : nullptr;
return invoice && (invoice->currency == "XTR");
}
} // namespace
Fn<void(NonPanelPaymentForm)> ProcessNonPanelPaymentFormFactory(
not_null<Window::SessionController*> controller) {
return [=](NonPanelPaymentForm form) {
using CreditsFormDataPtr = std::shared_ptr<CreditsFormData>;
if (const auto creditsData = std::get_if<CreditsFormDataPtr>(&form)) {
controller->uiShow()->show(Box(Ui::SendCreditsBox, *creditsData));
}
};
}
Fn<void(NonPanelPaymentForm)> ProcessNonPanelPaymentFormFactory(
not_null<Window::SessionController*> controller,
not_null<HistoryItem*> item) {
return IsCreditsInvoice(item)
? ProcessNonPanelPaymentFormFactory(controller)
: nullptr;
}
} // namespace Payments