You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
cake_wallet/lib/core/wallet_creation_service.dart

69 lines
2.4 KiB

import 'package:cake_wallet/di.dart';
4 years ago
import 'package:flutter/foundation.dart';
4 years ago
import 'package:flutter_secure_storage/flutter_secure_storage.dart';
import 'package:shared_preferences/shared_preferences.dart';
import 'package:cake_wallet/core/key_service.dart';
4 years ago
import 'package:cake_wallet/core/generate_wallet_password.dart';
import 'package:cake_wallet/store/app_store.dart';
4 years ago
import 'package:cake_wallet/core/wallet_credentials.dart';
4 years ago
import 'package:cake_wallet/bitcoin/bitcoin_wallet_service.dart';
import 'package:cake_wallet/monero/monero_wallet_service.dart';
import 'package:cake_wallet/core/wallet_service.dart';
4 years ago
import 'package:cake_wallet/src/domain/common/wallet_type.dart';
4 years ago
class WalletCreationService {
WalletCreationService(
{WalletType initialType,
this.appStore,
this.secureStorage,
this.keyService,
4 years ago
this.sharedPreferences})
: type = initialType {
if (type != null) {
changeWalletType(type: type);
}
}
4 years ago
4 years ago
WalletType type;
4 years ago
final AppStore appStore;
final FlutterSecureStorage secureStorage;
final SharedPreferences sharedPreferences;
final KeyService keyService;
4 years ago
WalletService _service;
4 years ago
void changeWalletType({@required WalletType type}) {
4 years ago
this.type = type;
_service = getIt.get<WalletService>(param1: type);
4 years ago
}
Future<void> create(WalletCredentials credentials) async {
4 years ago
final password = generateWalletPassword(type);
credentials.password = password;
await keyService.saveWalletPassword(
password: password, walletName: credentials.name);
4 years ago
final wallet = await _service.create(credentials);
appStore.wallet = wallet;
appStore.authenticationStore.allowed();
4 years ago
}
Future<void> restoreFromKeys(WalletCredentials credentials) async {
4 years ago
final password = generateWalletPassword(type);
credentials.password = password;
await keyService.saveWalletPassword(
password: password, walletName: credentials.name);
4 years ago
final wallet = await _service.restoreFromKeys(credentials);
appStore.wallet = wallet;
appStore.authenticationStore.allowed();
4 years ago
}
Future<void> restoreFromSeed(WalletCredentials credentials) async {
4 years ago
final password = generateWalletPassword(type);
credentials.password = password;
await keyService.saveWalletPassword(
password: password, walletName: credentials.name);
4 years ago
final wallet = await _service.restoreFromSeed(credentials);
appStore.wallet = wallet;
appStore.authenticationStore.allowed();
}
4 years ago
}