From 3b9f1ce15e43e6613c2307c59480a3ba25720849 Mon Sep 17 00:00:00 2001 From: cyan Date: Thu, 10 Jul 2025 13:25:31 +0200 Subject: [PATCH] fix: monero wallets crashing when switching back from hardware wallet to another monero wallet (#2370) --- cw_monero/lib/api/subaddress_list.dart | 11 +++++------ cw_monero/lib/monero_wallet.dart | 4 +++- 2 files changed, 8 insertions(+), 7 deletions(-) diff --git a/cw_monero/lib/api/subaddress_list.dart b/cw_monero/lib/api/subaddress_list.dart index 46bdc10bc..9a33dd12c 100644 --- a/cw_monero/lib/api/subaddress_list.dart +++ b/cw_monero/lib/api/subaddress_list.dart @@ -3,7 +3,6 @@ import 'package:cw_monero/api/account_list.dart'; import 'package:cw_monero/api/transaction_history.dart'; import 'package:cw_monero/api/wallet.dart'; import 'package:monero/monero.dart'; -import 'package:monero/src/monero.dart'; bool isUpdating = false; @@ -17,7 +16,7 @@ class SubaddressInfoMetadata { SubaddressInfoMetadata? subaddress = null; String getRawLabel({required int accountIndex, required int addressIndex}) { - return currentWallet!.getSubaddressLabel(accountIndex: accountIndex, addressIndex: addressIndex); + return currentWallet?.getSubaddressLabel(accountIndex: accountIndex, addressIndex: addressIndex)??""; } void refreshSubaddresses({required int accountIndex}) { @@ -47,7 +46,7 @@ class Subaddress { final int received; final int txCount; String get label { - final localLabel = currentWallet!.getSubaddressLabel(accountIndex: accountIndex, addressIndex: addressIndex); + final localLabel = currentWallet?.getSubaddressLabel(accountIndex: accountIndex, addressIndex: addressIndex) ?? ""; if (localLabel.startsWith("#$addressIndex")) return localLabel; // don't duplicate the ID if it was user-providen return "#$addressIndex ${localLabel}".trim(); } @@ -120,17 +119,17 @@ List getAllSubaddresses() { } int numSubaddresses(int subaccountIndex) { - return currentWallet!.numSubaddresses(accountIndex: subaccountIndex); + return currentWallet?.numSubaddresses(accountIndex: subaccountIndex) ?? 0; } Future addSubaddress({required int accountIndex, required String label}) async { - currentWallet!.addSubaddress(accountIndex: accountIndex, label: label); + currentWallet?.addSubaddress(accountIndex: accountIndex, label: label); refreshSubaddresses(accountIndex: accountIndex); await store(); } Future setLabelForSubaddress( {required int accountIndex, required int addressIndex, required String label}) async { - currentWallet!.setSubaddressLabel(accountIndex: accountIndex, addressIndex: addressIndex, label: label); + currentWallet?.setSubaddressLabel(accountIndex: accountIndex, addressIndex: addressIndex, label: label); await store(); } \ No newline at end of file diff --git a/cw_monero/lib/monero_wallet.dart b/cw_monero/lib/monero_wallet.dart index 9a8cb70b4..6f32af646 100644 --- a/cw_monero/lib/monero_wallet.dart +++ b/cw_monero/lib/monero_wallet.dart @@ -195,7 +195,9 @@ abstract class MoneroWalletBase extends WalletBase