Skip to content

Commit

Permalink
[skip upload metadata] add skip rule (#145)
Browse files Browse the repository at this point in the history
  • Loading branch information
mike-diamond authored Aug 1, 2024
1 parent 803fbb3 commit ba0e064
Show file tree
Hide file tree
Showing 6 changed files with 22 additions and 19 deletions.
2 changes: 1 addition & 1 deletion src/methods/vault/transactions/create/common.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
7 changes: 1 addition & 6 deletions src/methods/vault/transactions/create/createVaultEncode.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
7 changes: 1 addition & 6 deletions src/methods/vault/transactions/create/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
2 changes: 1 addition & 1 deletion src/methods/vault/transactions/create/types.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ export type CreateVaultCommonInput = Omit<BaseInput, 'vaultAddress'> & {
export type CreateVaultInput = CreateVaultCommonInput & UploadMetadataInput

export type CreateVaultTransactionInput = CreateVaultCommonInput & {
metadataIpfsHash: string | null
metadataIpfsHash?: string
}

export interface CreateVault {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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({
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { vaultMulticall } from '../../../../../contracts'


type SetMetadataParams = {
metadataIpfsHash: string | null
metadataIpfsHash: string
}

const getMetadataParams = (values: SetMetadataParams) => {
Expand Down

0 comments on commit ba0e064

Please sign in to comment.