diff --git a/packages/api/src/utils/autocompleteBlockHash.ts b/packages/api/src/utils/autocompleteBlockHash.ts index a9e5929d..f32db69d 100644 --- a/packages/api/src/utils/autocompleteBlockHash.ts +++ b/packages/api/src/utils/autocompleteBlockHash.ts @@ -6,6 +6,10 @@ import { logger } from "@blobscan/logger"; @returns The block hash, if there is a single ocurrence, or null. */ export async function autocompleteBlockHash(partialHash: string) { + if (!partialHash) { + return null + } + const blocks = await prisma.block.findMany({ where: { hash: { @@ -17,12 +21,12 @@ export async function autocompleteBlockHash(partialHash: string) { }, }); - if (blocks[0] === undefined) { + if (blocks.length === 0) { return null; } if (blocks.length > 1) { - logger.error(`Multiple blocks found for hash ${partialHash}`); + logger.error(`Found ${blocks.length} blocks while autocompleting block hash ${partialHash}`); } return blocks[0].hash;