diff --git a/cw_monero/lib/api/account_list.dart b/cw_monero/lib/api/account_list.dart index b753b4656..84c41e9df 100644 --- a/cw_monero/lib/api/account_list.dart +++ b/cw_monero/lib/api/account_list.dart @@ -1,5 +1,6 @@ import 'dart:async'; +import 'package:cw_core/utils/print_verbose.dart'; import 'package:cw_monero/api/wallet.dart'; import 'package:cw_monero/monero_account_list.dart'; import 'package:monero/src/wallet2.dart'; @@ -13,9 +14,13 @@ Wallet2WalletListener? _wlptr = null; Wallet2WalletListener? getWlptr() { if (currentWallet == null) return null; - _wlptrForW = currentWallet!.ffiAddress(); - _wlptr = currentWallet!.getWalletListener(); - return _wlptr!; + if (_wlptrForW == currentWallet!.ffiAddress()) { + return _wlptr; + } else { + _wlptrForW = currentWallet!.ffiAddress(); + _wlptr = currentWallet!.getWalletListener(); + return _wlptr; + } } Wallet2SubaddressAccount? subaddressAccount; diff --git a/cw_monero/lib/api/wallet.dart b/cw_monero/lib/api/wallet.dart index 148b271ff..43e0875a6 100644 --- a/cw_monero/lib/api/wallet.dart +++ b/cw_monero/lib/api/wallet.dart @@ -1,6 +1,7 @@ import 'dart:async'; import 'dart:ffi'; import 'dart:isolate'; +import 'dart:math'; import 'package:cw_core/utils/print_verbose.dart'; import 'package:cw_monero/api/account_list.dart'; @@ -156,6 +157,9 @@ int cachedNodeHeight = 0; bool isHeightRefreshing = false; int getNodeHeightSync() { if (isHeightRefreshing == false) { + if (cachedNodeHeight != 0 && getWlptr()?.height() == 1) { + return cachedNodeHeight; + } (() async { try { isHeightRefreshing = true; @@ -329,7 +333,13 @@ class SyncListener { _initialSyncHeight = syncHeight; } - final bchHeight = await getNodeHeightOrUpdate(syncHeight); + // in case when node didn't report new height yet + // it is a workaround for moving height request to another isolate + final nodeHeight = await getNodeHeightOrUpdate(syncHeight); + if (nodeHeight == 0) { + return; + } + final bchHeight = max(nodeHeight, syncHeight); // printV("syncHeight: $syncHeight, _lastKnownBlockHeight: $_lastKnownBlockHeight, bchHeight: $bchHeight"); if (_lastKnownBlockHeight == syncHeight) { return; @@ -341,7 +351,8 @@ class SyncListener { final ptc = diff <= 0 ? 0.0 : diff / track; final left = bchHeight - syncHeight; - if (syncHeight < 0 || left < 0) { + if ((syncHeight < 0 || left < 0)) { + printV("not calling onNewBlock: syncHeight: $syncHeight, left: $left"); return; }