cake_wallet/lib/core/wallet_creation_service.dart

68 lines
1.9 KiB
Dart
Raw Normal View History

2020-06-01 18:13:56 +00:00
import 'package:cake_wallet/core/wallet_creation_state.dart';
import 'package:flutter/foundation.dart';
import 'package:mobx/mobx.dart';
import 'package:cake_wallet/core/wallet_credentials.dart';
import 'package:cake_wallet/core/bitcoin_wallet_list_service.dart';
import 'package:cake_wallet/core/monero_wallet_list_service.dart';
import 'package:cake_wallet/core/wallet_list_service.dart';
import 'package:cake_wallet/src/domain/common/wallet_type.dart';
part 'wallet_creation_service.g.dart';
class WalletCreationService = WalletCreationServiceBase
with _$WalletCreationService;
abstract class WalletCreationServiceBase with Store {
@observable
WalletCreationState state;
2020-06-03 09:56:23 +00:00
WalletType type;
2020-06-01 18:13:56 +00:00
WalletListService _service;
void changeWalletType({@required WalletType type}) {
2020-06-03 09:56:23 +00:00
this.type = type;
2020-06-01 18:13:56 +00:00
switch (type) {
case WalletType.monero:
_service = MoneroWalletListService();
break;
case WalletType.bitcoin:
_service = BitcoinWalletListService();
break;
default:
break;
}
}
Future<void> create(WalletCredentials credentials) async {
try {
state = WalletCreating();
await _service.create(credentials);
state = WalletCreatedSuccessfully();
} catch (e) {
state = WalletCreationFailure(error: e.toString());
}
}
Future<void> restoreFromKeys(WalletCredentials credentials) async {
try {
state = WalletCreating();
await _service.restoreFromKeys(credentials);
state = WalletCreatedSuccessfully();
} catch (e) {
state = WalletCreationFailure(error: e.toString());
}
}
Future<void> restoreFromSeed(WalletCredentials credentials) async {
try {
state = WalletCreating();
await _service.restoreFromSeed(credentials);
state = WalletCreatedSuccessfully();
} catch (e) {
state = WalletCreationFailure(error: e.toString());
}
}
}