Skip to content

Commit

Permalink
Merge pull request #11404 from kodadot/feat--fetch-oda-on-drops-page
Browse files Browse the repository at this point in the history
  • Loading branch information
vikiival authored Feb 7, 2025
2 parents b2e7c11 + 6625370 commit 5514c43
Show file tree
Hide file tree
Showing 6 changed files with 82 additions and 2 deletions.
10 changes: 9 additions & 1 deletion components/collection/drop/GenerativeLayout.vue
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,10 @@
<div class="font-bold is-size-5 mb-4 capitalize">
{{ $t('tooltip.created') }}
</div>
<CollectionDropCreatedBy :address="address" />
<CollectionDropCreatedBy
:address="address"
:show-popover="false"
/>
</div>
<div
v-if="ownerAddresses.length"
Expand Down Expand Up @@ -48,6 +51,11 @@
/>

<CollectionUnlockableTag :collection-id="drop?.collection" />

<CollectionDropRefreshMetadata
:collection-id="drop?.collection"
:chain="drop?.chain"
/>
</div>

<div
Expand Down
1 change: 1 addition & 0 deletions components/collection/drop/ItemsGrid.vue
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
hide-listing
show-timestamp
:reset-search-query-params="['sort']"
fetch-onchain-data
/>
</div>
</template>
Expand Down
32 changes: 32 additions & 0 deletions components/collection/drop/RefreshMetadata.vue
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
<template>
<div class="text-k-grey text-xs p-4 border border-k-shade">
The images and metadata below are from its official website or on-chain data, cached by Koda. It’s our <span class="font-bold">best effort</span>, and we <span class="font-bold">don’t take any responsibility for any incorrectness</span>. You can <NuxtLink
@click="refreshMetadata"
>
<span class="font-bold">request an update</span>
</NuxtLink> or <NuxtLink
to="https://github.com/kodadot/nft-gallery/issues/new?q=sort%3Aupdated-desc+is%3Aissue+is%3Aopen&template=bug.yml"
target="_blank"
>
<span class="font-bold">report any problem</span>
</NuxtLink> you find.
</div>
</template>

<script setup lang="ts">
import type { Prefix } from '@kodadot1/static'
import { refreshOdaCollectionTokensMetadata } from '@/services/oda'
const props = defineProps<{
collectionId: string
chain: Prefix
}>()
const { toast } = useToast()
const { $i18n } = useNuxtApp()
const refreshMetadata = () => {
toast($i18n.t('toast.refreshMetdata'))
refreshOdaCollectionTokensMetadata(props.chain, props.collectionId)
}
</script>
38 changes: 38 additions & 0 deletions components/items/ItemsGrid/ItemsGrid.vue
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,7 @@ import { useListingCartStore } from '@/stores/listingCart'
import DynamicGrid from '@/components/shared/DynamicGrid.vue'
import type { NFT } from '@/types'
import type { GridSection } from '@/stores/preferences'
import { fetchOdaToken } from '@/services/oda'
const slots = useSlots()
Expand All @@ -151,6 +152,7 @@ const props = defineProps<{
collectionPopoverHide?: boolean
hideListing?: boolean
linkTarget?: string
fetchOnchainData?: boolean
}>()
const emit = defineEmits(['total', 'loading'])
Expand Down Expand Up @@ -287,4 +289,40 @@ const getSkeletonVariant = (slotProps) => {
}
return 'primary'
}
const { urlPrefix } = usePrefix()
const { isAssetHub } = useIsChain(urlPrefix)
const processOnchainData = useDebounceFn(async () => {
items.value = await Promise.all(items.value.map(async (item) => {
if (item.sn && !isTokenEntity(item)) {
const tokenData = await fetchOdaToken(urlPrefix.value, item.collection.id, item.sn)
if (tokenData.metadata && tokenData.metadata_uri) {
return {
...item,
name: tokenData.metadata?.name || item.meta.name,
meta: {
...item.meta,
name: tokenData.metadata?.name || item.meta.name,
id: tokenData.metadata?.image || item.meta.id,
image: tokenData.metadata?.image || item.meta.image,
animationUrl: tokenData.metadata?.animation_url || item.meta.animationUrl,
},
}
}
}
return {
...item,
name: item.collection.name,
}
}))
}, 500)
watch(() => items.value.length, () => {
if (isAssetHub.value && items.value.length && props.fetchOnchainData) {
processOnchainData()
}
}, { immediate: true })
</script>
1 change: 1 addition & 0 deletions composables/useNft.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ export type TokenEntity = {
name: string
floorPrice: [{ price: string }]
}
sn?: string
}

export type NFTOffer = {
Expand Down
2 changes: 1 addition & 1 deletion services/oda.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import type { Prefix } from '@kodadot1/static'
import type { Abi } from '@/composables/transaction/types'

const BASE_URL = isProduction ? 'https://oda.koda.art' : 'https://oda-beta.koda.art'
const BASE_URL = isProduction ? 'https://oda.koda.art' : 'https://5977602c-oda-beta.kodadot.workers.dev'
const api = $fetch.create({ baseURL: BASE_URL, retry: 3 })

type OnchainCollection = {
Expand Down

0 comments on commit 5514c43

Please sign in to comment.