Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: Resolve duplicate definition, logical checks, and error handling… #374

Open
wants to merge 1 commit into
base: dev
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 12 additions & 8 deletions packages/core-sdk/src/resources/nftClient.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand All @@ -43,13 +43,16 @@ export class NftClient {
*/
public async createNFTCollection(
request: CreateNFTCollectionRequest,
): Promise<CreateNFTCollectionResponse> {
): Promise<CreateNFTCollectionResponse | undefined> {
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 = {
Expand Down Expand Up @@ -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
}
}
}
Loading