Skip to content

Commit

Permalink
Added logic to get chainData for chainId
Browse files Browse the repository at this point in the history
  • Loading branch information
farhanW3 committed Jul 7, 2023
1 parent 74773ce commit 0c23d61
Showing 1 changed file with 15 additions and 9 deletions.
24 changes: 15 additions & 9 deletions server/helpers/dbOperations.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
import { Knex } from "knex";
import { getChainBySlug } from "@thirdweb-dev/chains";
import { getChainByChainId, getChainBySlug } from "@thirdweb-dev/chains";
import { createCustomError } from "../../core/error/customError";
import { StatusCodes } from "http-status-codes";
import { v4 as uuid } from "uuid";
import { connectWithDatabase, getSDK } from "../../core";
import { FastifyRequest } from "fastify";
import {
ChainId,
DeployTransaction,
Transaction,
TransactionError,
Expand Down Expand Up @@ -54,15 +55,20 @@ export const queueTransaction = async (
throw new Error(`Transaction simulation failed with reason: ${message}`);
}

const chainData = getChainBySlug(network);
let chainData;

if (!chainData) {
const error = createCustomError(
`Chain with name/id ${network} not found`,
StatusCodes.NOT_FOUND,
"NOT_FOUND",
);
throw error;
if (isNaN(Number(network))) {
chainData = getChainBySlug(network);
if (!chainData) {
const error = createCustomError(
`Chain with name/id ${network} not found`,
StatusCodes.NOT_FOUND,
"NOT_FOUND",
);
throw error;
}
} else {
chainData = getChainByChainId(parseInt(network, 10));
}

const chainId = chainData.chainId.toString();
Expand Down

0 comments on commit 0c23d61

Please sign in to comment.