mirror of
https://github.com/cake-tech/cake_wallet.git
synced 2024-11-17 17:57:36 +00:00
63 lines
1.8 KiB
Dart
63 lines
1.8 KiB
Dart
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;
|
|
|
|
WalletListService _service;
|
|
|
|
void changeWalletType({@required WalletType type}) {
|
|
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());
|
|
}
|
|
}
|
|
}
|