Skip to content

Commit

Permalink
moved stuff around
Browse files Browse the repository at this point in the history
  • Loading branch information
oveddan committed Nov 16, 2023
1 parent 1069e3b commit b8c29ec
Showing 1 changed file with 28 additions and 40 deletions.
68 changes: 28 additions & 40 deletions packages/protocol-sdk/src/mint/mint-client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,44 +35,7 @@ const zora721Abi = parseAbi([
"function zoraFeeForAmount(uint256 amount) public view returns (address, uint256)",
] as const);

export type MintContractType = "721" | "1155";

export function getMintType(
mintable: MintableGetTokenResponse,
): MintContractType | undefined {
const mintContextType = mintable.mint_context?.mint_context_type;

if (mintContextType === "zora_create") return "721";
if (mintContextType === "zora_create_1155") return "1155";

return;
}

function validateMintable(mintable: MintableGetTokenResponse | undefined) {
if (!mintable) {
throw new MintError("No mintable found");
}

if (!mintable.is_active) {
throw new MintInactiveError("Minting token is inactive");
}

if (!mintable.mint_context) {
throw new MintError("No minting context data from zora API");
}

if (
!["zora_create", "zora_create_1155"].includes(
mintable.mint_context?.mint_context_type!,
)
) {
throw new MintError(
`Mintable type ${mintable.mint_context.mint_context_type} is currently unsupported.`,
);
}

return mintable.mint_context.mint_context_type;
}

class MintClient extends ClientBase {
apiClient: typeof MintAPIClient;
Expand Down Expand Up @@ -112,7 +75,7 @@ class MintClient extends ClientBase {
mintable: MintableGetTokenResponse;
mintArguments: MintArguments;
}): Promise<SimulateContractParameters> {
const mintContextType = validateMintable(mintable);
const mintContextType = validateMintableAndGetContextType(mintable);

const thisPublicClient = this.getPublicClient(publicClient);

Expand Down Expand Up @@ -150,6 +113,31 @@ export function createMintClient({
}) {
return new MintClient(chain, mintAPIClient);
}
export function validateMintableAndGetContextType(mintable: MintableGetTokenResponse | undefined) {
if (!mintable) {
throw new MintError("No mintable found");
}

if (!mintable.is_active) {
throw new MintInactiveError("Minting token is inactive");
}

if (!mintable.mint_context) {
throw new MintError("No minting context data from zora API");
}

if (
!["zora_create", "zora_create_1155"].includes(
mintable.mint_context?.mint_context_type!,
)
) {
throw new MintError(
`Mintable type ${mintable.mint_context.mint_context_type} is currently unsupported.`,
);
}

return mintable.mint_context.mint_context_type;
}

async function makePrepareMint721TokenParams({
publicClient,
Expand All @@ -160,7 +148,7 @@ async function makePrepareMint721TokenParams({
}: {
publicClient: PublicClient;
mintable: MintableGetTokenResponse;
mintContextType: ReturnType<typeof validateMintable>;
mintContextType: ReturnType<typeof validateMintableAndGetContextType>;
minterAccount: Address;
mintArguments: MintArguments;
}): Promise<SimulateContractParameters<typeof zora721Abi, "mintWithRewards">> {
Expand Down Expand Up @@ -208,7 +196,7 @@ async function makePrepareMint1155TokenParams({
publicClient: PublicClient;
apiClient: typeof MintAPIClient;
mintable: MintableGetTokenResponse;
mintContextType: ReturnType<typeof validateMintable>;
mintContextType: ReturnType<typeof validateMintableAndGetContextType>;
minterAccount: Address;
mintArguments: MintArguments;
subgraphUrl: string;
Expand Down

0 comments on commit b8c29ec

Please sign in to comment.