From c5b018afc385b6e5ca0ed2513655fd84f9c3953a Mon Sep 17 00:00:00 2001 From: Franco Montenegro Date: Tue, 31 May 2022 15:03:29 -0300 Subject: [PATCH] Reconnect to default server if custom server fails. --- ui/component/settingWalletServer/index.js | 8 +- ui/component/settingWalletServer/view.jsx | 37 +++++++-- ui/constants/action_types.js | 1 + ui/redux/actions/settings.js | 2 +- ui/redux/actions/wallet.js | 97 +++++++++++++---------- ui/redux/reducers/wallet.js | 21 +++-- ui/redux/selectors/wallet.js | 7 ++ 7 files changed, 111 insertions(+), 62 deletions(-) diff --git a/ui/component/settingWalletServer/index.js b/ui/component/settingWalletServer/index.js index 95d4b169b..9f16d6171 100644 --- a/ui/component/settingWalletServer/index.js +++ b/ui/component/settingWalletServer/index.js @@ -1,5 +1,9 @@ import { connect } from 'react-redux'; -import { selectIsWalletReconnecting } from 'redux/selectors/wallet'; +import { + selectIsWalletReconnecting, + selectWalletRollbackToDefault, + selectWalletConnectingToDefault, +} from 'redux/selectors/wallet'; import * as DAEMON_SETTINGS from 'constants/daemon_settings'; import { doSetDaemonSetting, @@ -15,6 +19,8 @@ const select = (state) => ({ customWalletServers: selectSavedWalletServers(state), hasWalletServerPrefs: selectHasWalletServerPrefs(state), walletReconnecting: selectIsWalletReconnecting(state), + walletRollbackToDefault: selectWalletRollbackToDefault(state), + walletReconnectingToDefault: selectWalletConnectingToDefault(state), }); const perform = (dispatch) => ({ diff --git a/ui/component/settingWalletServer/view.jsx b/ui/component/settingWalletServer/view.jsx index 268aa42f0..791afa584 100644 --- a/ui/component/settingWalletServer/view.jsx +++ b/ui/component/settingWalletServer/view.jsx @@ -30,6 +30,8 @@ type Props = { hasWalletServerPrefs: boolean, daemonStatus: DaemonStatus, walletReconnecting: boolean, + walletRollbackToDefault: boolean, + walletReconnectingToDefault: boolean, }; function SettingWalletServer(props: Props) { @@ -42,9 +44,12 @@ function SettingWalletServer(props: Props) { customWalletServers, hasWalletServerPrefs, walletReconnecting, + walletRollbackToDefault, + walletReconnectingToDefault, } = props; - const [advancedMode, setAdvancedMode] = useState(false); + const [usingCustomServer, setUsingCustomServer] = useState(false); + const [showCustomServers, setShowCustomServers] = useState(false); const walletStatus = daemonStatus && daemonStatus.wallet; const activeWalletServers: ServerStatus = (walletStatus && walletStatus.servers) || []; @@ -73,7 +78,7 @@ function SettingWalletServer(props: Props) { useEffect(() => { if (hasWalletServerPrefs) { - setAdvancedMode(true); + setUsingCustomServer(true); } }, []); @@ -84,8 +89,20 @@ function SettingWalletServer(props: Props) { return () => clearInterval(interval); }, []); + useEffect(() => { + if (walletRollbackToDefault) { + doClear(); + } + }, [walletRollbackToDefault]); + + useEffect(() => { + if (usingCustomServer) { + setShowCustomServers(true); + } + }, [usingCustomServer]); + function doClear() { - setAdvancedMode(false); + setUsingCustomServer(false); clearWalletServers(); } @@ -112,7 +129,7 @@ function SettingWalletServer(props: Props) { { if (e.target.checked) { @@ -123,9 +140,9 @@ function SettingWalletServer(props: Props) { { - setAdvancedMode(e.target.checked); + setUsingCustomServer(e.target.checked); if (e.target.checked && customWalletServers.length) { setCustomWalletServers(stringifyServerParam(customWalletServers)); } @@ -133,7 +150,7 @@ function SettingWalletServer(props: Props) { label={__('Use custom wallet servers')} /> - {advancedMode && ( + {showCustomServers && (
{serverConfig && serverConfig.map((entry, index) => { @@ -151,7 +168,11 @@ function SettingWalletServer(props: Props) { {host}:{port} - {available ? __('Connected') : walletReconnecting ? __('Connecting...') : __('Not connected')} + {available + ? __('Connected') + : walletReconnecting && !walletReconnectingToDefault + ? __('Connecting...') + : __('Not connected')}