Skip to content

Commit

Permalink
fix all biome errors
Browse files Browse the repository at this point in the history
  • Loading branch information
dirtycajunrice committed Dec 12, 2024
1 parent f76cbc0 commit f248a67
Show file tree
Hide file tree
Showing 34 changed files with 185 additions and 123 deletions.
5 changes: 4 additions & 1 deletion .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,10 @@ jobs:
with:
node-version: "18"
cache: "yarn"


- name: Enable Corepack
run: corepack enable

- name: Install dependencies
run: yarn install

Expand Down
5 changes: 4 additions & 1 deletion .github/workflows/lint.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,10 @@ jobs:
with:
node-version: "18"
cache: "yarn"


- name: Enable Corepack
run: corepack enable

- name: Install dependencies
run: yarn install

Expand Down
3 changes: 3 additions & 0 deletions .github/workflows/npm-publish.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,9 @@ jobs:
node-version: "18"
cache: "yarn"

- name: Enable Corepack
run: corepack enable

- name: Install dependencies
run: yarn install

Expand Down
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,7 @@
"superjson": "^2.2.1",
"thirdweb": "^5.71.0",
"uuid": "^9.0.1",
"viem": "^2.21.54",
"winston": "^3.14.1",
"zod": "^3.23.8"
},
Expand Down
3 changes: 2 additions & 1 deletion src/polyfill.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import * as crypto from "node:crypto";

if (typeof globalThis.crypto === "undefined") {
(globalThis as any).crypto = crypto;
// @ts-expect-error
globalThis.crypto = crypto;
}
2 changes: 1 addition & 1 deletion src/server/listeners/update-tx-listener.ts
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ export const updateTxListener = async (): Promise<void> => {
});
});

