Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feat: Total Supply for AssetHubs #8346 #8347

Closed
wants to merge 5 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions components/collection/CollectionInfo.vue
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,10 @@
:value="stats.uniqueOwners" />
</div>
<div>
<CollectionInfoLine
v-if="isAssetHub"
title="Total Supply"
:value="stats.maxSupply" />
<CollectionInfoLine :title="$t('activity.floor')">
<CommonTokenMoney
:value="stats.collectionFloorPrice"
Expand Down Expand Up @@ -77,6 +81,7 @@ const chain = computed(
availableChains.value.find((chain) => chain.value === route.params.prefix)
?.text,
)
const { isAssetHub } = useIsChain(urlPrefix)
const address = computed(() => collectionInfo.value?.currentOwner)
const seeAllDescription = ref(false)
const DESCRIPTION_MAX_LENGTH = 210
Expand Down
1 change: 1 addition & 0 deletions components/collection/utils/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ export type Stats = {
uniqueOwners?: number
uniqueOwnersPercent?: string
collectionTradedVolumeNumber?: string | number
maxSupply?: number | string
}

export type CollectionEntityMinimal = {
Expand Down
15 changes: 14 additions & 1 deletion components/collection/utils/useCollectionDetails.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ const differentOwner = (nft: {

export const useCollectionDetails = ({ collectionId }) => {
const { urlPrefix } = usePrefix()
const { apiInstance } = useApi()
const { data } = useGraphql({
queryPrefix: 'subsquid',
queryName: chainsSupportingOffers.includes(urlPrefix.value)
Expand All @@ -24,7 +25,7 @@ export const useCollectionDetails = ({ collectionId }) => {
})
const stats = ref<Stats>({})

watch(data, () => {
watch(data, async () => {
if (data.value?.stats) {
const uniqueOwnerCount = [
...new Set(data.value.stats.base.map((item) => item.currentOwner)),
Expand All @@ -47,8 +48,20 @@ export const useCollectionDetails = ({ collectionId }) => {
})

const listedNfts = data.value.stats.listed
const api = await apiInstance.value
const supply = await api.query.nfts.collectionConfigOf(collectionId)

// Check if supply string is not empty before parsing
const supplyString = supply.toString()
const supplyJsonParse = supplyString ? JSON.parse(supplyString) : null

// Check if supplyJsonParse is not null before accessing properties
const getTotalSupply = supplyJsonParse
? supplyJsonParse.maxSupply || 'Unlimited'
: 'Unlimited'

stats.value = {
maxSupply: getTotalSupply,
listedCount: data.value.stats.listed.length,
collectionLength: data.value.stats.base.length,
collectionFloorPrice:
Expand Down