diff --git a/package.json b/package.json index 6ab4a339..318f0c2b 100644 --- a/package.json +++ b/package.json @@ -167,6 +167,7 @@ "@types/react-router": "^5.1.18", "@types/react-router-dom": "^5.3.3", "@types/react-test-renderer": "^17.0.1", + "@types/shelljs": "^0.8.11", "@types/sqlite3": "^3.1.7", "@types/terser-webpack-plugin": "^5.0.4", "@types/underscore": "^1.11.3", @@ -260,6 +261,7 @@ "react-router-dom": "^6.2.2", "react-toastify": "^8.2.0", "regenerator-runtime": "^0.13.9", + "shelljs": "^0.8.5", "styled-components": "^5.3.3", "typescript-lru-cache": "^1.2.3", "underscore": "^1.13.1", diff --git a/src/main/anchor.ts b/src/main/anchor.ts index abefe4d6..f34d9168 100644 --- a/src/main/anchor.ts +++ b/src/main/anchor.ts @@ -1,5 +1,6 @@ import { FetchAnchorIDLRequest } from '../types/types'; import { execAsync, RESOURCES_PATH } from './const'; +import { logger } from './logger'; const fetchAnchorIdl = async (msg: FetchAnchorIDLRequest) => { // Anchor doesn't seem to accept a flag for where Anchor.toml is (???) @@ -11,7 +12,7 @@ const fetchAnchorIdl = async (msg: FetchAnchorIDLRequest) => { process.chdir(cwd); return JSON.parse(stdout); } catch (error) { - console.log(error); + logger.error(error); return { error, }; diff --git a/src/main/main.ts b/src/main/main.ts index dd7b871c..c78a0242 100644 --- a/src/main/main.ts +++ b/src/main/main.ts @@ -56,7 +56,7 @@ ipcMain.on( break; case 'fetch-anchor-idl': res = await fetchAnchorIdl(msg); - console.log(`fetchIDL(${msg}: (${res})`); + logger.debug(`fetchIDL(${msg}: (${res})`); break; // case 'update-account-name': // await updateAccountName(msg); diff --git a/src/main/validator.ts b/src/main/validator.ts index 9bfa2da1..12ae7cbe 100644 --- a/src/main/validator.ts +++ b/src/main/validator.ts @@ -1,3 +1,4 @@ +import * as shell from 'shelljs'; import { Net, ValidatorLogsRequest } from '../types/types'; import { execAsync } from './const'; import { logger } from './logger'; @@ -12,9 +13,17 @@ if (process.platform === 'darwin') { } const runValidator = async () => { + if (!shell.which(DOCKER_PATH)) { + logger.info('Docker executable not found.'); + return; + } + + // TODO: and now test if there's a Docker daemon up + try { await execAsync(`${DOCKER_PATH} inspect solana-test-validator`); } catch (e) { + logger.error(e); // TODO: check for image, pull if not present await execAsync( `${DOCKER_PATH} run \ @@ -48,13 +57,17 @@ const validatorLogs = async (msg: ValidatorLogsRequest) => { const MAX_DISPLAY_LINES = 30; if (net !== Net.Localhost) { - return ''; + return `Cannot show validator container output from ${net}`; } // TODO: doing this out of process might be a better fit const maxBuffer = 104857600; // 100MB - let output: string; + if (!shell.which(DOCKER_PATH)) { + return 'Docker executable not found.'; + } + + // TODO: and now test if there's a Docker daemon up try { if (filter !== '') { @@ -66,7 +79,7 @@ const validatorLogs = async (msg: ValidatorLogsRequest) => { const matchingLines = lines .slice(Math.max(lines.length - MAX_DISPLAY_LINES, 0)) .join('\n'); - logger.info('Filtered log lookup', { + logger.debug('Filtered log lookup', { matchLinesLen: matchingLines.length, filterLinesLen: lines.length, }); @@ -78,9 +91,11 @@ const validatorLogs = async (msg: ValidatorLogsRequest) => { ); return stderr; } catch (error) { - output = error as string; + logger.error('catch', error as string); + return error as string; } - return { output }; + + return ''; }; export { runValidator, validatorLogs }; diff --git a/src/renderer/App.tsx b/src/renderer/App.tsx index 7cf66271..acfd8434 100644 --- a/src/renderer/App.tsx +++ b/src/renderer/App.tsx @@ -46,6 +46,7 @@ const logger = window.electron.log; // So we can electron declare global { interface Window { + // eslint-disable-next-line @typescript-eslint/no-explicit-any electron?: any; } } @@ -265,6 +266,7 @@ function App() { Object.assign(console, logger.functions); useEffect(() => { + // eslint-disable-next-line @typescript-eslint/no-explicit-any const listener = (resp: any) => { const { method, res } = resp; switch (method) { diff --git a/src/renderer/components/CopyIcon.tsx b/src/renderer/components/CopyIcon.tsx index d4eead98..08c907b4 100644 --- a/src/renderer/components/CopyIcon.tsx +++ b/src/renderer/components/CopyIcon.tsx @@ -10,7 +10,7 @@ function CopyIcon(props: { writeValue: string }) { ); const renderCopyTooltip = (id: string) => - // eslint-disable-next-line @typescript-eslint/no-explicit-any + // eslint-disable-next-line @typescript-eslint/no-explicit-any,func-names function (ttProps: any) { return ( // eslint-disable-next-line react/jsx-props-no-spreading diff --git a/src/renderer/data/Config/configState.ts b/src/renderer/data/Config/configState.ts index d16d53bb..d1b1ba93 100644 --- a/src/renderer/data/Config/configState.ts +++ b/src/renderer/data/Config/configState.ts @@ -34,6 +34,7 @@ export const configSlice = createSlice({ // eslint-disable-next-line @typescript-eslint/no-explicit-any setConfigValue: ( state, + // eslint-disable-next-line @typescript-eslint/no-explicit-any action: PayloadAction<{ key: string; value: any }> ) => { if (state.values) { diff --git a/src/renderer/nav/Validator.tsx b/src/renderer/nav/Validator.tsx index 23347cd5..8979d490 100644 --- a/src/renderer/nav/Validator.tsx +++ b/src/renderer/nav/Validator.tsx @@ -7,7 +7,6 @@ import { debounce } from 'underscore'; import { useInterval, useAppSelector } from '../hooks'; import { - Net, NetStatus, selectValidatorNetworkState, } from '../data/ValidatorNetwork/validatorNetworkState'; @@ -21,6 +20,7 @@ const Validator = () => { if (validator.status === NetStatus.Running) { window.electron.ipcRenderer.validatorLogs({ filter: filterRef.current.value || '', + net: validator.net, }); } }, 5000); @@ -39,12 +39,12 @@ const Validator = () => { window.electron.ipcRenderer.on('main', listener); window.electron.ipcRenderer.validatorLogs({ filter: '', - net: Net.Localhost, + net: validator.net, }); return () => { window.electron.ipcRenderer.removeListener('main', listener); }; - }, []); + }, [validator.net]); // TODO(nathanleclaire): Don't nest ternary return ( @@ -78,16 +78,17 @@ const Validator = () => { if (validator.status === NetStatus.Running) { window.electron.ipcRenderer.validatorLogs({ filter: filterRef.current.value || '', + net: validator.net, }); } }, 300)} /> -
-            {validatorLogs}
-          
)} +
+        {validatorLogs}
+      
); };