diff --git a/lib/services/coins/coin_service.dart b/lib/services/coins/coin_service.dart index ff953708f..fb433466c 100644 --- a/lib/services/coins/coin_service.dart +++ b/lib/services/coins/coin_service.dart @@ -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 confirmSend({required Map txData}); - /// create and submit tx to network - /// - /// Returns the txid of the sent tx - /// will throw exceptions on failure - Future send( - {required String toAddress, - required int amount, - Map args}); - Future get fees; Future get maxFee; Future get currentReceivingAddress; - // Future get currentLegacyReceivingAddress; - Future get availableBalance; - Future get pendingBalance; - Future get totalBalance; - Future get balanceMinusMaxFee; + Balance get balance; - Future> get allOwnAddresses; - - Future get transactionData; - Future> get unspentOutputs; + Future> get transactions; + Future> get utxos; Future refresh(); diff --git a/lib/services/coins/manager.dart b/lib/services/coins/manager.dart index 1c2163c04..a590752e0 100644 --- a/lib/services/coins/manager.dart +++ b/lib/services/coins/manager.dart @@ -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 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 send({ - required String toAddress, - required int amount, - Map 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 get fees => _currentWallet.fees; Future get maxFee => _currentWallet.maxFee; Future get currentReceivingAddress => _currentWallet.currentReceivingAddress; - // Future get currentLegacyReceivingAddress => - // _currentWallet.currentLegacyReceivingAddress; - Future get availableBalance async { - _cachedAvailableBalance = await _currentWallet.availableBalance; - return _cachedAvailableBalance; - } + Balance get balance => _currentWallet.balance; - Decimal _cachedAvailableBalance = Decimal.zero; - Decimal get cachedAvailableBalance => _cachedAvailableBalance; - - Future get pendingBalance => _currentWallet.pendingBalance; - Future get balanceMinusMaxFee => _currentWallet.balanceMinusMaxFee; - - Future get totalBalance async { - _cachedTotalBalance = await _currentWallet.totalBalance; - return _cachedTotalBalance; - } - - Decimal _cachedTotalBalance = Decimal.zero; - Decimal get cachedTotalBalance => _cachedTotalBalance; - - // Future get fiatBalance async { - // final balance = await _currentWallet.availableBalance; - // final price = await _currentWallet.basePrice; - // return balance * price; - // } - // - // Future get fiatTotalBalance async { - // final balance = await _currentWallet.totalBalance; - // final price = await _currentWallet.basePrice; - // return balance * price; - // } - - Future> get allOwnAddresses => _currentWallet.allOwnAddresses; - - Future get transactionData => _currentWallet.transactionData; - Future> get unspentOutputs => _currentWallet.unspentOutputs; + Future> get transactions => + _currentWallet.transactions; + Future> get utxos => _currentWallet.utxos; Future refresh() async { await _currentWallet.refresh(); @@ -233,11 +177,6 @@ class Manager with ChangeNotifier { } } - // Future initializeWallet() async { - // final success = await _currentWallet.initializeWallet(); - // return success; - // } - Future exitCurrentWallet() async { final name = _currentWallet.walletName; final id = _currentWallet.walletId; @@ -260,11 +199,6 @@ class Manager with ChangeNotifier { } } - Future isOwnAddress(String address) async { - final allOwnAddresses = await this.allOwnAddresses; - return allOwnAddresses.contains(address); - } - bool get isConnected => _currentWallet.isConnected; Future estimateFeeFor(int satoshiAmount, int feeRate) async {