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

Optional NFT Types #90

Open
wants to merge 4 commits into
base: development
Choose a base branch
from
Open
Show file tree
Hide file tree
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
22 changes: 15 additions & 7 deletions src/handlers/generate-erc721-permit.ts
Original file line number Diff line number Diff line change
Expand Up @@ -68,9 +68,23 @@ export async function generateErc721PermitSignature(
_userId = contextOrPermitPayload.userId;
} else {
const { NFT_MINTER_PRIVATE_KEY, NFT_CONTRACT_ADDRESS } = contextOrPermitPayload.env;

_logger = contextOrPermitPayload.logger;

if (!NFT_MINTER_PRIVATE_KEY) {
const errorMessage = "NFT minter private key is not defined";
_logger.error(errorMessage);
throw new Error(errorMessage);
}

if (!NFT_CONTRACT_ADDRESS) {
const errorMessage = "NFT contract address is not defined";
_logger.error(errorMessage);
throw new Error(errorMessage);
}

const { evmNetworkId } = contextOrPermitPayload.config;
const adapters = contextOrPermitPayload.adapters;
_logger = contextOrPermitPayload.logger;
_nftContractAddress = NFT_CONTRACT_ADDRESS;
_evmNetworkId = evmNetworkId;
_nftMinterPrivateKey = NFT_MINTER_PRIVATE_KEY;
Expand Down Expand Up @@ -102,12 +116,6 @@ export async function generateErc721PermitSignature(
throw new Error("Provider is not defined");
}

if (!_nftContractAddress) {
const errorMessage = "NFT contract address is not defined";
_logger.error(errorMessage);
throw new Error(errorMessage);
}

Comment on lines -105 to -110
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This block of code was removed since above a validation is already performed when NFT_CONTRACT_ADDRESS is not defined or its string value is empty

let adminWallet;

try {
Expand Down
4 changes: 2 additions & 2 deletions src/types/env.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@ export const envSchema = T.Object({
GITHUB_TOKEN: T.String(),
SUPABASE_URL: T.String(),
SUPABASE_KEY: T.String(),
NFT_MINTER_PRIVATE_KEY: T.String(),
NFT_CONTRACT_ADDRESS: T.String(),
NFT_MINTER_PRIVATE_KEY: T.Optional(T.String()),
NFT_CONTRACT_ADDRESS: T.Optional(T.String()),
});

export type Env = StaticDecode<typeof envSchema>;
2 changes: 1 addition & 1 deletion tests/generate-erc721-permit.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ describe("generateErc721PermitSignature", () => {

it("should throw an error if NFT minter private key is not defined", async () => {
delete process.env.NFT_MINTER_PRIVATE_KEY;
await expect(generateErc721PermitSignature(context, "123", "contribution")).rejects.toThrow("Failed to" + " instantiate wallet");
await expect(generateErc721PermitSignature(context, "123", "contribution")).rejects.toThrow("NFT minter" + " private key" + " is not defined");
Copy link
Author

@luisantoniocrag luisantoniocrag Nov 4, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I Updated the error message in the unit test when NFT_MINTER_PRIVATE_KEY is not defined with a more concise message in this case

expect(context.logger.error).toHaveBeenCalled();
});

Expand Down