mirror of
https://github.com/Such-Software/hash-wallet.git
synced 2026-11-23 10:45:27 +01:00
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:
@@ -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;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user