mirror of
https://github.com/cypherstack/stack_wallet.git
synced 2025-01-22 10:34:32 +00:00
fix: banano network pinging, clean up imports, move file to separate folder
This commit is contained in:
parent
117007180e
commit
91dd677e28
2 changed files with 69 additions and 14 deletions
|
@ -4,28 +4,29 @@ import 'dart:convert';
|
|||
import 'package:http/http.dart' as http;
|
||||
import 'package:isar/isar.dart';
|
||||
import 'package:nanodart/nanodart.dart';
|
||||
import 'package:stackwallet/db/isar/main_db.dart';
|
||||
import 'package:stackwallet/models/balance.dart';
|
||||
import 'package:stackwallet/models/isar/models/isar_models.dart';
|
||||
import 'package:stackwallet/models/node_model.dart';
|
||||
import 'package:stackwallet/models/paymint/fee_object_model.dart';
|
||||
import 'package:stackwallet/services/coins/coin_service.dart';
|
||||
import 'package:stackwallet/services/event_bus/events/global/node_connection_status_changed_event.dart';
|
||||
import 'package:stackwallet/services/event_bus/events/global/wallet_sync_status_changed_event.dart';
|
||||
import 'package:stackwallet/services/event_bus/global_event_bus.dart';
|
||||
import 'package:stackwallet/services/mixins/coin_control_interface.dart';
|
||||
import 'package:stackwallet/services/mixins/wallet_cache.dart';
|
||||
import 'package:stackwallet/services/mixins/wallet_db.dart';
|
||||
import 'package:stackwallet/services/node_service.dart';
|
||||
import 'package:stackwallet/services/transaction_notification_tracker.dart';
|
||||
import 'package:stackwallet/utilities/amount/amount.dart';
|
||||
import 'package:stackwallet/utilities/constants.dart';
|
||||
import 'package:stackwallet/utilities/default_nodes.dart';
|
||||
import 'package:stackwallet/utilities/enums/coin_enum.dart';
|
||||
import 'package:stackwallet/utilities/flutter_secure_storage_interface.dart';
|
||||
import 'package:stackwallet/utilities/logger.dart';
|
||||
import 'package:stackwallet/utilities/prefs.dart';
|
||||
import 'package:tuple/tuple.dart';
|
||||
|
||||
import '../../../db/isar/main_db.dart';
|
||||
import '../../../models/node_model.dart';
|
||||
import '../../../utilities/default_nodes.dart';
|
||||
import '../../../utilities/flutter_secure_storage_interface.dart';
|
||||
import '../../../utilities/prefs.dart';
|
||||
import '../../node_service.dart';
|
||||
import '../../transaction_notification_tracker.dart';
|
||||
|
||||
const int MINIMUM_CONFIRMATIONS = 1;
|
||||
const String DEFAULT_REPRESENTATIVE =
|
||||
"ban_1ka1ium4pfue3uxtntqsrib8mumxgazsjf58gidh1xeo5te3whsq8z476goo";
|
||||
|
@ -118,13 +119,26 @@ class BananoWallet extends CoinServiceAPI
|
|||
late final TransactionNotificationTracker txTracker;
|
||||
final _prefs = Prefs.instance;
|
||||
|
||||
Timer? timer;
|
||||
bool _shouldAutoSync = false;
|
||||
|
||||
@override
|
||||
bool get shouldAutoSync => _shouldAutoSync;
|
||||
|
||||
@override
|
||||
set shouldAutoSync(bool shouldAutoSync) => _shouldAutoSync = shouldAutoSync;
|
||||
set shouldAutoSync(bool shouldAutoSync) {
|
||||
if (_shouldAutoSync != shouldAutoSync) {
|
||||
_shouldAutoSync = shouldAutoSync;
|
||||
if (!shouldAutoSync) {
|
||||
timer?.cancel();
|
||||
timer = null;
|
||||
stopNetworkAlivePinging();
|
||||
} else {
|
||||
startNetworkAlivePinging();
|
||||
refresh();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@override
|
||||
Balance get balance => _balance ??= getCachedBalance();
|
||||
|
@ -753,6 +767,49 @@ class BananoWallet extends CoinServiceAPI
|
|||
return Future.value(false);
|
||||
}
|
||||
|
||||
Timer? _networkAliveTimer;
|
||||
|
||||
void startNetworkAlivePinging() {
|
||||
// call once on start right away
|
||||
_periodicPingCheck();
|
||||
|
||||
// then periodically check
|
||||
_networkAliveTimer = Timer.periodic(
|
||||
Constants.networkAliveTimerDuration,
|
||||
(_) async {
|
||||
_periodicPingCheck();
|
||||
},
|
||||
);
|
||||
}
|
||||
|
||||
void _periodicPingCheck() async {
|
||||
bool hasNetwork = await testNetworkConnection();
|
||||
|
||||
if (_isConnected != hasNetwork) {
|
||||
NodeConnectionStatus status = hasNetwork
|
||||
? NodeConnectionStatus.connected
|
||||
: NodeConnectionStatus.disconnected;
|
||||
|
||||
GlobalEventBus.instance.fire(
|
||||
NodeConnectionStatusChangedEvent(
|
||||
status,
|
||||
walletId,
|
||||
coin,
|
||||
),
|
||||
);
|
||||
|
||||
_isConnected = hasNetwork;
|
||||
if (hasNetwork) {
|
||||
unawaited(refresh());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void stopNetworkAlivePinging() {
|
||||
_networkAliveTimer?.cancel();
|
||||
_networkAliveTimer = null;
|
||||
}
|
||||
|
||||
@override
|
||||
Future<List<Transaction>> get transactions =>
|
||||
db.getTransactions(walletId).findAll();
|
|
@ -14,6 +14,7 @@ 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/banano/banano_wallet.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';
|
||||
|
@ -24,7 +25,6 @@ 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/nano/banano_wallet.dart';
|
||||
import 'package:stackwallet/services/coins/nano/nano_wallet.dart';
|
||||
import 'package:stackwallet/services/coins/particl/particl_wallet.dart';
|
||||
import 'package:stackwallet/services/coins/wownero/wownero_wallet.dart';
|
||||
|
@ -244,8 +244,7 @@ abstract class CoinServiceAPI {
|
|||
walletName: walletName,
|
||||
coin: coin,
|
||||
tracker: tracker,
|
||||
secureStore: secureStorageInterface
|
||||
);
|
||||
secureStore: secureStorageInterface);
|
||||
|
||||
case Coin.banano:
|
||||
return BananoWallet(
|
||||
|
@ -253,8 +252,7 @@ abstract class CoinServiceAPI {
|
|||
walletName: walletName,
|
||||
coin: coin,
|
||||
tracker: tracker,
|
||||
secureStore: secureStorageInterface
|
||||
);
|
||||
secureStore: secureStorageInterface);
|
||||
|
||||
case Coin.dogecoinTestNet:
|
||||
return DogecoinWallet(
|
||||
|
|
Loading…
Reference in a new issue