add delete all functionality for IOS

This commit is contained in:
Marco 2022-10-11 14:45:11 -06:00
parent 7f8392522d
commit 548bc273f7
3 changed files with 89 additions and 17 deletions

View file

@ -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<DeleteAccountView> {
Future<void> 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<StackColors>()!
.getSecondaryEnabledButtonColor(context),
onPressed: () {
Navigator.pop(context);
},
child: Text(
"Cancel",
style: STextStyles.button(context).copyWith(
color: Theme.of(context)
.extension<StackColors>()!
.accentColorDark),
),
),
rightButton: TextButton(
style: Theme.of(context)
.extension<StackColors>()!
.getPrimaryEnabledButtonColor(context),
onPressed: () async {
await deleteEverything();
await Navigator.of(context).pushNamedAndRemoveUntil(
IntroView.routeName,
(route) => false,
);
},
child: Text(
"Delete",
style: STextStyles.button(context),
),
),
),
);
}

View file

@ -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

View file

@ -0,0 +1,30 @@
import 'package:stackwallet/hive/db.dart';
import 'package:stackwallet/utilities/logger.dart';
Future<bool> 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;
}
}