Skip to content

Commit

Permalink
Refactor useSearchDao to utilize useResolveENSName for address resolu…
Browse files Browse the repository at this point in the history
…tion and update resolved address handling
  • Loading branch information
Da-Colon committed Dec 16, 2024
1 parent 6cdc66e commit 8fc85e2
Showing 1 changed file with 10 additions and 4 deletions.
14 changes: 10 additions & 4 deletions src/hooks/DAO/useSearchDao.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,16 @@ import SafeApiKit from '@safe-global/api-kit';
import { useState, useEffect, useCallback } from 'react';
import { useTranslation } from 'react-i18next';
import { Address } from 'viem';
import { useResolveAddressMultiChain } from '../utils/useResolveAddressMultiChain';
import { supportedNetworks } from '../../providers/NetworkConfig/useNetworkConfigStore';
import { useResolveENSName } from '../utils/useResolveENSName';

type ResolvedAddressWithPrefix = {
address: Address;
chainId: number;
};
export const useSearchDao = () => {
const { t } = useTranslation('dashboard');
const { resolveAddressMultiChain, isLoading: isAddressLoading } = useResolveAddressMultiChain();
const { resolveAddressMultiChain, isLoading: isAddressLoading } = useResolveENSName();
const [searchString, setSearchString] = useState<string>('');
const [errorMessage, setErrorMessage] = useState<string>();

Expand Down Expand Up @@ -41,9 +42,14 @@ export const useSearchDao = () => {

const resolveInput = useCallback(
async (input: string) => {
const { resolved, isValid } = await resolveAddressMultiChain(input);
const { resolvedAddress, isValid } = await resolveAddressMultiChain(input);
if (isValid) {
await findSafes(resolved);
await findSafes(
supportedNetworks.map(network => ({
address: resolvedAddress,
chainId: network.chain.id,
})),
);
} else {
setErrorMessage('Invalid search');
}
Expand Down

0 comments on commit 8fc85e2

Please sign in to comment.