CW-1078: Electrum Wallets not reconencting correctly if the OS closes the connection (#2405)

* fix: Electrum Wallets not reconencting correctly if the OS closes the connection

* fix: Electrum connectivity bug. Enahnced checks and reconnect when needed, and Socket health logs page for logs

* fix: Add extra checks

* chore: Migrate to static log list instead of file storage

* fix: Electrum connectivity review comments

This change:
- Adds reset count for used trusted nodes
- Adds context guards for ScaffoldMessenger calls

* fix: Reset the state for _resetCount when there is a wallet switch
This commit is contained in:
David Adegoke
2025-07-31 17:24:54 +03:00
committed by GitHub
parent 723103d429
commit 186247d849
16 changed files with 740 additions and 17 deletions
+17
View File
@@ -15,6 +15,15 @@ class NodeSwitchingService {
static const int _healthCheckIntervalSeconds = 30;
// The number of times we want to reset the overall used trusted nodes list.
// We don't want an infinite loop if all trusted nodes are down.
static const int _usedTrustedNodeResetCount = 2;
// State to manage the reset count
int _resetCount = 0;
String walletName = '';
Timer? _healthCheckTimer;
bool _isSwitching = false;
@@ -64,6 +73,10 @@ class NodeSwitchingService {
Future<void> _switchToNextTrustedNode() async {
_isSwitching = true;
if (walletName.isNotEmpty && (walletName != appStore.wallet!.name)) _resetCount = 0;
walletName = appStore.wallet!.name;
try {
final walletType = appStore.wallet!.type;
final currentNode = settingsStore.getCurrentNode(walletType);
@@ -98,6 +111,10 @@ class NodeSwitchingService {
// If all trusted nodes have been used, reset the list and start over
if (nextNode == null) {
printV('All trusted nodes have been tried, resetting and starting over');
_resetCount++;
if (_resetCount > _usedTrustedNodeResetCount) return;
_usedNodeKeys[walletType]!.clear();
nextNode = trustedNodes.first;
}