diff --git a/cw_bitcoin/lib/electrum_wallet.dart b/cw_bitcoin/lib/electrum_wallet.dart index 644899311..620813446 100644 --- a/cw_bitcoin/lib/electrum_wallet.dart +++ b/cw_bitcoin/lib/electrum_wallet.dart @@ -533,15 +533,6 @@ abstract class ElectrumWalletBase } Future getNodeSupportsSilentPayments() async { - int secondsWaited = 0; - while (!electrumClient.isConnected) { - await Future.delayed(const Duration(seconds: 1)); - secondsWaited++; - if (secondsWaited > 5) { - return false; - } - } - // As of today (august 2024), only ElectrumRS supports silent payments if (!(await getNodeIsElectrs())) { return false; diff --git a/cw_core/lib/sync_status.dart b/cw_core/lib/sync_status.dart index bd3a83651..8d0f491ad 100644 --- a/cw_core/lib/sync_status.dart +++ b/cw_core/lib/sync_status.dart @@ -84,7 +84,7 @@ class LostConnectionSyncStatus extends NotConnectedSyncStatus { } // when the application has been paused by the OS: -class StoppedSyncingSyncStatus extends SyncStatus { +class StoppedSyncingSyncStatus extends NotConnectedSyncStatus { @override double progress() => 0.0; diff --git a/lib/entities/background_tasks.dart b/lib/entities/background_tasks.dart index 10839ff10..cfe0975af 100644 --- a/lib/entities/background_tasks.dart +++ b/lib/entities/background_tasks.dart @@ -2,7 +2,9 @@ import 'dart:async'; import 'dart:io'; import 'dart:ui'; +import 'package:cake_wallet/core/sync_status_title.dart'; import 'package:cake_wallet/core/wallet_loading_service.dart'; +import 'package:cake_wallet/generated/i18n.dart'; import 'package:cake_wallet/store/settings_store.dart'; import 'package:cake_wallet/utils/device_info.dart'; import 'package:cake_wallet/utils/feature_flag.dart'; @@ -159,7 +161,7 @@ Future onStart(ServiceInstance service) async { for (int i = 0; i < moneroWallets.length; i++) { final wallet = await walletLoadingService.load(moneroWallets[i].type, moneroWallets[i].name); final node = settingsStore.getCurrentNode(moneroWallets[i].type); - await wallet.connectToNode(node: node); + wallet.connectToNode(node: node); wallet.startSync(); syncingWallets.add(wallet); } @@ -194,6 +196,7 @@ Future onStart(ServiceInstance service) async { final wallet = await walletLoadingService.load(bitcoinWallets[i].type, bitcoinWallets[i].name); final node = settingsStore.getCurrentNode(WalletType.bitcoin); + await wallet.connectToNode(node: node); bool nodeSupportsSP = await (wallet as ElectrumWallet).getNodeSupportsSilentPayments(); if (!nodeSupportsSP) { @@ -204,7 +207,6 @@ Future onStart(ServiceInstance service) async { continue; } - await wallet.connectToNode(node: node); syncingWallets.add(wallet); } catch (e) { print("error syncing bitcoin wallet_$i: $e"); @@ -228,9 +230,26 @@ Future onStart(ServiceInstance service) async { String title = "$prefix - ${wallet.name}"; late String content; try { - final blocksLeft = (wallet.syncStatus as SyncingSyncStatus).blocksLeft; - content = "${blocksLeft} Blocks Left"; + // TODO: not sure how to do locatization from the service since buildcontext is null: + // content = syncStatusTitle(wallet.syncStatus); + + if (wallet.syncStatus is SyncingSyncStatus) { + final blocksLeft = (wallet.syncStatus as SyncingSyncStatus).blocksLeft; + content = "${blocksLeft} Blocks Left"; + } else if (wallet.syncStatus is SyncedSyncStatus) { + content = "Synced"; + } else if (wallet.syncStatus is SyncedTipSyncStatus) { + final tip = (wallet.syncStatus as SyncedTipSyncStatus).tip; + content = "Scanned Tip: $tip"; + } else if (wallet.syncStatus is NotConnectedSyncStatus) { + content = "Not Connected"; + } else if (wallet.syncStatus is AttemptingSyncStatus) { + content = "Attempting Sync"; + } else { + throw Exception("sync type not covered"); + } } catch (e) { + print(e); content = "${syncProgress}% Synced"; } content += " - ${DateTime.now().toIso8601String()}"; diff --git a/lib/src/screens/root/root.dart b/lib/src/screens/root/root.dart index 51d3c864c..35c928e10 100644 --- a/lib/src/screens/root/root.dart +++ b/lib/src/screens/root/root.dart @@ -182,11 +182,11 @@ class RootState extends State with WidgetsBindingObserver { case AppLifecycleState.paused: // TODO: experimental: maybe should uncomment this: // getIt.get().serviceBackground(false, showNotifications); + getIt.get().serviceReady(); case AppLifecycleState.inactive: case AppLifecycleState.detached: default: // anything other than resumed update the notification to say we're in the "ready" state: - getIt.get().serviceReady(); // if we enter any state other than resumed start a timer for 30 seconds // after which we'll consider the app to be in the background _stateTimer?.cancel();