mirror of
https://github.com/cake-tech/cake_wallet.git
synced 2025-01-19 01:04:43 +00:00
updates - slow when syncing multiple wallets
This commit is contained in:
parent
30047209e3
commit
4411f7bea6
4 changed files with 25 additions and 15 deletions
|
@ -533,15 +533,6 @@ abstract class ElectrumWalletBase
|
|||
}
|
||||
|
||||
Future<bool> 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;
|
||||
|
|
|
@ -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;
|
||||
|
||||
|
|
|
@ -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<void> 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<void> 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<void> 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<void> 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()}";
|
||||
|
|
|
@ -182,11 +182,11 @@ class RootState extends State<Root> with WidgetsBindingObserver {
|
|||
case AppLifecycleState.paused:
|
||||
// TODO: experimental: maybe should uncomment this:
|
||||
// getIt.get<BackgroundTasks>().serviceBackground(false, showNotifications);
|
||||
getIt.get<BackgroundTasks>().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<BackgroundTasks>().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();
|
||||
|
|
Loading…
Reference in a new issue