CW-974: Add support for automatic node switching. (#2361)

* feat: Add support for automatic node switching.

This change:
- Adds isTrustedNodeForSwitching property to Node class.
- Adds UI Checkbox to mark a node as trusted for automatic switching in Node create or edit form.
- Implements checkNodeHealth method in wallet classes to verify node connectivity.
- Adds NodeSwitchingService for managing automatic node switching based on health checks.
- Adds setting option for user to enable/disable automated node switching

* fix(automatic-node-switch): Set node health check interval to 5 minutes in NodeSwitchingService

* refactor: Update handler method

* feat: Automatic Node Switching Improvements

This change:
- Moves enable automatic node switch to the Manage Nodes Page
- Adds check to verify node health before attempting to sync in EVM, Sol and Tron Wallets.
- Modifies trusted ndoes list for monero
- Adds trigger for Node Health Check when app resumes from background

* fix: Increase default request timeout for Tron and update health check interval for node switch

* feat: Enhance Node health check functionality.

This change adds additional checks for token balance in EVM, Solana and Tron Wallets in checkNodeHealth.

* fix: Update health check interval to 30 seconds in NodeSwitchingService

* Update bitcoin_electrum_server_list.yml

* fix: Electru wallet not connecting to new node after switching

* fix: Automated Node Switch not working on Decred Wallet

* fix: Add more nodes for AutoSwitching

This change:
- Enables more nodes across wallet types for auto switching
- Modifies CTA for checkbox
- Renames flags to fit

* fix: Add migration function for setting up default nodes for autoswitching

* fix: Review and testing fixes

* chore: Adjust balance and history fetch timer
This commit is contained in:
David Adegoke
2025-07-25 16:42:59 +03:00
committed by GitHub
parent 8f4eed4d9b
commit 4b2af63fa5
73 changed files with 639 additions and 68 deletions
+16
View File
@@ -128,6 +128,7 @@ abstract class SettingsStoreBase with Store {
required this.mwebEnabled,
required this.hasEnabledMwebBefore,
required this.mwebNodeUri,
required bool initialEnableAutomaticNodeSwitching,
TransactionPriority? initialBitcoinTransactionPriority,
TransactionPriority? initialMoneroTransactionPriority,
TransactionPriority? initialWowneroTransactionPriority,
@@ -186,6 +187,7 @@ abstract class SettingsStoreBase with Store {
currentSyncMode = initialSyncMode,
currentSyncAll = initialSyncAll,
currentBuiltinTor = initialBuiltinTor,
enableAutomaticNodeSwitching = initialEnableAutomaticNodeSwitching,
priority = ObservableMap<WalletType, TransactionPriority>() {
//this.nodes = ObservableMap<WalletType, Node>.of(nodes);
@@ -613,6 +615,11 @@ abstract class SettingsStoreBase with Store {
(_) => mwebNodeUri,
(String mwebNodeUri) =>
_sharedPreferences.setString(PreferencesKey.mwebNodeUri, mwebNodeUri));
reaction(
(_) => enableAutomaticNodeSwitching,
(bool enableAutomaticNodeSwitching) => _sharedPreferences.setBool(
PreferencesKey.enableAutomaticNodeSwitching, enableAutomaticNodeSwitching));
this.nodes.observe((change) {
if (change.newValue != null && change.key != null) {
@@ -859,6 +866,9 @@ abstract class SettingsStoreBase with Store {
@observable
String mwebNodeUri;
@observable
bool enableAutomaticNodeSwitching;
final SecureStorage _secureStorage;
final SharedPreferences _sharedPreferences;
@@ -1034,6 +1044,8 @@ abstract class SettingsStoreBase with Store {
sharedPreferences.getBool(PreferencesKey.hasEnabledMwebBefore) ?? false;
final mwebNodeUri = sharedPreferences.getString(PreferencesKey.mwebNodeUri) ??
"ltc-electrum.cakewallet.com:9333";
final enableAutomaticNodeSwitching =
sharedPreferences.getBool(PreferencesKey.enableAutomaticNodeSwitching) ?? true;
// If no value
if (pinLength == null || pinLength == 0) {
@@ -1335,6 +1347,7 @@ abstract class SettingsStoreBase with Store {
mwebEnabled: mwebEnabled,
mwebNodeUri: mwebNodeUri,
hasEnabledMwebBefore: hasEnabledMwebBefore,
initialEnableAutomaticNodeSwitching: enableAutomaticNodeSwitching,
initialMoneroTransactionPriority: moneroTransactionPriority,
initialWowneroTransactionPriority: wowneroTransactionPriority,
initialZanoTransactionPriority: zanoTransactionPriority,
@@ -1478,6 +1491,9 @@ abstract class SettingsStoreBase with Store {
actionlistDisplayMode = ObservableList<ActionListDisplayMode>();
actionlistDisplayMode.addAll(deserializeActionlistDisplayModes(
sharedPreferences.getInt(PreferencesKey.displayActionListModeKey) ?? defaultActionsMode));
enableAutomaticNodeSwitching =
sharedPreferences.getBool(PreferencesKey.enableAutomaticNodeSwitching) ??
enableAutomaticNodeSwitching;
var pinLength = sharedPreferences.getInt(PreferencesKey.currentPinLength);
// If no value
if (pinLength == null || pinLength == 0) {