initialize isar instance correctly for desktop secure wrapper

This commit is contained in:
julian 2022-11-10 15:40:23 -06:00
parent 3299f4ecd9
commit 7105deeb24
2 changed files with 22 additions and 3 deletions

View file

@ -7,9 +7,11 @@ import 'package:stackwallet/notifications/show_flush_bar.dart';
import 'package:stackwallet/pages_desktop_specific/forgot_password_desktop_view.dart';
import 'package:stackwallet/pages_desktop_specific/home/desktop_home_view.dart';
import 'package:stackwallet/providers/desktop/storage_crypto_handler_provider.dart';
import 'package:stackwallet/providers/global/secure_store_provider.dart';
import 'package:stackwallet/utilities/assets.dart';
import 'package:stackwallet/utilities/constants.dart';
import 'package:stackwallet/utilities/enums/flush_bar_type.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/widgets/custom_buttons/blue_text_button.dart';
@ -47,6 +49,8 @@ class _DesktopLoginViewState extends ConsumerState<DesktopLoginView> {
.read(storageCryptoHandlerProvider)
.initFromExisting(passwordController.text);
await (ref.read(secureStoreProvider).store as DesktopSecureStore).init();
await widget.load?.call();
// if no errors passphrase is correct

View file

@ -6,6 +6,8 @@ import 'package:stack_wallet_backup/secure_storage.dart';
import 'package:stackwallet/models/isar/models/encrypted_string_value.dart';
abstract class SecureStorageInterface {
dynamic get store;
Future<void> write({
required String key,
required String? value,
@ -54,6 +56,7 @@ class DesktopSecureStore {
[EncryptedStringValueSchema],
directory: appDirectory!.path,
inspector: false,
name: "desktopStore",
);
}
@ -77,7 +80,9 @@ class DesktopSecureStore {
}) async {
if (value == null) {
// here we assume that a value is to be deleted
await isar.encryptedStringValues.deleteByKey(key);
await isar.writeTxn(() async {
await isar.encryptedStringValues.deleteByKey(key);
});
} else {
// otherwise created encrypted object value
final object = EncryptedStringValue();
@ -85,14 +90,18 @@ class DesktopSecureStore {
object.value = await handler.encryptValue(key, value);
// store object value
await isar.encryptedStringValues.put(object);
await isar.writeTxn(() async {
await isar.encryptedStringValues.put(object);
});
}
}
Future<void> delete({
required String key,
}) async {
await isar.encryptedStringValues.deleteByKey(key);
await isar.writeTxn(() async {
await isar.encryptedStringValues.deleteByKey(key);
});
}
}
@ -101,6 +110,9 @@ class SecureStorageWrapper implements SecureStorageInterface {
final dynamic _store;
final bool _isDesktop;
@override
dynamic get store => _store;
const SecureStorageWrapper({
required dynamic store,
required bool isDesktop,
@ -245,4 +257,7 @@ class FakeSecureStorage implements SecureStorageInterface {
_deletes++;
_store.remove(key);
}
@override
dynamic get store => throw UnimplementedError();
}