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: Holder of drop page iteration #9027

Merged
merged 38 commits into from
Feb 1, 2024
Merged
Show file tree
Hide file tree
Changes from 26 commits
Commits
Show all changes
38 commits
Select commit Hold shift + click to select a range
607e2db
add: new holder of drop iteration
hassnian Jan 16, 2024
cf925a3
ref: move simple minimum-funds
hassnian Jan 16, 2024
6a273c2
ref: holder of collection requirements
hassnian Jan 16, 2024
49b343f
add: holder of collection tooltip
hassnian Jan 17, 2024
4d746f5
add: check if holder of collection nfts are already claimed
hassnian Jan 17, 2024
792d0b2
remove: empy tags
hassnian Jan 17, 2024
5f99825
add: check has minimumFunds amount
hassnian Jan 17, 2024
1a257fc
add: requiremnt check available for mint amount
hassnian Jan 17, 2024
a7f99de
Merge branch 'main' into issue-8886
hassnian Jan 17, 2024
14a49f4
add: missing hasAmount minimumFundsProps
hassnian Jan 17, 2024
a942544
add: mobile version holder of requirements
hassnian Jan 17, 2024
cc92d98
fix: checkAlreadyClaimedNfts wrong collection
hassnian Jan 17, 2024
848884a
ref: use correct transaltion
hassnian Jan 17, 2024
20350eb
ref: transaltion key rename
hassnian Jan 17, 2024
7df5f90
add: check hasMinimumFunds mint button disabled and label
hassnian Jan 17, 2024
502800b
ref: move holder of collection logic
hassnian Jan 17, 2024
7decf03
Merge branch 'main' into issue-8886
hassnian Jan 17, 2024
5c58d26
fix: on wallet disconnect update available nft count
hassnian Jan 17, 2024
439141a
Merge branch 'issue-8886' of https://github.com/hassnian/nft-gallery …
hassnian Jan 17, 2024
37101e0
ref: remove boolean
hassnian Jan 17, 2024
225234e
fix: disabled button if does not have available nfts
hassnian Jan 17, 2024
441529a
ref: rename checkAvailableNfts
hassnian Jan 17, 2024
690dbab
Merge branch 'main' into issue-8886
hassnian Jan 17, 2024
bffc3a2
ref: icon name and class
hassnian Jan 17, 2024
7ee4b5f
Merge branch 'issue-8886' of https://github.com/hassnian/nft-gallery …
hassnian Jan 17, 2024
e587ff7
Merge branch 'main' into issue-8886
hassnian Jan 18, 2024
7bc773f
remove: default holder of collection prop for other drops
hassnian Jan 18, 2024
facab5b
Merge branch 'main' into issue-8886
hassnian Jan 29, 2024
59a8490
remove: dupicate mintedAmountForCurrentUser
hassnian Jan 29, 2024
4afc864
add: check holds field from api holder of generative
hassnian Jan 29, 2024
1ea8f75
add: mint requirements checking state
hassnian Jan 30, 2024
1eb5c38
fix: always show available nfts
hassnian Jan 30, 2024
579594b
ref: remove chain balances to useMultiBalance
hassnian Jan 30, 2024
945d92d
ref: use computed chainBalances on teleport page
hassnian Jan 30, 2024
08608f2
ref: use computed chainBalances on use autoteleport
hassnian Jan 30, 2024
ea67ae1
ref: move HolderOfCollectionProp to types.ts
hassnian Jan 30, 2024
488caad
Merge branch 'main' into issue-8886
hassnian Feb 1, 2024
bc2b1c8
Merge branch 'main' into issue-8886
hassnian Feb 1, 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
5 changes: 3 additions & 2 deletions components/collection/drop/Generative.vue
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,7 @@ const minimumFundsDescription = computed(() =>
const minimumFundsProps = computed(() => ({
amount: minimumFunds.value,
description: minimumFundsDescription.value,
hasAmount: hasMinimumFunds.value,
}))

const isWalletConnecting = ref(false)
Expand Down Expand Up @@ -157,10 +158,10 @@ const {
defaultImage,
})

