mirror of
https://github.com/cake-tech/cake_wallet.git
synced 2025-06-28 12:29:51 +00:00
Part 1
This commit is contained in:
parent
5e1132a299
commit
e4ebfc94b2
273 changed files with 2472 additions and 7285 deletions
35
lib/reactions/check_connection.dart
Normal file
35
lib/reactions/check_connection.dart
Normal file
|
@ -0,0 +1,35 @@
|
|||
import 'dart:async';
|
||||
|
||||
import 'package:cake_wallet/core/wallet_base.dart';
|
||||
import 'package:cake_wallet/entities/sync_status.dart';
|
||||
import 'package:cake_wallet/store/settings_store.dart';
|
||||
import 'package:connectivity/connectivity.dart';
|
||||
|
||||
Timer _checkConnectionTimer;
|
||||
|
||||
void startCheckConnectionReaction(WalletBase wallet, SettingsStore settingsStore, {int timeInterval = 5}) {
|
||||
_checkConnectionTimer?.cancel();
|
||||
_checkConnectionTimer = Timer.periodic(Duration(seconds: timeInterval), (_) async {
|
||||
final connectivityResult = await (Connectivity().checkConnectivity());
|
||||
|
||||
if (connectivityResult == ConnectivityResult.none) {
|
||||
wallet.syncStatus = FailedSyncStatus();
|
||||
return;
|
||||
}
|
||||
|
||||
if (wallet.syncStatus is LostConnectionSyncStatus ||
|
||||
wallet.syncStatus is FailedSyncStatus) {
|
||||
try {
|
||||
final alive =
|
||||
await settingsStore.getCurrentNode(wallet.type).requestNode();
|
||||
|
||||
if (alive) {
|
||||
await wallet.connectToNode(
|
||||
node: settingsStore.getCurrentNode(wallet.type));
|
||||
}
|
||||
} catch (_) {
|
||||
// FIXME: empty catch clojure
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue