Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implement knip and remove unused code #1897

Draft
wants to merge 4 commits into
base: develop
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
]
},
"scripts": {
"knip": "knip",
"build": "lerna run build --include-dependencies --stream",
"test": "lerna run test --stream",
"lint": "lerna run lint --stream",
Expand All @@ -36,6 +37,7 @@
"depcheck": "^1.4.7",
"eslint": "^8.44.0",
"eslint-config-react-app": "^7.0.1",
"knip": "^5.2.2",
"lerna": "^6.3.0",
"mocha": "^10.2.0",
"nodemon": "^3.0.2",
Expand Down
5 changes: 0 additions & 5 deletions packages/admin-ui/src/api/interface.ts
Original file line number Diff line number Diff line change
Expand Up @@ -48,8 +48,3 @@ export interface IApiRpc {
): void;
call<R>(payload: RpcPayload): Promise<RpcResponse<R>>;
}

export interface IApi {
auth: IApiAuth;
rpc: IApiRpc;
}
6 changes: 3 additions & 3 deletions packages/admin-ui/src/api/rpc.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import io, { Socket } from "socket.io-client";
import { Emitter } from "mitt";
import { Args, RpcPayload, RpcResponse } from "@dappnode/types";
import { IApiRpc } from "./interface";
import { socketIoUrl } from "params";
import { apiUrl } from "params";
import { subscriptionsData } from "@dappnode/types";

let socketGlobal: Socket | null = null;
Expand Down Expand Up @@ -54,8 +54,8 @@ export const apiRpc: IApiRpc = {
function setupSocket(): Socket {
if (!socketGlobal) {
/* eslint-disable-next-line no-console */
console.log("Connecting API with Socket.io to", socketIoUrl);
socketGlobal = io(socketIoUrl);
console.log("Connecting API with Socket.io to", apiUrl);
socketGlobal = io(apiUrl);
}
return socketGlobal;
}
2 changes: 1 addition & 1 deletion packages/admin-ui/src/components/Button.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import ButtonBootstap, {
import { joinCssClass } from "utils/css";
import "./button.scss";

export type ButtonType = "button" | "submit" | "reset" | undefined;
type ButtonType = "button" | "submit" | "reset" | undefined;
export type ButtonVariant =
| "secondary"
| "dappnode"
Expand Down
1 change: 0 additions & 1 deletion packages/admin-ui/src/params.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@ export const apiUrls = {
containerLogs: urlJoin(apiUrl, "container-logs"),
userActionLogs: urlJoin(apiUrl, "user-action-logs")
};
export const socketIoUrl = apiUrl;

// Allow cross-domain cookies
export const apiTestMode = process.env.REACT_APP_API_TEST;
Expand Down
5 changes: 0 additions & 5 deletions packages/admin-ui/src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,11 +39,6 @@ export interface ProgressLogsByDnp {
[dnpName: string]: ProgressLogs;
}

export interface DappnodeParams {
DNCORE_DIR: string;
REPO_DIR: string;
}

export type Theme = "light" | "dark";

export type UiModuleStatus = "enabled" | "disabled";
Expand Down
8 changes: 1 addition & 7 deletions packages/chains/src/types.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,3 @@
import { ChainDriver, ChainData } from "@dappnode/types";

export interface Chain {
dnpName: string; // geth.dnp.dappnode.eth
api: string; // http://geth.dappnode:8545
driverName: ChainDriver; // ethereum
}
import { ChainData } from "@dappnode/types";

export type ChainDataResult = Omit<ChainData, "dnpName">;
4 changes: 1 addition & 3 deletions packages/daemons/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -43,8 +43,6 @@
"@types/node": "^20.6.2",
"@types/node-telegram-bot-api": "^0.64.2",
"@types/semver": "^7.3.13",
"@types/systeminformation": "^3.54.1",
"rewiremock": "^3.13.7",
"sinon": "^5.0.10"
"@types/systeminformation": "^3.54.1"
}
}
7 changes: 1 addition & 6 deletions packages/dappmanager/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,6 @@
"@types/multicodec": "^1.0.0",
"@types/node": "^18.15.11",
"@types/semver": "^7.3.13",
"@types/sinon": "^7.0.13",
"@types/socket.io": "^3.0.2",
"ajv": "^6.10.2",
"async-retry": "^1.3.1",
Expand Down Expand Up @@ -85,10 +84,6 @@
"devDependencies": {
"@types/node": "^18.15.11",
"dotenv": "^8.2.0",
"kubo-rpc-client": "^3.0.2",
"prettier": "^2.3.2",
"rewiremock": "^3.13.7",
"sinon": "^5.0.10",
"socket.io-client": "^4.5.1"
"prettier": "^2.3.2"
}
}
2 changes: 1 addition & 1 deletion packages/dappmanager/src/api/auth/adminPasswordDb.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ interface AdminStatusById {
[id: string]: { isAdmin: boolean };
}

