fix: wallet not reporting finishing sync (#2377)
cyan committed
Jul 11, 2025 at 23:17 UTC
4009f64ee9453f0a26c1187bf83f89adf2e00f37
2 files changed
+21
-5
cw_monero/lib/api/account_list.dart
+8
-3
@@ -1,5 +1,6 @@
1
import 'dart:async';
2
3
+import 'package:cw_core/utils/print_verbose.dart';
4
import 'package:cw_monero/api/wallet.dart';
5
import 'package:cw_monero/monero_account_list.dart';
6
import 'package:monero/src/wallet2.dart';
@@ -13,9 +14,13 @@ Wallet2WalletListener? _wlptr = null;
14
15
Wallet2WalletListener? getWlptr() {
16
if (currentWallet == null) return null;
16
- _wlptrForW = currentWallet!.ffiAddress();
17
- _wlptr = currentWallet!.getWalletListener();
18
- return _wlptr!;
17
+ if (_wlptrForW == currentWallet!.ffiAddress()) {
18
+ return _wlptr;
19
+ } else {
20
+ _wlptrForW = currentWallet!.ffiAddress();
21
+ _wlptr = currentWallet!.getWalletListener();
22
+ return _wlptr;
23
+ }
24
}
25
26
Wallet2SubaddressAccount? subaddressAccount;
cw_monero/lib/api/wallet.dart
+13
-2
@@ -1,6 +1,7 @@
1
import 'dart:async';
2
import 'dart:ffi';
3
import 'dart:isolate';
4
+import 'dart:math';
5
6
import 'package:cw_core/utils/print_verbose.dart';
7
import 'package:cw_monero/api/account_list.dart';
@@ -156,6 +157,9 @@ int cachedNodeHeight = 0;
157
bool isHeightRefreshing = false;
158
int getNodeHeightSync() {
159
if (isHeightRefreshing == false) {
160
+ if (cachedNodeHeight != 0 && getWlptr()?.height() == 1) {
161
+ return cachedNodeHeight;
162
+ }
163
(() async {
164
try {
165
isHeightRefreshing = true;
@@ -329,7 +333,13 @@ class SyncListener {
333
_initialSyncHeight = syncHeight;
334
}
335
332
- final bchHeight = await getNodeHeightOrUpdate(syncHeight);
336
+ // in case when node didn't report new height yet
337
+ // it is a workaround for moving height request to another isolate
338
+ final nodeHeight = await getNodeHeightOrUpdate(syncHeight);
339
+ if (nodeHeight == 0) {
340
+ return;
341
+ }
342
+ final bchHeight = max(nodeHeight, syncHeight);
343
// printV("syncHeight: $syncHeight, _lastKnownBlockHeight: $_lastKnownBlockHeight, bchHeight: $bchHeight");
344
if (_lastKnownBlockHeight == syncHeight) {
345
return;
@@ -341,7 +351,8 @@ class SyncListener {
351
final ptc = diff <= 0 ? 0.0 : diff / track;
352
final left = bchHeight - syncHeight;
353
344
- if (syncHeight < 0 || left < 0) {
354
+ if ((syncHeight < 0 || left < 0)) {
355
+ printV("not calling onNewBlock: syncHeight: $syncHeight, left: $left");
356
return;
357
}
358