From f701b2d0e6b2b85fbc3f36899ffb5c75dfbe779a Mon Sep 17 00:00:00 2001 From: jnsdls Date: Wed, 11 Dec 2024 22:13:09 +0000 Subject: [PATCH] handle empty address in fetchPublishedContracts (#5702) partially fixes: DASH-572 --- .../fetchPublishedContracts.ts | 48 ++++++++++++------- 1 file changed, 30 insertions(+), 18 deletions(-) diff --git a/apps/dashboard/src/components/contract-components/fetchPublishedContracts.ts b/apps/dashboard/src/components/contract-components/fetchPublishedContracts.ts index 4d540d8d03a..a8c199c3db7 100644 --- a/apps/dashboard/src/components/contract-components/fetchPublishedContracts.ts +++ b/apps/dashboard/src/components/contract-components/fetchPublishedContracts.ts @@ -4,25 +4,37 @@ import { getAllPublishedContracts, getContractPublisher, } from "thirdweb/extensions/thirdweb"; -import invariant from "tiny-invariant"; import { fetchDeployMetadata } from "./fetchDeployMetadata"; +// TODO: clean this up, jesus export async function fetchPublishedContracts(address?: string | null) { - invariant(address, "address is not defined"); - const resolvedAddress = (await resolveEns(address)).address; - invariant(resolvedAddress, "invalid ENS"); - const tempResult = ( - (await getAllPublishedContracts({ - contract: getContractPublisher(getThirdwebClient()), - publisher: resolvedAddress, - })) || [] - ) - .filter((c) => c.contractId) - .sort((a, b) => a.contractId.localeCompare(b.contractId)); - return await Promise.all( - tempResult.map(async (c) => ({ - ...c, - metadata: await fetchDeployMetadata(c.publishMetadataUri), - })), - ); + try { + if (!address) { + return []; + } + const resolvedAddress = (await resolveEns(address)).address; + + if (!resolvedAddress) { + return []; + } + + const tempResult = ( + (await getAllPublishedContracts({ + contract: getContractPublisher(getThirdwebClient()), + publisher: resolvedAddress, + })) || [] + ) + .filter((c) => c.contractId) + .sort((a, b) => a.contractId.localeCompare(b.contractId)); + + return await Promise.all( + tempResult.map(async (c) => ({ + ...c, + metadata: await fetchDeployMetadata(c.publishMetadataUri), + })), + ); + } catch (e) { + console.error("Error fetching published contracts", e); + return []; + } }