cake_wallet/lib/entities/load_current_wallet.dart
OmarHatem 851d22fd33 Merge branch 'main' of https://github.com/cake-tech/cake_wallet into cw_linux_direct_input_password
 Conflicts:
	.gitignore
	cw_haven/pubspec.lock
	cw_nano/lib/nano_wallet.dart
	cw_nano/pubspec.lock
	lib/buy/moonpay/moonpay_provider.dart
	lib/di.dart
	lib/entities/load_current_wallet.dart
2024-01-16 02:11:28 +02:00

31 lines
1.1 KiB
Dart

import 'package:cake_wallet/di.dart';
import 'package:shared_preferences/shared_preferences.dart';
import 'package:cake_wallet/store/app_store.dart';
import 'package:cake_wallet/entities/background_tasks.dart';
import 'package:cake_wallet/entities/preferences_key.dart';
import 'package:cw_core/wallet_type.dart';
import 'package:cake_wallet/core/wallet_loading_service.dart';
Future<void> loadCurrentWallet({String? password}) async {
final appStore = getIt.get<AppStore>();
final name = getIt
.get<SharedPreferences>()
.getString(PreferencesKey.currentWalletName);
final typeRaw =
getIt.get<SharedPreferences>().getInt(PreferencesKey.currentWalletType) ??
0;
if (name == null) {
throw Exception('Incorrect current wallet name: $name');
}
final type = deserializeFromInt(typeRaw);
final walletLoadingService = getIt.get<WalletLoadingService>();
final wallet = await walletLoadingService.load(
type,
name,
password: password);
await appStore.changeCurrentWallet(wallet);
getIt.get<BackgroundTasks>().registerSyncTask();
}