import { useEffect , useState } from 'react' ; import ContractBasedAccount from '@tasit/contract-based-account' ; const { Deploy } = ContractBasedAccount ; const { create } = Deploy ; type GnosisSafeCreationData = { address : string ; hasError : boolean ; } ; const BASE_URL = 'https://safe-relay.staging.gnosisdev.com/api' ; export function useGnosisSafe ( owners , threshold , randomBytes , baseURL = BASE_URL ) { console . log ( 'useGnosisSafe called' ) ; const [ gnosisSafeAddress , setGnosisSafeAddress ] = useState ( '' ) ; const [ hasError , setHasError ] = useState ( false ) ; const gnosisSafeUndefined = gnosisSafeAddress === '' ; const randomBytesUsable = randomBytes . length !== 0 ; useEffect ( ( ) => { console . log ( 'useEffect called' ) ; async function createAsync ( owners , threshold , randomBytes , baseURL ) { try { const address = await create ( owners , threshold , randomBytes , baseURL ) ; setGnosisSafeAddress ( address ) ; } catch ( error ) { setHasError ( true ) ; } } if ( gnosisSafeUndefined && randomBytesUsable ) { console . log ( { owners , threshold , randomBytes , baseURL , gnosisSafeAddress , gnosisSafeUndefined , randomBytesUsable , } ) ; createAsync ( owners , threshold , randomBytes , baseURL ) ; } } , [ owners , threshold , randomBytes , baseURL , gnosisSafeAddress , gnosisSafeUndefined , randomBytesUsable , ] ) ; return { address : gnosisSafeAddress , hasError , } ; }