From cd4408449c74ca29b18330cad412164762a7a893 Mon Sep 17 00:00:00 2001 From: julian Date: Wed, 18 Jan 2023 08:07:25 -0600 Subject: [PATCH] desktop db migrate enabled --- lib/main.dart | 4 +-- .../password/desktop_login_view.dart | 30 +++++++++++++++++++ 2 files changed, 32 insertions(+), 2 deletions(-) diff --git a/lib/main.dart b/lib/main.dart index 304d3d8fb..6292c39ef 100644 --- a/lib/main.dart +++ b/lib/main.dart @@ -157,7 +157,7 @@ void main() async { await Hive.openBox(DB.boxNameDBInfo); - // todo: db migrate stuff for desktop needs to be handled eventually + // Desktop migrate handled elsewhere (currently desktop_login_view.dart) if (!Util.isDesktop) { int dbVersion = DB.instance.get( boxName: DB.boxNameDBInfo, key: "hive_data_version") as int? ?? @@ -172,7 +172,7 @@ void main() async { ), ); } catch (e, s) { - Logging.instance.log("Cannot migrate database\n$e $s", + Logging.instance.log("Cannot migrate mobile database\n$e $s", level: LogLevel.Error, printFullLength: true); } } diff --git a/lib/pages_desktop_specific/password/desktop_login_view.dart b/lib/pages_desktop_specific/password/desktop_login_view.dart index 713cb52c2..67eab0903 100644 --- a/lib/pages_desktop_specific/password/desktop_login_view.dart +++ b/lib/pages_desktop_specific/password/desktop_login_view.dart @@ -13,12 +13,17 @@ import 'package:stackwallet/utilities/constants.dart'; import 'package:stackwallet/utilities/flutter_secure_storage_interface.dart'; import 'package:stackwallet/utilities/text_styles.dart'; import 'package:stackwallet/utilities/theme/stack_colors.dart'; +import 'package:stackwallet/utilities/util.dart'; import 'package:stackwallet/widgets/custom_buttons/blue_text_button.dart'; import 'package:stackwallet/widgets/desktop/desktop_scaffold.dart'; import 'package:stackwallet/widgets/desktop/primary_button.dart'; import 'package:stackwallet/widgets/loading_indicator.dart'; import 'package:stackwallet/widgets/stack_text_field.dart'; +import '../../hive/db.dart'; +import '../../utilities/db_version_migration.dart'; +import '../../utilities/logger.dart'; + class DesktopLoginView extends ConsumerStatefulWidget { const DesktopLoginView({ Key? key, @@ -43,6 +48,25 @@ class _DesktopLoginViewState extends ConsumerState { bool hidePassword = true; bool _continueEnabled = false; + Future _checkDesktopMigrate() async { + if (Util.isDesktop) { + int dbVersion = DB.instance.get( + boxName: DB.boxNameDBInfo, key: "hive_data_version") as int? ?? + 0; + if (dbVersion < Constants.currentHiveDbVersion) { + try { + await DbVersionMigrator().migrate( + dbVersion, + secureStore: ref.read(secureStoreProvider), + ); + } catch (e, s) { + Logging.instance.log("Cannot migrate desktop database\n$e $s", + level: LogLevel.Error, printFullLength: true); + } + } + } + } + Future login() async { try { unawaited( @@ -63,12 +87,18 @@ class _DesktopLoginViewState extends ConsumerState { await Future.delayed(const Duration(seconds: 1)); + // init security context await ref .read(storageCryptoHandlerProvider) .initFromExisting(passwordController.text); + // init desktop secure storage await (ref.read(secureStoreProvider).store as DesktopSecureStore).init(); + // check and migrate if needed + await _checkDesktopMigrate(); + + // load data await widget.load?.call(); // if no errors passphrase is correct