import { Contract } from '@ethersproject/contracts' ; import { JsonRpcSigner , Web3Provider } from '@ethersproject/providers' ; import { useMemo } from 'react' ; import PREMIUM_MEMBERSHIP_CONTRACT_ABI from 'abis/premium-membership-contract.json' ; import GENERAL_MEMBERSHIP_CONTRACT_ABI from 'abis/general-membership-contract.json' ; import { network } from 'connectors/index' ; import { useActiveWeb3React } from './useWeb3' ; export const PREMIUM_MEMBERSHIP_CONTRACT_ADDRESS = '0xe01569ca9b39E55Bc7C0dFa09F05fa15CB4C7698' ; export const GENERAL_MEMBERSHIP_CONRTACT_ADDRESS = '0x989Cb023620Cec6798161EcA6C7eccFf68C0C9c3' ; function getSigner ( library , account ) { return library . getSigner ( account ) . connectUnchecked ( ) ; } function getProviderOrSigner ( library , account ? ) { return account ? getSigner ( library , account ) : library ; } function getContract ( address , ABI , library , account ? ) { return new Contract ( address , ABI , getProviderOrSigner ( library , account ) ) ; } function useContract ( address , abi ) { const { library , account , activate } = useActiveWeb3React ( ) ; if ( ! library ) { void activate ( network ) ; } return useMemo ( ( ) => { if ( ! address || ! library ) { return null ; } try { return getContract ( address , abi , library , account ? account : undefined ) ; } catch { console . error ( 'Error getting contract' ) ; return null ; } } , [ abi , account , address , library ] ) ; } export function usePremiumMembershipCardContract ( ) { return useContract ( PREMIUM_MEMBERSHIP_CONTRACT_ADDRESS , PREMIUM_MEMBERSHIP_CONTRACT_ABI ) ; } export function useGeneralMembershipCardContract ( ) { return useContract ( GENERAL_MEMBERSHIP_CONRTACT_ADDRESS , GENERAL_MEMBERSHIP_CONTRACT_ABI ) ; }