From 994dbf9eb577bee3e470cebc037d1df9f63b4e4f Mon Sep 17 00:00:00 2001 From: John Preston Date: Wed, 24 Mar 2021 16:41:46 +0400 Subject: [PATCH] Validate saved information on payment form open. --- .../payments/payments_checkout_process.cpp | 26 ++++++++++++++++++- .../payments/payments_checkout_process.h | 2 ++ 2 files changed, 27 insertions(+), 1 deletion(-) diff --git a/Telegram/SourceFiles/payments/payments_checkout_process.cpp b/Telegram/SourceFiles/payments/payments_checkout_process.cpp index ea7aff424d..030803b838 100644 --- a/Telegram/SourceFiles/payments/payments_checkout_process.cpp +++ b/Telegram/SourceFiles/payments/payments_checkout_process.cpp @@ -101,8 +101,14 @@ not_null CheckoutProcess::panelDelegate() { void CheckoutProcess::handleFormUpdate(const FormUpdate &update) { v::match(update.data, [&](const FormReady &) { - showForm(); + performInitialSilentValidation(); + if (!_initialSilentValidation) { + showForm(); + } }, [&](const ValidateFinished &) { + if (_initialSilentValidation) { + _initialSilentValidation = false; + } showForm(); if (_submitState == SubmitState::Validation) { _submitState = SubmitState::Validated; @@ -156,6 +162,11 @@ void CheckoutProcess::handleError(const Error &error) { if (_submitState == SubmitState::Validation) { _submitState = SubmitState::None; } + if (_initialSilentValidation) { + _initialSilentValidation = false; + showForm(); + return; + } if (id == u"REQ_INFO_NAME_INVALID"_q) { showEditError(Ui::EditField::Name); } else if (id == u"REQ_INFO_EMAIL_INVALID"_q) { @@ -373,6 +384,19 @@ void CheckoutProcess::panelShowBox(object_ptr box) { _panel->showBox(std::move(box)); } +void CheckoutProcess::performInitialSilentValidation() { + const auto &invoice = _form->invoice(); + const auto &saved = _form->savedInformation(); + if ((invoice.isNameRequested && saved.name.isEmpty()) + || (invoice.isEmailRequested && saved.email.isEmpty()) + || (invoice.isPhoneRequested && saved.phone.isEmpty()) + || (invoice.isShippingAddressRequested && !saved.shippingAddress)) { + return; + } + _initialSilentValidation = true; + _form->validateInformation(saved); +} + QString CheckoutProcess::webviewDataPath() const { return _session->domain().local().webviewDataPath(); } diff --git a/Telegram/SourceFiles/payments/payments_checkout_process.h b/Telegram/SourceFiles/payments/payments_checkout_process.h index 65d09d986c..bd3210d142 100644 --- a/Telegram/SourceFiles/payments/payments_checkout_process.h +++ b/Telegram/SourceFiles/payments/payments_checkout_process.h @@ -61,6 +61,7 @@ private: void showEditError(Ui::EditField field); void chooseShippingOption(); + void performInitialSilentValidation(); [[nodiscard]] QString webviewDataPath() const; void panelRequestClose() override; @@ -84,6 +85,7 @@ private: const std::unique_ptr _panel; std::unique_ptr _webviewWindow; SubmitState _submitState = SubmitState::None; + bool _initialSilentValidation = false; rpl::lifetime _lifetime;