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

fix: drops max count #10713

Merged
merged 27 commits into from
Aug 15, 2024
Merged
Show file tree
Hide file tree
Changes from 21 commits
Commits
Show all changes
27 commits
Select commit Hold shift + click to select a range
b6529de
fix: drops max count
preschian Aug 1, 2024
c25e266
refactor(tests): simplify image loading wait logic in explore.spec.ts
preschian Aug 1, 2024
5f4bf39
feat(tests): ensure images load during scroll in e2e explore
preschian Aug 1, 2024
5e481d8
refactor(tests): update collection spec to new data and optimize wait…
preschian Aug 1, 2024
c0cbc89
chore(workflow): increase shard count in Playwright configuration
preschian Aug 1, 2024
ac63e8b
chore(tests): add network idle state wait in gallery item interaction…
preschian Aug 1, 2024
9836743
feat(playwright): increase timeout and ensure server start command
preschian Aug 1, 2024
44c96a0
feat(playwright): increase timeout settings and add expect timeout
preschian Aug 1, 2024
318da3f
revert: flaky e2e test
preschian Aug 2, 2024
22f6985
Merge branch 'main' of github.com:kodadot/nft-gallery into fix--drops…
preschian Aug 2, 2024
515f22d
Merge branch 'main' of github.com:kodadot/nft-gallery into fix--drops…
preschian Aug 5, 2024
6cdf1a8
feat(drop): integrate EVM and Substrate collection data handling
preschian Aug 5, 2024
841d325
refactor(mint-button): add null check for maxCount comparison
preschian Aug 5, 2024
bb09b10
Merge branch 'main' of github.com:kodadot/nft-gallery into fix--drops…
preschian Aug 5, 2024
fa8b050
Update composables/drop/useGenerativeDropMint.ts
preschian Aug 5, 2024
90b9695
refactor(onchain): change API endpoint and adjust result parsing
preschian Aug 5, 2024
ff2ec26
feat(ogi): add service to fetch EVM collection data
preschian Aug 7, 2024
916e98c
refactor(drop): replace collection entity references with drop
preschian Aug 8, 2024
ae281ab
refactor(drop): replace useDrop with storeToRefs to streamline state
preschian Aug 8, 2024
ca3ac44
Merge branch 'main' of github.com:kodadot/nft-gallery into fix--drops…
preschian Aug 8, 2024
631991e
refactor(generative-drop): correct typos in function names and fix me…
preschian Aug 8, 2024
643fb86
Update components/drops/useDrops.ts
preschian Aug 8, 2024
942547e
fix(drops): prevent execution if collection is undefined in useDrop
preschian Aug 8, 2024
7dc049e
Merge branch 'main' of github.com:kodadot/nft-gallery into fix--drops…
preschian Aug 8, 2024
7c46b44
Merge branch 'main' of github.com:kodadot/nft-gallery into fix--drops…
preschian Aug 15, 2024
25292da
refactor(onchain): remove unused wagmi config definitions
preschian Aug 15, 2024
74c9bd5
chore(config): remove use-wagmi from dependencies
preschian Aug 15, 2024
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
7 changes: 2 additions & 5 deletions components/collection/drop/GenerativeLayout.vue
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
<CollectionUnlockableCollectionInfo
class="mt-7"
:collection-id="drop?.collection"
:description="description"
:description="drop.collectionDescription"
/>

<hr class="hidden md:block mt-4 mb-0">
Expand Down Expand Up @@ -93,22 +93,19 @@ import type {
Drop } from '@/components/drops/useDrops'
import {
getFormattedDropItem,
useDrop,
} from '@/components/drops/useDrops'
import { useCollectionActivity } from '@/composables/collectionActivity/useCollectionActivity'
import { useCollectionMinimal } from '@/components/collection/utils/useCollectionDetails'
import useCursorDropEvents from '@/composables/party/useCursorDropEvents'
import { DropEventType } from '@/composables/party/types'
import { useCollectionEntity } from '@/composables/drop/useGenerativeDropMint'
import type { DropItem } from '@/params/types'

const mdBreakpoint = 768

const emit = defineEmits(['mint'])

const { drop } = useDrop()
const { drop } = storeToRefs(useDropStore())
const { previewItem, userMintsCount } = storeToRefs(useDropStore())
const { description } = useCollectionEntity()
const { width } = useWindowSize()

