Skip to content

Commit

Permalink
Merge pull request #90 from luisantoniocrag/development
Browse files Browse the repository at this point in the history
Optional NFT Types
  • Loading branch information
0x4007 authored Nov 18, 2024
2 parents 961ebeb + 9c3526e commit f9f5b6e
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 10 deletions.
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);
}

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 @@ -119,7 +119,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");
expect(context.logger.error).toHaveBeenCalled();
});

Expand Down

0 comments on commit f9f5b6e

Please sign in to comment.