mirror of
https://github.com/cypherstack/stack_wallet.git
synced 2024-11-17 09:47:37 +00:00
clean up coinservice and manager classes to handle new isar models and balance model
This commit is contained in:
parent
e203da866d
commit
78db152ff4
2 changed files with 13 additions and 94 deletions
|
@ -1,13 +1,15 @@
|
|||
import 'package:decimal/decimal.dart';
|
||||
import 'package:stackwallet/electrumx_rpc/cached_electrumx.dart';
|
||||
import 'package:stackwallet/electrumx_rpc/electrumx.dart';
|
||||
import 'package:stackwallet/models/models.dart';
|
||||
import 'package:stackwallet/models/balance.dart';
|
||||
import 'package:stackwallet/models/isar/models/isar_models.dart' as isar_models;
|
||||
import 'package:stackwallet/models/node_model.dart';
|
||||
import 'package:stackwallet/models/paymint/fee_object_model.dart';
|
||||
import 'package:stackwallet/services/coins/bitcoin/bitcoin_wallet.dart';
|
||||
import 'package:stackwallet/services/coins/bitcoincash/bitcoincash_wallet.dart';
|
||||
import 'package:stackwallet/services/coins/dogecoin/dogecoin_wallet.dart';
|
||||
import 'package:stackwallet/services/coins/epiccash/epiccash_wallet.dart';
|
||||
import 'package:stackwallet/services/coins/firo/firo_wallet.dart';
|
||||
import 'package:stackwallet/services/coins/litecoin/litecoin_wallet.dart';
|
||||
import 'package:stackwallet/services/coins/monero/monero_wallet.dart';
|
||||
import 'package:stackwallet/services/coins/namecoin/namecoin_wallet.dart';
|
||||
import 'package:stackwallet/services/coins/particl/particl_wallet.dart';
|
||||
|
@ -17,8 +19,6 @@ import 'package:stackwallet/utilities/enums/coin_enum.dart';
|
|||
import 'package:stackwallet/utilities/flutter_secure_storage_interface.dart';
|
||||
import 'package:stackwallet/utilities/prefs.dart';
|
||||
|
||||
import 'litecoin/litecoin_wallet.dart';
|
||||
|
||||
abstract class CoinServiceAPI {
|
||||
CoinServiceAPI();
|
||||
|
||||
|
@ -240,30 +240,15 @@ abstract class CoinServiceAPI {
|
|||
|
||||
Future<String> confirmSend({required Map<String, dynamic> txData});
|
||||
|
||||
/// create and submit tx to network
|
||||
///
|
||||
/// Returns the txid of the sent tx
|
||||
/// will throw exceptions on failure
|
||||
Future<String> send(
|
||||
{required String toAddress,
|
||||
required int amount,
|
||||
Map<String, String> args});
|
||||
|
||||
Future<FeeObject> get fees;
|
||||
Future<int> get maxFee;
|
||||
|
||||
Future<String> get currentReceivingAddress;
|
||||
// Future<String> get currentLegacyReceivingAddress;
|
||||
|
||||
Future<Decimal> get availableBalance;
|
||||
Future<Decimal> get pendingBalance;
|
||||
Future<Decimal> get totalBalance;
|
||||
Future<Decimal> get balanceMinusMaxFee;
|
||||
Balance get balance;
|
||||
|
||||
Future<List<String>> get allOwnAddresses;
|
||||
|
||||
Future<TransactionData> get transactionData;
|
||||
Future<List<UtxoObject>> get unspentOutputs;
|
||||
Future<List<isar_models.Transaction>> get transactions;
|
||||
Future<List<isar_models.UTXO>> get utxos;
|
||||
|
||||
Future<void> refresh();
|
||||
|
||||
|
|
|
@ -1,8 +1,9 @@
|
|||
import 'dart:async';
|
||||
|
||||
import 'package:decimal/decimal.dart';
|
||||
import 'package:event_bus/event_bus.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:stackwallet/models/balance.dart';
|
||||
import 'package:stackwallet/models/isar/models/isar_models.dart' as isar_models;
|
||||
import 'package:stackwallet/models/models.dart';
|
||||
import 'package:stackwallet/services/coins/coin_service.dart';
|
||||
import 'package:stackwallet/services/event_bus/events/global/node_connection_status_changed_event.dart';
|
||||
|
@ -59,7 +60,6 @@ class Manager with ChangeNotifier {
|
|||
Future<void> updateNode(bool shouldRefresh) async {
|
||||
await _currentWallet.updateNode(shouldRefresh);
|
||||
}
|
||||
// Function(bool isActive)? onIsActiveWalletChanged;
|
||||
|
||||
CoinServiceAPI get wallet => _currentWallet;
|
||||
|
||||
|
@ -120,73 +120,17 @@ class Manager with ChangeNotifier {
|
|||
}
|
||||
}
|
||||
|
||||
/// create and submit tx to network
|
||||
///
|
||||
/// Returns the txid of the sent tx
|
||||
/// will throw exceptions on failure
|
||||
Future<String> send({
|
||||
required String toAddress,
|
||||
required int amount,
|
||||
Map<String, String> args = const {},
|
||||
}) async {
|
||||
try {
|
||||
final txid = await _currentWallet.send(
|
||||
toAddress: toAddress,
|
||||
amount: amount,
|
||||
args: args,
|
||||
);
|
||||
notifyListeners();
|
||||
return txid;
|
||||
} catch (e, s) {
|
||||
Logging.instance.log("$e\n $s", level: LogLevel.Error);
|
||||
// rethrow to pass error in alert
|
||||
rethrow;
|
||||
}
|
||||
}
|
||||
|
||||
Future<FeeObject> get fees => _currentWallet.fees;
|
||||
Future<int> get maxFee => _currentWallet.maxFee;
|
||||
|
||||
Future<String> get currentReceivingAddress =>
|
||||
_currentWallet.currentReceivingAddress;
|
||||
// Future<String> get currentLegacyReceivingAddress =>
|
||||
// _currentWallet.currentLegacyReceivingAddress;
|
||||
|
||||
Future<Decimal> get availableBalance async {
|
||||
_cachedAvailableBalance = await _currentWallet.availableBalance;
|
||||
return _cachedAvailableBalance;
|
||||
}
|
||||
Balance get balance => _currentWallet.balance;
|
||||
|
||||
Decimal _cachedAvailableBalance = Decimal.zero;
|
||||
Decimal get cachedAvailableBalance => _cachedAvailableBalance;
|
||||
|
||||
Future<Decimal> get pendingBalance => _currentWallet.pendingBalance;
|
||||
Future<Decimal> get balanceMinusMaxFee => _currentWallet.balanceMinusMaxFee;
|
||||
|
||||
Future<Decimal> get totalBalance async {
|
||||
_cachedTotalBalance = await _currentWallet.totalBalance;
|
||||
return _cachedTotalBalance;
|
||||
}
|
||||
|
||||
Decimal _cachedTotalBalance = Decimal.zero;
|
||||
Decimal get cachedTotalBalance => _cachedTotalBalance;
|
||||
|
||||
// Future<Decimal> get fiatBalance async {
|
||||
// final balance = await _currentWallet.availableBalance;
|
||||
// final price = await _currentWallet.basePrice;
|
||||
// return balance * price;
|
||||
// }
|
||||
//
|
||||
// Future<Decimal> get fiatTotalBalance async {
|
||||
// final balance = await _currentWallet.totalBalance;
|
||||
// final price = await _currentWallet.basePrice;
|
||||
// return balance * price;
|
||||
// }
|
||||
|
||||
Future<List<String>> get allOwnAddresses => _currentWallet.allOwnAddresses;
|
||||
|
||||
Future<TransactionData> get transactionData => _currentWallet.transactionData;
|
||||
Future<List<UtxoObject>> get unspentOutputs => _currentWallet.unspentOutputs;
|
||||
Future<List<isar_models.Transaction>> get transactions =>
|
||||
_currentWallet.transactions;
|
||||
Future<List<isar_models.UTXO>> get utxos => _currentWallet.utxos;
|
||||
|
||||
Future<void> refresh() async {
|
||||
await _currentWallet.refresh();
|
||||
|
@ -233,11 +177,6 @@ class Manager with ChangeNotifier {
|
|||
}
|
||||
}
|
||||
|
||||
// Future<bool> initializeWallet() async {
|
||||
// final success = await _currentWallet.initializeWallet();
|
||||
// return success;
|
||||
// }
|
||||
|
||||
Future<void> exitCurrentWallet() async {
|
||||
final name = _currentWallet.walletName;
|
||||
final id = _currentWallet.walletId;
|
||||
|
@ -260,11 +199,6 @@ class Manager with ChangeNotifier {
|
|||
}
|
||||
}
|
||||
|
||||
Future<bool> isOwnAddress(String address) async {
|
||||
final allOwnAddresses = await this.allOwnAddresses;
|
||||
return allOwnAddresses.contains(address);
|
||||
}
|
||||
|
||||
bool get isConnected => _currentWallet.isConnected;
|
||||
|
||||
Future<int> estimateFeeFor(int satoshiAmount, int feeRate) async {
|
||||
|
|
Loading…
Reference in a new issue