| 1 | import 'package:cake_wallet/entities/sync_status_display_mode.dart'; |
| 2 | import 'package:cake_wallet/generated/i18n.dart'; |
| 3 | import 'package:cw_core/sync_status.dart'; |
| 4 | |
| 5 | String syncStatusTitle(SyncStatus syncStatus, SyncStatusDisplayMode syncStatusDisplayMode) { |
| 6 | if (syncStatus is SyncingSyncStatus) { |
| 7 | // Show blocks remaining for the first 3 seconds, then switch to percentage |
| 8 | if (syncStatus.shouldShowBlocksRemaining()) { |
| 9 | if (syncStatus.blocksLeft == 1) { |
| 10 | return S.current.block_remaining; |
| 11 | } |
| 12 | return S.current.Blocks_remaining('${syncStatus.blocksLeft}'); |
| 13 | } |
| 14 | |
| 15 | // After 3 seconds, show percentage-based display |
| 16 | // Don't show ETA for very few blocks (less than 100) to avoid inconsistency |
| 17 | if (syncStatus.blocksLeft < 100) { |
| 18 | return S.current.Blocks_remaining('${syncStatus.blocksLeft}'); |
| 19 | } |
| 20 | |
| 21 | if (syncStatus.blocksLeft == 1) { |
| 22 | return S.current.block_remaining; |
| 23 | } |
| 24 | |
| 25 | // Check user preference for sync status display |
| 26 | if (syncStatusDisplayMode == SyncStatusDisplayMode.eta) { |
| 27 | // Get ETA with placeholder while gathering data |
| 28 | String eta = syncStatus.getFormattedEtaWithPlaceholder() ?? ''; |
| 29 | |
| 30 | if (eta.isEmpty) { |
| 31 | return S.current.Blocks_remaining('${syncStatus.blocksLeft}'); |
| 32 | } else { |
| 33 | return "$eta"; |
| 34 | } |
| 35 | } else { |
| 36 | return S.current.Blocks_remaining('${syncStatus.blocksLeft}'); |
| 37 | } |
| 38 | } |
| 39 | |
| 40 | if (syncStatus is SyncedTipSyncStatus) { |
| 41 | return S.current.silent_payments_scanned_tip(syncStatus.tip.toString()); |
| 42 | } |
| 43 | |
| 44 | if (syncStatus is SyncedSyncStatus) { |
| 45 | return S.current.sync_synced; |
| 46 | } |
| 47 | |
| 48 | if (syncStatus is FailedSyncStatus) { |
| 49 | if (syncStatus.error != null) { |
| 50 | return syncStatus.error!; |
| 51 | } |
| 52 | return S.current.sync_offline; |
| 53 | } |
| 54 | |
| 55 | if (syncStatus is LostConnectionSyncStatus) { |
| 56 | return S.current.sync_offline; |
| 57 | } |
| 58 | |
| 59 | if (syncStatus is NotConnectedSyncStatus) { |
| 60 | return S.current.sync_not_connected; |
| 61 | } |
| 62 | |
| 63 | if (syncStatus is AttemptingSyncStatus) { |
| 64 | return S.current.sync_attempting; |
| 65 | } |
| 66 | |
| 67 | if (syncStatus is ConnectingSyncStatus) { |
| 68 | return S.current.sync_connecting; |
| 69 | } |
| 70 | |
| 71 | if (syncStatus is ConnectedSyncStatus) { |
| 72 | return S.current.connected; |
| 73 | } |
| 74 | |
| 75 | if (syncStatus is UnsupportedSyncStatus) { |
| 76 | return S.current.sync_unsupported_node; |
| 77 | } |
| 78 | |
| 79 | if (syncStatus is TimedOutSyncStatus) { |
| 80 | return S.current.sync_timed_out; |
| 81 | } |
| 82 | |
| 83 | if (syncStatus is SyncronizingSyncStatus) { |
| 84 | return S.current.sync_syncing; |
| 85 | } |
| 86 | |
| 87 | if (syncStatus is StartingScanSyncStatus) { |
| 88 | return "${S.current.sync_starting_scan} (${(syncStatus.beginHeight.toString())})"; |
| 89 | } |
| 90 | |
| 91 | if (syncStatus is AttemptingScanSyncStatus) { |
| 92 | return "Attempting scan"; |
| 93 | } |
| 94 | |
| 95 | if (syncStatus is ProcessingSyncStatus) { |
| 96 | return syncStatus.message ?? S.current.processing; |
| 97 | } |
| 98 | |
| 99 | return ''; |
| 100 | } |