* initial /publish * custom contract init (#27) * clean up customContract interface for the moment * upgrade sdk & make multi-uri publish work * upgraded dependencies and customContract workflow * more custom contract stuff * publish ui update * basic publish & deploy flow works * cleanup eslint * update sdk * add contract address to toast and log it out * integrate newer sdk version * upgrade deps * full deploy loop functional with updated sdk * upgrade sdk * upgrade deps * upgrade sdk to fix big contracts * full flow! * update deps * update to latest sdk, support custom contracts in contracts list * one more sdk update * cache keys // analytics mapping * make mr. typescript happy * try catch the resolve type (need to fix it in SDK) * fix type check * upgrade sdk & handle `ipfs=` from cli * fix yarn lock * publishBatch * add very basic code tab * fix build * init cleaning up code tab * fix zindex issue * update code segments * prep some more stuff * remove duplication * this wont build and that is ok * fix build * upgrade react package * add super basic mint button * update sdk * clean up some custom contract interfaces a bit * updated sdks all around * change minting to useNFTMint * append contract.functions to signatures so you can copy paste * add byoc page tracking * new publish page * slightly fix hook * custom deploy form update * completely overhauled deploy flow now * some improvements, empty states etc * only show coming soon on non-mumbai * tw-components * fix contract items table * upgrade deps * fix secondary cta * fix string * fixed things more * fix up code-block * small code tab improvements * Add mint drawer if ERC721 (#95) * Update thumbnail/title/desc * Add custom nft mint * Fix FormHelperText * Delete unused imports * Remove imports * fix build issues etc * Add token drop (#93) * Update thumbnail/title/desc * Merge * wip * Token drop page working * Add claim phases tab, add TokenDrop to conditionals * update font size * NFTs/token conditional * Add QuantityInputWithUnlimited * Update SDK * Fix unlimited * Remove fontSize Co-authored-by: Jonas Daniels <[email protected]> * set tokendrop back to coming soon * remove "@dev" tag for sdk installation * fix mappings file * fix indentation on custom code tab * ship central 🚢 * fix build Co-authored-by: Joaquim Verges <[email protected]> Co-authored-by: Jake Loo <[email protected]> Co-authored-by: Nacho Iacovino <[email protected]>
205 lines
6.0 KiB
TypeScript
205 lines
6.0 KiB
TypeScript
import { NFTDropKeys } from "../cache-keys";
|
|
import {
|
|
useMutationWithInvalidate,
|
|
useQueryWithNetwork,
|
|
} from "./query/useQueryWithNetwork";
|
|
import { useContractMetadata } from "./useContract";
|
|
import { getAllQueryKey, getTotalCountQueryKey } from "./useGetAll";
|
|
import { useWeb3 } from "@3rdweb-sdk/react";
|
|
import { useNFTDrop } from "@thirdweb-dev/react";
|
|
import {
|
|
ClaimConditionInput,
|
|
NFTDrop,
|
|
NFTMetadataInput,
|
|
} from "@thirdweb-dev/sdk";
|
|
import { BigNumber } from "ethers";
|
|
import invariant from "tiny-invariant";
|
|
import { parseAttributes } from "utils/parseAttributes";
|
|
|
|
export function useNFTDropContractMetadata(contractAddress?: string) {
|
|
return useContractMetadata(useNFTDrop(contractAddress));
|
|
}
|
|
export function useNFTDropSupply(contractAddress?: string) {
|
|
const dropContract = useNFTDrop(contractAddress);
|
|
return useQueryWithNetwork(
|
|
NFTDropKeys.supply(contractAddress),
|
|
async () => {
|
|
return {
|
|
totalSupply: (await dropContract?.totalSupply())?.toNumber() || 0,
|
|
totalClaimedSupply:
|
|
(await dropContract?.totalClaimedSupply())?.toNumber() || 0,
|
|
totalUnclaimedSupply:
|
|
(await dropContract?.totalUnclaimedSupply())?.toNumber() || 0,
|
|
};
|
|
},
|
|
{
|
|
enabled: !!dropContract && !!contractAddress,
|
|
},
|
|
);
|
|
}
|
|
|
|
export function useNFTDropActiveClaimCondition(contractAddress?: string) {
|
|
const dropContract = useNFTDrop(contractAddress);
|
|
return useQueryWithNetwork(
|
|
NFTDropKeys.activeClaimCondition(contractAddress),
|
|
async () => {
|
|
return await dropContract?.claimConditions.getActive();
|
|
},
|
|
{
|
|
enabled: !!dropContract && !!contractAddress,
|
|
},
|
|
);
|
|
}
|
|
|
|
export function useNFTDropBalance(contractAddress?: string) {
|
|
const dropContract = useNFTDrop(contractAddress);
|
|
const { address } = useWeb3();
|
|
return useQueryWithNetwork(
|
|
NFTDropKeys.balanceOf(contractAddress, address),
|
|
async () => {
|
|
return await dropContract?.balanceOf(address || "");
|
|
},
|
|
{
|
|
enabled: !!dropContract && !!contractAddress && !!address,
|
|
},
|
|
);
|
|
}
|
|
|
|
export function useBatchesToReveal(contractAddress?: string) {
|
|
const dropContract = useNFTDrop(contractAddress);
|
|
const { address } = useWeb3();
|
|
return useQueryWithNetwork(
|
|
NFTDropKeys.batchesToReveal(contractAddress),
|
|
async () => {
|
|
return await dropContract?.revealer.getBatchesToReveal();
|
|
},
|
|
{
|
|
enabled: !!dropContract && !!contractAddress && !!address,
|
|
},
|
|
);
|
|
}
|
|
|
|
// ----------------------------------------------------------------
|
|
// Mutations
|
|
// ----------------------------------------------------------------
|
|
|
|
export function useNFTDropMintMutation(contract?: NFTDrop) {
|
|
return useMutationWithInvalidate(
|
|
async (data: NFTMetadataInput) => {
|
|
invariant(contract, "contract is required");
|
|
return await contract.createBatch([parseAttributes(data)]);
|
|
},
|
|
{
|
|
onSuccess: (_data, _variables, _options, invalidate) => {
|
|
return invalidate([
|
|
getAllQueryKey(contract),
|
|
getTotalCountQueryKey(contract),
|
|
NFTDropKeys.supply(contract?.getAddress()),
|
|
]);
|
|
},
|
|
},
|
|
);
|
|
}
|
|
|
|
export function useNFTDropBatchMint(contract?: NFTDrop) {
|
|
return useMutationWithInvalidate(
|
|
async (data: NFTMetadataInput[]) => {
|
|
invariant(contract, "contract is required");
|
|
return await contract.createBatch(data);
|
|
},
|
|
{
|
|
onSuccess: (_data, _variables, _options, invalidate) => {
|
|
return invalidate([
|
|
getAllQueryKey(contract),
|
|
getTotalCountQueryKey(contract),
|
|
NFTDropKeys.supply(contract?.getAddress()),
|
|
]);
|
|
},
|
|
},
|
|
);
|
|
}
|
|
|
|
export function useNFTDropResetClaimEligibilityMutation(contract?: NFTDrop) {
|
|
return useMutationWithInvalidate(async () => {
|
|
invariant(contract, "contract is required");
|
|
const claimConditions = await contract.claimConditions.getAll();
|
|
|
|
const cleaned = claimConditions.map((c) => ({
|
|
...c,
|
|
price: c.currencyMetadata.displayValue,
|
|
maxQuantity: c.maxQuantity.toString(),
|
|
quantityLimitPerTransaction: c.quantityLimitPerTransaction.toString(),
|
|
}));
|
|
|
|
return await contract.claimConditions.set(cleaned, true);
|
|
});
|
|
}
|
|
export function useNFTDropClaimConditionMutation(contract?: NFTDrop) {
|
|
return useMutationWithInvalidate(
|
|
async (data: ClaimConditionInput[]) => {
|
|
invariant(contract, "contract is required");
|
|
return await contract.claimConditions.set(data);
|
|
},
|
|
{
|
|
onSuccess: (_data, _variables, _options, invalidate) => {
|
|
return invalidate([
|
|
NFTDropKeys.activeClaimCondition(contract?.getAddress()),
|
|
]);
|
|
},
|
|
},
|
|
);
|
|
}
|
|
|
|
interface DelayedRevealInput {
|
|
placeholder: NFTMetadataInput;
|
|
metadatas: NFTMetadataInput[];
|
|
password: string;
|
|
}
|
|
|
|
export function useNFTDropDelayedRevealBatchMint(contract?: NFTDrop) {
|
|
return useMutationWithInvalidate(
|
|
async (data: DelayedRevealInput) => {
|
|
invariant(contract, "contract is required");
|
|
return await contract.revealer.createDelayedRevealBatch(
|
|
data.placeholder,
|
|
data.metadatas,
|
|
data.password,
|
|
);
|
|
},
|
|
{
|
|
onSuccess: (_data, _variables, _options, invalidate) => {
|
|
return invalidate([
|
|
getAllQueryKey(contract),
|
|
getTotalCountQueryKey(contract),
|
|
NFTDropKeys.supply(contract?.getAddress()),
|
|
NFTDropKeys.batchesToReveal(contract?.getAddress()),
|
|
]);
|
|
},
|
|
},
|
|
);
|
|
}
|
|
|
|
interface RevealInput {
|
|
batchId: BigNumber;
|
|
password: string;
|
|
}
|
|
|
|
export function useNFTDropRevealMutation(contract?: NFTDrop) {
|
|
return useMutationWithInvalidate(
|
|
async (data: RevealInput) => {
|
|
invariant(contract, "contract is required");
|
|
|
|
return await contract.revealer.reveal(data.batchId, data.password);
|
|
},
|
|
{
|
|
onSuccess: (_data, _variables, _options, invalidate) => {
|
|
return invalidate([
|
|
getAllQueryKey(contract),
|
|
NFTDropKeys.detail(contract?.getAddress()),
|
|
NFTDropKeys.batchesToReveal(contract?.getAddress()),
|
|
]);
|
|
},
|
|
},
|
|
);
|
|
}
|