mirror of
https://github.com/Such-Software/hash-wallet.git
synced 2026-10-19 05:58:50 +02:00
Flutter upgrade
This commit is contained in:
@@ -3,7 +3,7 @@ import 'package:cake_wallet/generated/i18n.dart';
|
||||
import 'package:cw_core/wallet_type.dart';
|
||||
|
||||
class AddressLabelValidator extends TextValidator {
|
||||
AddressLabelValidator({WalletType type})
|
||||
AddressLabelValidator({WalletType? type})
|
||||
: super(
|
||||
errorMessage: S.current.error_text_subaddress_name,
|
||||
pattern: '''^[^`,'"]{1,20}\$''',
|
||||
|
||||
@@ -4,7 +4,7 @@ import 'package:cake_wallet/core/validator.dart';
|
||||
import 'package:cw_core/crypto_currency.dart';
|
||||
|
||||
class AddressValidator extends TextValidator {
|
||||
AddressValidator({@required CryptoCurrency type})
|
||||
AddressValidator({required CryptoCurrency type})
|
||||
: super(
|
||||
errorMessage: S.current.error_text_address,
|
||||
pattern: getPattern(type),
|
||||
@@ -79,7 +79,7 @@ class AddressValidator extends TextValidator {
|
||||
}
|
||||
}
|
||||
|
||||
static List<int> getLength(CryptoCurrency type) {
|
||||
static List<int>? getLength(CryptoCurrency type) {
|
||||
switch (type) {
|
||||
case CryptoCurrency.xmr:
|
||||
return null;
|
||||
|
||||
+27
-27
@@ -1,37 +1,37 @@
|
||||
abstract class Amount {
|
||||
Amount(this.value);
|
||||
// abstract class Amount {
|
||||
// Amount(this.value);
|
||||
|
||||
int value;
|
||||
// int value;
|
||||
|
||||
int minorDigits;
|
||||
// int minorDigits;
|
||||
|
||||
String code;
|
||||
// String code;
|
||||
|
||||
String formatted();
|
||||
}
|
||||
// String formatted();
|
||||
// }
|
||||
|
||||
class MoneroAmount extends Amount {
|
||||
MoneroAmount(int value) : super(value) {
|
||||
minorDigits = 12;
|
||||
code = 'XMR';
|
||||
}
|
||||
// class MoneroAmount extends Amount {
|
||||
// MoneroAmount(int value) : super(value) {
|
||||
// minorDigits = 12;
|
||||
// code = 'XMR';
|
||||
// }
|
||||
|
||||
// const moneroAmountLength = 12;
|
||||
// const moneroAmountDivider = 1000000000000;
|
||||
// final moneroAmountFormat = NumberFormat()
|
||||
// ..maximumFractionDigits = moneroAmountLength
|
||||
// ..minimumFractionDigits = 1;
|
||||
// // const moneroAmountLength = 12;
|
||||
// // const moneroAmountDivider = 1000000000000;
|
||||
// // final moneroAmountFormat = NumberFormat()
|
||||
// // ..maximumFractionDigits = moneroAmountLength
|
||||
// // ..minimumFractionDigits = 1;
|
||||
|
||||
// String moneroAmountToString({int amount}) =>
|
||||
// moneroAmountFormat.format(cryptoAmountToDouble(amount: amount, divider: moneroAmountDivider));
|
||||
// // String moneroAmountToString({int amount}) =>
|
||||
// // moneroAmountFormat.format(cryptoAmountToDouble(amount: amount, divider: moneroAmountDivider));
|
||||
|
||||
// double moneroAmountToDouble({int amount}) => cryptoAmountToDouble(amount: amount, divider: moneroAmountDivider);
|
||||
// // double moneroAmountToDouble({int amount}) => cryptoAmountToDouble(amount: amount, divider: moneroAmountDivider);
|
||||
|
||||
// int moneroParseAmount({String amount}) => moneroAmountFormat.parse(amount).toInt();
|
||||
// // int moneroParseAmount({String amount}) => moneroAmountFormat.parse(amount).toInt();
|
||||
|
||||
@override
|
||||
String formatted() {
|
||||
// TODO: implement formatted
|
||||
throw UnimplementedError();
|
||||
}
|
||||
}
|
||||
// @override
|
||||
// String formatted() {
|
||||
// // TODO: implement formatted
|
||||
// throw UnimplementedError();
|
||||
// }
|
||||
// }
|
||||
|
||||
@@ -47,7 +47,7 @@ class AmountConverter {
|
||||
case CryptoCurrency.xusd:
|
||||
return _moneroAmountToDouble(amount);
|
||||
default:
|
||||
return null;
|
||||
return 0.0;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -71,7 +71,7 @@ class AmountConverter {
|
||||
case CryptoCurrency.xusd:
|
||||
return _moneroParseAmount(amount);
|
||||
default:
|
||||
return null;
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -97,11 +97,11 @@ class AmountConverter {
|
||||
case CryptoCurrency.xusd:
|
||||
return _moneroAmountToString(amount);
|
||||
default:
|
||||
return null;
|
||||
return '';
|
||||
}
|
||||
}
|
||||
|
||||
static double cryptoAmountToDouble({num amount, num divider}) =>
|
||||
static double cryptoAmountToDouble({required num amount, required num divider}) =>
|
||||
amount / divider;
|
||||
|
||||
static String _moneroAmountToString(int amount) => _moneroAmountFormat.format(
|
||||
|
||||
@@ -3,7 +3,7 @@ import 'package:cake_wallet/generated/i18n.dart';
|
||||
import 'package:cw_core/wallet_type.dart';
|
||||
|
||||
class AmountValidator extends TextValidator {
|
||||
AmountValidator({WalletType type, bool isAutovalidate = false})
|
||||
AmountValidator({required WalletType type, bool isAutovalidate = false})
|
||||
: super(
|
||||
errorMessage: S.current.error_text_amount,
|
||||
pattern: _pattern(type),
|
||||
|
||||
@@ -6,12 +6,12 @@ import 'package:cake_wallet/entities/secret_store_key.dart';
|
||||
import 'package:cake_wallet/entities/encrypt.dart';
|
||||
|
||||
class AuthService with Store {
|
||||
AuthService({this.secureStorage, this.sharedPreferences});
|
||||
AuthService({required this.secureStorage, required this.sharedPreferences});
|
||||
|
||||
final FlutterSecureStorage secureStorage;
|
||||
final SharedPreferences sharedPreferences;
|
||||
|
||||
Future setPassword(String password) async {
|
||||
Future<void> setPassword(String password) async {
|
||||
final key = generateStoreKeyFor(key: SecretStoreKey.pinCodePassword);
|
||||
final encodedPassword = encodedPinCode(pin: password);
|
||||
await secureStorage.write(key: key, value: encodedPassword);
|
||||
@@ -24,7 +24,7 @@ class AuthService with Store {
|
||||
var password = '';
|
||||
|
||||
try {
|
||||
password = await secureStorage.read(key: key);
|
||||
password = await secureStorage.read(key: key) ?? '';
|
||||
} catch (e) {
|
||||
print(e);
|
||||
}
|
||||
@@ -35,7 +35,7 @@ class AuthService with Store {
|
||||
Future<bool> authenticate(String pin) async {
|
||||
final key = generateStoreKeyFor(key: SecretStoreKey.pinCodePassword);
|
||||
final encodedPin = await secureStorage.read(key: key);
|
||||
final decodedPin = decodedPinCode(pin: encodedPin);
|
||||
final decodedPin = decodedPinCode(pin: encodedPin!);
|
||||
|
||||
return decodedPin == pin;
|
||||
}
|
||||
|
||||
@@ -7,13 +7,13 @@ class AuthenticationInProgress extends AuthState {}
|
||||
class AuthenticatedSuccessfully extends AuthState {}
|
||||
|
||||
class AuthenticationFailure extends AuthState {
|
||||
AuthenticationFailure({this.error});
|
||||
AuthenticationFailure({required this.error});
|
||||
|
||||
final String error;
|
||||
}
|
||||
|
||||
class AuthenticationBanned extends AuthState {
|
||||
AuthenticationBanned({this.error});
|
||||
AuthenticationBanned({required this.error});
|
||||
|
||||
final String error;
|
||||
}
|
||||
|
||||
@@ -20,7 +20,8 @@ import 'package:cake_wallet/wallet_types.g.dart';
|
||||
class BackupService {
|
||||
BackupService(this._flutterSecureStorage, this._walletInfoSource,
|
||||
this._keyService, this._sharedPreferences)
|
||||
: _cipher = chacha20Poly1305Aead;
|
||||
: _cipher = Cryptography.instance.chacha20Poly1305Aead(),
|
||||
_correctWallets = <WalletInfo>[];
|
||||
|
||||
static const currentVersion = _v1;
|
||||
|
||||
@@ -54,7 +55,7 @@ class BackupService {
|
||||
case _v1:
|
||||
return await _exportBackupV1(password, nonce: nonce);
|
||||
default:
|
||||
return null;
|
||||
throw Exception('Incorrect version: $version for exportBackup');
|
||||
}
|
||||
}
|
||||
|
||||
@@ -91,8 +92,8 @@ class BackupService {
|
||||
});
|
||||
await keychainDumpFile.writeAsBytes(keychainDump.toList());
|
||||
await preferencesDumpFile.writeAsString(preferencesDump);
|
||||
zipEncoder.addFile(preferencesDumpFile, '~_preferences_dump');
|
||||
zipEncoder.addFile(keychainDumpFile, '~_keychain_dump');
|
||||
await zipEncoder.addFile(preferencesDumpFile, '~_preferences_dump');
|
||||
await zipEncoder.addFile(keychainDumpFile, '~_keychain_dump');
|
||||
zipEncoder.close();
|
||||
|
||||
final content = File(archivePath).readAsBytesSync();
|
||||
@@ -103,7 +104,7 @@ class BackupService {
|
||||
}
|
||||
|
||||
Future<void> _importBackupV1(Uint8List data, String password,
|
||||
{@required String nonce}) async {
|
||||
{required String nonce}) async {
|
||||
final appDir = await getApplicationDocumentsDirectory();
|
||||
final decryptedData = await _decrypt(data, password, nonce);
|
||||
final zip = ZipDecoder().decodeBytes(decryptedData);
|
||||
@@ -214,7 +215,7 @@ class BackupService {
|
||||
}
|
||||
|
||||
Future<void> _importKeychainDump(String password,
|
||||
{@required String nonce,
|
||||
{required String nonce,
|
||||
String keychainSalt = secrets.backupKeychainSalt}) async {
|
||||
final appDir = await getApplicationDocumentsDirectory();
|
||||
final keychainDumpFile = File('${appDir.path}/~_keychain_dump');
|
||||
@@ -251,11 +252,11 @@ class BackupService {
|
||||
}
|
||||
|
||||
Future<Uint8List> _exportKeychainDump(String password,
|
||||
{@required String nonce,
|
||||
{required String nonce,
|
||||
String keychainSalt = secrets.backupKeychainSalt}) async {
|
||||
final key = generateStoreKeyFor(key: SecretStoreKey.pinCodePassword);
|
||||
final encodedPin = await _flutterSecureStorage.read(key: key);
|
||||
final decodedPin = decodedPinCode(pin: encodedPin);
|
||||
final decodedPin = decodedPinCode(pin: encodedPin!);
|
||||
final wallets =
|
||||
await Future.wait(_walletInfoSource.values.map((walletInfo) async {
|
||||
return {
|
||||
@@ -281,41 +282,42 @@ class BackupService {
|
||||
}
|
||||
|
||||
Future<String> _exportPreferencesJSON() async {
|
||||
// FIX-ME: Force unwrap
|
||||
final preferences = <String, Object>{
|
||||
PreferencesKey.currentWalletName:
|
||||
_sharedPreferences.getString(PreferencesKey.currentWalletName),
|
||||
_sharedPreferences.getString(PreferencesKey.currentWalletName)!,
|
||||
PreferencesKey.currentNodeIdKey:
|
||||
_sharedPreferences.getInt(PreferencesKey.currentNodeIdKey),
|
||||
_sharedPreferences.getInt(PreferencesKey.currentNodeIdKey)!,
|
||||
PreferencesKey.currentBalanceDisplayModeKey: _sharedPreferences
|
||||
.getInt(PreferencesKey.currentBalanceDisplayModeKey),
|
||||
.getInt(PreferencesKey.currentBalanceDisplayModeKey)!,
|
||||
PreferencesKey.currentWalletType:
|
||||
_sharedPreferences.getInt(PreferencesKey.currentWalletType),
|
||||
_sharedPreferences.getInt(PreferencesKey.currentWalletType)!,
|
||||
PreferencesKey.currentFiatCurrencyKey:
|
||||
_sharedPreferences.getString(PreferencesKey.currentFiatCurrencyKey),
|
||||
_sharedPreferences.getString(PreferencesKey.currentFiatCurrencyKey)!,
|
||||
PreferencesKey.shouldSaveRecipientAddressKey: _sharedPreferences
|
||||
.getBool(PreferencesKey.shouldSaveRecipientAddressKey),
|
||||
.getBool(PreferencesKey.shouldSaveRecipientAddressKey)!,
|
||||
PreferencesKey.isDarkThemeLegacy:
|
||||
_sharedPreferences.getBool(PreferencesKey.isDarkThemeLegacy),
|
||||
_sharedPreferences.getBool(PreferencesKey.isDarkThemeLegacy)!,
|
||||
PreferencesKey.currentPinLength:
|
||||
_sharedPreferences.getInt(PreferencesKey.currentPinLength),
|
||||
_sharedPreferences.getInt(PreferencesKey.currentPinLength)!,
|
||||
PreferencesKey.currentTransactionPriorityKeyLegacy: _sharedPreferences
|
||||
.getInt(PreferencesKey.currentTransactionPriorityKeyLegacy),
|
||||
.getInt(PreferencesKey.currentTransactionPriorityKeyLegacy)!,
|
||||
PreferencesKey.allowBiometricalAuthenticationKey: _sharedPreferences
|
||||
.getBool(PreferencesKey.allowBiometricalAuthenticationKey),
|
||||
.getBool(PreferencesKey.allowBiometricalAuthenticationKey)!,
|
||||
PreferencesKey.currentBitcoinElectrumSererIdKey: _sharedPreferences
|
||||
.getInt(PreferencesKey.currentBitcoinElectrumSererIdKey),
|
||||
.getInt(PreferencesKey.currentBitcoinElectrumSererIdKey)!,
|
||||
PreferencesKey.currentLanguageCode:
|
||||
_sharedPreferences.getString(PreferencesKey.currentLanguageCode),
|
||||
_sharedPreferences.getString(PreferencesKey.currentLanguageCode)!,
|
||||
PreferencesKey.displayActionListModeKey:
|
||||
_sharedPreferences.getInt(PreferencesKey.displayActionListModeKey),
|
||||
_sharedPreferences.getInt(PreferencesKey.displayActionListModeKey)!,
|
||||
PreferencesKey.currentTheme:
|
||||
_sharedPreferences.getInt(PreferencesKey.currentTheme),
|
||||
_sharedPreferences.getInt(PreferencesKey.currentTheme)!,
|
||||
PreferencesKey.currentDefaultSettingsMigrationVersion: _sharedPreferences
|
||||
.getInt(PreferencesKey.currentDefaultSettingsMigrationVersion),
|
||||
.getInt(PreferencesKey.currentDefaultSettingsMigrationVersion)!,
|
||||
PreferencesKey.bitcoinTransactionPriority:
|
||||
_sharedPreferences.getInt(PreferencesKey.bitcoinTransactionPriority),
|
||||
_sharedPreferences.getInt(PreferencesKey.bitcoinTransactionPriority)!,
|
||||
PreferencesKey.moneroTransactionPriority:
|
||||
_sharedPreferences.getInt(PreferencesKey.moneroTransactionPriority),
|
||||
_sharedPreferences.getInt(PreferencesKey.moneroTransactionPriority)!,
|
||||
};
|
||||
|
||||
return json.encode(preferences);
|
||||
@@ -330,17 +332,26 @@ class BackupService {
|
||||
|
||||
Future<Uint8List> _encrypt(
|
||||
Uint8List data, String secretKeySource, String nonceBase64) async {
|
||||
final secretKeyHash = await sha256.hash(utf8.encode(secretKeySource));
|
||||
final secretKeyHash = await Cryptography.instance.sha256().hash(utf8.encode(secretKeySource));
|
||||
final secretKey = SecretKey(secretKeyHash.bytes);
|
||||
final nonce = Nonce(base64.decode(nonceBase64));
|
||||
return await _cipher.encrypt(data, secretKey: secretKey, nonce: nonce);
|
||||
final nonce = base64.decode(nonceBase64).toList();
|
||||
final box = await _cipher.encrypt(data.toList(), secretKey: secretKey, nonce: nonce);
|
||||
return Uint8List.fromList(box.cipherText);
|
||||
}
|
||||
|
||||
Future<Uint8List> _decrypt(
|
||||
Uint8List data, String secretKeySource, String nonceBase64) async {
|
||||
final secretKeyHash = await sha256.hash(utf8.encode(secretKeySource));
|
||||
final secretKey = SecretKey(secretKeyHash.bytes);
|
||||
final nonce = Nonce(base64.decode(nonceBase64));
|
||||
return await _cipher.decrypt(data, secretKey: secretKey, nonce: nonce);
|
||||
throw Exception('Unimplemented');
|
||||
//final secretKeyHash = await sha256.hash(utf8.encode(secretKeySource));
|
||||
//final secretKey = SecretKey(secretKeyHash.bytes);
|
||||
//final nonce = Nonce(base64.decode(nonceBase64));
|
||||
//return await _cipher.decrypt(data, secretKey: secretKey, nonce: nonce);
|
||||
|
||||
// final secretKeyHash = await Cryptography.instance.sha256().hash(utf8.encode(secretKeySource));
|
||||
// final secretKey = SecretKey(secretKeyHash.bytes);
|
||||
// final nonce = base64.decode(nonceBase64).toList();
|
||||
// final box = SecretBox(data.toList(), nonce: nonce, mac: Mac);
|
||||
// final plainData = await _cipher.decrypt(box, secretKey: secretKey);
|
||||
// return Uint8List.fromList(plainData);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -16,7 +16,7 @@ Future<double> _fetchPrice(Map<String, dynamic> args) async {
|
||||
final fiatStringified = fiat.toString();
|
||||
final uri = Uri.https(fiatApiAuthority, fiatApiPath,
|
||||
<String, String>{'convert': fiatStringified});
|
||||
final response = await get(uri.toString());
|
||||
final response = await get(uri);
|
||||
|
||||
if (response.statusCode != 200) {
|
||||
return 0.0;
|
||||
|
||||
@@ -7,15 +7,14 @@ class KeyService {
|
||||
|
||||
final FlutterSecureStorage _secureStorage;
|
||||
|
||||
Future<String> getWalletPassword({String walletName}) async {
|
||||
Future<String> getWalletPassword({required String walletName}) async {
|
||||
final key = generateStoreKeyFor(
|
||||
key: SecretStoreKey.moneroWalletPassword, walletName: walletName);
|
||||
final encodedPassword = await _secureStorage.read(key: key);
|
||||
|
||||
return decodeWalletPassword(password: encodedPassword);
|
||||
return decodeWalletPassword(password: encodedPassword!);
|
||||
}
|
||||
|
||||
Future<void> saveWalletPassword({String walletName, String password}) async {
|
||||
Future<void> saveWalletPassword({required String walletName, required String password}) async {
|
||||
final key = generateStoreKeyFor(
|
||||
key: SecretStoreKey.moneroWalletPassword, walletName: walletName);
|
||||
final encodedPassword = encodeWalletPassword(password: password);
|
||||
|
||||
@@ -4,7 +4,7 @@ import 'package:cake_wallet/core/validator.dart';
|
||||
import 'package:cw_core/crypto_currency.dart';
|
||||
|
||||
class MoneroLabelValidator extends TextValidator {
|
||||
MoneroLabelValidator({@required CryptoCurrency type})
|
||||
MoneroLabelValidator()
|
||||
: super(
|
||||
errorMessage: S.current.error_text_account_name,
|
||||
pattern: '^[a-zA-Z0-9_ ]{1,15}\$',
|
||||
|
||||
@@ -7,23 +7,24 @@ import 'package:cake_wallet/monero/monero.dart';
|
||||
import 'package:cake_wallet/utils/language_list.dart';
|
||||
|
||||
class SeedValidator extends Validator<MnemonicItem> {
|
||||
SeedValidator({this.type, this.language})
|
||||
: _words = getWordList(type: type, language: language);
|
||||
SeedValidator({required this.type, required this.language})
|
||||
: _words = getWordList(type: type, language: language),
|
||||
super(errorMessage: 'Wrong seed mnemonic');
|
||||
|
||||
final WalletType type;
|
||||
final String language;
|
||||
final List<String> _words;
|
||||
|
||||
static List<String> getWordList({WalletType type, String language}) {
|
||||
static List<String> getWordList({required WalletType type, required String language}) {
|
||||
switch (type) {
|
||||
case WalletType.bitcoin:
|
||||
return getBitcoinWordList(language);
|
||||
case WalletType.litecoin:
|
||||
return getBitcoinWordList(language);
|
||||
case WalletType.monero:
|
||||
return monero.getMoneroWordList(language);
|
||||
return monero!.getMoneroWordList(language);
|
||||
case WalletType.haven:
|
||||
return haven.getMoneroWordList(language);
|
||||
return haven!.getMoneroWordList(language);
|
||||
default:
|
||||
return [];
|
||||
}
|
||||
@@ -31,9 +32,9 @@ class SeedValidator extends Validator<MnemonicItem> {
|
||||
|
||||
static List<String> getBitcoinWordList(String language) {
|
||||
assert(language.toLowerCase() == LanguageList.english.toLowerCase());
|
||||
return bitcoin.getWordList();
|
||||
return bitcoin!.getWordList();
|
||||
}
|
||||
|
||||
@override
|
||||
bool isValid(MnemonicItem value) => _words.contains(value.text);
|
||||
bool isValid(MnemonicItem? value) => _words.contains(value?.text);
|
||||
}
|
||||
|
||||
@@ -33,4 +33,6 @@ String syncStatusTitle(SyncStatus syncStatus) {
|
||||
if (syncStatus is LostConnectionSyncStatus) {
|
||||
return S.current.sync_status_failed_connect;
|
||||
}
|
||||
|
||||
return '';
|
||||
}
|
||||
+12
-12
@@ -1,13 +1,13 @@
|
||||
import 'package:flutter/foundation.dart';
|
||||
|
||||
abstract class Validator<T> {
|
||||
Validator({@required this.errorMessage});
|
||||
Validator({required this.errorMessage});
|
||||
|
||||
final String errorMessage;
|
||||
|
||||
bool isValid(T value);
|
||||
bool isValid(T? value);
|
||||
|
||||
String call(T value) => !isValid(value) ? errorMessage : null;
|
||||
String? call(T? value) => !isValid(value) ? errorMessage : null;
|
||||
}
|
||||
|
||||
class TextValidator extends Validator<String> {
|
||||
@@ -15,28 +15,28 @@ class TextValidator extends Validator<String> {
|
||||
{this.minLength,
|
||||
this.maxLength,
|
||||
this.pattern,
|
||||
String errorMessage = '',
|
||||
this.length,
|
||||
this.isAutovalidate = false,
|
||||
String errorMessage})
|
||||
this.isAutovalidate = false})
|
||||
: super(errorMessage: errorMessage);
|
||||
|
||||
final int minLength;
|
||||
final int maxLength;
|
||||
final List<int> length;
|
||||
final int? minLength;
|
||||
final int? maxLength;
|
||||
final List<int>? length;
|
||||
final bool isAutovalidate;
|
||||
String pattern;
|
||||
String? pattern;
|
||||
|
||||
@override
|
||||
bool isValid(String value) {
|
||||
bool isValid(String? value) {
|
||||
if (value == null || value.isEmpty) {
|
||||
return isAutovalidate ? true : false;
|
||||
}
|
||||
|
||||
return value.length > (minLength ?? 0) &&
|
||||
(length?.contains(value.length) ?? true) &&
|
||||
((maxLength ?? 0) > 0 ? (value.length <= maxLength) : true) &&
|
||||
((maxLength ?? 0) > 0 ? (value.length <= maxLength!) : true) &&
|
||||
(pattern != null ? match(value) : true);
|
||||
}
|
||||
|
||||
bool match(String value) => RegExp(pattern).hasMatch(value);
|
||||
bool match(String value) => pattern != null ? RegExp(pattern!).hasMatch(value) : false;
|
||||
}
|
||||
|
||||
@@ -14,15 +14,13 @@ import 'package:cw_core/wallet_type.dart';
|
||||
|
||||
class WalletCreationService {
|
||||
WalletCreationService(
|
||||
{WalletType initialType,
|
||||
this.secureStorage,
|
||||
this.keyService,
|
||||
this.sharedPreferences,
|
||||
this.walletInfoSource})
|
||||
{required WalletType initialType,
|
||||
required this.secureStorage,
|
||||
required this.keyService,
|
||||
required this.sharedPreferences,
|
||||
required this.walletInfoSource})
|
||||
: type = initialType {
|
||||
if (type != null) {
|
||||
changeWalletType(type: type);
|
||||
}
|
||||
changeWalletType(type: type);
|
||||
}
|
||||
|
||||
WalletType type;
|
||||
@@ -30,11 +28,11 @@ class WalletCreationService {
|
||||
final SharedPreferences sharedPreferences;
|
||||
final KeyService keyService;
|
||||
final Box<WalletInfo> walletInfoSource;
|
||||
WalletService _service;
|
||||
WalletService? _service;
|
||||
|
||||
static const _isNewMoneroWalletPasswordUpdated = true;
|
||||
|
||||
void changeWalletType({@required WalletType type}) {
|
||||
void changeWalletType({required WalletType type}) {
|
||||
this.type = type;
|
||||
_service = getIt.get<WalletService>(param1: type);
|
||||
}
|
||||
@@ -64,7 +62,7 @@ class WalletCreationService {
|
||||
credentials.password = password;
|
||||
await keyService.saveWalletPassword(
|
||||
password: password, walletName: credentials.name);
|
||||
final wallet = await _service.create(credentials);
|
||||
final wallet = await _service!.create(credentials);
|
||||
|
||||
if (wallet.type == WalletType.monero) {
|
||||
await sharedPreferences
|
||||
@@ -82,7 +80,7 @@ class WalletCreationService {
|
||||
credentials.password = password;
|
||||
await keyService.saveWalletPassword(
|
||||
password: password, walletName: credentials.name);
|
||||
final wallet = await _service.restoreFromKeys(credentials);
|
||||
final wallet = await _service!.restoreFromKeys(credentials);
|
||||
|
||||
if (wallet.type == WalletType.monero) {
|
||||
await sharedPreferences
|
||||
@@ -100,7 +98,7 @@ class WalletCreationService {
|
||||
credentials.password = password;
|
||||
await keyService.saveWalletPassword(
|
||||
password: password, walletName: credentials.name);
|
||||
final wallet = await _service.restoreFromSeed(credentials);
|
||||
final wallet = await _service!.restoreFromSeed(credentials);
|
||||
|
||||
if (wallet.type == WalletType.monero) {
|
||||
await sharedPreferences
|
||||
|
||||
@@ -7,7 +7,7 @@ class WalletCreating extends WalletCreationState {}
|
||||
class WalletCreatedSuccessfully extends WalletCreationState {}
|
||||
|
||||
class WalletCreationFailure extends WalletCreationState {
|
||||
WalletCreationFailure({@required this.error});
|
||||
WalletCreationFailure({required this.error});
|
||||
|
||||
final String error;
|
||||
}
|
||||
@@ -17,18 +17,15 @@ class WalletLoadingService {
|
||||
final WalletService Function(WalletType type) walletServiceFactory;
|
||||
|
||||
Future<WalletBase> load(WalletType type, String name) async {
|
||||
if (walletServiceFactory == null) {
|
||||
throw Exception('WalletLoadingService.walletServiceFactory is not set');
|
||||
}
|
||||
final walletService = walletServiceFactory?.call(type);
|
||||
final walletService = walletServiceFactory.call(type);
|
||||
final password = await keyService.getWalletPassword(walletName: name);
|
||||
final wallet = await walletService.openWallet(name, password);
|
||||
final wallet = await walletService.openWallet(name, password);
|
||||
|
||||
if (type == WalletType.monero) {
|
||||
await upateMoneroWalletPassword(wallet);
|
||||
}
|
||||
if (type == WalletType.monero) {
|
||||
await upateMoneroWalletPassword(wallet);
|
||||
}
|
||||
|
||||
return wallet;
|
||||
return wallet;
|
||||
}
|
||||
|
||||
Future<void> upateMoneroWalletPassword(WalletBase wallet) async {
|
||||
|
||||
Reference in New Issue
Block a user