fix: getWlptr failing nullcheck in hardware monero wallets ()

now null wptr on listener calls will be handled gracefully

Co-authored-by: Omar Hatem <omarh.ismail1@gmail.com>
This commit is contained in:
cyan 2025-04-03 03:34:45 +02:00 committed by GitHub
parent 23a47ed561
commit 7a5999d90e
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 10 additions and 6 deletions

View file

@ -7,7 +7,8 @@ bool get isViewOnly => int.tryParse(monero.Wallet_secretSpendKey(wptr!)) == 0;
int _wlptrForW = 0;
monero.WalletListener? _wlptr = null;
monero.WalletListener getWlptr() {
monero.WalletListener? getWlptr() {
if (wptr == null) return null;
if (wptr!.address == _wlptrForW) return _wlptr!;
_wlptrForW = wptr!.address;
_wlptr = monero.MONERO_cw_getWalletListener(wptr!);

View file

@ -2,7 +2,6 @@ import 'dart:async';
import 'dart:ffi';
import 'dart:isolate';
import 'package:cw_core/root_dir.dart';
import 'package:cw_core/utils/print_verbose.dart';
import 'package:cw_monero/api/account_list.dart';
import 'package:cw_monero/api/exceptions/setup_wallet_exception.dart';
@ -22,14 +21,18 @@ int getSyncingHeight() {
}
bool isNeededToRefresh() {
final ret = monero.MONERO_cw_WalletListener_isNeedToRefresh(getWlptr());
monero.MONERO_cw_WalletListener_resetNeedToRefresh(getWlptr());
final wlptr = getWlptr();
if (wlptr == null) return false;
final ret = monero.MONERO_cw_WalletListener_isNeedToRefresh(wlptr);
monero.MONERO_cw_WalletListener_resetNeedToRefresh(wlptr);
return ret;
}
bool isNewTransactionExist() {
final ret = monero.MONERO_cw_WalletListener_isNewTransactionExist(getWlptr());
monero.MONERO_cw_WalletListener_resetIsNewTransactionExist(getWlptr());
final wlptr = getWlptr();
if (wlptr == null) return false;
final ret = monero.MONERO_cw_WalletListener_isNewTransactionExist(wlptr);
monero.MONERO_cw_WalletListener_resetIsNewTransactionExist(wlptr);
return ret;
}