-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1918 from decentdao/useDaoName-consolidation
Show loading message when My Safe names are loading
- Loading branch information
Showing
6 changed files
with
103 additions
and
125 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,81 @@ | ||
import { FractalRegistry } from '@fractal-framework/fractal-contracts'; | ||
import { useCallback, useEffect, useState } from 'react'; | ||
import { Address, PublicClient } from 'viem'; | ||
import { usePublicClient } from 'wagmi'; | ||
import { getEventRPC } from '../../helpers'; | ||
import { useFractal } from '../../providers/App/AppProvider'; | ||
import { FractalContracts } from '../../types'; | ||
import { createAccountSubstring } from '../utils/useDisplayName'; | ||
|
||
const getDAOName = async ({ | ||
address, | ||
registryName, | ||
publicClient, | ||
baseContracts, | ||
}: { | ||
address: Address; | ||
registryName?: string | null; | ||
publicClient: PublicClient | undefined; | ||
baseContracts: FractalContracts | undefined; | ||
}) => { | ||
if (!publicClient) { | ||
throw new Error('Public client not available'); | ||
} | ||
|
||
const ensName = await publicClient.getEnsName({ address: address }); | ||
if (ensName) { | ||
return ensName; | ||
} | ||
|
||
if (registryName) { | ||
return registryName; | ||
} | ||
|
||
if (!baseContracts) { | ||
throw new Error('Base contracts not set'); | ||
} | ||
|
||
const rpc = getEventRPC<FractalRegistry>(baseContracts.fractalRegistryContract); | ||
const events = await rpc.queryFilter(rpc.filters.FractalNameUpdated(address)); | ||
const latestEvent = events.pop(); | ||
|
||
if (!latestEvent) { | ||
return createAccountSubstring(address); | ||
} | ||
|
||
return latestEvent.args.daoName; | ||
}; | ||
|
||
const useGetDAOName = ({ | ||
address, | ||
registryName, | ||
}: { | ||
address: Address; | ||
registryName?: string | null; | ||
}) => { | ||
const publicClient = usePublicClient(); | ||
const { baseContracts } = useFractal(); | ||
|
||
const [daoName, setDaoName] = useState<string>(); | ||
useEffect(() => { | ||
getDAOName({ address, registryName, publicClient, baseContracts }).then(name => { | ||
setDaoName(name); | ||
}); | ||
}, [address, baseContracts, publicClient, registryName]); | ||
|
||
return { daoName }; | ||
}; | ||
|
||
const useGetDAONameDeferred = () => { | ||
const publicClient = usePublicClient(); | ||
const { baseContracts } = useFractal(); | ||
return { | ||
getDAOName: useCallback( | ||
({ address, registryName }: { address: Address; registryName?: string | null }) => | ||
getDAOName({ address, registryName, publicClient, baseContracts }), | ||
[baseContracts, publicClient], | ||
), | ||
}; | ||
}; | ||
|
||
export { useGetDAOName, useGetDAONameDeferred }; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters