From 548bc273f7358b416b590bce56d1e90d32aa23c9 Mon Sep 17 00:00:00 2001 From: Marco Date: Tue, 11 Oct 2022 14:45:11 -0600 Subject: [PATCH] add delete all functionality for IOS --- .../delete_account_view.dart | 46 +++++++++++++++++-- .../global_settings_view.dart | 30 ++++++------ lib/utilities/delete_everything.dart | 30 ++++++++++++ 3 files changed, 89 insertions(+), 17 deletions(-) create mode 100644 lib/utilities/delete_everything.dart diff --git a/lib/pages/settings_views/global_settings_view/delete_account_view.dart b/lib/pages/settings_views/global_settings_view/delete_account_view.dart index 5fdabf6ad..e9cc819dc 100644 --- a/lib/pages/settings_views/global_settings_view/delete_account_view.dart +++ b/lib/pages/settings_views/global_settings_view/delete_account_view.dart @@ -8,6 +8,10 @@ import 'package:stackwallet/widgets/desktop/desktop_scaffold.dart'; import 'package:stackwallet/widgets/desktop/primary_button.dart'; import 'package:stackwallet/widgets/rounded_white_container.dart'; +import 'package:stackwallet/widgets/stack_dialog.dart'; +import 'package:stackwallet/utilities/delete_everything.dart'; +import 'package:stackwallet/utilities/theme/stack_colors.dart'; + class DeleteAccountView extends StatefulWidget { const DeleteAccountView({Key? key}) : super(key: key); @@ -22,9 +26,45 @@ class _DeleteAccountViewState extends State { Future onConfirmDeleteAccount() async { // TODO delete everything then pop to intro view - await Navigator.of(context).pushNamedAndRemoveUntil( - IntroView.routeName, - (route) => false, + + await showDialog( + barrierDismissible: true, + context: context, + builder: (_) => StackDialog( + title: "Are you sure you want to delete all Wallets?", + leftButton: TextButton( + style: Theme.of(context) + .extension()! + .getSecondaryEnabledButtonColor(context), + onPressed: () { + Navigator.pop(context); + }, + child: Text( + "Cancel", + style: STextStyles.button(context).copyWith( + color: Theme.of(context) + .extension()! + .accentColorDark), + ), + ), + rightButton: TextButton( + style: Theme.of(context) + .extension()! + .getPrimaryEnabledButtonColor(context), + onPressed: () async { + await deleteEverything(); + + await Navigator.of(context).pushNamedAndRemoveUntil( + IntroView.routeName, + (route) => false, + ); + }, + child: Text( + "Delete", + style: STextStyles.button(context), + ), + ), + ), ); } diff --git a/lib/pages/settings_views/global_settings_view/global_settings_view.dart b/lib/pages/settings_views/global_settings_view/global_settings_view.dart index 85e71f44f..fe6529c20 100644 --- a/lib/pages/settings_views/global_settings_view/global_settings_view.dart +++ b/lib/pages/settings_views/global_settings_view/global_settings_view.dart @@ -23,6 +23,8 @@ import 'package:stackwallet/utilities/theme/stack_colors.dart'; import 'package:stackwallet/widgets/custom_buttons/app_bar_icon_button.dart'; import 'package:stackwallet/widgets/rounded_white_container.dart'; +import 'package:stackwallet/utilities/delete_everything.dart'; + class GlobalSettingsView extends StatelessWidget { const GlobalSettingsView({ Key? key, @@ -191,6 +193,20 @@ class GlobalSettingsView extends StatelessWidget { AppearanceSettingsView.routeName); }, ), + if (Platform.isIOS) + const SizedBox( + height: 8, + ), + if (Platform.isIOS) + SettingsListButton( + iconAssetName: Assets.svg.circleAlert, + iconSize: 16, + title: "Delete account", + onPressed: () async { + await Navigator.of(context) + .pushNamed(DeleteAccountView.routeName); + }, + ), const SizedBox( height: 8, ), @@ -227,20 +243,6 @@ class GlobalSettingsView extends StatelessWidget { .pushNamed(SupportView.routeName); }, ), - if (Platform.isIOS) - const SizedBox( - height: 8, - ), - if (Platform.isIOS) - SettingsListButton( - iconAssetName: Assets.svg.circleAlert, - iconSize: 16, - title: "Delete account", - onPressed: () async { - await Navigator.of(context) - .pushNamed(DeleteAccountView.routeName); - }, - ), // TextButton( // style: Theme.of(context) // .textButtonTheme diff --git a/lib/utilities/delete_everything.dart b/lib/utilities/delete_everything.dart new file mode 100644 index 000000000..497cd71f4 --- /dev/null +++ b/lib/utilities/delete_everything.dart @@ -0,0 +1,30 @@ +import 'package:stackwallet/hive/db.dart'; +import 'package:stackwallet/utilities/logger.dart'; + +Future deleteEverything() async { + try { + await DB.instance.deleteBoxFromDisk(boxName: DB.boxNameAddressBook); + await DB.instance.deleteBoxFromDisk(boxName: DB.boxNameDebugInfo); + await DB.instance.deleteBoxFromDisk(boxName: DB.boxNameNodeModels); + await DB.instance.deleteBoxFromDisk(boxName: DB.boxNamePrimaryNodes); + await DB.instance.deleteBoxFromDisk(boxName: DB.boxNameAllWalletsData); + await DB.instance.deleteBoxFromDisk(boxName: DB.boxNameNotifications); + await DB.instance.deleteBoxFromDisk(boxName: DB.boxNameWatchedTransactions); + await DB.instance.deleteBoxFromDisk(boxName: DB.boxNameWatchedTrades); + await DB.instance.deleteBoxFromDisk(boxName: DB.boxNameTrades); + await DB.instance.deleteBoxFromDisk(boxName: DB.boxNameTradesV2); + await DB.instance.deleteBoxFromDisk(boxName: DB.boxNameTradeNotes); + await DB.instance.deleteBoxFromDisk(boxName: DB.boxNameTradeLookup); + await DB.instance.deleteBoxFromDisk(boxName: DB.boxNameFavoriteWallets); + await DB.instance.deleteBoxFromDisk(boxName: DB.boxNamePrefs); + await DB.instance + .deleteBoxFromDisk(boxName: DB.boxNameWalletsToDeleteOnStart); + await DB.instance.deleteBoxFromDisk(boxName: DB.boxNamePriceCache); + await DB.instance.deleteBoxFromDisk(boxName: DB.boxNameDBInfo); + await DB.instance.deleteBoxFromDisk(boxName: DB.boxNameTheme); + return true; + } catch (e, s) { + Logging.instance.log("$e $s", level: LogLevel.Error); + return false; + } +}