Skip to content

Commit

Permalink
Merge pull request #10890 from kodadot/refactor--drop-store-value
Browse files Browse the repository at this point in the history
refactor: drop store value
  • Loading branch information
preschian authored Aug 26, 2024
2 parents e2e16b8 + 3bb671a commit 090d8af
Show file tree
Hide file tree
Showing 8 changed files with 46 additions and 88 deletions.
4 changes: 0 additions & 4 deletions components/collection/drop/MintButton.vue
Original file line number Diff line number Diff line change
Expand Up @@ -90,9 +90,6 @@ const label = computed(() => {
if (isCheckingMintRequirements.value) {
return $i18n.t('checking')
}
if (drop.value.userAccess === false) {
return $i18n.t('mint.unlockable.notEligibility')
}
if (isMintNotLive.value) {
return $i18n.t('mint.unlockable.mintingNotLive')
Expand Down Expand Up @@ -131,7 +128,6 @@ const enabled = computed(() => {
|| !previewItem.value // no image
|| isCheckingMintRequirements.value // still checking requirements
|| loading.value // still loading
|| drop.value.userAccess === false // no access due to geofencing
) {
return false
}
Expand Down
54 changes: 32 additions & 22 deletions components/drops/useDrops.ts
Original file line number Diff line number Diff line change
Expand Up @@ -171,7 +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 { isEvm } = useIsChain(usePrefix().urlPrefix)

const drop = computed({
get: () => dropStore.drop,
Expand All @@ -182,31 +182,42 @@ export function useDrop(alias?: string) {
const token = computed(() => prefixToToken[drop.value?.chain ?? 'ahp'])

const fetchDrop = async () => {
drop.value = await getDropById(alias ?? params.id.toString())
// get some offchain data
const campaign = await getDropById(alias ?? params.id.toString())
const offChainData = {
id: campaign.id,
chain: campaign.chain,
alias: campaign.alias,
collection: campaign.collection,
type: campaign.type,
disabled: campaign.disabled,
start_at: campaign.start_at,
holder_of: campaign.holder_of,

// would be nice if we could get this from the onchain
price: campaign.price,
creator: campaign.creator,
}

if (!drop.value.collection) {
const address = campaign.collection
if (!address) {
return
}

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
// get some onchain data
const { maxSupply: supply, minted, metadata } = isEvm.value ? await evmCollection(address as `0x${string}`, usePrefix().urlPrefix.value) : await subCollection(address)
const onChainData = {
max: supply,
minted: minted || await fetchDropMintedCount(drop.value),
name: metadata.name,
collectionName: metadata.name,
collectionDescription: metadata.description,
image: metadata.image,
banner: metadata.banner || metadata.image,
content: metadata.generative_uri || campaign.content,
}

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
}
drop.value = { ...offChainData, ...onChainData }
}

watch(() => params.id, fetchDrop)
Expand Down Expand Up @@ -249,10 +260,9 @@ export const useDropMinimumFunds = (amount = ref(1)) => {
const { fetchMultipleBalance, transferableCurrentChainBalance }
= useMultipleBalance()

const meta = computed<number>(() => Number(drop.value?.meta) || 0)
const price = computed<number>(() => Number(drop.value?.price) || 0)
const minimumFunds = computed<number>(() =>
price.value ? amount.value * price.value : meta.value,
price.value ? amount.value * price.value : 0,
)
const hasMinimumFunds = computed(
() =>
Expand Down
59 changes: 1 addition & 58 deletions params/types.ts
Original file line number Diff line number Diff line change
@@ -1,64 +1,11 @@
// Copyright 2017-2019 @polkadot/react-components authors & contributors
// This software may be modified and distributed under the terms
// of the Apache-2.0 license. See the LICENSE file for details.

import type { TypeDef } from '@polkadot/types/types'
// import { BareProps } from '@polkadot/react-components/types';
import type { Prefix } from '@kodadot1/static'

// FIXME Ideally, we want these as Base from api-codec - as a stop-gap, any this until we have
// params returning types extending Base (i.e. anything from api-codec)
export type RawParamValue = any | undefined

export type RawParamValueArray = (RawParamValue | RawParamValue[])[]

export type RawParamValues = RawParamValue | RawParamValueArray

export interface RawParam {
isValid: boolean
value: RawParamValues
}

export interface RawParamOnChangeValue {
isValid: boolean
value: RawParamValues
}
export type RawParamOnChange = (value: RawParamOnChangeValue) => void
export type RawParamOnEnter = () => void

export type RawParams = RawParam[]

// export interface BaseProps extends BareProps {
// defaultValue: RawParam;
// name?: string;
// onChange?: RawParamOnChange;
// onEnter?: RawParamOnEnter;
// type: TypeDef;
// }

// export interface Props extends BaseProps {
// isDisabled?: boolean;
// isError?: boolean;
// isReadOnly?: boolean;
// label?: React.ReactNode;
// withLabel?: boolean;
// }

export type Size = 'full' | 'large' | 'medium' | 'small'

export type ComponentMap = Record<string, Vue.Component>

export interface Unit {
name: string
value: number
}

export interface ParamDef {
name?: string
type: TypeDef
}

export type DropType = 'paid' | 'free' | 'holder'
type DropType = 'paid' | 'free' | 'holder'

export type DropItem = {
id: string
Expand All @@ -72,15 +19,11 @@ export type DropItem = {
content: string
alias: string
type: DropType
meta: string
disabled: number
minted: number
max?: number
price?: string
holder_of?: string
location?: string
userLocation?: string
userAccess?: boolean
start_at?: string
creator?: string
}
1 change: 0 additions & 1 deletion stores/drop.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ const DEFAULT_DROP: Omit<DropItem, 'chain'> = {
content: '',
alias: '',
type: 'paid',
meta: '',
disabled: 0,
}
interface State {
Expand Down
2 changes: 1 addition & 1 deletion tests/e2e/drops.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ test('Drop page verification', async ({ page, Commands }) => {

test('View Collection', async ({ page }) => {
await page.goto(addresses[0])
await page.waitForTimeout(2000)
await page.waitForLoadState('networkidle')
await expect(page.getByTestId('drops-view-collection-button')).toBeVisible()
await page.getByTestId('drops-view-collection-button').click()
await page.waitForTimeout(2000)
Expand Down
3 changes: 2 additions & 1 deletion utils/onchain/evm.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { readContract } from '@wagmi/core'
import type { Prefix } from '@kodadot1/static'
import type { OnChainData } from './types'
import { GENSOL_ABI } from '@/composables/transaction/evm/utils'
import { getEvmCollection } from '@/services/ogi'

Expand Down Expand Up @@ -27,7 +28,7 @@ export const evmCollection = async (address: `0x${string}`, chain: Prefix) => {
getEvmCollection(chain, address),
]) as [bigint, string, { claimed?: string }]

let metadata = { description: '', name: '', image: '' }
let metadata: OnChainData = { description: '', name: '', image: '', generative_uri: '', banner: '' }
if (collectionMetadata) {
metadata = await $fetch(sanitizeIpfsUrl(collectionMetadata))
}
Expand Down
4 changes: 3 additions & 1 deletion utils/onchain/sub.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import type { OnChainData } from './types'

export const subCollection = async (id: string) => {
const api = await useApi().apiInstance.value
const [queryCollectionConfig, queryCollection, queryCollectionMetadata] = await Promise.all([
Expand All @@ -9,7 +11,7 @@ export const subCollection = async (id: string) => {
const collection = queryCollection.toJSON() as unknown as { items?: number }

const collectionMetadata = queryCollectionMetadata.toHuman() as unknown as { data?: string }
let metadata = { description: '', name: '', image: '' }
let metadata: OnChainData = { description: '', name: '', image: '', generative_uri: '', banner: '' }
if (collectionMetadata.data) {
metadata = await $fetch(sanitizeIpfsUrl(collectionMetadata.data))
}
Expand Down
7 changes: 7 additions & 0 deletions utils/onchain/types.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
export type OnChainData = {
name: string
description: string
image: string
banner: string
generative_uri: string
}

0 comments on commit 090d8af

Please sign in to comment.