const { emitEvent, completeLastEvent } = useCursorDropEvents()
Expand Down
25 changes: 14 additions & 11 deletions components/collection/drop/GenerativePreview.vue
Original file line number Diff line number Diff line change
Expand Up @@ -56,16 +56,23 @@
<div class="mr-4 text-neutral-7">
{{ mintedPercent }}% ~
</div>
<div class="font-bold">
{{ dropStore.mintsCount }}/{{ maxCount }}
<div
v-if="drop.minted >= 0 && drop.max"
class="font-bold"
>
{{ drop.minted }}/{{ drop.max }}
{{ $t('statsOverview.minted') }}
</div>
<div v-else>
<NeoSkeleton width="100" />
</div>
</div>
</div>

<CollectionUnlockableSlider
v-if="drop.max"
class="text-neutral-5 dark:text-neutral-9"
:value="dropStore.mintsCount / maxCount"
:value="drop.minted / drop.max"
/>

<div class="flex mt-6 gap-4 max-md:flex-col">
Expand All @@ -88,18 +95,14 @@
</template>

<script setup lang="ts">
import { NeoButton, NeoIcon } from '@kodadot1/brick'
import { NeoButton, NeoIcon, NeoSkeleton } from '@kodadot1/brick'
import { sanitizeIpfsUrl } from '@/utils/ipfs'
import useGenerativeIframeData from '@/composables/drop/useGenerativeIframeData'
import { useDrop } from '@/components/drops/useDrops'
import useGenerativeDropMint from '@/composables/drop/useGenerativeDropMint'

