Add aditional check if wallet exists with special name

This commit is contained in:
M
2022-07-14 12:48:59 +01:00
parent 52b8bafac9
commit a63c099f26
7 changed files with 45 additions and 28 deletions
+7 -6
View File
@@ -1,3 +1,4 @@
import 'package:cake_wallet/core/wallet_creation_service.dart';
import 'package:flutter/foundation.dart';
import 'package:hive/hive.dart';
import 'package:mobx/mobx.dart';
@@ -15,7 +16,7 @@ part 'wallet_creation_vm.g.dart';
class WalletCreationVM = WalletCreationVMBase with _$WalletCreationVM;
abstract class WalletCreationVMBase with Store {
WalletCreationVMBase(this._appStore, this._walletInfoSource,
WalletCreationVMBase(this._appStore, this._walletInfoSource, this.walletCreationService,
{@required this.type, @required this.isRecovery}) {
state = InitialExecutionState();
name = '';
@@ -29,14 +30,12 @@ abstract class WalletCreationVMBase with Store {
WalletType type;
final bool isRecovery;
final WalletCreationService walletCreationService;
final Box<WalletInfo> _walletInfoSource;
final AppStore _appStore;
bool nameExists(String name) {
final walletNameList = _walletInfoSource.values.map((e) => e.name.toLowerCase()).toList();
return walletNameList.contains(name.toLowerCase());
}
bool nameExists(String name)
=> walletCreationService.exists(name);
Future<void> create({dynamic options}) async {
try {
@@ -44,6 +43,8 @@ abstract class WalletCreationVMBase with Store {
if (name?.isEmpty ?? true) {
name = await generateName();
}
walletCreationService.checkIfExists(name);
final dirPath = await pathForWalletDir(name: name, type: type);
final path = await pathForWallet(name: name, type: type);
final credentials = getCredentials(options);
+4 -6
View File
@@ -17,19 +17,17 @@ part 'wallet_new_vm.g.dart';
class WalletNewVM = WalletNewVMBase with _$WalletNewVM;
abstract class WalletNewVMBase extends WalletCreationVM with Store {
WalletNewVMBase(AppStore appStore, this._walletCreationService,
WalletNewVMBase(AppStore appStore, WalletCreationService walletCreationService,
Box<WalletInfo> walletInfoSource,
{@required WalletType type})
: selectedMnemonicLanguage = '',
super(appStore, walletInfoSource, type: type, isRecovery: false);
super(appStore, walletInfoSource, walletCreationService, type: type, isRecovery: false);
@observable
String selectedMnemonicLanguage;
bool get hasLanguageSelector => type == WalletType.monero || type == WalletType.haven;
final WalletCreationService _walletCreationService;
@override
WalletCredentials getCredentials(dynamic options) {
switch (type) {
@@ -50,7 +48,7 @@ abstract class WalletNewVMBase extends WalletCreationVM with Store {
@override
Future<WalletBase> process(WalletCredentials credentials) async {
_walletCreationService.changeWalletType(type: type);
return _walletCreationService.create(credentials);
walletCreationService.changeWalletType(type: type);
return walletCreationService.create(credentials);
}
}
@@ -20,9 +20,9 @@ class WalletRestorationFromKeysVM = WalletRestorationFromKeysVMBase
abstract class WalletRestorationFromKeysVMBase extends WalletCreationVM
with Store {
WalletRestorationFromKeysVMBase(AppStore appStore,
this._walletCreationService, Box<WalletInfo> walletInfoSource,
WalletCreationService walletCreationService, Box<WalletInfo> walletInfoSource,
{@required WalletType type, @required this.language})
: super(appStore, walletInfoSource, type: type, isRecovery: true);
: super(appStore, walletInfoSource, walletCreationService, type: type, isRecovery: true);
@observable
int height;
@@ -42,7 +42,6 @@ abstract class WalletRestorationFromKeysVMBase extends WalletCreationVM
bool get hasRestorationHeight => type == WalletType.monero;
final String language;
final WalletCreationService _walletCreationService;
@override
WalletCredentials getCredentials(dynamic options) {
@@ -68,5 +67,5 @@ abstract class WalletRestorationFromKeysVMBase extends WalletCreationVM
@override
Future<WalletBase> process(WalletCredentials credentials) async =>
_walletCreationService.restoreFromKeys(credentials);
walletCreationService.restoreFromKeys(credentials);
}
@@ -20,9 +20,9 @@ class WalletRestorationFromSeedVM = WalletRestorationFromSeedVMBase
abstract class WalletRestorationFromSeedVMBase extends WalletCreationVM
with Store {
WalletRestorationFromSeedVMBase(AppStore appStore,
this._walletCreationService, Box<WalletInfo> walletInfoSource,
WalletCreationService walletCreationService, Box<WalletInfo> walletInfoSource,
{@required WalletType type, @required this.language, this.seed})
: super(appStore, walletInfoSource, type: type, isRecovery: true);
: super(appStore, walletInfoSource, walletCreationService, type: type, isRecovery: true);
@observable
String seed;
@@ -33,7 +33,6 @@ abstract class WalletRestorationFromSeedVMBase extends WalletCreationVM
bool get hasRestorationHeight => type == WalletType.monero;
final String language;
final WalletCreationService _walletCreationService;
@override
WalletCredentials getCredentials(dynamic options) {
@@ -53,5 +52,5 @@ abstract class WalletRestorationFromSeedVMBase extends WalletCreationVM
@override
Future<WalletBase> process(WalletCredentials credentials) async =>
_walletCreationService.restoreFromSeed(credentials);
walletCreationService.restoreFromSeed(credentials);
}
@@ -22,7 +22,7 @@ class WalletRestoreViewModel = WalletRestoreViewModelBase
with _$WalletRestoreViewModel;
abstract class WalletRestoreViewModelBase extends WalletCreationVM with Store {
WalletRestoreViewModelBase(AppStore appStore, this._walletCreationService,
WalletRestoreViewModelBase(AppStore appStore, WalletCreationService walletCreationService,
Box<WalletInfo> walletInfoSource,
{@required WalletType type})
: availableModes = (type == WalletType.monero || type == WalletType.haven)
@@ -30,11 +30,11 @@ abstract class WalletRestoreViewModelBase extends WalletCreationVM with Store {
: [WalletRestoreMode.seed],
hasSeedLanguageSelector = type == WalletType.monero || type == WalletType.haven,
hasBlockchainHeightLanguageSelector = type == WalletType.monero || type == WalletType.haven,
super(appStore, walletInfoSource, type: type, isRecovery: true) {
super(appStore, walletInfoSource, walletCreationService, type: type, isRecovery: true) {
isButtonEnabled =
!hasSeedLanguageSelector && !hasBlockchainHeightLanguageSelector;
mode = WalletRestoreMode.seed;
_walletCreationService.changeWalletType(type: type);
walletCreationService.changeWalletType(type: type);
}
static const moneroSeedMnemonicLength = 25;
@@ -44,7 +44,6 @@ abstract class WalletRestoreViewModelBase extends WalletCreationVM with Store {
final List<WalletRestoreMode> availableModes;
final bool hasSeedLanguageSelector;
final bool hasBlockchainHeightLanguageSelector;
final WalletCreationService _walletCreationService;
@observable
WalletRestoreMode mode;
@@ -123,9 +122,9 @@ abstract class WalletRestoreViewModelBase extends WalletCreationVM with Store {
@override
Future<WalletBase> process(WalletCredentials credentials) async {
if (mode == WalletRestoreMode.keys) {
return _walletCreationService.restoreFromKeys(credentials);
return walletCreationService.restoreFromKeys(credentials);
}
return _walletCreationService.restoreFromSeed(credentials);
return walletCreationService.restoreFromSeed(credentials);
}
}