mirror of
https://github.com/cake-tech/cake_wallet.git
synced 2025-01-31 06:55:59 +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 {
|
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
|
// As of today (august 2024), only ElectrumRS supports silent payments
|
||||||
if (!(await getNodeIsElectrs())) {
|
if (!(await getNodeIsElectrs())) {
|
||||||
return false;
|
return false;
|
||||||
|
|
|
@ -84,7 +84,7 @@ class LostConnectionSyncStatus extends NotConnectedSyncStatus {
|
||||||
}
|
}
|
||||||
|
|
||||||
// when the application has been paused by the OS:
|
// when the application has been paused by the OS:
|
||||||
class StoppedSyncingSyncStatus extends SyncStatus {
|
class StoppedSyncingSyncStatus extends NotConnectedSyncStatus {
|
||||||
@override
|
@override
|
||||||
double progress() => 0.0;
|
double progress() => 0.0;
|
||||||
|
|
||||||
|
|
|
@ -2,7 +2,9 @@ import 'dart:async';
|
||||||
import 'dart:io';
|
import 'dart:io';
|
||||||
import 'dart:ui';
|
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/core/wallet_loading_service.dart';
|
||||||
|
import 'package:cake_wallet/generated/i18n.dart';
|
||||||
import 'package:cake_wallet/store/settings_store.dart';
|
import 'package:cake_wallet/store/settings_store.dart';
|
||||||
import 'package:cake_wallet/utils/device_info.dart';
|
import 'package:cake_wallet/utils/device_info.dart';
|
||||||
import 'package:cake_wallet/utils/feature_flag.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++) {
|
for (int i = 0; i < moneroWallets.length; i++) {
|
||||||
final wallet = await walletLoadingService.load(moneroWallets[i].type, moneroWallets[i].name);
|
final wallet = await walletLoadingService.load(moneroWallets[i].type, moneroWallets[i].name);
|
||||||
final node = settingsStore.getCurrentNode(moneroWallets[i].type);
|
final node = settingsStore.getCurrentNode(moneroWallets[i].type);
|
||||||
await wallet.connectToNode(node: node);
|
wallet.connectToNode(node: node);
|
||||||
wallet.startSync();
|
wallet.startSync();
|
||||||
syncingWallets.add(wallet);
|
syncingWallets.add(wallet);
|
||||||
}
|
}
|
||||||
|
@ -194,6 +196,7 @@ Future<void> onStart(ServiceInstance service) async {
|
||||||
final wallet =
|
final wallet =
|
||||||
await walletLoadingService.load(bitcoinWallets[i].type, bitcoinWallets[i].name);
|
await walletLoadingService.load(bitcoinWallets[i].type, bitcoinWallets[i].name);
|
||||||
final node = settingsStore.getCurrentNode(WalletType.bitcoin);
|
final node = settingsStore.getCurrentNode(WalletType.bitcoin);
|
||||||
|
await wallet.connectToNode(node: node);
|
||||||
|
|
||||||
bool nodeSupportsSP = await (wallet as ElectrumWallet).getNodeSupportsSilentPayments();
|
bool nodeSupportsSP = await (wallet as ElectrumWallet).getNodeSupportsSilentPayments();
|
||||||
if (!nodeSupportsSP) {
|
if (!nodeSupportsSP) {
|
||||||
|
@ -204,7 +207,6 @@ Future<void> onStart(ServiceInstance service) async {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
await wallet.connectToNode(node: node);
|
|
||||||
syncingWallets.add(wallet);
|
syncingWallets.add(wallet);
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
print("error syncing bitcoin wallet_$i: $e");
|
print("error syncing bitcoin wallet_$i: $e");
|
||||||
|
@ -228,9 +230,26 @@ Future<void> onStart(ServiceInstance service) async {
|
||||||
String title = "$prefix - ${wallet.name}";
|
String title = "$prefix - ${wallet.name}";
|
||||||
late String content;
|
late String content;
|
||||||
try {
|
try {
|
||||||
final blocksLeft = (wallet.syncStatus as SyncingSyncStatus).blocksLeft;
|
// TODO: not sure how to do locatization from the service since buildcontext is null:
|
||||||
content = "${blocksLeft} Blocks Left";
|
// 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) {
|
} catch (e) {
|
||||||
|
print(e);
|
||||||
content = "${syncProgress}% Synced";
|
content = "${syncProgress}% Synced";
|
||||||
}
|
}
|
||||||
content += " - ${DateTime.now().toIso8601String()}";
|
content += " - ${DateTime.now().toIso8601String()}";
|
||||||
|
|
|
@ -182,11 +182,11 @@ class RootState extends State<Root> with WidgetsBindingObserver {
|
||||||
case AppLifecycleState.paused:
|
case AppLifecycleState.paused:
|
||||||
// TODO: experimental: maybe should uncomment this:
|
// TODO: experimental: maybe should uncomment this:
|
||||||
// getIt.get<BackgroundTasks>().serviceBackground(false, showNotifications);
|
// getIt.get<BackgroundTasks>().serviceBackground(false, showNotifications);
|
||||||
|
getIt.get<BackgroundTasks>().serviceReady();
|
||||||
case AppLifecycleState.inactive:
|
case AppLifecycleState.inactive:
|
||||||
case AppLifecycleState.detached:
|
case AppLifecycleState.detached:
|
||||||
default:
|
default:
|
||||||
// anything other than resumed update the notification to say we're in the "ready" state:
|
// 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
|
// 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
|
// after which we'll consider the app to be in the background
|
||||||
_stateTimer?.cancel();
|
_stateTimer?.cancel();
|
||||||
|
|
Loading…
Reference in a new issue