export interface AdminPasswordDbParams {
interface AdminPasswordDbParams {
ADMIN_PASSWORDS_JSON_FILE: string;
ADMIN_STATUS_JSON_FILE: string;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,13 @@ import express from "express";
import { params } from "@dappnode/params";
import { urlJoin } from "@dappnode/utils";
import { logs } from "@dappnode/logger";
import * as views from "./views/index.js";
import {
noEth,
noIpfs,
noSwarm,
notFound,
unknownError
} from "./views/index.js";
import {
NodeNotAvailable,
ProxyError,
Expand Down Expand Up @@ -115,18 +121,18 @@ function errorToResponseHtml(e: Error, domain?: string): string {

// Not found views
if (e instanceof EnsResolverError || e instanceof NotFoundError)
return views.notFound(e);
return notFound(e);

// Node not available views
if (e instanceof EthProviderError) return views.noEth(e);
if (e instanceof EthProviderError) return noEth(e);
if (e instanceof NodeNotAvailable)
if (e.location === "swarm") return views.noSwarm(e);
else if (e.location === "ipfs") return views.noIpfs(e);
if (e.location === "swarm") return noSwarm(e);
else if (e.location === "ipfs") return noIpfs(e);

// Proxy errors
if (e instanceof ProxyError) return views.unknownError(e);
if (e instanceof ProxyError) return unknownError(e);

// Unknown errors, log to error
logs.error(`ETHFORWARD Unknown error resolving ${domain}`, e);
return views.unknownError(e);
return unknownError(e);
}
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,9 @@ export function ResolveDomainWithCache(): (domain: string) => Promise<Content> {
return async function (domain: string): Promise<Content> {
const network = parseNetworkFromDomain(domain);
const providerUrl = await _getEthersProviderByNetwork(network);
const provider = new ethers.JsonRpcProvider(providerUrl, "mainnet", { staticNetwork: true });
const provider = new ethers.JsonRpcProvider(providerUrl, "mainnet", {
staticNetwork: true
});
return _resolveDomain(domain, provider);
};
}
Expand All @@ -75,7 +77,7 @@ export function ResolveDomainWithCache(): (domain: string) => Promise<Content> {
* @param domain
* @returns content object
*/
export async function resolveDomain(
async function resolveDomain(
domain: string,
provider: ethers.Provider
): Promise<Content> {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/**
* Content locations supported by the ETH FORWARD
*/
export type Location = "ipfs" | "swarm";
type Location = "ipfs" | "swarm";

/**
* Network names supported by the ETH FORWARD
Expand All @@ -24,13 +24,13 @@ export type Content =
/**
* Custom errors
*/
export type EthForwardErrorCode =
type EthForwardErrorCode =
| "NOTFOUND"
| "RESOLVERNOTFOUND"
| "PROXYERROR"
| "NODENOTAVAILABLE";

export class EthForwardError extends Error {
class EthForwardError extends Error {
code: EthForwardErrorCode;
constructor(message: string, code: EthForwardErrorCode) {
super(message);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ import { params } from "@dappnode/params";
const adminUiUrl = `http://my.dappnode/`;
const adminUiInstallUrl = `${adminUiUrl}/installer`;
const adminUiPackagesUrl = `${adminUiUrl}/packages`;
const ropstenName = "ropsten.dnp.dappnode.eth";
const swarmName = "swarm.dnp.dappnode.eth";

const a = (url: string, text?: string): string =>
Expand All @@ -30,15 +29,6 @@ export function noEth(e: Error): string {
);
}

export function noRopsten(): string {
return base(
"Ropsten not installed",
`Please install the Ropsten DNP (DAppNode package) to resolve .test domains
<br />
${a(`${adminUiInstallUrl}/${ropstenName}`, "Install Ropsten")}`
);
}

export function noSwarm(e: Error): string {
return base(
"Swarm not installed",
Expand All @@ -58,15 +48,6 @@ export function noIpfs(e: Error): string {
);
}

export function ethSyncing(): string {
return base(
"Page Not Available",
`Please wait until the chain is synced to browse decentralized webs
<br />
Go to the ${a(adminUiUrl, "Admin UI")} to check the sync status`
);
}

export function unknownError(e: Error): string {
return base("Page Not Available", `Unknown error`, e);
}
26 changes: 13 additions & 13 deletions packages/dappmanager/src/api/routes/index.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
export * from "./containerLogs.js";
export * from "./dataSend.js";
export * from "./download.js";
export * from "./downloadUserActionLogs.js";
export * from "./fileDownload.js";
export * from "./globalEnvs.js";
export * from "./packageManifest.js";
export * from "./publicPackagesData.js";
export * from "./sign.js";
export * from "./upload.js";
export * from "./downloadWireguardConfig.js";
export * from "./notificationSend.js";
export * from "./metrics.js";
export { containerLogs } from "./containerLogs.js";
export { dataSend } from "./dataSend.js";
export { download } from "./download.js";
export { downloadUserActionLogs } from "./downloadUserActionLogs.js";
export { fileDownload } from "./fileDownload.js";
export { globalEnvs } from "./globalEnvs.js";
export { packageManifest } from "./packageManifest.js";
export { publicPackagesData } from "./publicPackagesData.js";
export { sign } from "./sign.js";
export { upload } from "./upload.js";
export { downloadWireguardConfig } from "./downloadWireguardConfig.js";
export { notificationSend } from "./notificationSend.js";
export { metrics } from "./metrics.js";
4 changes: 2 additions & 2 deletions packages/dappmanager/src/api/startHttpApi.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ import {
} from "@dappnode/types";
import { getRpcHandler } from "./handler/index.js";

export interface HttpApiParams
interface HttpApiParams
extends ClientSideCookiesParams,
AuthPasswordSessionParams {
AUTH_IP_ALLOW_LOCAL_IP: boolean;
Expand All @@ -38,7 +38,7 @@ export interface HttpApiParams
HTTP_CORS_WHITELIST: string[];
}

export interface HttpRoutes {
interface HttpRoutes {
containerLogs: RequestHandler<{ containerName: string }>;
dataSend: RequestHandler;
download: RequestHandler<{ fileId: string }>;
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 @@ -23,7 +23,7 @@ const vpnApiRoutesData: { [P in keyof VpnApiClient]: true } = {
getVersionData: true
};

export interface VpnApiClientParams {
interface VpnApiClientParams {
VPN_API_RPC_URL: string;
}

Expand Down
1 change: 0 additions & 1 deletion packages/dappmanager/src/utils/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,4 +10,3 @@ export {
getAddressFromPrivateKey
} from "./sign.js";
export { validateBackupArray } from "./validateBackupArray.js";
export { verifyXz } from "./verifyXz.js";
26 changes: 0 additions & 26 deletions packages/dappmanager/src/utils/verifyXz.ts

This file was deleted.

Loading
Loading