diff --git a/packages/storykit/src/providers/IpProvider/IpProvider.tsx b/packages/storykit/src/providers/IpProvider/IpProvider.tsx index 984a05a..fb629cc 100644 --- a/packages/storykit/src/providers/IpProvider/IpProvider.tsx +++ b/packages/storykit/src/providers/IpProvider/IpProvider.tsx @@ -9,9 +9,14 @@ import { RESOURCE_TYPE } from "../../types/api" import { Asset, IPAPolicy, License, Policy, RoyaltyPolicy } from "../../types/assets" import { NFTMetadata } from "../../types/simplehash" +export interface IpProviderOptions { + assetData?: boolean + policyData?: boolean + licenseData?: boolean + royaltyData?: boolean +} + const IpContext = React.createContext<{ - // activeTab: string - // setActiveTab: React.Dispatch> assetData: Asset | undefined nftData: NFTMetadata | undefined isNftDataLoading: boolean @@ -26,11 +31,27 @@ const IpContext = React.createContext<{ isRoyaltyDataLoading: boolean } | null>(null) -export const IpProvider = ({ children, ipId }: { children: React.ReactNode; ipId: Address }) => { +export const IpProvider = ({ + children, + ipId, + options = {}, +}: { + children: React.ReactNode + ipId: Address + options?: IpProviderOptions +}) => { + const queryOptions = { + assetData: true, + policyData: true, + licenseData: true, + royaltyData: true, + ...options, + } // Fetch asset data const { isLoading: isAssetDataLoading, data: assetData } = useQuery({ queryKey: [RESOURCE_TYPE.ASSET, ipId], queryFn: () => getResource(RESOURCE_TYPE.ASSET, ipId), + enabled: queryOptions.assetData, }) const ipaPolicyQueryOptions = { @@ -46,6 +67,7 @@ export const IpProvider = ({ children, ipId }: { children: React.ReactNode; ipId const { isLoading: isIPAPolicyDataLoading, data: ipPolicyData } = useQuery({ queryKey: [RESOURCE_TYPE.IPA_POLICY, ipaPolicyQueryOptions], queryFn: () => listResource(RESOURCE_TYPE.IPA_POLICY, ipaPolicyQueryOptions), + enabled: queryOptions.policyData, }) async function fetchPolicyDetails(data: IPAPolicy[]) { @@ -74,7 +96,7 @@ export const IpProvider = ({ children, ipId }: { children: React.ReactNode; ipId const { isLoading: isPolicyDataLoading, data: policyData } = useQuery({ queryKey: ["fetchPolicyDetails", ipPolicyData?.data], queryFn: () => fetchPolicyDetails(ipPolicyData?.data), - enabled: Boolean(ipPolicyData) && Boolean(ipPolicyData.data), + enabled: Boolean(ipPolicyData) && Boolean(ipPolicyData.data) && queryOptions.policyData, }) const licenseQueryOptions = { @@ -90,6 +112,7 @@ export const IpProvider = ({ children, ipId }: { children: React.ReactNode; ipId const { isLoading: isLicenseDataLoading, data: licenseData } = useQuery({ queryKey: [RESOURCE_TYPE.LICENSE, licenseQueryOptions], queryFn: () => listResource(RESOURCE_TYPE.LICENSE, licenseQueryOptions), + enabled: queryOptions.licenseData, }) // Fetch Royalty Data @@ -107,17 +130,14 @@ export const IpProvider = ({ children, ipId }: { children: React.ReactNode; ipId }, ], queryFn: () => getResource(RESOURCE_TYPE.ROYALTY_POLICY, ipId), + enabled: queryOptions.royaltyData, }) - // const { isLoading: isNftDataLoading, data: nftData } = useQuery({ - // queryKey: ["getNFTByTokenId", assetData?.data?.tokenContract, assetData?.data?.tokenId], - // queryFn: () => getNFTByTokenId(assetData.data.tokenContract, assetData.data.tokenId), - // enabled: Boolean(assetData) && Boolean(assetData.data.tokenContract) && Boolean(assetData.data.tokenId), - // }) const { isLoading: isNftDataLoading, data: nftData } = useQuery({ queryKey: ["getNFTByTokenId", assetData?.data?.nftMetadata?.tokenContract, assetData?.data?.nftMetadata?.tokenId], queryFn: () => getNFTByTokenId(assetData.data.nftMetadata.tokenContract, assetData.data.nftMetadata.tokenId), enabled: + queryOptions.assetData && Boolean(assetData) && Boolean(assetData.data.nftMetadata.tokenContract) && Boolean(assetData.data.nftMetadata.tokenId), @@ -126,8 +146,6 @@ export const IpProvider = ({ children, ipId }: { children: React.ReactNode; ipId return (