Skip to content

Commit

Permalink
ref(transaction): transactionUpdateCollection optional update metadata
Browse files Browse the repository at this point in the history
  • Loading branch information
hassnian committed Nov 23, 2024
1 parent 8907dc0 commit 492f13b
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 11 deletions.
16 changes: 14 additions & 2 deletions components/collection/HeroButtonEditCollection.vue
Original file line number Diff line number Diff line change
Expand Up @@ -44,11 +44,20 @@ const collectinoMetadata = computed(() =>
description: props.collection.meta.description,
image: props.collection.meta.image,
imageType: props.collection.meta.type,
banner: props.collection.meta.banner,
banner: props.collection.meta.banner || undefined,
max: props.collection.max,
} as CollectionEditMetadata
: null)
const updateMetadata = (a: UpdateCollection, b: UpdateCollection) => {
const getMetadataKey = (m: UpdateCollection) => {
const { max, ...rest } = m
return JSON.stringify(rest)
}
return getMetadataKey(a) !== getMetadataKey(b)
}
const editCollection = async (collection: UpdateCollection) => {
isModalActive.value = false
Expand All @@ -60,7 +69,10 @@ const editCollection = async (collection: UpdateCollection) => {
interaction: Collections.UPDATE_COLLECTION,
collectionId: route.params.id.toString(),
collection,
update: { max: collection.max !== collectinoMetadata.value.max },
update: {
metadata: updateMetadata(collection, collectinoMetadata.value),
max: collection.max !== collectinoMetadata.value.max,
},
urlPrefix: urlPrefix.value,
successMessage: $i18n.t('edit.collection.success'),
})
Expand Down
14 changes: 7 additions & 7 deletions composables/transaction/transactionUpdateCollection.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { createMetadata, unSanitizeIpfsUrl } from '@kodadot1/minimark/utils'
import type { SubmittableExtrinsic } from '@polkadot/api-base/types'
import { uploadMediaFiles } from './mintToken/constructDirectoryMeta'
import type { ActionUpdateCollection, UpdateCollectionParams } from './types'
import { pinFileToIPFS, pinJson } from '@/services/nftStorage'
Expand Down Expand Up @@ -63,16 +64,15 @@ async function execUpdateCollectionStatmine({ item, api, executeTransaction, isL
isLoading.value = true
status.value = 'loader.ipfs'

const metadata = await constructMeta(item)
const args: SubmittableExtrinsic<'promise'>[] = []

const collectionId = item.collectionId.toString()

const args = [
api.tx.nfts.setCollectionMetadata(collectionId, metadata),
]
if (item.update.metadata) {
const metadata = await constructMeta(item)
args.push(api.tx.nfts.setCollectionMetadata(item.collectionId, metadata))
}

if (item.update.max) {
args.push(api.tx.nfts.setCollectionMaxSupply(collectionId, item.collection.max ? item.collection.max : undefined))
args.push(api.tx.nfts.setCollectionMaxSupply(item.collectionId, item.collection.max ? item.collection.max : undefined))
}

executeTransaction({
Expand Down
2 changes: 1 addition & 1 deletion composables/transaction/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -297,7 +297,7 @@ export interface ActionUpdateCollection {
interaction: Collections.UPDATE_COLLECTION
collectionId: string
collection: UpdateCollection
update: { max: boolean }
update: { max: boolean, metadata: boolean }
urlPrefix: string
successMessage?: string | ((blockNumber: string) => string)
errorMessage?: string
Expand Down
2 changes: 1 addition & 1 deletion composables/transaction/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ export function isActionValid(action: Actions): boolean {
[Collections.DELETE]: (action: ActionDeleteCollection) =>
Boolean(action.collectionId),
[Collections.UPDATE_COLLECTION]: (action: ActionUpdateCollection) =>
Boolean(action.collectionId),
Boolean(action.collectionId) && (action.update.metadata || action.update.max),
[NFTs.BURN_MULTIPLE]: (action: ActionBurnMultipleNFTs) =>
hasContent(action.nftIds),
[NFTs.SET_METADATA]: (action: ActionSetNftMetadata) =>
Expand Down

0 comments on commit 492f13b

Please sign in to comment.