diff --git a/lib/db/hive/db.dart b/lib/db/hive/db.dart index 42e938279..b25041532 100644 --- a/lib/db/hive/db.dart +++ b/lib/db/hive/db.dart @@ -253,6 +253,36 @@ class DB { Future deleteBoxFromDisk({required String boxName}) async => await mutex.protect(() async => await Hive.deleteBoxFromDisk(boxName)); + + /////////////////////////////////////////////////////////////////////////// + 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: "theme"); + return true; + } catch (e, s) { + Logging.instance.log("$e $s", level: LogLevel.Error); + return false; + } + } } abstract class DBKeys { 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 2b794f351..f6acc0ac8 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 @@ -9,9 +9,9 @@ */ import 'package:flutter/material.dart'; +import 'package:stackwallet/db/hive/db.dart'; import 'package:stackwallet/pages/intro_view.dart'; import 'package:stackwallet/themes/stack_colors.dart'; -import 'package:stackwallet/utilities/delete_everything.dart'; import 'package:stackwallet/utilities/text_styles.dart'; import 'package:stackwallet/utilities/util.dart'; import 'package:stackwallet/widgets/custom_buttons/app_bar_icon_button.dart'; @@ -36,7 +36,7 @@ class _DeleteAccountViewState extends State { Future onConfirmDeleteAccount() async { // TODO delete everything then pop to intro view - await showDialog( + await showDialog( barrierDismissible: true, context: context, builder: (_) => StackDialog( @@ -61,12 +61,14 @@ class _DeleteAccountViewState extends State { .extension()! .getPrimaryEnabledButtonStyle(context), onPressed: () async { - await deleteEverything(); + await DB.instance.deleteEverything(); - await Navigator.of(context).pushNamedAndRemoveUntil( - IntroView.routeName, - (route) => false, - ); + if (mounted) { + await Navigator.of(context).pushNamedAndRemoveUntil( + IntroView.routeName, + (route) => false, + ); + } }, child: Text( "Delete", @@ -82,7 +84,7 @@ class _DeleteAccountViewState extends State { return MasterScaffold( isDesktop: isDesktop, appBar: isDesktop - ? DesktopAppBar(isCompactHeight: true) + ? const DesktopAppBar(isCompactHeight: true) : AppBar( leading: AppBarBackButton( onPressed: () async { diff --git a/lib/utilities/delete_everything.dart b/lib/utilities/delete_everything.dart deleted file mode 100644 index 65a1c36a4..000000000 --- a/lib/utilities/delete_everything.dart +++ /dev/null @@ -1,40 +0,0 @@ -/* - * This file is part of Stack Wallet. - * - * Copyright (c) 2023 Cypher Stack - * All Rights Reserved. - * The code is distributed under GPLv3 license, see LICENSE file for details. - * Generated by Cypher Stack on 2023-05-26 - * - */ - -import 'package:stackwallet/db/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: "theme"); - return true; - } catch (e, s) { - Logging.instance.log("$e $s", level: LogLevel.Error); - return false; - } -}