mirror of
https://github.com/Such-Software/hash-wallet.git
synced 2026-10-17 05:41:29 +02:00
* 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
101 lines
2.9 KiB
Dart
101 lines
2.9 KiB
Dart
import 'package:cake_wallet/entities/sync_status_display_mode.dart';
|
|
import 'package:cake_wallet/generated/i18n.dart';
|
|
import 'package:cw_core/sync_status.dart';
|
|
|
|
String syncStatusTitle(SyncStatus syncStatus, SyncStatusDisplayMode syncStatusDisplayMode) {
|
|
if (syncStatus is SyncingSyncStatus) {
|
|
// Show blocks remaining for the first 3 seconds, then switch to percentage
|
|
if (syncStatus.shouldShowBlocksRemaining()) {
|
|
if (syncStatus.blocksLeft == 1) {
|
|
return S.current.block_remaining;
|
|
}
|
|
return S.current.Blocks_remaining('${syncStatus.blocksLeft}');
|
|
}
|
|
|
|
// After 3 seconds, show percentage-based display
|
|
// Don't show ETA for very few blocks (less than 100) to avoid inconsistency
|
|
if (syncStatus.blocksLeft < 100) {
|
|
return S.current.Blocks_remaining('${syncStatus.blocksLeft}');
|
|
}
|
|
|
|
if (syncStatus.blocksLeft == 1) {
|
|
return S.current.block_remaining;
|
|
}
|
|
|
|
// Check user preference for sync status display
|
|
if (syncStatusDisplayMode == SyncStatusDisplayMode.eta) {
|
|
// Get ETA with placeholder while gathering data
|
|
String eta = syncStatus.getFormattedEtaWithPlaceholder() ?? '';
|
|
|
|
if (eta.isEmpty) {
|
|
return S.current.Blocks_remaining('${syncStatus.blocksLeft}');
|
|
} else {
|
|
return "${syncStatus.formattedProgress()} - ${S.current.eta} $eta";
|
|
}
|
|
} else {
|
|
return S.current.Blocks_remaining('${syncStatus.blocksLeft}');
|
|
}
|
|
}
|
|
|
|
if (syncStatus is SyncedTipSyncStatus) {
|
|
return S.current.silent_payments_scanned_tip(syncStatus.tip.toString());
|
|
}
|
|
|
|
if (syncStatus is SyncedSyncStatus) {
|
|
return S.current.sync_status_syncronized;
|
|
}
|
|
|
|
if (syncStatus is FailedSyncStatus) {
|
|
if (syncStatus.error != null) {
|
|
return syncStatus.error!;
|
|
}
|
|
return S.current.sync_status_failed_connect;
|
|
}
|
|
|
|
if (syncStatus is NotConnectedSyncStatus) {
|
|
return S.current.sync_status_not_connected;
|
|
}
|
|
|
|
if (syncStatus is AttemptingSyncStatus) {
|
|
return S.current.sync_status_attempting_sync;
|
|
}
|
|
|
|
if (syncStatus is ConnectingSyncStatus) {
|
|
return S.current.sync_status_connecting;
|
|
}
|
|
|
|
if (syncStatus is ConnectedSyncStatus) {
|
|
return S.current.sync_status_connected;
|
|
}
|
|
|
|
if (syncStatus is LostConnectionSyncStatus) {
|
|
return S.current.sync_status_failed_connect;
|
|
}
|
|
|
|
if (syncStatus is UnsupportedSyncStatus) {
|
|
return S.current.sync_status_unsupported;
|
|
}
|
|
|
|
if (syncStatus is TimedOutSyncStatus) {
|
|
return S.current.sync_status_timed_out;
|
|
}
|
|
|
|
if (syncStatus is SyncronizingSyncStatus) {
|
|
return S.current.sync_status_syncronizing;
|
|
}
|
|
|
|
if (syncStatus is StartingScanSyncStatus) {
|
|
return S.current.sync_status_starting_scan(syncStatus.beginHeight.toString());
|
|
}
|
|
|
|
if (syncStatus is AttemptingScanSyncStatus) {
|
|
return S.current.sync_status_attempting_scan;
|
|
}
|
|
|
|
if (syncStatus is ProcessingSyncStatus) {
|
|
return syncStatus.message ?? S.current.processing;
|
|
}
|
|
|
|
return '';
|
|
}
|