cake_wallet/lib/src/domain/services/wallet_service.dart

132 lines
3.8 KiB
Dart
Raw Normal View History

2020-01-04 19:31:52 +00:00
import 'package:rxdart/rxdart.dart';
import 'package:cake_wallet/src/domain/common/balance.dart';
import 'package:cake_wallet/src/domain/common/wallet_description.dart';
import 'package:cake_wallet/src/domain/common/wallet.dart';
import 'package:cake_wallet/src/domain/common/transaction_history.dart';
import 'package:cake_wallet/src/domain/common/wallet_type.dart';
import 'package:cake_wallet/src/domain/common/sync_status.dart';
import 'package:cake_wallet/src/domain/common/transaction_creation_credentials.dart';
import 'package:cake_wallet/src/domain/common/pending_transaction.dart';
import 'package:cake_wallet/src/domain/common/node.dart';
class WalletService extends Wallet {
2020-01-08 12:26:34 +00:00
WalletService() {
_currentWallet = null;
walletType = WalletType.none;
_syncStatus = BehaviorSubject<SyncStatus>();
_onBalanceChange = BehaviorSubject<Balance>();
_onWalletChanged = BehaviorSubject<Wallet>();
}
@override
2020-01-04 19:31:52 +00:00
Observable<Balance> get onBalanceChange => _onBalanceChange.stream;
2020-01-08 12:26:34 +00:00
@override
2020-01-04 19:31:52 +00:00
Observable<SyncStatus> get syncStatus => _syncStatus.stream;
2020-01-08 12:26:34 +00:00
@override
2020-01-04 19:31:52 +00:00
Observable<String> get onAddressChange => _currentWallet.onAddressChange;
2020-01-08 12:26:34 +00:00
@override
2020-01-04 19:31:52 +00:00
Observable<String> get onNameChange => _currentWallet.onNameChange;
2020-01-08 12:26:34 +00:00
@override
2020-01-04 19:31:52 +00:00
String get address => _currentWallet.address;
2020-01-08 12:26:34 +00:00
@override
2020-01-04 19:31:52 +00:00
String get name => _currentWallet.name;
2020-01-08 12:26:34 +00:00
@override
2020-01-04 19:31:52 +00:00
WalletType get walletType => _currentWallet.walletType;
2020-01-08 12:26:34 +00:00
Observable<Wallet> get onWalletChange => _onWalletChanged.stream;
SyncStatus get syncStatusValue => _syncStatus.value;
Wallet get currentWallet => _currentWallet;
2020-01-04 19:31:52 +00:00
set currentWallet(Wallet wallet) {
_currentWallet = wallet;
if (wallet == null) {
return;
}
_currentWallet.onBalanceChange
.listen((wallet) => _onBalanceChange.add(wallet));
_currentWallet.syncStatus.listen((status) => _syncStatus.add(status));
_onWalletChanged.add(wallet);
final type = wallet.getType();
wallet.getName().then(
(name) => description = WalletDescription(name: name, type: type));
}
BehaviorSubject<Wallet> _onWalletChanged;
BehaviorSubject<Balance> _onBalanceChange;
BehaviorSubject<SyncStatus> _syncStatus;
Wallet _currentWallet;
WalletDescription description;
2020-01-08 12:26:34 +00:00
@override
2020-01-04 19:31:52 +00:00
WalletType getType() => WalletType.monero;
2020-01-08 12:26:34 +00:00
@override
2020-01-04 19:31:52 +00:00
Future<String> getFilename() => _currentWallet.getFilename();
2020-01-08 12:26:34 +00:00
@override
2020-01-04 19:31:52 +00:00
Future<String> getName() => _currentWallet.getName();
2020-01-08 12:26:34 +00:00
@override
2020-01-04 19:31:52 +00:00
Future<String> getAddress() => _currentWallet.getAddress();
2020-01-08 12:26:34 +00:00
@override
2020-01-04 19:31:52 +00:00
Future<String> getSeed() => _currentWallet.getSeed();
2020-01-08 12:26:34 +00:00
@override
2020-01-04 19:31:52 +00:00
Future<Map<String, String>> getKeys() => _currentWallet.getKeys();
2020-01-08 12:26:34 +00:00
@override
2020-01-04 19:31:52 +00:00
Future<String> getFullBalance() => _currentWallet.getFullBalance();
2020-01-08 12:26:34 +00:00
@override
2020-01-04 19:31:52 +00:00
Future<String> getUnlockedBalance() => _currentWallet.getUnlockedBalance();
2020-01-08 12:26:34 +00:00
@override
2020-01-04 19:31:52 +00:00
Future<int> getCurrentHeight() => _currentWallet.getCurrentHeight();
2020-01-08 12:26:34 +00:00
@override
2020-01-04 19:31:52 +00:00
Future<int> getNodeHeight() => _currentWallet.getNodeHeight();
2020-01-08 12:26:34 +00:00
@override
2020-01-04 19:31:52 +00:00
Future<bool> isConnected() => _currentWallet.isConnected();
2020-01-08 12:26:34 +00:00
@override
2020-01-04 19:31:52 +00:00
Future close() => _currentWallet.close();
2020-01-08 12:26:34 +00:00
@override
Future connectToNode(
{Node node, bool useSSL = false, bool isLightWallet = false}) =>
2020-01-04 19:31:52 +00:00
_currentWallet.connectToNode(
2020-01-08 12:26:34 +00:00
node: node, useSSL: useSSL, isLightWallet: isLightWallet);
2020-01-04 19:31:52 +00:00
2020-01-08 12:26:34 +00:00
@override
2020-01-04 19:31:52 +00:00
Future startSync() => _currentWallet.startSync();
2020-01-08 12:26:34 +00:00
@override
2020-01-04 19:31:52 +00:00
TransactionHistory getHistory() => _currentWallet.getHistory();
2020-01-08 12:26:34 +00:00
@override
2020-01-04 19:31:52 +00:00
Future<PendingTransaction> createTransaction(
TransactionCreationCredentials credentials) =>
_currentWallet.createTransaction(credentials);
2020-01-08 12:26:34 +00:00
@override
2020-01-04 19:31:52 +00:00
Future updateInfo() async => _currentWallet.updateInfo();
2020-01-08 12:26:34 +00:00
@override
Future rescan({int restoreHeight = 0}) async =>
_currentWallet.rescan(restoreHeight: restoreHeight);
2020-01-04 19:31:52 +00:00
}