fix: monero wallets crashing when switching back from hardware wallet to another monero wallet (#2370)
cyan committed
Jul 10, 2025 at 13:25 UTC
3b9f1ce15e43e6613c2307c59480a3ba25720849
2 files changed
+8
-7
cw_monero/lib/api/subaddress_list.dart
+5
-6
@@ -3,7 +3,6 @@ import 'package:cw_monero/api/account_list.dart';
3
import 'package:cw_monero/api/transaction_history.dart';
4
import 'package:cw_monero/api/wallet.dart';
5
import 'package:monero/monero.dart';
6
-import 'package:monero/src/monero.dart';
6
7
bool isUpdating = false;
8
@@ -17,7 +16,7 @@ class SubaddressInfoMetadata {
16
SubaddressInfoMetadata? subaddress = null;
17
18
String getRawLabel({required int accountIndex, required int addressIndex}) {
20
- return currentWallet!.getSubaddressLabel(accountIndex: accountIndex, addressIndex: addressIndex);
19
+ return currentWallet?.getSubaddressLabel(accountIndex: accountIndex, addressIndex: addressIndex)??"";
20
}
21
22
void refreshSubaddresses({required int accountIndex}) {
@@ -47,7 +46,7 @@ class Subaddress {
46
final int received;
47
final int txCount;
48
String get label {
50
- final localLabel = currentWallet!.getSubaddressLabel(accountIndex: accountIndex, addressIndex: addressIndex);
49
+ final localLabel = currentWallet?.getSubaddressLabel(accountIndex: accountIndex, addressIndex: addressIndex) ?? "";
50
if (localLabel.startsWith("#$addressIndex")) return localLabel; // don't duplicate the ID if it was user-providen
51
return "#$addressIndex ${localLabel}".trim();
52
}
@@ -120,17 +119,17 @@ List<Subaddress> getAllSubaddresses() {
119
}
120
121
int numSubaddresses(int subaccountIndex) {
123
- return currentWallet!.numSubaddresses(accountIndex: subaccountIndex);
122
+ return currentWallet?.numSubaddresses(accountIndex: subaccountIndex) ?? 0;
123
}
124
125
Future<void> addSubaddress({required int accountIndex, required String label}) async {
127
- currentWallet!.addSubaddress(accountIndex: accountIndex, label: label);
126
+ currentWallet?.addSubaddress(accountIndex: accountIndex, label: label);
127
refreshSubaddresses(accountIndex: accountIndex);
128
await store();
129
}
130
131
Future<void> setLabelForSubaddress(
132
{required int accountIndex, required int addressIndex, required String label}) async {
134
- currentWallet!.setSubaddressLabel(accountIndex: accountIndex, addressIndex: addressIndex, label: label);
133
+ currentWallet?.setSubaddressLabel(accountIndex: accountIndex, addressIndex: addressIndex, label: label);
134
await store();
135
}
\ No newline at end of file
cw_monero/lib/monero_wallet.dart
+3
-1
@@ -195,7 +195,9 @@ abstract class MoneroWalletBase extends WalletBase<MoneroBalance,
195
final waddr = openedWalletsByPath["$currentWalletDirPath/$name"]!.ffiAddress();
196
openedWalletsByPath.remove("$currentWalletDirPath/$name");
197
closeWalletAwaitIfShould(wmaddr, waddr);
198
- currentWallet = null;
198
+ if (currentWallet?.ffiAddress() == waddr) {
199
+ currentWallet = null;
200
+ }
201
printV("wallet closed");
202
}
203
}