Sure. Here it is:
export const useGetNftAssetsData = (collectionId: string) => {
const [data, setData] = useState(null)
const [isLoading, setIsLoading] = useState(true)
const [fetchError, setFetchError] = useState(false)
const { chainId } = useMoralis()
const { account } = useWeb3React()
const Web3Api = useMoralisWeb3Api();
useEffect(() => {
const fetchData = async () => {
try {
if (collectionId && chainId && account) {
const options = {
chain: chainId,
address: 'addressString',
token_address: collectionId,
// limit must be less than 500
limit: 499
}
setIsLoading(true)
// @ts-ignore
const response = await Web3Api.account.getNFTsForContract(options)
setData(response?.result)
setIsLoading(false)
}
} catch (error) {
console.error('Unable to fetch data:', error)
setFetchError(true)
setIsLoading(false)
}
}
fetchData()
}, [collectionId, chainId, account, setData, setIsLoading, Web3Api.account, Web3Api.token])
return { data, isLoading, fetchError }
}
I also have an issue with typescript showing the following:
TS2345: Argument of type '{ chain: string; address: string; token_address: string; limit: number; }' is not assignable to parameter of type '{ chain?: "eth" | "0x1" | "ropsten" | "0x3" | "rinkeby" | "0x4" | "goerli" | "0x5" | "kovan" | "0x2a" | "polygon" | "0x89" | "mumbai" | "0x13881" | "bsc" | "0x38" | "bsc testnet" | ... 6 more ... | "0xfa"; format?: "decimal" | "hex"; offset?: number; limit?: number; } & { ...; }'. Type '{ chain: string; address: string; token_address: string; limit: number; }' is not assignable to type '{ chain?: "eth" | "0x1" | "ropsten" | "0x3" | "rinkeby" | "0x4" | "goerli" | "0x5" | "kovan" | "0x2a" | "polygon" | "0x89" | "mumbai" | "0x13881" | "bsc" | "0x38" | "bsc testnet" | "0x61" | ... 5 more ... | "0xfa"; format?: "decimal" | "hex"; offset?: number; limit?: number; }'. Types of property 'chain' are incompatible. Type 'string' is not assignable to type '"eth" | "0x1" | "ropsten" | "0x3" | "rinkeby" | "0x4" | "goerli" | "0x5" | "kovan" | "0x2a" | "polygon" | "0x89" | "mumbai" | "0x13881" | "bsc" | "0x38" | "bsc testnet" | "0x61" | ... 5 more ... | "0xfa"'.
for options variable. Where it complaints about the chain not being compatible.
And also:
const Providers: React.FC = ({ children }) => {
return (
<Provider store={store}>
<Web3ReactProvider getLibrary={getLibrary}>
<ToastsProvider>
<HelmetProvider>
<MoralisProvider appId={MORALIS_APP_ID} serverUrl={MORALIS_SERVER_URL}>
<ThemeProviderWrapper>
<LanguageProvider>
<RefreshContextProvider>
<PancakeModalProvider>
<ModalProvider>{children}</ModalProvider>
...