Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Error safety #71

Merged
merged 1 commit into from
Oct 24, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion apps/abcswap/src/pages/Home.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,15 @@ import { Button, Divider, HStack, Image, Stack, Text, VStack } from '@chakra-ui/
import { useState } from 'react';
import { useNavigate } from 'react-router-dom';
import { DaoNameInput, useIsRegisteredDaoWithApp } from 'dao-utils';
import { DAONotFoundError } from 'dao-utils/src/hooks/useDao';

export default function Home() {

const navigate = useNavigate();

const [daoName, setDaoName] = useState('');
const { isRegistered, isLoading, error } = useIsRegisteredDaoWithApp(daoName, 'augmented-bonding-curve.open.aragonpm.eth');
const daoExists = error?.message !== 'DAO not found';
const daoExists = !error || !(error instanceof DAONotFoundError);

return (
<VStack bg="brand.100" pb="100px0" textAlign="center">
Expand Down
10 changes: 9 additions & 1 deletion pkg/dao-utils/src/hooks/useDao.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,14 @@ import { useContractRead } from "wagmi";
import useInstalledApp from "./useInstalledApp";
import { ARAGON_ENS_CONTRACT, ZERO_ADDRESS } from "../constants";


export class DAONotFoundError extends Error {
constructor(message: string) {
super(message);
this.name = "DAONotFoundError";
}
}

export function useDaoAddress(name: string = "") {
let normalizedName: string = "";
let error: Error | null = null;
Expand Down Expand Up @@ -41,7 +49,7 @@ export function useDaoAddress(name: string = "") {
const isLoading = ensIsLoading || resolverIsLoading;

if (!isLoading && !error && (!address || address === ZERO_ADDRESS)) {
error = new Error("DAO not found");
error = new DAONotFoundError("DAO not found");
}

return { address, error, isLoading };
Expand Down