Skip to content

Commit

Permalink
feat(nft): integrate collection ABI fetching across components
Browse files Browse the repository at this point in the history
  • Loading branch information
preschian committed Sep 30, 2024
1 parent f0ffd27 commit 3ab723a
Show file tree
Hide file tree
Showing 5 changed files with 17 additions and 18 deletions.
2 changes: 1 addition & 1 deletion components/gallery/GalleryItemButton/GalleryItemButton.vue
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ import { extractTwitterIdFromDescription } from '@/utils/parse'
const { $i18n } = useNuxtApp()
const imageData = ref()
const { getNft: nft, getNftMetadata: nftMetadata, getNftMimeType: nftMimeType } = storeToRefs(useNftStore())
const { getNft: nft, getNftMetadata: nftMetadata, getNftMimeType: nftMimeType, getAbi: abi } = storeToRefs(useNftStore())
const customSharingContent = computed(() => {
const twitterId = nft.value?.meta?.description
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -174,9 +174,9 @@ const unlist = () => {
}
const refreshMetadata = async () => {
if (props.collectionId && props.nftSn) {
if (props.nft?.collection?.id && props.nft?.sn) {
toast('Refreshing metadata. Check back in a minute...')
await refreshOdaTokenMetadata(urlPrefix.value, props.collectionId!, props.nftSn!)
await refreshOdaTokenMetadata(urlPrefix.value, props.nft.collection.id, props.nft.sn)
}
}
Expand Down
16 changes: 1 addition & 15 deletions components/gallery/useGalleryItem.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,9 @@ import useSubscriptionGraphql from '@/composables/useSubscriptionGraphql'
import { getDrops } from '@/services/fxart'
import { getCloudflareMp4 } from '@/services/imageWorker'
import type { NFTMetadata } from '@/services/oda'
import { fetchMimeType, fetchOdaToken, fetchOdaCollectionAbi } from '@/services/oda'
import { fetchMimeType, fetchOdaToken } from '@/services/oda'
import { useHistoryStore } from '@/stores/history'
import { sanitizeIpfsUrl } from '@/utils/ipfs'
import type { Abi } from '@/composables/transaction/types'

interface NFTData {
nftEntity?: NftEntity
Expand All @@ -24,7 +23,6 @@ export interface GalleryItem {
nftAnimationMimeType: Ref<string>
nftImage: Ref<string>
nftHighestOffer: Ref<NFTOffer | undefined>
abi: Ref<Abi | null | undefined>
}

export const useGalleryItem = (nftId?: string): GalleryItem => {
Expand Down Expand Up @@ -66,12 +64,6 @@ export const useGalleryItem = (nftId?: string): GalleryItem => {
},
})

const { data: abi } = useQuery({
queryKey: ['collection-abi', nft.value?.collection.id],
queryFn: () => isEvm(urlPrefix.value) ? fetchOdaCollectionAbi(urlPrefix.value, nft.value?.collection.id as string) : Promise.resolve(null),
enabled: computed(() => Boolean(nft.value)),
})

useSubscriptionGraphql({
query: ` nft: nftEntityById(id: "${id}") {
id
Expand Down Expand Up @@ -133,12 +125,7 @@ export const useGalleryItem = (nftId?: string): GalleryItem => {
}
})

const { isRemark } = useIsChain(usePrefix().urlPrefix)
onBeforeMount(async () => {
if (isRemark.value) {
return
}

const getMetadata = await fetchOdaToken(urlPrefix.value, collectionId, tokenId)
const metadata = getMetadata.metadata

Expand Down Expand Up @@ -187,6 +174,5 @@ export const useGalleryItem = (nftId?: string): GalleryItem => {
nftMimeType,
nftMetadata,
nftHighestOffer,
abi,
}
}
10 changes: 10 additions & 0 deletions pages/[prefix]/gallery/[id].vue
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,9 @@
</template>

<script setup lang="ts">
import { useQuery } from '@tanstack/vue-query'
import { useGalleryItem } from '@/components/gallery/useGalleryItem'
import { fetchOdaCollectionAbi } from '@/services/oda'
const nftStore = useNftStore()
Expand All @@ -16,13 +18,21 @@ const {
nftMimeType,
} = useGalleryItem()
const { urlPrefix } = usePrefix()
const { data: abi } = useQuery({
queryKey: ['collection-abi', nft.value?.collection.id],
queryFn: () => isEvm(urlPrefix.value) ? fetchOdaCollectionAbi(urlPrefix.value, nft.value?.collection.id as string) : Promise.resolve(null),
enabled: computed(() => Boolean(nft.value)),
})
watchEffect(() => {
nftStore.nft = nft.value
nftStore.nftMetadata = nftMetadata.value
nftStore.nftImage = nftImage.value
nftStore.nftAnimation = nftAnimation.value
nftStore.nftAnimationMimeType = nftAnimationMimeType.value
nftStore.nftMimeType = nftMimeType.value
nftStore.abi = abi.value ?? null
})
definePageMeta({
Expand Down
3 changes: 3 additions & 0 deletions stores/nft.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { defineStore } from 'pinia'
import type { NFTMetadata } from '@/services/oda'
import type { NFT } from '@/components/rmrk/service/scheme'
import type { Abi } from '@/composables/transaction/types'

export const useNftStore = defineStore('nft', {
state: () => ({
Expand All @@ -13,6 +14,7 @@ export const useNftStore = defineStore('nft', {
nftMimeType: '',
nftAnimation: '',
nftAnimationMimeType: '',
abi: null as Abi | null,
}),

getters: {
Expand All @@ -22,5 +24,6 @@ export const useNftStore = defineStore('nft', {
getNftMimeType: state => state.nftMimeType,
getNftAnimation: state => state.nftAnimation,
getNftAnimationMimeType: state => state.nftAnimationMimeType,
getAbi: state => state.abi,
},
})

0 comments on commit 3ab723a

Please sign in to comment.