Skip to content

Commit

Permalink
use strict typescript rules
Browse files Browse the repository at this point in the history
  • Loading branch information
pablomendezroyo committed Aug 6, 2024
1 parent bd10337 commit c292bf8
Show file tree
Hide file tree
Showing 44 changed files with 125 additions and 171 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ node_modules/\.yarn-integrity
# Typescript build artifacts
build/src/dist/
build/src/.temp-transfer/
packages/*/tsconfig.tsbuildinfo

# Common
packages/*/node_modules/
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@
"nodemon": "^3.0.2",
"rimraf": "^3.0.2",
"ts-node": "^10.9.2",
"typescript": "^5.3.3"
"typescript": "^5.5.4"
},
"packageManager": "[email protected]"
}
26 changes: 13 additions & 13 deletions packages/admin-ui/src/App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,9 @@ export const AppContext = React.createContext<AppContextIface>({
theme: "light",
stakersModuleStatus: "enabled",
rollupsModuleStatus: "disabled",
toggleTheme: () => { },
toggleStakersModuleStatus: () => { },
toggleRollupsModuleStatus: () => { }
toggleTheme: () => {},
toggleStakersModuleStatus: () => {},
toggleRollupsModuleStatus: () => {}
});

const useLocalStorage = <T extends string>(
Expand Down Expand Up @@ -169,16 +169,16 @@ export default function App() {

// Keep retrying if there is a loggin error, probably due a network error
useEffect(() => {
if (isError) {
let timeToNext = 500;
let timeout: unknown;
const recursiveTimeout = () => {
onFetchLoginStatus();
timeout = setTimeout(recursiveTimeout, (timeToNext *= 2));
};
recursiveTimeout();
return () => clearTimeout(timeout as number);
}
if (!isError) return;

let timeToNext = 500;
let timeout: unknown;
const recursiveTimeout = () => {
onFetchLoginStatus();
timeout = setTimeout(recursiveTimeout, (timeToNext *= 2));
};
recursiveTimeout();
return () => clearTimeout(timeout as number);
}, [isError, onFetchLoginStatus]);

if (!loginStatus) {
Expand Down
4 changes: 2 additions & 2 deletions packages/admin-ui/src/__mock-backend__/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,7 @@ export const otherCalls: Omit<Routes, keyof typeof namedSpacedCalls> = {
dnpName: "dnp.prysm.eth"
}
],
dappnodeWebNameSet: async ({ dappnodeWebName }) => {},
dappnodeWebNameSet: async () => {},
statsCpuGet: async () => ({
usedPercentage: 88,
numberOfCores: 4,
Expand Down Expand Up @@ -256,7 +256,7 @@ export const otherCalls: Omit<Routes, keyof typeof namedSpacedCalls> = {
ipfsClientTarget: IpfsClientTarget.remote,
ipfsGateway: "https://gateway.ipfs.dappnode.io"
}),
enableEthicalMetrics: async ({ mail }) => {},
enableEthicalMetrics: async () => {},
getEthicalMetricsConfig: async () => ({
mail: "@example.com",
enabled: true,
Expand Down
6 changes: 3 additions & 3 deletions packages/admin-ui/src/api/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ async function callRoute<R>(method: string, params: any[]): Promise<R> {
*/
export const api: Routes = mapValues(
routesData,
(data, route) => (...args: any[]) => callRoute<any>(route, args)
(_data, route) => (...args: any[]) => callRoute<any>(route, args)
);

/**
Expand All @@ -111,7 +111,7 @@ export const useApi: {
[K in keyof Routes]: (
...args: Parameters<Routes[K]>
) => responseInterface<ResolvedType<Routes[K]>, Error>;
} = mapValues(routesData, (data, route) => {
} = mapValues(routesData, (_data, route) => {
return function(...args: any[]) {
const argsKey = args.length > 0 ? JSON.stringify(args) : "";
const fetcher = (...args: any[]) => callRoute<any>(route, args);
Expand Down Expand Up @@ -166,7 +166,7 @@ export const useSubscription: {
[K in keyof Subscriptions]: (
callback: (...args: Parameters<SubscriptionsTypes[K]>) => void
) => void;
} = mapValues(subscriptionsData, (data, route) => {
} = mapValues(subscriptionsData, (_data, route) => {
return function(callback: (...args: any) => void) {
useSubscribe(route as keyof Subscriptions, callback);
};
Expand Down
8 changes: 4 additions & 4 deletions packages/admin-ui/src/api/mock/auth.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,23 +5,23 @@ export const apiAuth: IApiAuth = {
return { status: "logged-in", username: "admin" };
},

async login(data) {
async login() {
return { ok: true };
},

async logoutAndReload() {
window.location.reload();
},

async register(data) {
async register() {
return { recoveryToken: "TEST_TOKEN" };
},

async changePass(data) {
async changePass() {
return { ok: true };
},

async recoverPass(data) {
async recoverPass() {
return { ok: true };
}
};
2 changes: 1 addition & 1 deletion packages/admin-ui/src/api/mock/rpc.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ export const apiRpc: IApiRpc = {
return { result };
},

start(apiEventBridge, onConnect) {
start(_, onConnect) {
onConnect();
}
};
2 changes: 1 addition & 1 deletion packages/admin-ui/src/api/routes/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ export const apiRoutes: IApiRoutes = {
});

// Define what happens in case of error
xhr.addEventListener("error", e => reject(Error("Error loading file")));
xhr.addEventListener("error", _e => reject(Error("Error loading file")));

if (xhr.upload)
xhr.upload.addEventListener("progress", onProgress, false);
Expand Down
8 changes: 1 addition & 7 deletions packages/admin-ui/src/components/Loading.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,7 @@ import React, { useState, useEffect } from "react";
import logoAnimated from "img/dappNodeAnimation.gif";
import "./loading.scss";

export default function Loading({
size = 200,
steps
}: {
size?: number;
steps: string[];
}) {
export default function Loading({ steps }: { steps: string[] }) {
const [index, setIndex] = useState(0);
useEffect(() => {
const interval = setInterval(() => setIndex(i => i + 1), 3000);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -77,12 +77,12 @@ export default function EnableEthicalMetrics({

// clear the success message after 5 seconds
useEffect(() => {
if (validationMessage === "Ethical metrics enabled successfully.") {
const timer = setTimeout(() => {
setValidationMessage("");
}, 5000);
return () => clearTimeout(timer);
}
if (validationMessage !== "Ethical metrics enabled successfully.") return;

const timer = setTimeout(() => {
setValidationMessage("");
}, 5000);
return () => clearTimeout(timer);
}, [validationMessage]);

function toggleEthicalSwitch() {
Expand Down
1 change: 0 additions & 1 deletion packages/admin-ui/src/index.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import React from "react";
import ReactDOM from "react-dom";
import { createRoot } from "react-dom/client";
import { Provider } from "react-redux";
import { BrowserRouter as Router } from "react-router-dom";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ import { getEthClientWarning } from "services/dappnodeStatus/selectors";
import { confirmPromise } from "components/ConfirmDialog";
import { stakehouseLsdUrl } from "params";

export const InstallerDnp: React.FC = routeProps => {
export const InstallerDnp: React.FC = () => {
const navigate = useNavigate();

const directory = useSelector(getDnpDirectory);
Expand All @@ -49,7 +49,7 @@ export const InstallerDnp: React.FC = routeProps => {
// Limit the number of requests [TESTED]
const fetchQueryThrottled = useMemo(
() =>
throttle((query: string) => {
throttle((_query: string) => {
// #### TODO: provide feedback to the user if the query is found
}, 500),
[]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ import { activateFallbackPath } from "pages/system/data";
import { getEthClientWarning } from "services/dappnodeStatus/selectors";
import { fetchDnpRegistry } from "services/dnpRegistry/actions";

export const InstallerPublic: React.FC = routeProps => {
export const InstallerPublic: React.FC = () => {
const navigate = useNavigate();

const registry = useSelector(getDnpRegistry);
Expand All @@ -42,13 +42,13 @@ export const InstallerPublic: React.FC = routeProps => {
const [showErrorDnps, setShowErrorDnps] = useState(false);

useEffect(() => {
dispatch(fetchDnpRegistry({}));
dispatch(fetchDnpRegistry());
}, [dispatch]);

// Limit the number of requests [TESTED]
const fetchQueryThrottled = useMemo(
() =>
throttle((query: string) => {
throttle((_query: string) => {
// #### TODO: provide feedback to the user if the query is found
}, 500),
[]
Expand Down
40 changes: 22 additions & 18 deletions packages/admin-ui/src/pages/repository/components/Eth.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -69,24 +69,28 @@ export default function Eth() {
* "Alert!" your target is OFF, go to remote or install it again
*/
function renderEthMultiClientWarning() {
if (ethClientStatus && !ethClientStatus.ok)
switch (ethClientStatus.code) {
case "NOT_RUNNING":
return (
<Alert variant="warning">
Selected client is not running. Please, restart the client or
select remote
</Alert>
);
case "NOT_INSTALLED":
case "UNINSTALLED":
return (
<Alert variant="warning">
Selected client is not installed. Please, re-install the client or
select remote
</Alert>
);
}
if (!ethClientStatus) return null;
if (ethClientStatus.ok) return null;

switch (ethClientStatus.code) {
case "NOT_RUNNING":
return (
<Alert variant="warning">
Selected client is not running. Please, restart the client or select
remote
</Alert>
);
case "NOT_INSTALLED":
case "UNINSTALLED":
return (
<Alert variant="warning">
Selected client is not installed. Please, re-install the client or
select remote
</Alert>
);
default:
return null;
}
}
return (
<Card className="dappnode-identity">
Expand Down
2 changes: 1 addition & 1 deletion packages/admin-ui/src/pages/system/actions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -164,7 +164,7 @@ export const passwordChange = (
dispatch(fetchPasswordIsSecure());
};

export const volumeRemove = (name: string): AppThunk => async dispatch => {
export const volumeRemove = (name: string): AppThunk => async () => {
// Display a dialog to confirm the password change
await new Promise<void>(resolve =>
confirm({
Expand Down
6 changes: 1 addition & 5 deletions packages/admin-ui/src/services/dnpRegistry/actions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,7 @@ export const updateStatus = createAction<RequestStatus>(

// Redux-thunk actions

export const fetchDnpRegistry = ({
addressOrEnsName
}: {
addressOrEnsName?: string;
}): AppThunk => async dispatch => {
export const fetchDnpRegistry = (): AppThunk => async dispatch => {
try {
dispatch(updateStatus({ loading: true }));
const registry = await api.fetchRegistry();
Expand Down
1 change: 1 addition & 0 deletions packages/daemons/src/natRenewal/getLocalIp.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,5 +17,6 @@ export async function getLocalIp(options?: {
return isIp(internalIp) ? internalIp : undefined;
} catch (e) {
if (!silent) logs.error(`Error getting internal IP: ${e.message}`);
return undefined;
}
}
2 changes: 1 addition & 1 deletion packages/dappmanager/src/api/auth/sessionAuth.ts
Original file line number Diff line number Diff line change
Expand Up @@ -194,7 +194,7 @@ export class AuthPasswordSession {
/**
* Middleware to protect routes only for admin sessions
*/
onlyAdmin = wrapHandler((req, res, next) => {
onlyAdmin = wrapHandler((req, _, next) => {
this.assertOnlyAdmin(req);
next();
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import * as db from "@dappnode/db";
let counter = 0;

export function getViewsCounterMiddleware(): express.RequestHandler {
return (req, res, next): void => {
return (req, _, next): void => {
try {
// Only count views for the main page and login status
// Other requests are not from the UI but for other API calls
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { wrapHandlerHtml } from "../utils.js";
/**
* Endpoint to download user action logs.
*/
export const downloadUserActionLogs = wrapHandlerHtml(async (req, res) => {
export const downloadUserActionLogs = wrapHandlerHtml(async (_, res) => {
const logs = logUserAction.get();

const filename = `dappnode-user-action-logs_${new Date().toISOString()}.json`;
Expand Down
2 changes: 1 addition & 1 deletion packages/dappmanager/src/api/routes/fileDownload.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ export const fileDownload = wrapHandlerHtml<Params>(async (req, res) => {
throw e;
}

const filetype = await dockerGetPathType(containerNameOrId, filepath);
const filetype = await dockerGetPathType(filepath);
const isSingleFile = filetype === "file";

// Download single file as same mimetype, directory as .tar
Expand Down
2 changes: 1 addition & 1 deletion packages/dappmanager/src/api/routes/metrics.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ import { mevBoost, execution, consensus } from "../../index.js";
* - Dappnode graffiti or other
* - User sessions
*/
export const metrics = wrapHandler(async (req, res) => {
export const metrics = wrapHandler(async (_, res) => {
// Return all metrics the Prometheus exposition format
res.setHeader("Content-Type", register.contentType);
res.end(await register.metrics());
Expand Down
1 change: 1 addition & 0 deletions packages/dappmanager/src/api/routes/packageManifest.ts
Original file line number Diff line number Diff line change
Expand Up @@ -58,4 +58,5 @@ export const packageManifest = wrapHandler<Params>(async (req, res) => {
]);

res.status(200).send(filteredManifest);
return;
});
2 changes: 2 additions & 0 deletions packages/dappmanager/src/api/routes/upload.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,5 +38,7 @@ export const upload = wrapHandler(async (req, res) => {
if (errFs) logs.error(`Error deleting file: ${errFs.message}`);
});
}, 15 * 60 * 1000);
return;
});
return;
});
2 changes: 1 addition & 1 deletion packages/dappmanager/src/api/startHttpApi.ts
Original file line number Diff line number Diff line change
Expand Up @@ -195,7 +195,7 @@ export function startHttpApi({

// Serve UI. React-router, index.html at all routes
// prettier-ignore
app.get("*", (req, res) => res.sendFile(path.resolve(params.UI_FILES_PATH, "index.html")));
app.get("*", (_, res) => res.sendFile(path.resolve(params.UI_FILES_PATH, "index.html")));

server.listen(params.HTTP_API_PORT, () =>
logs.info(`HTTP API ${params.HTTP_API_PORT}`)
Expand Down
4 changes: 2 additions & 2 deletions packages/dappmanager/src/api/startTestApi.ts
Original file line number Diff line number Diff line change
Expand Up @@ -68,11 +68,11 @@ export function startTestApi(): http.Server {
}

// Health check
app.get("/ping", (req, res) => {
app.get("/ping", (_, res) => {
res.send("OK");
});

app.use((req, res) => {
app.use((_, res) => {
res.status(404).send("Not found");
});

Expand Down
2 changes: 1 addition & 1 deletion packages/dappmanager/src/api/vpnApiClient.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ export function getVpnApiClient(params: VpnApiClientParams): VpnApiClient {
// eslint-disable-next-line @typescript-eslint/no-explicit-any
return mapValues(
vpnApiRoutesData,
(data, route) =>
(_, route) =>
// eslint-disable-next-line @typescript-eslint/no-explicit-any
(...args: Args): any =>
vpnRpcCall(params, route, ...args)
Expand Down
Loading

0 comments on commit c292bf8

Please sign in to comment.