2020-09-21 11:50:26 +00:00
|
|
|
import 'package:cake_wallet/di.dart';
|
|
|
|
import 'package:shared_preferences/shared_preferences.dart';
|
|
|
|
import 'package:cake_wallet/store/app_store.dart';
|
2023-08-04 17:55:56 +00:00
|
|
|
import 'package:cake_wallet/entities/background_tasks.dart';
|
2020-09-21 11:50:26 +00:00
|
|
|
import 'package:cake_wallet/entities/preferences_key.dart';
|
2021-12-24 12:37:24 +00:00
|
|
|
import 'package:cw_core/wallet_type.dart';
|
2022-07-19 14:29:28 +00:00
|
|
|
import 'package:cake_wallet/core/wallet_loading_service.dart';
|
2020-09-21 11:50:26 +00:00
|
|
|
|
2023-03-30 22:33:59 +00:00
|
|
|
Future<void> loadCurrentWallet({String? password}) async {
|
2020-09-21 11:50:26 +00:00
|
|
|
final appStore = getIt.get<AppStore>();
|
|
|
|
final name = getIt
|
|
|
|
.get<SharedPreferences>()
|
|
|
|
.getString(PreferencesKey.currentWalletName);
|
|
|
|
final typeRaw =
|
|
|
|
getIt.get<SharedPreferences>().getInt(PreferencesKey.currentWalletType) ??
|
|
|
|
0;
|
2022-10-12 17:09:57 +00:00
|
|
|
|
|
|
|
if (name == null) {
|
|
|
|
throw Exception('Incorrect current wallet name: $name');
|
|
|
|
}
|
|
|
|
|
2020-09-21 11:50:26 +00:00
|
|
|
final type = deserializeFromInt(typeRaw);
|
2022-07-19 14:29:28 +00:00
|
|
|
final walletLoadingService = getIt.get<WalletLoadingService>();
|
2023-03-30 22:33:59 +00:00
|
|
|
final wallet = await walletLoadingService.load(
|
|
|
|
type,
|
|
|
|
name,
|
|
|
|
password: password);
|
2023-12-28 01:37:36 +00:00
|
|
|
await appStore.changeCurrentWallet(wallet);
|
2023-08-04 17:55:56 +00:00
|
|
|
|
|
|
|
getIt.get<BackgroundTasks>().registerSyncTask();
|
2020-09-21 11:50:26 +00:00
|
|
|
}
|