From e9507fdc18712864b9ca5c9eb42624ba4baeb629 Mon Sep 17 00:00:00 2001 From: Pablo Castellano Date: Tue, 12 Nov 2024 11:48:28 +0700 Subject: [PATCH 1/2] fix: some improvements in autocompleteBlockHash function --- packages/api/src/utils/autocompleteBlockHash.ts | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) 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; From db7f411a72d88a726c1161b5b8b4d7b84e13d5be Mon Sep 17 00:00:00 2001 From: Pablo Castellano Date: Wed, 13 Nov 2024 10:54:15 +0700 Subject: [PATCH 2/2] fix: ts --- packages/api/src/utils/autocompleteBlockHash.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/api/src/utils/autocompleteBlockHash.ts b/packages/api/src/utils/autocompleteBlockHash.ts index f32db69d..39ae88c1 100644 --- a/packages/api/src/utils/autocompleteBlockHash.ts +++ b/packages/api/src/utils/autocompleteBlockHash.ts @@ -21,7 +21,7 @@ export async function autocompleteBlockHash(partialHash: string) { }, }); - if (blocks.length === 0) { + if (blocks[0] === undefined) { return null; }