Potential fix for possible crash when wallet is deleted
What changed, and why it matters
This is a one-line defensive fix in a Dart wallet app. It prevents the app from notifying UI listeners about a connection change if the underlying wallet object has already been deleted. The change likely avoids a crash or inconsistent UI state when a wallet is removed, but it is not a security vulnerability that an attacker can directly exploit.
Treat as a routine stability fix. Review the broader wallet deletion flow to ensure _w2Wallet cleanup and listener disposal are ordered safely, and add regression tests for deletion during connection checks.
Security signals we found
Defensive null-guard added around listener notification
Crash-avoidance change in wallet deletion lifecycle
No input validation, cryptographic, or authentication changes
Evidence from the diff
In lib/models/wallet_model.dart, the checkConnection() method now only updates _isConnected and calls notifyListeners() when getIsConnected() differs from the cached _isConnected value AND _w2Wallet is non-null. This guards against state notifications after wallet deletion. The patch is partial and narrow: it suppresses a notification rather than restructuring lifecycle management.
Changed components
lib/models/wallet_model.dartWalletModel.checkConnection()ChangeNotifier listener notification pathInspect captured patch +1 / −1
diff --git a/lib/models/wallet_model.dart b/lib/models/wallet_model.dart
index 8ec8725..36180c7 100644
--- a/lib/models/wallet_model.dart
+++ b/lib/models/wallet_model.dart
@@ -186,7 +186,7 @@ class WalletModel with ChangeNotifier {
final isConnected = await getIsConnected();
- if (isConnected != _isConnected) {
+ if (isConnected != _isConnected && _w2Wallet != null) {
_isConnected = isConnected;
notifyListeners();
}
Why this scored 23/100
Community notes
Notes can correct, qualify, or add evidence to the AI analysis. Every note shown here has been validated by a human moderator.
The AI analysis stands alone for now. Submit a note if you can add evidence or important context.