mirror of
https://github.com/cake-tech/cake_wallet.git
synced 2024-12-24 04:29:28 +00:00
6dba73a1d5
Some checks failed
Cache Dependencies / test (push) Has been cancelled
* reset brightness after using * set default qr to auto detect * minor safety enhancement * close socket after checking connectivity * fix incorrect parent exception class * pump medium and fast priorities even if they are equal to slow * Add Ton to exchange * fix silent payments add Seth bitcoin node * deselect quantex add seth node for existing users * fix node uri
42 lines
1.5 KiB
Dart
42 lines
1.5 KiB
Dart
import 'dart:async';
|
|
|
|
import 'package:connectivity_plus/connectivity_plus.dart';
|
|
import 'package:cw_core/wallet_base.dart';
|
|
import 'package:cw_core/sync_status.dart';
|
|
import 'package:cw_core/wallet_type.dart';
|
|
import 'package:cake_wallet/store/settings_store.dart';
|
|
|
|
Timer? _checkConnectionTimer;
|
|
|
|
void startCheckConnectionReaction(WalletBase wallet, SettingsStore settingsStore,
|
|
{int timeInterval = 5}) {
|
|
_checkConnectionTimer?.cancel();
|
|
// TODO: check the validity of this code, and if it's working fine, then no need for
|
|
// having the connect function in electrum.dart when the syncstatus is lost or failed and add the not connected state
|
|
_checkConnectionTimer = Timer.periodic(Duration(seconds: timeInterval), (_) async {
|
|
if (wallet.type == WalletType.bitcoin && wallet.syncStatus is SyncingSyncStatus) {
|
|
return;
|
|
}
|
|
|
|
try {
|
|
final connectivityResult = await (Connectivity().checkConnectivity());
|
|
|
|
if (connectivityResult == ConnectivityResult.none) {
|
|
wallet.syncStatus = FailedSyncStatus();
|
|
return;
|
|
}
|
|
|
|
if (wallet.type != WalletType.bitcoin &&
|
|
(wallet.syncStatus is LostConnectionSyncStatus ||
|
|
wallet.syncStatus is FailedSyncStatus)) {
|
|
final alive = await settingsStore.getCurrentNode(wallet.type).requestNode();
|
|
|
|
if (alive) {
|
|
await wallet.connectToNode(node: settingsStore.getCurrentNode(wallet.type));
|
|
}
|
|
}
|
|
} catch (e) {
|
|
print(e.toString());
|
|
}
|
|
});
|
|
}
|