Skip to content

Commit

Permalink
Merge branch 'main' into issue-10753
Browse files Browse the repository at this point in the history
  • Loading branch information
Jarsen136 committed Aug 11, 2024
2 parents 677727b + afe7159 commit 7408760
Show file tree
Hide file tree
Showing 44 changed files with 304 additions and 267 deletions.
2 changes: 1 addition & 1 deletion .github/diagram.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
2 changes: 1 addition & 1 deletion components/Navbar.vue
Original file line number Diff line number Diff line change
Expand Up @@ -290,7 +290,7 @@ const logoSrc = computed(() => {
const dropsPath = computed(() => {
const prefix = pickByVm({
SUB: 'ahp',
EVM: 'base',
EVM: urlPrefix.value,
})
return `/${prefix}/drops`
})
Expand Down
7 changes: 4 additions & 3 deletions components/carousel/CarouselTypeDrops.vue
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,10 @@
import type { Drop } from '@/components/drops/useDrops'
import { useDrops } from '@/components/drops/useDrops'
import { openReconnectWalletModal } from '@/components/common/ConnectWallet/openReconnectWalletModal'
import { vmOf } from '@/utils/config/chain.config'
let queries = {
limit: 12,
limit: 14,
active: [true],
chain: ['ahp', 'base'],
}
Expand All @@ -48,7 +49,7 @@ if (!isProduction && urlPrefix.value === 'ahk') {
const container = ref()
const { accountId } = useAuth()
const { vmOf } = useChain()
const router = useRouter()
const { cols, isReady: isDynamicGridReady } = useDynamicGrid({
container,
Expand All @@ -63,7 +64,7 @@ const skeletonCount = computed(() =>
Number.isInteger(perView.value) ? perView.value : Math.ceil(perView.value),
)
const { drops, loaded: isReady } = useDrops(queries)
const { drops, loaded: isReady } = useDrops(queries, { filterOutMinted: true })
const dropsAlias = computed(() => drops.value.map(drop => drop.alias))
const onDropClick = ({ path, drop }: { path: string, drop: Drop }) => {
Expand Down
4 changes: 2 additions & 2 deletions components/codeChecker/CodeChecker.vue
Original file line number Diff line number Diff line change
Expand Up @@ -234,11 +234,11 @@ import type { AssetMessage, Validity } from './types'
const RESOURCES_LIST = [
{
title: 'codeChecker.kodahashTemplate',
url: 'https://hello.kodadot.xyz/tutorial/generative-art',
url: 'https://github.com/vikiival/kodahash',
},
{
title: 'codeChecker.learnAboutGenArt',
url: 'https://github.com/vikiival/kodahash',
url: 'https://hello.kodadot.xyz/tutorial/generative-art',
},
{
title: 'codeChecker.codeChecker',
Expand Down
12 changes: 0 additions & 12 deletions components/collection/drop/modal/PaidMint.vue
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,6 @@
:title="title"
:scrollable="false"
:loading="loading"
:custom-skeleton-title="preStepTitle"
:estimated-time="estimedTime"
@close="close"
>
<MintOverview
Expand Down Expand Up @@ -63,8 +61,6 @@ enum ModalStep {
SUCCEEDED = 'succeded',
}
const IPFS_ESTIMATED_TIME_SECONDS = 15
const emit = defineEmits(['confirm', 'update:modelValue', 'list', 'close'])
const props = defineProps<{
modelValue: boolean
Expand Down Expand Up @@ -94,10 +90,6 @@ const isSingleMintNotReady = computed(
() => amountToMint.value === 1 && !canMint.value,
)
const estimedTime = computed(() =>
isSingleMintNotReady.value ? IPFS_ESTIMATED_TIME_SECONDS : undefined,
)
const mintButton = computed(() => {
if (!canMint.value) {
return {
Expand All @@ -117,10 +109,6 @@ const loading = computed(
|| false,
)
const preStepTitle = computed<string | undefined>(() =>
isSingleMintNotReady.value ? $i18n.t('drops.mintDropError') : undefined,
)
const isMintOverviewStep = computed(
() => modalStep.value === ModalStep.OVERVIEW,
)
Expand Down
45 changes: 32 additions & 13 deletions components/collection/drop/modal/shared/SuccessfulDrop.vue
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ const { toast } = useToast()
const { urlPrefix } = usePrefix()
const { accountId } = useAuth()
const { getCollectionFrameUrl } = useSocialShare()
const { toMintNFTs } = storeToRefs(useDropStore())
const cantList = computed(() => !props.canListNfts)
const txHash = computed(() => props.mintingSession.txHash ?? '')
Expand All @@ -42,30 +43,48 @@ const mintedNft = computed<MintedNFT | undefined>(
() => props.mintingSession.items[0],
)
const items = computed<ItemMedia[]>(() =>
props.mintingSession.items.map(item => ({
id: item.id,
name: item.name,
image: item.image,
collection: item.collection.id,
collectionName: item.collection.name,
mimeType: item.mimeType,
})),
)
const itemMedias = props.mintingSession.items.map(item => ({
id: item.id,
name: item.name,
image: item.image,
collection: item.collection.id,
collectionName: item.collection.name,
mimeType: item.mimeType,
metadata: item.metadata,
}))
const items = ref<ItemMedia[]>(itemMedias)
// update serial number in nft.name asynchronously
onMounted(async () => {
const metadatas = await Promise.all(
items.value.map(item => $fetch<{ name?: string }>(item.metadata)),
)
items.value.forEach((_, index) => {
const metadata = metadatas[index]
if (metadata.name) {
items.value[index].name = metadata.name
toMintNFTs.value[index].name = metadata.name
}
})
})
const nftPath = computed(
() => `/${mintedNft.value?.chain}/gallery/${mintedNft.value?.id}`,
() =>
`/${mintedNft.value?.chain}/gallery/${mintedNft.value?.collection.id}-${mintedNft.value?.id}`,
)
const nftFullUrl = computed(() => `${window.location.origin}${nftPath.value}`)
const userProfilePath = computed(
() => `/${urlPrefix.value}/u/${accountId.value}`,
)
const getItemSn = (name: string) => `#${name.split('#')[1]}`
const sharingTxt = computed(() =>
singleMint.value
? $i18n.t('sharing.dropNft', [`#${mintedNft.value?.index}`])
? $i18n.t('sharing.dropNft', [getItemSn(items.value[0].name)])
: $i18n.t('sharing.dropNfts', [
props.mintingSession.items.map(item => `#${item.index}`).join(', '),
items.value.map(item => getItemSn(item.name)).join(', '),
]),
)
Expand Down
4 changes: 2 additions & 2 deletions components/collection/drop/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,8 @@ export type MintedNFT = {
chain: string
name: string
image: string
index: number
collection: { id: string, name: string, max: number }
collection: { id: string, name: string, max?: number }
metadata: string
mimeType?: string
}

Expand Down
1 change: 1 addition & 0 deletions components/common/successfulModal/SuccessfulItemsMedia.vue
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ export type ItemMedia = {
collectionName: string
price?: string
mimeType?: string
metadata: string
}
const props = defineProps<{
Expand Down
6 changes: 4 additions & 2 deletions components/create/CreateCollection.vue
Original file line number Diff line number Diff line change
Expand Up @@ -277,8 +277,10 @@ const royalty = ref({
})
const menus = availablePrefixes().filter(
menu => menu.value !== 'ksm' && menu.value !== 'rmrk',
)
(menu) => {
const { isRemark, isEvm } = useIsChain(computed(() => menu.value as Prefix))
return !isRemark.value && !isEvm.value
})
const chainByPrefix = menus.find(menu => menu.value === urlPrefix.value)
const selectBlockchain = ref(chainByPrefix?.value || menus[0].value)
Expand Down
7 changes: 5 additions & 2 deletions components/create/CreateNft.vue
Original file line number Diff line number Diff line change
Expand Up @@ -393,8 +393,11 @@ const imagePreview = computed(() => {
// select available blockchain
const menus = availablePrefixes().filter(
menu => menu.value !== 'ksm' && menu.value !== 'rmrk',
)
(menu) => {
const { isRemark, isEvm } = useIsChain(computed(() => menu.value as Prefix))
return !isRemark.value && !isEvm.value
})
const chainByPrefix = computed(() =>
menus.find(menu => menu.value === urlPrefix.value),
)
Expand Down
6 changes: 4 additions & 2 deletions components/drops/Drops.vue
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@
:drops="currentDrops"
:loaded="loaded"
:default-skeleton-count="DEFAULT_SKELETON_COUNT"
:async-skeleton-count="Math.round((count/2) - currentDrops.length)"
:async-skeleton-count="asyncSkeletonCountOf(currentDrops.length)"
skeleton-key="current-drops-skeleton"
/>

Expand All @@ -56,7 +56,7 @@
:drops="pastDrops"
:loaded="loaded"
:default-skeleton-count="DEFAULT_SKELETON_COUNT"
:async-skeleton-count="Math.round((count/2) - pastDrops.length)"
:async-skeleton-count="asyncSkeletonCountOf(pastDrops.length)"
skeleton-key="skeleton"
/>

Expand Down Expand Up @@ -96,6 +96,8 @@ const pastDrops = computed(() =>
filter(drops.value, { status: DropStatus.MINTING_ENDED }),
)
const asyncSkeletonCountOf = (amount: number) => count.value ? Math.max(0, Math.round((count.value) / 2) - amount) : DEFAULT_SKELETON_COUNT
const checkRouteAvailability = () => {
if (!dropsVisible(urlPrefix.value)) {
navigateTo('/')
Expand Down
8 changes: 5 additions & 3 deletions components/drops/DropsGrid.vue
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
persist
>
<template
v-if="asyncSkeletonCount ? true : loaded"
v-if="isAsync || loaded"
>
<div
v-for="(drop, index) in drops"
Expand All @@ -23,7 +23,7 @@
</template>
<template v-if="!loaded">
<DropsDropCardSkeleton
v-for="x in asyncSkeletonCount || defaultSkeletonCount"
v-for="x in isAsync ? asyncSkeletonCount : defaultSkeletonCount"
:key="`${skeletonKey}-${x}`"
/>
</template>
Expand All @@ -41,7 +41,7 @@ const GRID_DEFAULT_WIDTH = {
large: 0,
}
defineProps<{
const props = defineProps<{
drops: Drop[] | InternalDropCalendar[]
loaded: boolean
defaultSkeletonCount: number
Expand All @@ -50,6 +50,8 @@ defineProps<{
clickable?: boolean
}>()
const isAsync = computed(() => typeof props.asyncSkeletonCount === 'number')
const isDrop = (item: Drop | InternalDropCalendar): item is Drop =>
(item as Drop).collection !== undefined
</script>
4 changes: 2 additions & 2 deletions components/drops/useDrops.ts
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ const DROP_LIST_ORDER = [

const ONE_DAYH_IN_MS = 24 * 60 * 60 * 1000

export function useDrops(query?: GetDropsQuery, { async = false }: { async?: boolean } = { }) {
export function useDrops(query?: GetDropsQuery, { async = false, filterOutMinted = false }: { async?: boolean, filterOutMinted?: boolean } = { }) {
const drops = ref<Drop[]>([])
const dropsList = ref<DropItem[]>([])
const count = computed(() => dropsList.value.length)
Expand Down Expand Up @@ -79,7 +79,7 @@ export function useDrops(query?: GetDropsQuery, { async = false }: { async?: boo
else {
drops.value = await Promise.all(
dropsList.value.map(async drop => getFormattedDropItem(drop, drop)),
)
).then(dropsList => filterOutMinted ? dropsList.filter(drop => !drop.isMintedOut) : dropsList)

loaded.value = true
}
Expand Down
78 changes: 45 additions & 33 deletions composables/drop/massmint/useDropMassMint.ts
Original file line number Diff line number Diff line change
@@ -1,36 +1,65 @@
import { useCollectionEntity } from '../useGenerativeDropMint'
import type { ToMintNft } from '@/components/collection/drop/types'
import type { DoResult } from '@/services/fxart'
import { updateMetadata } from '@/services/fxart'
import { generateId, setDyndataUrl } from '@/services/dyndata'

export type MassMintNFT = Omit<ToMintNft, 'priceUSD'> & {
metadata?: string
image: string
metadata: string
nft: number // nft id
sn?: number // serial numbers
}

export default () => {
const dropStore = useDropStore()
const { collectionName } = useCollectionEntity()

const { drop, amountToMint, toMintNFTs, loading } = storeToRefs(dropStore)
const { isSub } = useIsChain(usePrefix().urlPrefix)

// ensure tokenIds are unique on single user session
const tokenIds = ref<number[]>([])
const populateTokenIds = async () => {
for (const _ of Array.from({ length: amountToMint.value })) {
const tokenId = Number.parseInt(await generateId())
if (!tokenIds.value.includes(tokenId)) {
tokenIds.value.push(tokenId)
}
}

if (tokenIds.value.length < amountToMint.value) {
await populateTokenIds()
}
}

const clearMassmint = () => {
const clearMassMint = () => {
dropStore.resetMassmint()
tokenIds.value = []
}

const massGenerate = async () => {
try {
clearMassmint()
clearMassMint()
if (isSub.value) {
await populateTokenIds()
}

toMintNFTs.value = Array.from({ length: amountToMint.value }).map(
(_, index) => {
const { image, metadata } = setDyndataUrl({
chain: drop.value.chain,
collection: drop.value.collection,
nft: tokenIds.value[index],
})

toMintNFTs.value = Array.from({ length: amountToMint.value }).map(() => {
return {
name: drop.value.name,
collectionName: collectionName.value,
price: drop.value.price?.toString() || '',
nft: parseInt(uidMathDate()),
}
})
return {
name: drop.value.name,
collectionName: collectionName.value,
price: drop.value.price?.toString() || '',
nft: tokenIds.value[index],
metadata,
image,
}
},
)

console.log('[MASSMINT::GENERATE] Generated', toRaw(toMintNFTs.value))
}
Expand All @@ -40,27 +69,10 @@ export default () => {
}
}

const submitMint = async (nft: MassMintNFT): Promise<DoResult> => {
return new Promise((resolve, reject) => {
try {
updateMetadata({
chain: drop.value.chain,
collection: drop.value.collection,
nft: nft.nft,
sn: nft.sn,
}).then(result => resolve(result))
}
catch (e) {
reject(e)
}
})
}

onBeforeUnmount(clearMassmint)
onBeforeUnmount(clearMassMint)

return {
massGenerate,
submitMint,
clearMassMint: clearMassmint,
clearMassMint,
}
}
Loading

0 comments on commit 7408760

Please sign in to comment.