Skip to content

Commit

Permalink
chore: CollectionMintSettingType type
Browse files Browse the repository at this point in the history
  • Loading branch information
Jarsen136 committed Jan 1, 2025
1 parent 194f864 commit 9de8a8d
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 16 deletions.
20 changes: 10 additions & 10 deletions components/collection/EditModal.vue
Original file line number Diff line number Diff line change
Expand Up @@ -225,7 +225,7 @@
<script setup lang="ts">
import { NeoButton, NeoField, NeoInput, NeoModal, NeoSwitch, NeoSelect, NeoIcon } from '@kodadot1/brick'
import ModalBody from '@/components/shared/modals/ModalBody.vue'
import type { UpdateCollection, CollectionMintSetting, CollectionMintSettingType } from '@/composables/transaction/types'
import { type UpdateCollection, type CollectionMintSetting, CollectionMintSettingType } from '@/composables/transaction/types'
export type CollectionEditMetadata = {
name: string
Expand All @@ -237,7 +237,7 @@ export type CollectionEditMetadata = {
mintingSettings: CollectionMintSetting
}
const COLLECTION_MINTING_TYPES_OPTIONS = (['Issuer', 'Public', 'HolderOf'] as CollectionMintSettingType[]).map(type => ({ value: type, text: type }))
const COLLECTION_MINTING_TYPES_OPTIONS = ([CollectionMintSettingType.Issuer, CollectionMintSettingType.Public, CollectionMintSettingType.HolderOf]).map(type => ({ value: type, text: type }))
const emit = defineEmits(['submit'])
const props = defineProps<{
Expand Down Expand Up @@ -272,7 +272,7 @@ const mintPriceChanged = computed(() => mintingPrice.value !== originalMintPrice
const originalMintPrice = computed(() => props.collection.mintingSettings.price ? Number(props.collection.mintingSettings.price) / (10 ** decimals.value) : null)
const originalHolderOfCollectionId = computed(() => props.collection.mintingSettings.holderOf)
const holderOfCollectionId = ref<string | undefined>(originalHolderOfCollectionId.value)
const isHolderOfMintingTypeSelected = computed(() => selectedMintingType.value === 'HolderOf')
const isHolderOfMintingTypeSelected = computed(() => selectedMintingType.value === CollectionMintSettingType.HolderOf)
const disabled = computed(() => {
const hasImage = imageUrl.value
Expand Down Expand Up @@ -333,34 +333,34 @@ watch(isModalActive, (value) => {
immediate: true,
})
const mintTypeChangeHandlerMap: Record<CollectionMintSettingType, () => void> = {
Issuer: () => {
[CollectionMintSettingType.Issuer]: () => {
hasMintingPrice.value = false
mintingPrice.value = null
},
Public: () => {
[CollectionMintSettingType.Public]: () => {
hasMintingPrice.value = true
mintingPrice.value = null
},
HolderOf: () => {
[CollectionMintSettingType.HolderOf]: () => {
hasMintingPrice.value = false
mintingPrice.value = null
holderOfCollectionId.value = undefined
},
}
const permissionSettingCheckingMap: Record<CollectionMintSettingType, () => string | undefined> = {
Issuer: () => {
[CollectionMintSettingType.Issuer]: () => {
if (mintingPrice.value) {
return $i18n.t('mint.collection.permission.issuerWarning')
}
},
Public: () => {
[CollectionMintSettingType.Public]: () => {
if (!mintingPrice.value || mintingPrice.value <= 0) {
return $i18n.t('mint.collection.permission.publicWarning')
}
return $i18n.t('mint.collection.permission.publicWithPriceWarning')
},
HolderOf: () => {
[CollectionMintSettingType.HolderOf]: () => {
if (!holderOfCollectionId.value) {
return $i18n.t('mint.collection.permission.holderOfIdWarning')
}
Expand All @@ -370,7 +370,7 @@ const permissionSettingCheckingMap: Record<CollectionMintSettingType, () => stri
watch(selectedMintingType, (type, oldType) => {
if (oldType && type && mintTypeChangeHandlerMap[type]) {
mintTypeChangeHandlerMap[type as CollectionMintSettingType]()
mintTypeChangeHandlerMap[type]()
}
})
Expand Down
6 changes: 3 additions & 3 deletions components/collection/HeroButtonEditCollection.vue
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
<script setup lang="ts">
import { NeoDropdownItem } from '@kodadot1/brick'
import { type CollectionEditMetadata } from '@/components/collection/EditModal.vue'
import { type CollectionMintSettingType, Collections, type UpdateCollection, type CollectionMintSetting } from '@/composables/transaction/types'
import { CollectionMintSettingType, Collections, type UpdateCollection, type CollectionMintSetting } from '@/composables/transaction/types'
const props = defineProps<{
collection: any
Expand Down Expand Up @@ -63,7 +63,7 @@ const updateMetadata = (a: UpdateCollection, b: UpdateCollection) => {
}
const shouldUpdatePermission = (a: CollectionMintSetting, b: CollectionMintSetting) => {
return a.price !== b.price || a.mintType !== b.mintType
return a.price !== b.price || a.mintType !== b.mintType || a.holderOf !== b.holderOf
}
const editCollection = async (updatedCollection?: UpdateCollection) => {
Expand Down Expand Up @@ -108,7 +108,7 @@ watch(computed(() => collectionId), async () => {
if (typeof mintSettings.mintType !== 'string') {
mintSettings.holderOf = (mintSettings.mintType as any as { HolderOf: string }).HolderOf
mintSettings.mintType = 'HolderOf'
mintSettings.mintType = CollectionMintSettingType.HolderOf
}
collectionPermissionSettings.value = mintSettings
}, {
Expand Down
4 changes: 2 additions & 2 deletions composables/transaction/transactionUpdateCollection.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { createOpenSeaMetadata as createMetadata, protocolize } from '@kodadot1/hyperdata'
import type { SubmittableExtrinsic } from '@polkadot/api-base/types'
import { uploadMediaFiles } from './mintToken/constructDirectoryMeta'
import type { ActionUpdateCollection, UpdateCollectionParams } from './types'
import { CollectionMintSettingType, type ActionUpdateCollection, type UpdateCollectionParams } from './types'
import { pinFileToIPFS, pinJson } from '@/services/nftStorage'

const getIpfsMedia = async ({ collection: { image, banner, imageType } }: ActionUpdateCollection) => {
Expand Down Expand Up @@ -76,7 +76,7 @@ async function execUpdateCollectionStatmine({ item, api, executeTransaction, isL
}

if (item.update.permission) {
if (item.collection.mintingSettings.mintType === 'HolderOf') {
if (item.collection.mintingSettings.mintType === CollectionMintSettingType.HolderOf) {
args.push(api.tx.nfts.updateMintSettings(item.collectionId, {
price: item.collection.mintingSettings.price,
mintType: {
Expand Down
7 changes: 6 additions & 1 deletion composables/transaction/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -310,7 +310,12 @@ export interface ActionSetNftMetadata {
errorMessage?: string
}

export type CollectionMintSettingType = 'Issuer' | 'Public' | 'HolderOf'
export enum CollectionMintSettingType {
Issuer = 'Issuer',
Public = 'Public',
HolderOf = 'HolderOf',
}

export type CollectionMintSetting = {
price: string
mintType: CollectionMintSettingType
Expand Down

0 comments on commit 9de8a8d

Please sign in to comment.