From a1c2d63c9f090601beb23f799f1a5358fc2fc9cb Mon Sep 17 00:00:00 2001 From: Himess <95512809+Himess@users.noreply.github.com> Date: Wed, 1 Jan 2025 03:25:56 +0300 Subject: [PATCH] fix: Resolve duplicate definition, logical checks, and error handling in NFT Client --- packages/core-sdk/src/resources/nftClient.ts | 20 ++++++++++++-------- 1 file changed, 12 insertions(+), 8 deletions(-) diff --git a/packages/core-sdk/src/resources/nftClient.ts b/packages/core-sdk/src/resources/nftClient.ts index 0cd7646e..2611a397 100644 --- a/packages/core-sdk/src/resources/nftClient.ts +++ b/packages/core-sdk/src/resources/nftClient.ts @@ -31,7 +31,7 @@ export class NftClient { * @param request.isPublicMinting - If true, anyone can mint from the collection. If false, only the addresses with the minter role can mint. * @param request.mintOpen Whether the collection is open for minting on creation. * @param request.mintFeeRecipient - The address to receive mint fees. - * @param request.mintFeeRecipient - The contract URI for the collection. Follows ERC-7572 standard. See https://eips.ethereum.org/EIPS/eip-7572 + * @param request.contractURI - The contract URI for the collection. Follows ERC-7572 standard. See https://eips.ethereum.org/EIPS/eip-7572. * @param request.baseURI - [Optional] The base URI for the collection. If baseURI is not empty, tokenURI will be either baseURI + token ID (if nftMetadataURI is empty) or baseURI + nftMetadataURI. * @param request.maxSupply - [Optional] The maximum supply of the collection. * @param request.mintFee - [Optional] The cost to mint a token. @@ -43,13 +43,16 @@ export class NftClient { */ public async createNFTCollection( request: CreateNFTCollectionRequest, - ): Promise { + ): Promise { try { - if ( - request.mintFee !== undefined && - (request.mintFee < 0n || !isAddress(request.mintFeeToken || "")) - ) { - throw new Error("Invalid mint fee token address, mint fee is greater than 0."); + // Validates the mint fee and token + if (request.mintFee !== undefined) { + if (request.mintFee < 0n) { + throw new Error("Mint fee cannot be negative."); + } + if (request.mintFeeToken && !isAddress(request.mintFeeToken)) { + throw new Error("Invalid mint fee token address."); + } } const object: RegistrationWorkflowsCreateCollectionRequest = { @@ -85,13 +88,14 @@ export class NftClient { this.registrationWorkflowsClient.parseTxCollectionCreatedEvent(txReceipt); return { txHash: txHash, - spgNftContract: targetLogs[0].spgNftContract, + spgNftContract: targetLogs[0]?.spgNftContract || "", }; } return { txHash: txHash }; } } catch (error) { handleError(error, "Failed to create a SPG NFT collection"); + return undefined; // Ensures the function always returns a value } } }