import { AccountInfo , PublicKey } from '@solana/web3.js' ; import { useEffect , useState } from 'react' ; import { idlAddress as getIdlAddress } from './idlInstructions' ; import { contexts } from '@oyster/common' ; const { useConnection } = contexts . Connection ; export function useAnchorIdlAddress ( programId ) { const [ idlAddress , setIdlAddress ] = useState < PublicKey | undefined > ( ) ; useEffect ( ( ) => { ( async ( ) => { setIdlAddress ( await getIdlAddress ( programId ) ) ; } ) ( ) ; } , [ programId . toBase58 ( ) ] ) ; return idlAddress ; } export function useAnchorIdlAccount ( programId ) { const [ idlAccount , setIdlAccount ] = useState < AccountInfo < Buffer > | undefined > ( ) ; const connection = useConnection ( ) ; useEffect ( ( ) => { ( async ( ) => { const idlAddress = await getIdlAddress ( programId ) ; const accountInfo = await connection . getAccountInfo ( idlAddress ) ; if ( accountInfo ) { setIdlAccount ( accountInfo ) ; } } ) ( ) ; } , [ programId . toBase58 ( ) , connection ] ) ; return idlAccount ; }