diff --git a/src/methods/vault/transactions/create/common.ts b/src/methods/vault/transactions/create/common.ts index 2f2f3d04..d803693e 100644 --- a/src/methods/vault/transactions/create/common.ts +++ b/src/methods/vault/transactions/create/common.ts @@ -7,7 +7,7 @@ import validateCreateVaultArgs from './validateCreateVaultArgs' export const commonLogic = async (values: CreateVaultTransactionInput) => { const { - type = VaultType.Default, vaultToken, capacity, keysManagerFee, isOwnMevEscrow = false, metadataIpfsHash, + type = VaultType.Default, vaultToken, capacity, keysManagerFee, isOwnMevEscrow = false, metadataIpfsHash = '', contracts, userAddress, options, } = values diff --git a/src/methods/vault/transactions/create/createVaultEncode.ts b/src/methods/vault/transactions/create/createVaultEncode.ts index 456eb4ae..fd8d7192 100644 --- a/src/methods/vault/transactions/create/createVaultEncode.ts +++ b/src/methods/vault/transactions/create/createVaultEncode.ts @@ -7,12 +7,7 @@ const createVaultEncode = async (values: CreateVaultInput) => { const { image, displayName, description, ...rest } = values const { options } = rest - let metadataIpfsHash = '' - - if (image || displayName || description) { - metadataIpfsHash = await uploadMetadata({ image, displayName, description, options }) - } - + const metadataIpfsHash = await uploadMetadata({ image, displayName, description, options }) const { vaultFactory, params } = await commonLogic({ metadataIpfsHash, ...rest }) return vaultFactory.createVault.populateTransaction(...params) diff --git a/src/methods/vault/transactions/create/index.ts b/src/methods/vault/transactions/create/index.ts index 3e8b2170..210cebcc 100644 --- a/src/methods/vault/transactions/create/index.ts +++ b/src/methods/vault/transactions/create/index.ts @@ -9,12 +9,7 @@ const create: CreateVault = async (values) => { const { image, displayName, description, ...rest } = values const { provider, options, userAddress } = rest - let metadataIpfsHash = '' - - if (image || displayName || description) { - metadataIpfsHash = await uploadMetadata({ image, displayName, description, options }) - } - + const metadataIpfsHash = await uploadMetadata({ image, displayName, description, options }) const { vaultFactory, params } = await commonLogic({ metadataIpfsHash, ...rest }) const signer = await provider.getSigner(userAddress) diff --git a/src/methods/vault/transactions/create/types.d.ts b/src/methods/vault/transactions/create/types.d.ts index 489abd9e..2aa6865b 100644 --- a/src/methods/vault/transactions/create/types.d.ts +++ b/src/methods/vault/transactions/create/types.d.ts @@ -19,7 +19,7 @@ export type CreateVaultCommonInput = Omit & { export type CreateVaultInput = CreateVaultCommonInput & UploadMetadataInput export type CreateVaultTransactionInput = CreateVaultCommonInput & { - metadataIpfsHash: string | null + metadataIpfsHash?: string } export interface CreateVault { diff --git a/src/methods/vault/transactions/util/metadata/uploadMetadata/index.ts b/src/methods/vault/transactions/util/metadata/uploadMetadata/index.ts index 89ba4456..69f603e3 100644 --- a/src/methods/vault/transactions/util/metadata/uploadMetadata/index.ts +++ b/src/methods/vault/transactions/util/metadata/uploadMetadata/index.ts @@ -13,18 +13,31 @@ type Input = UploadMetadataInput & { } const uploadMetadata = async (input: Input) => { - const { image = '', displayName = '', description = '', options } = input + const skip = [ + input.image, + input.displayName, + input.description, + ] + .every((value) => typeof value === 'undefined') - if (image) { - validateArgs.image(image) + if (skip) { + return } + const { image = '', displayName = '', description = '', options } = input + + validateArgs.string({ image, displayName, description }) + + validateArgs.image(image) + validateArgs.maxLength({ displayName: { value: displayName, length: 30 }, description: { value: description, length: 1000 }, }) - validateArgs.string({ image, displayName, description }) + if (!image && !displayName && !description) { + return '' + } try { const data = await graphql.backend.vault.submitUploadMetadataMutation({ diff --git a/src/methods/vault/transactions/util/params/getMetadataParams.ts b/src/methods/vault/transactions/util/params/getMetadataParams.ts index 2a3d2476..ce31dd5f 100644 --- a/src/methods/vault/transactions/util/params/getMetadataParams.ts +++ b/src/methods/vault/transactions/util/params/getMetadataParams.ts @@ -2,7 +2,7 @@ import { vaultMulticall } from '../../../../../contracts' type SetMetadataParams = { - metadataIpfsHash: string | null + metadataIpfsHash: string } const getMetadataParams = (values: SetMetadataParams) => {