2020-07-06 20:09:03 +00:00
|
|
|
import 'package:cake_wallet/src/domain/common/wallet_info.dart';
|
2020-06-20 07:10:00 +00:00
|
|
|
import 'package:flutter/foundation.dart';
|
2020-07-06 20:09:03 +00:00
|
|
|
import 'package:hive/hive.dart';
|
2020-06-20 07:10:00 +00:00
|
|
|
import 'package:mobx/mobx.dart';
|
|
|
|
import 'package:cake_wallet/core/wallet_credentials.dart';
|
|
|
|
import 'package:cake_wallet/src/domain/common/wallet_type.dart';
|
|
|
|
import 'package:cake_wallet/view_model/wallet_creation_state.dart';
|
|
|
|
|
|
|
|
part 'wallet_creation_vm.g.dart';
|
|
|
|
|
|
|
|
class WalletCreationVM = WalletCreationVMBase with _$WalletCreationVM;
|
|
|
|
|
|
|
|
abstract class WalletCreationVMBase with Store {
|
2020-07-06 20:09:03 +00:00
|
|
|
WalletCreationVMBase(this._walletInfoSource,
|
|
|
|
{@required this.type, @required this.isRecovery}) {
|
2020-06-20 07:10:00 +00:00
|
|
|
state = InitialWalletCreationState();
|
|
|
|
name = '';
|
|
|
|
}
|
|
|
|
|
|
|
|
@observable
|
|
|
|
String name;
|
|
|
|
|
|
|
|
@observable
|
|
|
|
WalletCreationState state;
|
|
|
|
|
2020-07-06 20:09:03 +00:00
|
|
|
final WalletType type;
|
|
|
|
|
|
|
|
final bool isRecovery;
|
|
|
|
|
|
|
|
Box<WalletInfo> _walletInfoSource;
|
2020-06-20 07:10:00 +00:00
|
|
|
|
|
|
|
Future<void> create({dynamic options}) async {
|
|
|
|
try {
|
|
|
|
state = WalletCreating();
|
|
|
|
await process(getCredentials(options));
|
2020-07-06 20:09:03 +00:00
|
|
|
final id = walletTypeToString(type).toLowerCase() + '_' + name;
|
|
|
|
final walletInfo = WalletInfo(
|
|
|
|
id: id,
|
|
|
|
name: name,
|
|
|
|
type: type,
|
|
|
|
isRecovery: isRecovery,
|
|
|
|
restoreHeight: 0);
|
|
|
|
await _walletInfoSource.add(walletInfo);
|
2020-06-20 07:10:00 +00:00
|
|
|
state = WalletCreatedSuccessfully();
|
|
|
|
} catch (e) {
|
|
|
|
state = WalletCreationFailure(error: e.toString());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
WalletCredentials getCredentials(dynamic options) =>
|
|
|
|
throw UnimplementedError();
|
|
|
|
|
|
|
|
Future<void> process(WalletCredentials credentials) =>
|
|
|
|
throw UnimplementedError();
|
|
|
|
}
|