From 79f7aa703a1b63dde4ceb1609985c05b1ac1fdab Mon Sep 17 00:00:00 2001 From: John Preston Date: Wed, 7 Apr 2021 15:43:32 +0400 Subject: [PATCH] Allow clearing saved payments information. --- Telegram/Resources/langs/lang.strings | 9 ++ .../settings/settings_privacy_security.cpp | 82 +++++++++++++++++++ Telegram/lib_ui | 2 +- 3 files changed, 92 insertions(+), 1 deletion(-) diff --git a/Telegram/Resources/langs/lang.strings b/Telegram/Resources/langs/lang.strings index 1b38d34635..7207e92a6a 100644 --- a/Telegram/Resources/langs/lang.strings +++ b/Telegram/Resources/langs/lang.strings @@ -454,6 +454,15 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL "lng_settings_sensitive_title" = "Sensitive content"; "lng_settings_sensitive_disable_filtering" = "Disable filtering"; "lng_settings_sensitive_about" = "Display sensitive media in public channels on all your Telegram devices."; +"lng_settings_security_bots" = "Bots and websites"; +"lng_settings_clear_payment_info" = "Clear Payment and Shipping Info"; + +"lng_clear_payment_info_title" = "Clear payment info"; +"lng_clear_payment_info_sure" = "Are you sure you want to clear your payment and shipping info?"; +"lng_clear_payment_info_shipping" = "Shipping info"; +"lng_clear_payment_info_payment" = "Payment info"; +"lng_clear_payment_info_clear" = "Clear"; +"lng_clear_payment_info_confirm" = "Delete your shipping info and instruct all payment providers to remove your saved credit cards? Note that Telegram never stores your credit card data."; "lng_settings_auto_night_mode" = "Auto-Night mode"; "lng_settings_auto_night_enabled" = "Match the system settings"; diff --git a/Telegram/SourceFiles/settings/settings_privacy_security.cpp b/Telegram/SourceFiles/settings/settings_privacy_security.cpp index 3380091733..632c77f906 100644 --- a/Telegram/SourceFiles/settings/settings_privacy_security.cpp +++ b/Telegram/SourceFiles/settings/settings_privacy_security.cpp @@ -29,6 +29,8 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL #include "ui/widgets/shadow.h" #include "ui/widgets/labels.h" #include "ui/widgets/buttons.h" +#include "ui/widgets/checkbox.h" +#include "ui/layers/generic_box.h" #include "calls/calls_instance.h" #include "core/core_cloud_password.h" #include "core/update_checker.h" @@ -42,6 +44,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL #include "apiwrap.h" #include "facades.h" #include "styles/style_settings.h" +#include "styles/style_layers.h" #include "styles/style_boxes.h" #include @@ -566,6 +569,83 @@ void SetupSelfDestruction( AddSkip(container); } +void ClearPaymentInfoBoxBuilder( + not_null box, + not_null session) { + box->setTitle(tr::lng_clear_payment_info_title()); + + const auto checkboxPadding = style::margins( + st::boxRowPadding.left(), + st::boxRowPadding.left(), + st::boxRowPadding.right(), + st::boxRowPadding.bottom()); + const auto label = box->addRow(object_ptr( + box, + tr::lng_clear_payment_info_sure(), + st::boxLabel)); + const auto shipping = box->addRow( + object_ptr( + box, + tr::lng_clear_payment_info_shipping(tr::now), + true, + st::defaultBoxCheckbox), + checkboxPadding); + const auto payment = box->addRow( + object_ptr( + box, + tr::lng_clear_payment_info_payment(tr::now), + true, + st::defaultBoxCheckbox), + checkboxPadding); + + using Flags = MTPpayments_ClearSavedInfo::Flags; + const auto flags = box->lifetime().make_state(); + + box->addButton(tr::lng_clear_payment_info_clear(), [=] { + using Flag = Flags::Enum; + *flags = (shipping->checked() ? Flag::f_info : Flag(0)) + | (payment->checked() ? Flag::f_credentials : Flag(0)); + delete label; + delete shipping; + delete payment; + box->addRow(object_ptr( + box, + tr::lng_clear_payment_info_confirm(), + st::boxLabel)); + box->clearButtons(); + box->addButton(tr::lng_clear_payment_info_clear(), [=] { + session->api().request(MTPpayments_ClearSavedInfo( + MTP_flags(*flags) + )).send(); + box->closeBox(); + }, st::attentionBoxButton); + box->addButton(tr::lng_cancel(), [=] { box->closeBox(); }); + }, st::attentionBoxButton); + box->addButton(tr::lng_cancel(), [=] { box->closeBox(); }); +} + +auto ClearPaymentInfoBox(not_null session) { + return Box(ClearPaymentInfoBoxBuilder, session); +} + +void SetupBotsAndWebsites( + not_null controller, + not_null container) { + AddSkip(container); + AddSubsectionTitle(container, tr::lng_settings_security_bots()); + + const auto session = &controller->session(); + AddButton( + container, + tr::lng_settings_clear_payment_info(), + st::settingsButton + )->addClickHandler([=] { + Ui::show(ClearPaymentInfoBox(session)); + }); + + AddSkip(container); +} + void SetupSessionsList( not_null controller, not_null container, @@ -735,6 +815,8 @@ void PrivacySecurity::setupContent( AddDivider(content); #endif // !OS_MAC_STORE && !OS_WIN_STORE SetupSelfDestruction(controller, content, trigger()); + AddDivider(content); + SetupBotsAndWebsites(controller, content); Ui::ResizeFitChild(this, content); } diff --git a/Telegram/lib_ui b/Telegram/lib_ui index 876f0f06dc..a51db55ef2 160000 --- a/Telegram/lib_ui +++ b/Telegram/lib_ui @@ -1 +1 @@ -Subproject commit 876f0f06dc8eac766aecd695944455eaf577a4b9 +Subproject commit a51db55ef278b949e184a241bed03b04b0acba77