import{useWeb3React as a}from"@web3-react/core";import{useMemo as h}from"react";import{isAddress as m}from"@ethersproject/address";import{AddressZero as l}from"@ethersproject/constants";import{Contract as g}from"@ethersproject/contracts";function p(t,r){return t.getSigner(r).connectUnchecked()}function C(t,r){return r?p(t,r):t}function u(t,r,e,n){if(!m(t)||t===l)throw Error(`Invalid 'address' parameter '${t}'.`);return new g(t,r,C(e,n))}function F(t,r,e=!0){let{provider:n,account:i,chainId:c}=a();return h(()=>{if(!t||!r||!n||!c)return null;let o;if(typeof t=="string"?o=t:o=t[c],!o)return null;try{return u(o,r,n,e&&i?i:void 0)}catch(f){return console.error("Failed to get contract",f),null}},[t,r,n,c,e,i])}export{F as useContract};
