Files
hash-wallet/lib/reactions/check_connection.dart
T
David AdegokeandGitHub 9775f7a629 fix: Sync bar ETA (#2515)
* fix: Sync bar ETA

* fix: Smooth ETA - WIP

* fix: Show disconnected status when sync disconnects

* feat: Display blocks remaining for the first five seconds and then switch to percentage

* Update

* fix: Extend duration for showing blocks remaining during sync from 5 to 15 seconds; update connectivity check to handle multiple connectivity results, and handle disconnected state while syncing

* feat: Initially display block if the a reconnection is triggered while syncing

* fix: More improvements to syncing
2025-11-12 11:40:04 +01:00

52 lines
1.8 KiB
Dart

import 'dart:async';
import 'package:cake_wallet/utils/tor.dart';
import 'package:connectivity_plus/connectivity_plus.dart';
import 'package:cw_core/utils/print_verbose.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;
}
if (wallet.type == WalletType.decred && wallet.syncStatus is ProcessingSyncStatus) {
return;
}
try {
final connectivityResult = await (Connectivity().checkConnectivity());
if (connectivityResult.contains(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) {
if (settingsStore.currentBuiltinTor) {
await ensureTorStarted(context: null);
}
await wallet.connectToNode(node: settingsStore.getCurrentNode(wallet.type));
}
}
} catch (e) {
printV(e.toString());
}
});
}