Skip to content

Commit

Permalink
generalize asset to create
Browse files Browse the repository at this point in the history
  • Loading branch information
antho1404 committed Dec 23, 2022
1 parent 9104269 commit 7b789e8
Showing 1 changed file with 18 additions and 23 deletions.
41 changes: 18 additions & 23 deletions packages/hooks/src/useCreateNFT.ts
Original file line number Diff line number Diff line change
Expand Up @@ -196,32 +196,30 @@ export default function useCreateNFT(
isAnimation,
isPrivate,
})
const metadata: MetadataInput = {
name,
image: media.image,
description,
animationUrl: media.animationUrl,
unlockableContent: media.unlockableContent,
attributes: (traits || []).map((x) => ({
traitType: x.type,
value: x.value,
})),
const assetToCreate = {
creatorAddress: account.toLowerCase(),
royalties: royalties ? Math.round(royalties * 100) : null,
supply: amount ? amount.toString() : '1',
metadata: {
name,
image: media.image,
description,
animationUrl: media.animationUrl,
unlockableContent: media.unlockableContent,
attributes: (traits || []).map((x) => ({
traitType: x.type,
value: x.value,
})),
},
}

// lazy minting
if ((await config).hasLazyMint) {
const assetToCreate = {
creatorAddress: account.toLowerCase(),
royalties: royalties ? Math.round(royalties * 100) : null,
supply: amount ? amount.toString() : '1',
metadata: metadata,
} as LazyMintedAssetSignatureInput

const { createLazyMintedAssetSignature } =
await sdk.CreateLazyMintedAssetSignature({
chainId: chainId,
collectionAddress: collectionAddress,
asset: assetToCreate,
asset: assetToCreate as LazyMintedAssetSignatureInput, // TODO: remove this cast when attributes from the API are removed
})

invariant(
Expand All @@ -244,7 +242,7 @@ export default function useCreateNFT(
signature,
asset: {
tokenId: message.tokenId,
...assetToCreate,
...(assetToCreate as LazyMintedAssetSignatureInput), // TODO: remove this cast when attributes from the API are removed
},
})
invariant(
Expand All @@ -257,10 +255,7 @@ export default function useCreateNFT(
const { createAssetTransaction } = await sdk.CreateAssetTransaction({
chainId: chainId,
collectionAddress: collectionAddress,
creatorAddress: account.toLowerCase(),
metadata: metadata,
supply: amount ? amount.toString() : '1',
royalties: royalties ? Math.round(royalties * 100) : 0,
...assetToCreate,
})
invariant(
createAssetTransaction,
Expand Down

0 comments on commit 7b789e8

Please sign in to comment.