mirror of
https://github.com/Such-Software/hash-wallet.git
synced 2026-10-25 05:58:42 +01:00
General changes. CAKE-1.
This commit is contained in:
@@ -1,9 +1,13 @@
|
||||
import 'package:cake_wallet/core/key_service.dart';
|
||||
import 'package:cake_wallet/src/domain/common/sync_status.dart';
|
||||
import 'package:mobx/mobx.dart';
|
||||
import 'package:cake_wallet/di.dart';
|
||||
import 'package:shared_preferences/shared_preferences.dart';
|
||||
import 'package:flutter_secure_storage/flutter_secure_storage.dart';
|
||||
import 'package:cake_wallet/bitcoin/bitcoin_wallet_service.dart';
|
||||
import 'package:cake_wallet/bitcoin/bitcoin_wallet.dart';
|
||||
import 'package:cake_wallet/monero/monero_wallet_service.dart';
|
||||
import 'package:cake_wallet/core/wallet_base.dart';
|
||||
import 'package:cake_wallet/core/wallet_service.dart';
|
||||
import 'package:cake_wallet/store/app_store.dart';
|
||||
import 'package:cake_wallet/store/authentication_store.dart';
|
||||
@@ -11,22 +15,15 @@ import 'package:cake_wallet/src/domain/common/wallet_type.dart';
|
||||
import 'package:cake_wallet/src/domain/common/secret_store_key.dart';
|
||||
import 'package:cake_wallet/src/domain/common/encrypt.dart';
|
||||
|
||||
// FIXME: move me
|
||||
Future<String> getWalletPassword({String walletName}) async {
|
||||
final secureStorage = getIt.get<FlutterSecureStorage>();
|
||||
final key = generateStoreKeyFor(
|
||||
key: SecretStoreKey.moneroWalletPassword, walletName: walletName);
|
||||
final encodedPassword = await secureStorage.read(key: key);
|
||||
|
||||
return decodeWalletPassword(password: encodedPassword);
|
||||
}
|
||||
|
||||
// FIXME: move me
|
||||
Future<void> loadCurrentWallet() async {
|
||||
final appStore = getIt.get<AppStore>();
|
||||
final name = getIt.get<SharedPreferences>().getString('current_wallet_name');
|
||||
final type = WalletType.monero; // FIXME
|
||||
final password = await getWalletPassword(walletName: name);
|
||||
final typeRaw =
|
||||
getIt.get<SharedPreferences>().getInt('current_wallet_type') ?? 0;
|
||||
final type = deserializeFromInt(typeRaw);
|
||||
final password =
|
||||
await getIt.get<KeyService>().getWalletPassword(walletName: name);
|
||||
|
||||
WalletService _service;
|
||||
switch (type) {
|
||||
@@ -45,6 +42,8 @@ Future<void> loadCurrentWallet() async {
|
||||
}
|
||||
|
||||
ReactionDisposer _initialAuthReaction;
|
||||
ReactionDisposer _onCurrentWalletChangeReaction;
|
||||
ReactionDisposer _onWalletSyncStatusChangeReaction;
|
||||
|
||||
Future<void> bootstrap() async {
|
||||
final authenticationStore = getIt.get<AuthenticationStore>();
|
||||
@@ -63,4 +62,24 @@ Future<void> bootstrap() async {
|
||||
await loadCurrentWallet();
|
||||
}
|
||||
});
|
||||
|
||||
_onCurrentWalletChangeReaction ??=
|
||||
reaction((_) => getIt.get<AppStore>().wallet, (WalletBase wallet) async {
|
||||
print('Wallet name ${wallet.name}');
|
||||
|
||||
_onWalletSyncStatusChangeReaction?.reaction?.dispose();
|
||||
_onWalletSyncStatusChangeReaction = when(
|
||||
(_) => wallet.syncStatus is ConnectedSyncStatus,
|
||||
() async => await wallet.startSync());
|
||||
|
||||
await getIt
|
||||
.get<SharedPreferences>()
|
||||
.setString('current_wallet_name', wallet.name);
|
||||
|
||||
await getIt
|
||||
.get<SharedPreferences>()
|
||||
.setInt('current_wallet_type', serializeToInt(wallet.type));
|
||||
|
||||
await wallet.connectToNode(node: null);
|
||||
});
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user