Skip to content

Commit

Permalink
fetchModules: use JsonRpcBatchProvider rather than going through Wall…
Browse files Browse the repository at this point in the history
…etConnect
  • Loading branch information
jfschwarz committed Aug 8, 2023
1 parent a867fb8 commit e845a34
Showing 1 changed file with 10 additions and 19 deletions.
29 changes: 10 additions & 19 deletions extension/src/settings/Connection/useZodiacModules.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Web3Provider } from '@ethersproject/providers'
import { JsonRpcBatchProvider, Web3Provider } from '@ethersproject/providers'
import {
ContractAbis,
ContractAddresses,
Expand All @@ -13,6 +13,7 @@ import { useEffect, useState } from 'react'

import { validateAddress } from '../../utils'
import { useConnection } from '../connectionHooks'
import { ChainId, RPC } from '../../networks'

const SUPPORTED_MODULES = [KnownContracts.DELAY, KnownContracts.ROLES]
export type SupportedModuleType = KnownContracts.DELAY | KnownContracts.ROLES
Expand All @@ -32,20 +33,22 @@ export const useZodiacModules = (
const [error, setError] = useState(false)
const [modules, setModules] = useState<Module[]>([])

const { provider, connected, chainId } = useConnection(connectionId)
const { chainId } = useConnection(connectionId)

useEffect(() => {
if (!connected) return
if (!chainId) return
const provider = new JsonRpcBatchProvider(RPC[chainId as ChainId], chainId)

setLoading(true)
setError(false)
fetchModules(safeAddress, new Web3Provider(provider, chainId || undefined))
fetchModules(safeAddress, provider)
.then((modules) => setModules(modules))
.catch((e) => {
console.error(`Could not fetch modules of Safe ${safeAddress}`, e)
setError(true)
})
.finally(() => setLoading(false))
}, [provider, safeAddress, connected, chainId])
}, [chainId, safeAddress])

if (!validateAddress(safeAddress) || error) {
return { isValidSafe: false, loading, modules: [] }
Expand All @@ -66,25 +69,13 @@ async function fetchModules(
provider
)

console.log(
'FEEETCH',
await contract.populateTransaction.getModulesPaginated(ADDRESS_ONE, 100)
)

const moduleAddresses = (
await contract.getModulesPaginated(ADDRESS_ONE, 100)
)[0] as string[]
console.log({ moduleAddresses })

const enabledAndSupportedModules = moduleAddresses.map(
async (moduleAddress) => {
let isEnabled = false
try {
isEnabled = await contract.isModuleEnabled(moduleAddress)
} catch (e) {
console.error(e)
}
// const isEnabled = await contract.isModuleEnabled(moduleAddress)
console.log({ moduleAddress, isEnabled })
const isEnabled = await contract.isModuleEnabled(moduleAddress)
if (!isEnabled) return

const mastercopyAddress = await detectProxyTarget(moduleAddress, provider)
Expand Down

0 comments on commit e845a34

Please sign in to comment.