Prevent app lag when node is exceptionally slow (usually over tor)

This commit is contained in:
Czarek Nakamoto 2025-01-14 17:23:35 +01:00
parent 812c5e6e53
commit 179f039e31
4 changed files with 32 additions and 5 deletions

View file

@ -146,7 +146,21 @@ int getUnlockedBalance({int accountIndex = 0}) =>
int getCurrentHeight() => currentWallet?.blockChainHeight() ?? 0;
int getNodeHeightSync() => currentWallet?.daemonBlockChainHeight() ?? 0;
bool isHeightRefreshing = false;
int cachedNodeHeight = 0;
int getNodeHeightSync() {
if (isHeightRefreshing == false) {
(() async {
final wptrAddress = currentWallet!.ffiAddress();
cachedNodeHeight = await Isolate.run(() async {
return monero.Wallet_daemonBlockChainHeight(Pointer.fromAddress(wptrAddress));
});
isHeightRefreshing = true;
})();
}
return cachedNodeHeight;
}
bool isConnectedSync() => currentWallet?.connected() != 0;

View file

@ -110,8 +110,19 @@ int getUnlockedBalance({int accountIndex = 0}) =>
int getCurrentHeight() => wownero.Wallet_blockChainHeight(wptr!);
int getNodeHeightSync() => wownero.Wallet_daemonBlockChainHeight(wptr!);
bool isHeightRefreshing = false;
int cachedNodeHeight = 0;
int getNodeHeightSync() {
if (isHeightRefreshing == false) {
(() async {
cachedNodeHeight = await Isolate.run(() async {
return wownero.Wallet_daemonBlockChainHeight(wptr!);
});
isHeightRefreshing = true;
})();
}
return cachedNodeHeight;
}
bool isConnectedSync() => wownero.Wallet_connected(wptr!) != 0;
Future<bool> setupNodeSync(

View file

@ -9,6 +9,7 @@ import 'package:cw_core/node.dart';
import 'package:cake_wallet/entities/node_list.dart';
import 'package:cake_wallet/entities/default_settings_migration.dart';
import 'package:cw_core/wallet_type.dart';
import 'package:tor/tor.dart';
part 'node_list_view_model.g.dart';
@ -38,7 +39,7 @@ abstract class NodeListViewModelBase with Store {
String getAlertContent(String uri) =>
S.current.change_current_node(uri) +
'${uri.endsWith('.onion') || uri.contains('.onion:') ? '\n' + S.current.orbot_running_alert : ''}';
'${uri.endsWith('.onion') || uri.contains('.onion:') ? '\n' + (Tor.instance.enabled ? '' : S.current.orbot_running_alert) : ''}';
final ObservableList<Node> nodes;
final SettingsStore settingsStore;

View file

@ -9,6 +9,7 @@ import 'package:cw_core/node.dart';
import 'package:cake_wallet/entities/node_list.dart';
import 'package:cake_wallet/entities/default_settings_migration.dart';
import 'package:cw_core/wallet_type.dart';
import 'package:tor/tor.dart';
part 'pow_node_list_view_model.g.dart';
@ -38,7 +39,7 @@ abstract class PowNodeListViewModelBase with Store {
String getAlertContent(String uri) =>
S.current.change_current_node(uri) +
'${uri.endsWith('.onion') || uri.contains('.onion:') ? '\n' + S.current.orbot_running_alert : ''}';
'${uri.endsWith('.onion') || uri.contains('.onion:') ? '\n' + (Tor.instance.enabled ? '' : S.current.orbot_running_alert) : ''}';
final ObservableList<Node> nodes;
final SettingsStore settingsStore;