const mintButtonDisabled = computed(
const mintButtonDisabled = computed<boolean>(
() =>
!mintCountAvailable.value ||
disabledByBackend.value ||
Boolean(disabledByBackend.value) ||
(isLogIn.value && Boolean(!selectedImage.value)),
)

Expand Down
5 changes: 3 additions & 2 deletions components/collection/drop/GenerativeLayout.vue
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@

<script setup lang="ts">
import { DropItem } from '@/params/types'
import type { HolderOfCollectionProp } from './HolderOfGenerative.vue'

withDefaults(
defineProps<{
Expand All @@ -74,12 +75,12 @@ withDefaults(
mintedCount: number
mintCountAvailable: boolean
maxCount: number
minimumFunds: { amount: number; description: string }
minimumFunds: { amount: number; description: string; hasAmount: boolean }
isImageFetching: boolean
isWalletConnecting: boolean
isLoading: boolean
holderOfCollection?: HolderOfCollectionProp
userMintedNftId?: string
holderOfCollection?: { id?: string; isHolderOfTargetCollection?: boolean }

handleSelectImage: (image: string) => void
handleSubmitMint: () => void
Expand Down
51 changes: 0 additions & 51 deletions components/collection/drop/HolderOfCollection.vue

This file was deleted.

61 changes: 49 additions & 12 deletions components/collection/drop/HolderOfGenerative.vue
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,11 @@
import { createUnlockableMetadata } from '../unlockable/utils'
import { DropItem } from '@/params/types'
import { claimDropItem } from '@/services/waifu'
import { useDropMinimumFunds, useDropStatus } from '@/components/drops/useDrops'
import {
useDropMinimumFunds,
useDropStatus,
useHolderOfCollectionDrop,
} from '@/components/drops/useDrops'
import { fetchNft } from '@/components/items/ItemsGrid/useNftActions'
import holderOfCollectionById from '@/queries/subsquid/general/holderOfCollectionById.graphql'
import unlockableCollectionById from '@/queries/subsquid/general/unlockableCollectionById.graphql'
Expand All @@ -44,6 +48,16 @@ import useGenerativeDropDetails from '@/composables/drop/useGenerativeDropDetail

const holderOfCollectionId = '50' // ChaosFlakes | todo: mock for testing, should be fetched from backend

export type HolderOfCollectionProp = {
id: string
isHolder: boolean
hasAvailable: boolean
amount: {
total: number
available: number
}
}

const props = withDefaults(
defineProps<{
drop: DropItem
Expand All @@ -58,7 +72,7 @@ const { fetchMultipleBalance } = useMultipleBalance()
const { hasMinimumFunds, formattedMinimumFunds, minimumFunds } =
useDropMinimumFunds(props.drop)
const minimumFundsDescription = computed(() =>
$i18n.t('mint.unlockable.minimumFundsDescription', [
$i18n.t('mint.unlockable.holderOfCollectionMinimumFundsDescription', [
formattedMinimumFunds.value,
chainName.value,
]),
Expand All @@ -67,11 +81,13 @@ const minimumFundsDescription = computed(() =>
const minimumFundsProps = computed(() => ({
amount: minimumFunds.value,
description: minimumFundsDescription.value,
hasAmount: hasMinimumFunds.value,
}))

const isWalletConnecting = ref(false)
const { currentAccountMintedToken, mintedDropCount, fetchDropStatus } =
useDropStatus(props.drop.alias)
const { isNftClaimed } = useHolderOfCollectionDrop()
const instance = getCurrentInstance()
const mintNftSN = ref('0')
const { doAfterLogin } = useDoAfterlogin(instance)
Expand All @@ -84,6 +100,7 @@ const { client } = usePrefix()
const isLoading = ref(false)
const isImageFetching = ref(false)
const isAddFundModalActive = ref(false)
const availableNfts = ref(0)

const {
defaultName,
Expand Down Expand Up @@ -137,6 +154,7 @@ const {
userMintedNftId,
mintedCount,
mintCountAvailable,
mintedAmountForCurrentUser,
selectedImage,
description,
collectionName,
Expand Down Expand Up @@ -167,10 +185,6 @@ const { data: holderOfCollectionData } = await useAsyncData(
},
)

const mintedAmountForCurrentUser = computed(
() => collectionData.value?.nftEntitiesConnection?.totalCount || 0, // todo: fetch from backend
)

const maxMintLimitForCurrentUser = computed(
() => holderOfCollectionData.value?.nftEntitiesConnection?.totalCount || 0,
)
Expand All @@ -179,32 +193,44 @@ const isHolderOfTargetCollection = computed(
() => maxMintLimitForCurrentUser.value > 0,
)

const holderOfCollection = computed(() => ({
const hasAvailableNfts = computed(() => availableNfts.value !== 0)

const holderOfCollection = computed<HolderOfCollectionProp>(() => ({
id: holderOfCollectionId,
isHolderOfTargetCollection: isHolderOfTargetCollection.value,
isHolder: isHolderOfTargetCollection.value,
hasAvailable: hasAvailableNfts.value,
amount: {
total: maxMintLimitForCurrentUser.value,
available: availableNfts.value,
},
}))

const mintButtonLabel = computed(() => {
return isWalletConnecting.value
? $i18n.t('shoppingCart.wallet')
: isLogIn.value
? isHolderOfTargetCollection.value &&
maxMintLimitForCurrentUser.value > mintedAmountForCurrentUser.value
maxMintLimitForCurrentUser.value > mintedAmountForCurrentUser.value &&
hasMinimumFunds.value &&
hasAvailableNfts.value
? $i18n.t('mint.unlockable.claimPaidNft', [
`${depositAmount.value} ${depositChainSymbol.value}`,
])
: $i18n.t('mint.unlockable.notEligibility')
: $i18n.t('mint.unlockable.checkEligibility')
})
const mintButtonDisabled = computed(
const mintButtonDisabled = computed<boolean>(
() =>
!mintCountAvailable.value ||
disabledByBackend.value ||
Boolean(disabledByBackend.value) ||
(isLogIn.value &&
Boolean(
!selectedImage.value ||
!isHolderOfTargetCollection.value ||
maxMintLimitForCurrentUser.value <= mintedAmountForCurrentUser.value,
maxMintLimitForCurrentUser.value <=
mintedAmountForCurrentUser.value ||
!hasMinimumFunds.value ||
!hasAvailableNfts.value,
)),
)

Expand Down Expand Up @@ -340,10 +366,21 @@ const submitMint = async (sn: string) => {
}
}

const checkAvailableNfts = async () => {
const nftEntities = holderOfCollectionData.value?.nftEntities || []
const nftIds = nftEntities.map((nft) => nft.sn)
const claimed = await Promise.all(
nftIds.map((sn) => isNftClaimed(sn, holderOfCollectionId)),
)
availableNfts.value = claimed.filter((x) => !x).length
}

const handleDropAddModalConfirm = () => {
closeAddFundModal()
fetchMultipleBalance([urlPrefix.value])
}

watch(holderOfCollectionData, checkAvailableNfts, { immediate: true })
</script>

<style scoped lang="scss">
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,140 @@
<template>
<div>
<p class="text-k-grey mb-5">
{{ $t('mint.unlockable.requirements') }}
</p>

<div>
<div class="flex justify-between">
<div class="flex gap-4 flex-col w-full">
<MintRequirementItem
v-if="showHolderOfCollection && collection"
:fulfilled="fulfillsHolderOfCollection">
<div class="flex justify-between items-center w-full">
<p class="capitalize">
Holder of NFT from
<nuxt-link
class="has-text-link"
:to="`/${urlPrefix}/collection/${props.holderOfCollection.id}`">
{{ collection?.name }}
</nuxt-link>
collection
</p>
<div v-if="!isMintedOut" class="text-xs">
<span class="text-k-grey capitalize mr-2">
{{ $t('mint.unlockable.availableForMint') }}
</span>
<span
>{{ props.holderOfCollection.amount?.available }}/{{
props.holderOfCollection.amount?.total
}}</span
>

<NeoTooltip
position="top"
multiline
multiline-width="15rem"
root-class="ml-2"
content-class="capitalize">
<NeoIcon
icon="fa-info-circle"
pack="fa-regular"
class="text-k-grey" />

<template #content>
<p
v-dompurify-html="
$t('mint.unlockable.holderOfWarning1', [
collection?.name,
])
"
class="mb-3" />
<p
v-dompurify-html="
$t('mint.unlockable.holderOfWarning2')
" />
</template>
</NeoTooltip>
</div>
</div>
</MintRequirementItem>
<MintRequirementItem :fulfilled="fulfillsMinimumFunds">
<p v-dompurify-html="minimumFunds.description" />
</MintRequirementItem>
</div>
</div>

<div
class="flex items-start md:items-center mt-6 flex-col md:flex-row"
:class="[isMintedOut ? 'justify-end' : 'justify-between']">
<div
v-if="!isMintedOut"
class="border px-2 py-1 rounded-full h-fit w-fit capitalize text-xs flex"
:class="[readyToMint ? 'bg-k-green-accent' : 'bg-neutral-5']">
<p>
{{ mintLabel }}
</p>

<NeoIcon v-if="readyToMint" class="ml-1" icon="check" />
</div>

<div class="mt-[24px] md:mt-0">
<slot />
</div>
</div>
</div>
</div>
</template>

<script setup lang="ts">
import MintRequirementItem from './MintRequirementItem.vue'
import { useCollectionMinimal } from '@/components/collection/utils/useCollectionDetails'
import { NeoIcon, NeoTooltip } from '@kodadot1/brick'
import type { HolderOfCollectionProp } from '../HolderOfGenerative.vue'

const props = defineProps<{
holderOfCollection: HolderOfCollectionProp
minimumFunds: { amount: number; description: string; hasAmount: boolean }
isMintedOut: boolean
}>()

const { $i18n } = useNuxtApp()
const { urlPrefix } = usePrefix()
const { accountId } = useAuth()

const { collection } = useCollectionMinimal({
collectionId: computed(() => props.holderOfCollection.id || ''),
})

const showHolderOfCollection = computed(() => !!props.holderOfCollection.id)

const fulfillsHolderOfCollection = computed(
() =>
Boolean(props.holderOfCollection.isHolder) &&
props.holderOfCollection.hasAvailable,
)

const fulfillsMinimumFunds = computed(
() => Boolean(props.minimumFunds.amount) && props.minimumFunds.hasAmount,
)

const readyToMint = computed(
() => fulfillsHolderOfCollection.value && fulfillsMinimumFunds.value,
)

const availableForMint = computed(
() => props.holderOfCollection.amount?.available || 0,
)

const mintLabel = computed(() => {
if (!accountId.value) {
return $i18n.t('mint.unlockable.connectWallet')
}

if (readyToMint.value) {
return $i18n.t('mint.unlockable.readyToMint', [availableForMint.value])
}

return $i18n.t('mint.unlockable.requirementsNotMet')
})
</script>
Loading