const { accountId } = useAuth()
const { chainSymbol, decimals } = useChain()
const { drop } = useDrop()
const dropStore = useDropStore()
const { userMintsCount, mintsCount } = storeToRefs(dropStore)
const { maxCount } = useGenerativeDropMint()
const { userMintsCount, drop } = storeToRefs(dropStore)
const { imageDataPayload, imageDataLoaded } = useGenerativeIframeData()
const { formatted: formattedPrice } = useAmount(
computed(() => drop.value.price),
Expand All @@ -121,10 +124,10 @@ const { start: startTimer } = useTimeoutFn(() => {
const generativeImageUrl = ref('')

const mintedPercent = computed(() => {
if (!maxCount.value) {
if (!drop.value.max) {
return 0
}
return Math.round((mintsCount.value / maxCount.value) * 100)
return Math.round((drop.value.minted / drop.value.max) * 100)
})

const displayUrl = computed(() => generativeImageUrl.value || drop.value?.image)
Expand Down
8 changes: 1 addition & 7 deletions components/collection/drop/HolderOfGenerative.vue
Original file line number Diff line number Diff line change
Expand Up @@ -51,9 +51,7 @@
<script setup lang="ts">
import { NeoModal } from '@kodadot1/brick'
import {
useDrop,
useDropMinimumFunds,
useDropStatus,
} from '@/components/drops/useDrops'
import useGenerativeDropMint, {
useUpdateMetadata,
Expand Down Expand Up @@ -91,14 +89,12 @@ const { openListingCartModal } = useListingCartModal({
const { fetchMultipleBalance } = useMultipleBalance()
const { hasMinimumFunds } = useDropMinimumFunds()

const { drop } = useDrop()
const { subscribeDropStatus } = useDropStatus(drop)
const dropStore = useDropStore()
const { claimedNft, canListMintedNft } = useGenerativeDropMint()
const { availableNfts } = useHolderOfCollection()
const { isAutoTeleportModalOpen } = useAutoTeleportModal()

const { mintingSession, loading, walletConnecting, isCapturingImage }
const { mintingSession, loading, walletConnecting, isCapturingImage, drop }
= storeToRefs(dropStore)

useCursorDropEvents([isTransactionLoading, loading])
Expand Down Expand Up @@ -241,8 +237,6 @@ useTransactionTracker({
watch(txHash, () => {
mintingSession.value.txHash = txHash.value
})

onBeforeMount(subscribeDropStatus)
</script>

<style scoped lang="scss">
Expand Down
14 changes: 7 additions & 7 deletions components/collection/drop/MintButton.vue
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
import { NeoButton } from '@kodadot1/brick'
import useGenerativeDropMint from '@/composables/drop/useGenerativeDropMint'
import { useDropStore } from '@/stores/drop'
import { useDrop, useDropMinimumFunds } from '@/components/drops/useDrops'
import { useDropMinimumFunds } from '@/components/drops/useDrops'
import {
calculateBalanceUsdValue,
formatAmountWithRound,
Expand All @@ -38,10 +38,9 @@ const { isLogIn } = useAuth()
const { chainSymbol, decimals } = useChain()
const dropStore = useDropStore()
const { hasCurrentChainBalance } = useMultipleBalance()
const { drop } = useDrop()
const now = useNow()
const { mintCountAvailable, maxCount } = useGenerativeDropMint()
const { amountToMint, previewItem, userMintsCount } = storeToRefs(dropStore)
const { mintCountAvailable } = useGenerativeDropMint()
const { amountToMint, previewItem, userMintsCount, drop } = storeToRefs(dropStore)

const { hasMinimumFunds } = useDropMinimumFunds()
const { holderOfCollection } = useHolderOfCollection()
Expand All @@ -51,7 +50,8 @@ const priceUsd = ref()
const isHolderAndEligible = computed(
() =>
holderOfCollection.value.isHolder
&& maxCount.value > dropStore.mintsCount
&& drop.value.max
&& drop.value.max > drop.value.minted
&& hasMinimumFunds.value
&& holderOfCollection.value.hasAvailable,
)
Expand All @@ -74,7 +74,7 @@ const mintForLabel = computed(() =>
)

const label = computed(() => {
if (!mintCountAvailable.value) {
if (drop.value.max && (drop.value.max === drop.value.minted)) {
return $i18n.t('mint.unlockable.seeListings')
}
if (!isLogIn.value) {
Expand Down Expand Up @@ -138,7 +138,7 @@ const enabled = computed(() => {
case 'holder':
return isHolderAndEligible.value
case 'paid':
return maxCount.value > userMintsCount.value
return drop.value.max && drop.value.max > userMintsCount.value
default:
return false
}
Expand Down
13 changes: 1 addition & 12 deletions components/collection/drop/MintStepper.vue
Original file line number Diff line number Diff line change
Expand Up @@ -25,16 +25,5 @@ const min = computed(() =>
isHolder.value ? Math.min(1, availableNftsAmount.value) : 1,
)

const max = computed(() => {
// tmp remove when uploading to IPFS step can be skipped @see https://github.com/kodadot/nft-gallery/issues/10001#issuecomment-2041533819
const dropMax = DROP_MASSMINT_LIMIT[drop.value.alias] ?? undefined

if (isHolder.value) {
return dropMax
? Math.min(dropMax, availableNftsAmount.value)
: availableNftsAmount.value
}

return dropMax
})
const max = computed(() => isHolder.value ? availableNftsAmount.value : undefined)
</script>
7 changes: 1 addition & 6 deletions components/collection/drop/PaidGenerative.vue
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@
</template>

<script setup lang="ts">
import { useDrop, useDropStatus } from '@/components/drops/useDrops'
import { useUpdateMetadata } from '@/composables/drop/useGenerativeDropMint'
import type { AutoTeleportAction } from '@/composables/autoTeleport/types'
import { ActionlessInteraction } from '@/components/common/autoTeleport/utils'
Expand All @@ -23,8 +22,6 @@ import useDropMassMintListing from '@/composables/drop/massmint/useDropMassMintL
import useAutoTeleportModal from '@/composables/autoTeleport/useAutoTeleportModal'
import { NFTs } from '@/composables/transaction/types'

const { drop } = useDrop()
const { subscribeDropStatus } = useDropStatus(drop)
const { urlPrefix } = usePrefix()
const { doAfterLogin } = useDoAfterlogin()
const { $i18n, $consola } = useNuxtApp()
Expand All @@ -35,7 +32,7 @@ const { openListingCartModal } = useListingCartModal({
clearItemsOnModalClose: true,
})

const { loading, walletConnecting, mintingSession, isCapturingImage }
const { loading, walletConnecting, mintingSession, isCapturingImage, drop }
= storeToRefs(useDropStore())

const { isAutoTeleportModalOpen } = useAutoTeleportModal()
Expand Down Expand Up @@ -167,8 +164,6 @@ useTransactionTracker({
watch(txHash, () => {
mintingSession.value.txHash = txHash.value
})

onBeforeMount(subscribeDropStatus)
</script>

<style scoped lang="scss">
Expand Down
95 changes: 25 additions & 70 deletions components/drops/useDrops.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import orderBy from 'lodash/orderBy'
import type { Prefix } from '@kodadot1/static'
import type { WritableComputedRef } from 'nuxt/dist/app/compat/capi'
import { parseCETDate } from './utils'
import type { GetDropsQuery } from '@/services/fxart'
import { getDropById, getDrops } from '@/services/fxart'
Expand All @@ -11,6 +10,8 @@ import type { DropItem } from '@/params/types'
import { prefixToToken } from '@/components/common/shoppingCart/utils'
import { useDropStore } from '@/stores/drop'
import { getChainName } from '@/utils/chain'
import { subCollection } from '~/utils/onchain/sub'
import { evmCollection } from '~/utils/onchain/evm'
preschian marked this conversation as resolved.
Show resolved Hide resolved

export interface Drop {
collection: DropItem
Expand Down Expand Up @@ -170,6 +171,7 @@ export const getDropDetails = async (alias: string) => {
export function useDrop(alias?: string) {
const { params } = useRoute()
const dropStore = useDropStore()
const { isEvm, isSub } = useIsChain(usePrefix().urlPrefix)

const drop = computed({
get: () => dropStore.drop,
Expand All @@ -181,6 +183,28 @@ export function useDrop(alias?: string) {

const fetchDrop = async () => {
drop.value = await getDropById(alias ?? params.id.toString())

if (drop.value.collection) {
if (isSub.value) {
const { maxSupply: supply, minted, metadata } = await subCollection(drop.value.collection)

drop.value.max = supply
drop.value.minted = minted
drop.value.collectionName = metadata.name
drop.value.collectionDescription = metadata.description
}

if (isEvm.value) {
const { urlPrefix } = usePrefix()
const address = drop.value.collection as `0x${string}`
const { maxSupply: supply, metadata, minted } = await evmCollection(address, urlPrefix.value)

drop.value.max = supply
drop.value.minted = minted
drop.value.collectionName = metadata.name
drop.value.collectionDescription = metadata.description
}
}
hassnian marked this conversation as resolved.
Show resolved Hide resolved
}

watch(() => params.id, fetchDrop)
Expand Down Expand Up @@ -213,75 +237,6 @@ export const fetchDropMintedCount = async (
return data.value?.collectionEntityById?.nftCount ?? 0
}

const subscribeDropMintedCount = (
{ drop, account }: { drop: Pick<DropItem, 'collection'>, account: string },
onChange: (params: { collection?: number, user?: number }) => void,
) => {
return useSubscriptionGraphql({
query: `
collectionEntityById(id: "${drop.collection}") {
nftCount
nfts(where: { issuer_eq: "${account}" }) {
id
}
}
`,
onChange: ({ data }) => {
onChange({
collection: data.collectionEntityById?.nftCount,
user: data.collectionEntityById?.nfts?.length,
})
},
})
}

export const useDropStatus = (
drop: WritableComputedRef<{ collection: string, chain: Prefix }>,
) => {
const { mintsCount, userMintsCount } = storeToRefs(useDropStore())
const { accountId } = useAuth()

const dropStatusSubscription = ref<{
collection: string | undefined
account: string | undefined
unsubscribe: () => void
}>({
account: undefined,
collection: undefined,
unsubscribe: () => {},
})

const subscribeDropStatus = () => {
watch([() => drop.value, accountId], ([drop, account]) => {
if (drop) {
if (
drop.collection !== dropStatusSubscription.value.collection
|| account !== dropStatusSubscription.value.account
) {
dropStatusSubscription.value.unsubscribe?.()
}

dropStatusSubscription.value.collection = drop.collection
dropStatusSubscription.value.account = accountId.value
dropStatusSubscription.value.unsubscribe = subscribeDropMintedCount(
{ drop, account: accountId.value },
({ collection, user }) => {
mintsCount.value = collection ?? 0
userMintsCount.value = user ?? 0
},
)
}
})

onUnmounted(() => dropStatusSubscription.value.unsubscribe?.())
}

return {
mintsCount,
subscribeDropStatus,
}
}

export const useDropMinimumFunds = (amount = ref(1)) => {
const { drop } = useDrop()

Expand Down
4 changes: 1 addition & 3 deletions composables/drop/massmint/useDropMassMint.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import { useCollectionEntity } from '../useGenerativeDropMint'
import type { ToMintNft } from '@/components/collection/drop/types'
import { generateId, setDyndataUrl } from '@/services/dyndata'

Expand All @@ -11,7 +10,6 @@ export type MassMintNFT = Omit<ToMintNft, 'priceUSD'> & {

export default () => {
const dropStore = useDropStore()
const { collectionName } = useCollectionEntity()
const { drop, amountToMint, toMintNFTs, loading } = storeToRefs(dropStore)
const { isSub } = useIsChain(usePrefix().urlPrefix)

Expand Down Expand Up @@ -52,7 +50,7 @@ export default () => {

return {
name: drop.value.name,
collectionName: collectionName.value,
collectionName: drop.value.collectionName,
price: drop.value.price?.toString() || '',
nft: tokenIds.value[index],
metadata,
Expand Down
Loading
Loading