connection.on("error", async (err: any) => {
connection.on("error", async (err: unknown) => {
logger({
service: "server",
level: "error",
Expand Down
2 changes: 1 addition & 1 deletion src/server/middleware/auth.ts
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,7 @@ export async function withAuth(server: FastifyInstance) {
}if (error) {
message = error;
}
} catch (err: any) {
} catch (err: unknown) {
logger({
service: "server",
level: "warn",
Expand Down
12 changes: 6 additions & 6 deletions src/server/middleware/error.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ export const badChainError = (chain: string | number): CustomError =>
"INVALID_CHAIN",
);

const flipObject = (data: any) =>
const flipObject = (data: object) =>
Object.fromEntries(Object.entries(data).map(([key, value]) => [value, key]));

const isZodError = (err: unknown): boolean => {
Expand Down Expand Up @@ -72,15 +72,15 @@ export function withErrorHandler(server: FastifyInstance) {
message: "code" in error ? error.code : error.message,
reason: error.message,
statusCode: 400,
stack: env.NODE_ENV !== "production" ? error.stack : undefined,
stack: env.NODE_ENV === "production" ? undefined : error.stack,
},
});
}

// Zod Typings Errors
if (isZodError(error)) {
const _error = error as ZodError;
let parsedMessage: any[] = [];
let parsedMessage: unknown;

try {
parsedMessage = JSON.parse(_error.message);
Expand All @@ -98,7 +98,7 @@ export function withErrorHandler(server: FastifyInstance) {
message: errorObject.message ?? "Invalid Request",
reason: errorObject ?? undefined,
statusCode: 400,
stack: env.NODE_ENV !== "production" ? _error.stack : undefined,
stack: env.NODE_ENV === "production" ? undefined : _error.stack,
},
});
}
Expand All @@ -118,7 +118,7 @@ export function withErrorHandler(server: FastifyInstance) {
code,
message,
statusCode,
stack: env.NODE_ENV !== "production" ? error.stack : undefined,
stack: env.NODE_ENV === "production" ? undefined : error.stack,
},
});
}
Expand All @@ -128,7 +128,7 @@ export function withErrorHandler(server: FastifyInstance) {
statusCode: 500,
code: "INTERNAL_SERVER_ERROR",
message: error.message || ReasonPhrases.INTERNAL_SERVER_ERROR,
stack: env.NODE_ENV !== "production" ? error.stack : undefined,
stack: env.NODE_ENV === "production" ? undefined : error.stack,
},
});
},
Expand Down
5 changes: 3 additions & 2 deletions src/server/routes/backend-wallet/sign-transaction.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import { Type, type Static } from "@sinclair/typebox";
import type { FastifyInstance } from "fastify";
import { StatusCodes } from "http-status-codes";
import type { Hex } from "thirdweb";
import type { TransactionSerializable } from "viem";
import { getAccount } from "../../../shared/utils/account";
import {
getChecksumAddress,
Expand Down Expand Up @@ -71,7 +72,7 @@ export async function signTransaction(fastify: FastifyInstance) {
}

// @TODO: Assert type to viem TransactionSerializable.
const serializableTransaction: any = {
const serializableTransaction = {
chainId: transaction.chainId,
to: getChecksumAddress(transaction.to),
nonce: maybeInt(transaction.nonce),
Expand All @@ -86,7 +87,7 @@ export async function signTransaction(fastify: FastifyInstance) {
maxFeePerGas: maybeBigInt(transaction.maxFeePerGas),
maxPriorityFeePerGas: maybeBigInt(transaction.maxPriorityFeePerGas),
ccipReadEnabled: transaction.ccipReadEnabled,
};
} as TransactionSerializable;
const signature = await account.signTransaction(serializableTransaction);

reply.status(StatusCodes.OK).send({
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ export async function erc20AllowanceOf(fastify: FastifyInstance) {
chainId,
contractAddress,
});
const returnData: any = await contract.erc20.allowanceOf(
const returnData = await contract.erc20.allowanceOf(
ownerWallet ? ownerWallet : "",
spenderWallet ? spenderWallet : "",
);
Expand Down
4 changes: 2 additions & 2 deletions src/server/routes/contract/extensions/erc20/read/get.ts
Original file line number Diff line number Diff line change
Expand Up @@ -54,12 +54,12 @@ export async function erc20GetMetadata(fastify: FastifyInstance) {
chainId,
contractAddress,
});
const returnData: any = await contract.erc20.get();
const returnData = await contract.erc20.get();
reply.status(StatusCodes.OK).send({
result: {
symbol: returnData.symbol,
name: returnData.name,
decimals: returnData.decimals,
decimals: returnData.decimals.toString(),
},
});
},
Expand Down
30 changes: 17 additions & 13 deletions src/server/routes/transaction/blockchain/send-signed-user-op.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { Type, type Static } from "@sinclair/typebox";
import { Value } from "@sinclair/typebox/value";
import { TransformDecodeError } from "@sinclair/typebox/value/transform";
import type { FastifyInstance } from "fastify";
import { StatusCodes } from "http-status-codes";
import { env } from "../../../../shared/utils/env";
Expand Down Expand Up @@ -47,15 +48,15 @@ const responseBodySchema = Type.Union([

type RpcResponse =
| {
result: string;
error: undefined;
}
result: string;
error: undefined;
}
| {
result: undefined;
error: {
message: string;
};
};
result: undefined;
error: {
message: string;
};
};

export async function sendSignedUserOp(fastify: FastifyInstance) {
fastify.route<{
Expand All @@ -68,7 +69,7 @@ export async function sendSignedUserOp(fastify: FastifyInstance) {
schema: {
summary: "Send a signed user operation",
description: "Send a signed user operation",
tags: ["Transaction"],
tags: [ "Transaction" ],
operationId: "sendSignedUserOp",
params: walletChainParamSchema,
body: requestBodySchema,
Expand All @@ -86,10 +87,11 @@ export async function sendSignedUserOp(fastify: FastifyInstance) {
if (typeof signedUserOp === "string") {
try {
userOp = Value.Decode(UserOpString, signedUserOp);
} catch (err: any) {
} catch (err: unknown) {
const msg = err instanceof TransformDecodeError ? err.message : err;
return res.status(400).send({
error: {
message: `Invalid signed user operation. - ${err.message || err}`,
message: `Invalid signed user operation. - ${msg}`,
},
});
}
Expand All @@ -109,12 +111,14 @@ export async function sendSignedUserOp(fastify: FastifyInstance) {
id: 1,
jsonrpc: "2.0",
method: "eth_sendUserOperation",
params: [userOp, entryPointAddress],
params: [ userOp, entryPointAddress ],
}),
});

const { result: userOpHash, error } =
(await userOpRes.json()) as RpcResponse;
(
await userOpRes.json()
) as RpcResponse;

if (error) {
return res.status(400).send({
Expand Down
15 changes: 7 additions & 8 deletions src/server/utils/convertor.ts
Original file line number Diff line number Diff line change
@@ -1,14 +1,13 @@
import { BigNumber } from "ethers";

export const bigNumberReplacer = (value: any): any => {
const isHexBigNumber = (value: unknown) => {
const isNonNullObject = typeof value === "object" && value !== null;
const hasType = isNonNullObject && "type" in value;
return hasType && value.type === "BigNumber" && "hex" in value
}
export const bigNumberReplacer = (value: unknown): unknown => {
// if we find a BigNumber then make it into a string (since that is safe)
if (
BigNumber.isBigNumber(value) ||
(typeof value === "object" &&
value !== null &&
value.type === "BigNumber" &&
"hex" in value)
) {
if (BigNumber.isBigNumber(value) || isHexBigNumber(value)) {
return BigNumber.from(value).toString();
}

Expand Down
2 changes: 1 addition & 1 deletion src/shared/db/transactions/queue-tx.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import { parseTransactionOverrides } from "../../../server/utils/transaction-ove

interface QueueTxParams {
// we should move away from Transaction type (v4 SDK)
tx: Transaction<any> | DeployTransaction;
tx: Transaction<unknown> | DeployTransaction;
chainId: number;
extension: ContractExtension;
// TODO: These shouldn't be in here
Expand Down
15 changes: 6 additions & 9 deletions src/shared/utils/ethers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ export interface EthersError extends Error {
*
* This is generally helpful mostly for human-based debugging.
*/
info?: Record<string, any>;
info?: Record<string, unknown>;

/**
* Any related error.
Expand All @@ -35,17 +35,14 @@ export const ETHERS_ERROR_CODES = new Set(Object.values(ethers.errors));
* @param error
* @returns EthersError | null
*/
export const parseEthersError = (error: any): EthersError | null => {
if (
error &&
typeof error === "object" &&
"code" in error &&
ETHERS_ERROR_CODES.has(error.code)
) {
export const parseEthersError = (error: unknown): EthersError | null => {
const isNonNullObject = error && typeof error === "object";
const hasCodeProperty = isNonNullObject && "code" in error;
if (hasCodeProperty && ETHERS_ERROR_CODES.has(error.code as ethers.errors)) {
return error as EthersError;
}
return null;
};

export const isEthersErrorCode = (error: any, code: ethers.errors) =>
export const isEthersErrorCode = (error: unknown, code: ethers.errors) =>
parseEthersError(error)?.code === code;
4 changes: 2 additions & 2 deletions src/shared/utils/logger.ts
Original file line number Diff line number Diff line change
Expand Up @@ -82,8 +82,8 @@ interface LoggerParams {
level: (typeof env)["LOG_LEVEL"];
message: string;
queueId?: string | null;
error?: any;
data?: any;
error?: unknown;
data?: unknown;
}

export const logger = ({
Expand Down
6 changes: 5 additions & 1 deletion src/shared/utils/transaction/simulate-queued-transaction.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { TransactionError } from "@thirdweb-dev/sdk";
import {
prepareTransaction,
simulateTransaction,
Expand Down Expand Up @@ -70,7 +71,10 @@ export const doSimulateTransaction = async (
account,
});
return null;
} catch (e: any) {
} catch (e: unknown) {
if (!(e instanceof TransactionError)) {
throw e;
}
// Error should be of type TransactionError in the thirdweb SDK.
return `${e.name}: ${e.message}`;
}
Expand Down
2 changes: 1 addition & 1 deletion src/shared/utils/transaction/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ export type InsertedTransaction = {

data?: Hex;
functionName?: string;
functionArgs?: any[];
functionArgs?: unknown[];

// User-provided overrides.
overrides?: {
Expand Down
4 changes: 2 additions & 2 deletions src/worker/listeners/config-listener.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ export const newConfigurationListener = async (): Promise<void> => {
});
});

connection.on("error", async (err: any) => {
connection.on("error", async (err: unknown) => {
logger({
service: "worker",
level: "error",
Expand Down Expand Up @@ -93,7 +93,7 @@ export const updatedConfigurationListener = async (): Promise<void> => {
});
});

connection.on("error", async (err: any) => {
connection.on("error", async (err: unknown) => {
logger({
service: "worker",
level: "error",
Expand Down
4 changes: 2 additions & 2 deletions src/worker/listeners/webhook-listener.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ export const newWebhooksListener = async (): Promise<void> => {
});
});

connection.on("error", async (err: any) => {
connection.on("error", async (err: unknown) => {
logger({
service: "worker",
level: "error",
Expand Down Expand Up @@ -94,7 +94,7 @@ export const updatedWebhooksListener = async (): Promise<void> => {
});
});

connection.on("error", async (err: any) => {
connection.on("error", async (err: unknown) => {
logger({
service: "worker",
level: "error",
Expand Down
2 changes: 1 addition & 1 deletion src/worker/queues/send-webhook-queue.ts
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ export class SendWebhookQueue {
logger({
service: "worker",
level: "warn",
message: `Unexpected webhook type: ${(data as any).type}`,
message: `Unexpected webhook type: ${(data as { type: unknown }).type}`,
});
}
};
Expand Down
2 changes: 1 addition & 1 deletion src/worker/tasks/cancel-recycled-nonces-worker.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ export const initCancelRecycledNoncesWorker = () => {
/**
* Sends a cancel transaction for all recycled nonces.
*/
const handler: Processor<any, void, string> = async (job: Job<string>) => {
const handler: Processor<string, void, string> = async (job: Job<string>) => {
const keys = await redis.keys("nonce-recycled:*");

for (const key of keys) {
Expand Down
Loading

0 comments on commit f248a67

Please sign in to comment.