Fix unavailable balance not refreshing after the app got opened (#1920)

cyan committed Dec 31, 2024 at 17:47 UTC d33a901f669b9a2a3868b4c184be5fe58a2974a6
2 files changed +6 -1
cw_monero/lib/monero_wallet.dart
+4
@@ -503,6 +503,7 @@ abstract class MoneroWalletBase extends WalletBase<MoneroBalance,
503 }
504
505 Future<void> updateUnspent() async {
506 + await transaction_history.txHistoryMutex.acquire();
507 try {
508 refreshCoins(walletAddresses.account!.id);
509
@@ -531,6 +532,7 @@ abstract class MoneroWalletBase extends WalletBase<MoneroBalance,
532
533 if (unspentCoinsInfo.isEmpty) {
534 unspentCoins.forEach((coin) => _addCoinInfo(coin));
535 + transaction_history.txHistoryMutex.release();
536 return;
537 }
538
@@ -555,7 +557,9 @@ abstract class MoneroWalletBase extends WalletBase<MoneroBalance,
557
558 await _refreshUnspentCoinsInfo();
559 _askForUpdateBalance();
560 + transaction_history.txHistoryMutex.release();
561 } catch (e, s) {
562 + transaction_history.txHistoryMutex.release();
563 printV(e.toString());
564 onError?.call(FlutterErrorDetails(
565 exception: e,
cw_monero/lib/monero_wallet_service.dart
+2 -1
@@ -12,6 +12,7 @@ import 'package:cw_core/wallet_info.dart';
12 import 'package:cw_core/wallet_service.dart';
13 import 'package:cw_core/wallet_type.dart';
14 import 'package:cw_monero/api/account_list.dart';
15 +import 'package:cw_monero/api/transaction_history.dart';
16 import 'package:cw_monero/api/wallet_manager.dart' as monero_wallet_manager;
17 import 'package:cw_monero/api/wallet_manager.dart';
18 import 'package:cw_monero/ledger.dart';
@@ -159,7 +160,7 @@ class MoneroWalletService extends WalletService<
160 }
161
162 await wallet.init();
162 -
163 + await wallet.updateUnspent();
164 return wallet;
165 } catch (e) {
166 // TODO: Implement Exception for wallet list service.