Skip to content

Commit f701b2d

Browse files
committed
handle empty address in fetchPublishedContracts (#5702)
partially fixes: DASH-572
1 parent 3d6eb96 commit f701b2d

File tree

1 file changed

+30
-18
lines changed

1 file changed

+30
-18
lines changed

apps/dashboard/src/components/contract-components/fetchPublishedContracts.ts

Lines changed: 30 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -4,25 +4,37 @@ import {
44
getAllPublishedContracts,
55
getContractPublisher,
66
} from "thirdweb/extensions/thirdweb";
7-
import invariant from "tiny-invariant";
87
import { fetchDeployMetadata } from "./fetchDeployMetadata";
98

9+
// TODO: clean this up, jesus
1010
export async function fetchPublishedContracts(address?: string | null) {
11-
invariant(address, "address is not defined");
12-
const resolvedAddress = (await resolveEns(address)).address;
13-
invariant(resolvedAddress, "invalid ENS");
14-
const tempResult = (
15-
(await getAllPublishedContracts({
16-
contract: getContractPublisher(getThirdwebClient()),
17-
publisher: resolvedAddress,
18-
})) || []
19-
)
20-
.filter((c) => c.contractId)
21-
.sort((a, b) => a.contractId.localeCompare(b.contractId));
22-
return await Promise.all(
23-
tempResult.map(async (c) => ({
24-
...c,
25-
metadata: await fetchDeployMetadata(c.publishMetadataUri),
26-
})),
27-
);
11+
try {
12+
if (!address) {
13+
return [];
14+
}
15+
const resolvedAddress = (await resolveEns(address)).address;
16+
17+
if (!resolvedAddress) {
18+
return [];
19+
}
20+
21+
const tempResult = (
22+
(await getAllPublishedContracts({
23+
contract: getContractPublisher(getThirdwebClient()),
24+
publisher: resolvedAddress,
25+
})) || []
26+
)
27+
.filter((c) => c.contractId)
28+
.sort((a, b) => a.contractId.localeCompare(b.contractId));
29+
30+
return await Promise.all(
31+
tempResult.map(async (c) => ({
32+
...c,
33+
metadata: await fetchDeployMetadata(c.publishMetadataUri),
34+
})),
35+
);
36+
} catch (e) {
37+
console.error("Error fetching published contracts", e);
38+
return [];
39+
}
2840
}

0 commit comments

Comments
 (0)