Skip to content

Commit

Permalink
fix issue caused by circular module chains
Browse files Browse the repository at this point in the history
  • Loading branch information
jfschwarz committed Jul 26, 2024
1 parent 8de7fe3 commit 8d452b6
Showing 1 changed file with 9 additions and 4 deletions.
13 changes: 9 additions & 4 deletions extension/src/integrations/zodiac/useZodiacModules.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,6 @@ export const useZodiacModules = (
const [modules, setModules] = useState<Module[]>([])

const { chainId } = useRoute(connectionId)

useEffect(() => {
setLoading(true)
setError(false)
Expand All @@ -57,8 +56,15 @@ export const useZodiacModules = (

async function fetchModules(
safeOrModifierAddress: string,
chainId: ChainId
chainId: ChainId,
previous: Set<string> = new Set()
): Promise<Module[]> {
if (previous.has(safeOrModifierAddress.toLowerCase())) {
// circuit breaker in case of circular module references
return []
}
previous.add(safeOrModifierAddress.toLowerCase())

const provider = getReadOnlyProvider(chainId)

const mastercopyAddresses = ContractAddresses[chainId] || {}
Expand All @@ -67,7 +73,6 @@ async function fetchModules(
AvatarInterface,
provider
)

const moduleAddresses = (
await contract.getModulesPaginated(ADDRESS_ONE, 100)
)[0] as string[]
Expand Down Expand Up @@ -115,7 +120,7 @@ async function fetchModules(
if (MODIFIERS.includes(type)) {
// recursively fetch modules from modifier
try {
modules = await fetchModules(moduleAddress, chainId)
modules = await fetchModules(moduleAddress, chainId, previous)
} catch (e) {
console.error(
`Could not fetch sub modules of ${type} modifier ${moduleAddress}`,
Expand Down

0 comments on commit 8d452b6

Please sign in to comment.