From e3aae34f65b96b1dbbfcba3c4210c948559b413e Mon Sep 17 00:00:00 2001 From: jessop Date: Fri, 13 Dec 2019 12:26:59 -0500 Subject: [PATCH] refactor --- ui/component/settingWalletServer/view.jsx | 82 +++++++++-------------- 1 file changed, 32 insertions(+), 50 deletions(-) diff --git a/ui/component/settingWalletServer/view.jsx b/ui/component/settingWalletServer/view.jsx index 83cc596dc..f0eb7b346 100644 --- a/ui/component/settingWalletServer/view.jsx +++ b/ui/component/settingWalletServer/view.jsx @@ -24,16 +24,8 @@ type StatusOfServer = { }; type ServerTuple = Array; // ['host', 'port'] - -type DisplayOfServer = { - host: string, - port: string, - availability: boolean, -}; - type ServerStatus = Array; type ServerConfig = Array; -type DisplayList = Array; type Props = { daemonSettings: DaemonSettings, @@ -66,7 +58,6 @@ function SettingWalletServer(props: Props) { const currentServerConfig: ServerConfig = daemonSettings && daemonSettings.lbryum_servers; const serverConfig: ServerConfig = customWalletServers.length ? customWalletServers : currentServerConfig; const STATUS_INTERVAL = 5000; - console.log(hasWalletServerPrefs) useEffect(() => { if (hasWalletServerPrefs) { @@ -85,19 +76,6 @@ function SettingWalletServer(props: Props) { fetchDaemonSettings(); }, []); - function makeDisplayList(l) { - const displayList = []; - l.forEach(entry => { - displayList.push({ - host: entry[0], - port: entry[1], - available: - activeWalletServers.some(s => s.host === entry[0] && String(s.port) === entry[1] && s.availability) || false, - }); - }); - return displayList; - } - function makeServerParam(configList) { return configList.reduce((acc, cur) => { acc.push(`${cur[0]}:${cur[1]}`); @@ -131,29 +109,29 @@ function SettingWalletServer(props: Props) {
- { - if (e.target.checked) { - doClear(); - } - }} - /> - { - setAdvancedMode(e.target.checked); - if (e.target.checked) { - setCustomWalletServers(makeServerParam(customWalletServers)); - } - }} - label={__('customize')} - /> + { + if (e.target.checked) { + doClear(); + } + }} + /> + { + setAdvancedMode(e.target.checked); + if (e.target.checked) { + setCustomWalletServers(makeServerParam(customWalletServers)); + } + }} + label={__('customize')} + />
{advancedMode && (
@@ -168,11 +146,15 @@ function SettingWalletServer(props: Props) { {serverConfig && - makeDisplayList(serverConfig).map((t, i) => ( - - {t.host} - {t.port} - {t.available && } + serverConfig.map((entry, i) => ( + + {entry[0]} + {entry[1]} + + {activeWalletServers.some( + s => s.host === entry[0] && String(s.port) === entry[1] && s.availability + ) && } +