Skip to content

Commit

Permalink
Merge pull request #36 from storyprotocol/tea/refetch
Browse files Browse the repository at this point in the history
Adding refetch support for IPProvider
  • Loading branch information
allenchuang authored Sep 19, 2024
2 parents c19b424 + 79547f6 commit 27685db
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 7 deletions.
2 changes: 1 addition & 1 deletion packages/storykit/package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "@storyprotocol/storykit",
"author": "storyprotocol engineering <eng@storyprotocol.xyz>",
"version": "0.1.20",
"version": "0.1.21",
"type": "module",
"exports": {
".": {
Expand Down
48 changes: 42 additions & 6 deletions packages/storykit/src/providers/IpProvider/IpProvider.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,12 @@ const IpContext = React.createContext<{
isLicenseDataLoading: boolean
royaltyData: RoyaltyPolicy | undefined
isRoyaltyDataLoading: boolean
refetchAssetData: () => void
refetchIpLicenseData: () => void
refetchLicenseTermsData: () => void
refetchLicenseData: () => void
refetchRoyaltyData: () => void
refetchNFTData: () => void
} | null>(null)

export const IpProvider = ({
Expand All @@ -52,7 +58,11 @@ export const IpProvider = ({
...options,
}
// Fetch asset data
const { isLoading: isAssetDataLoading, data: assetData } = useQuery({
const {
isLoading: isAssetDataLoading,
data: assetData,
refetch: refetchAssetData,
} = useQuery({
queryKey: [RESOURCE_TYPE.ASSET, ipId],
queryFn: () => getResource(RESOURCE_TYPE.ASSET, ipId, { chain }),
enabled: queryOptions.assetData,
Expand All @@ -69,7 +79,11 @@ export const IpProvider = ({
},
}
// Fetch IP License Terms data
const { isLoading: isipLicenseDataLoading, data: ipLicenseData } = useQuery({
const {
isLoading: isipLicenseDataLoading,
data: ipLicenseData, /// <reference path=": " />
refetch: refetchIpLicenseData,
} = useQuery({
queryKey: [RESOURCE_TYPE.IP_LICENSE_TERMS, ipLicenseTermsQueryOptions],
queryFn: () => listResource(RESOURCE_TYPE.IP_LICENSE_TERMS, ipLicenseTermsQueryOptions),
enabled: queryOptions.licenseTermsData,
Expand All @@ -92,7 +106,11 @@ export const IpProvider = ({
})
}

const { isLoading: isLicenseTermsDataLoading, data: licenseTermsData } = useQuery({
const {
isLoading: isLicenseTermsDataLoading,
data: licenseTermsData,
refetch: refetchLicenseTermsData,
} = useQuery({
queryKey: ["fetchLicenseTermsDetails", ipLicenseData?.data],
queryFn: () => fetchLicenseTermsDetails(ipLicenseData?.data),
enabled: Boolean(ipLicenseData) && Boolean(ipLicenseData.data) && queryOptions.licenseTermsData,
Expand All @@ -110,14 +128,22 @@ export const IpProvider = ({
}

// Fetch License Data
const { isLoading: isLicenseDataLoading, data: licenseData } = useQuery({
const {
isLoading: isLicenseDataLoading,
data: licenseData,
refetch: refetchLicenseData,
} = useQuery({
queryKey: [RESOURCE_TYPE.LICENSE, licenseQueryOptions],
queryFn: () => listResource(RESOURCE_TYPE.LICENSE, licenseQueryOptions),
enabled: queryOptions.licenseData,
})

// Fetch Royalty Data
const { isLoading: isRoyaltyDataLoading, data: royaltyData } = useQuery({
const {
isLoading: isRoyaltyDataLoading,
data: royaltyData,
refetch: refetchRoyaltyData,
} = useQuery({
queryKey: [
RESOURCE_TYPE.ROYALTY_POLICY,
{
Expand All @@ -134,7 +160,11 @@ export const IpProvider = ({
enabled: queryOptions.royaltyData,
})

const { isLoading: isNftDataLoading, data: nftData } = useQuery({
const {
isLoading: isNftDataLoading,
data: nftData,
refetch: refetchNFTData,
} = useQuery({
queryKey: ["getNFTByTokenId", assetData?.data?.nftMetadata?.tokenContract, assetData?.data?.nftMetadata?.tokenId],
queryFn: () => getNFTByTokenId(assetData.data.nftMetadata.tokenContract, assetData.data.nftMetadata.tokenId, chain),
enabled:
Expand All @@ -160,6 +190,12 @@ export const IpProvider = ({
isLicenseDataLoading,
royaltyData: royaltyData?.data,
isRoyaltyDataLoading,
refetchAssetData,
refetchIpLicenseData,
refetchLicenseTermsData,
refetchLicenseData,
refetchRoyaltyData,
refetchNFTData,
}}
>
{children}
Expand Down

0 comments on commit 27685db

Please sign in to comment.