* 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]>
216 lines
6.8 KiB
TypeScript
216 lines
6.8 KiB
TypeScript
import { BatchTable } from "./BatchTable";
|
|
import { SelectReveal } from "./SelectReveal";
|
|
import { UploadStep } from "./UploadStep";
|
|
import { useGetTotalCount } from "@3rdweb-sdk/react/hooks/useGetAll";
|
|
import { Box, Container, Flex, HStack, Icon } from "@chakra-ui/react";
|
|
import { NFTDrop } from "@thirdweb-dev/sdk";
|
|
import Papa from "papaparse";
|
|
import { useCallback, useRef, useState } from "react";
|
|
import { DropzoneOptions, useDropzone } from "react-dropzone";
|
|
import { IoChevronBack } from "react-icons/io5";
|
|
import { Button, Card, Drawer, Heading } from "tw-components";
|
|
import {
|
|
CSVData,
|
|
getAcceptedFiles,
|
|
transformHeader,
|
|
useMergedData,
|
|
} from "utils/batch";
|
|
|
|
interface NftDropBatchUploadProps {
|
|
contract?: NFTDrop;
|
|
isOpen: boolean;
|
|
onClose: () => void;
|
|
}
|
|
|
|
export const NftDropBatchUpload: React.FC<NftDropBatchUploadProps> = ({
|
|
contract,
|
|
isOpen,
|
|
onClose,
|
|
}) => {
|
|
const nextTokenIdToMint = useGetTotalCount(contract);
|
|
const [step, setStep] = useState(0);
|
|
const [csvData, setCSVData] = useState<Papa.ParseResult<CSVData>>();
|
|
const [jsonData, setJsonData] = useState<any>();
|
|
const [imageFiles, setImageFiles] = useState<File[]>([]);
|
|
const [videoFiles, setVideoFiles] = useState<File[]>([]);
|
|
const [noFile, setNoFile] = useState(false);
|
|
|
|
const reset = useCallback(() => {
|
|
setCSVData(undefined);
|
|
setJsonData(undefined);
|
|
setImageFiles([]);
|
|
setVideoFiles([]);
|
|
setNoFile(false);
|
|
}, []);
|
|
|
|
const _onClose = useCallback(() => {
|
|
reset();
|
|
setStep(0);
|
|
onClose();
|
|
}, [onClose, setStep, reset]);
|
|
|
|
const onDrop = useCallback<Required<DropzoneOptions>["onDrop"]>(
|
|
async (acceptedFiles) => {
|
|
setNoFile(false);
|
|
|
|
const { csv, json, images, videos } = await getAcceptedFiles(
|
|
acceptedFiles,
|
|
);
|
|
|
|
if (csv) {
|
|
Papa.parse<CSVData>(csv, {
|
|
header: true,
|
|
transformHeader,
|
|
complete: (results) => {
|
|
const validResults: Papa.ParseResult<CSVData> = {
|
|
...results,
|
|
data: [],
|
|
};
|
|
for (let i = 0; i < results.data.length; i++) {
|
|
if (!results.errors.find((e) => e.row === i)) {
|
|
if (results.data[i].name) {
|
|
validResults.data.push(results.data[i]);
|
|
}
|
|
}
|
|
}
|
|
setCSVData(validResults);
|
|
},
|
|
});
|
|
} else if (json?.length > 0) {
|
|
setJsonData(json);
|
|
} else {
|
|
console.error("No CSV or JSON found");
|
|
setNoFile(true);
|
|
return;
|
|
}
|
|
setImageFiles(images);
|
|
setVideoFiles(videos);
|
|
},
|
|
[],
|
|
);
|
|
|
|
const mergedData = useMergedData(csvData, jsonData, imageFiles, videoFiles);
|
|
|
|
const { getRootProps, getInputProps, isDragActive } = useDropzone({
|
|
onDrop,
|
|
});
|
|
const paginationPortalRef = useRef<HTMLDivElement>(null);
|
|
return (
|
|
<Drawer
|
|
allowPinchZoom
|
|
preserveScrollBarGap
|
|
size="full"
|
|
onClose={_onClose}
|
|
isOpen={isOpen}
|
|
>
|
|
<Container
|
|
maxW="container.page"
|
|
borderRadius={{ base: 0, md: "2xl" }}
|
|
my={{ base: 0, md: 12 }}
|
|
p={{ base: 0, md: 4 }}
|
|
>
|
|
<Card bg="backgroundCardHighlight">
|
|
<Flex flexDir="column" width="100%" p={4}>
|
|
{step === 0 ? (
|
|
<>
|
|
<Flex
|
|
align="center"
|
|
justify="space-between"
|
|
py={{ base: 2, md: 4 }}
|
|
w="100%"
|
|
mb={2}
|
|
>
|
|
<Heading size="title.md">Upload your NFTs</Heading>
|
|
</Flex>
|
|
<Flex direction="column" gap={6} h="100%">
|
|
{csvData || jsonData ? (
|
|
<BatchTable
|
|
portalRef={paginationPortalRef}
|
|
data={mergedData}
|
|
nextTokenIdToMint={nextTokenIdToMint.data?.toNumber()}
|
|
/>
|
|
) : (
|
|
<UploadStep
|
|
getRootProps={getRootProps}
|
|
getInputProps={getInputProps}
|
|
noFile={noFile}
|
|
isDragActive={isDragActive}
|
|
/>
|
|
)}
|
|
<Flex borderTop="1px solid" borderTopColor="borderColor">
|
|
<Container maxW="container.page">
|
|
<Flex
|
|
align="center"
|
|
justify="space-between"
|
|
p={{ base: 0, md: 4 }}
|
|
flexDir={{ base: "column", md: "row" }}
|
|
mt={{ base: 4, md: 0 }}
|
|
>
|
|
<Box ref={paginationPortalRef} />
|
|
<Flex
|
|
gap={2}
|
|
align="center"
|
|
mt={{ base: 4, md: 0 }}
|
|
w={{ base: "100%", md: "auto" }}
|
|
>
|
|
<Button
|
|
borderRadius="md"
|
|
isDisabled={!csvData && !jsonData}
|
|
onClick={() => {
|
|
reset();
|
|
}}
|
|
w={{ base: "100%", md: "auto" }}
|
|
>
|
|
Reset
|
|
</Button>
|
|
<Button
|
|
borderRadius="md"
|
|
colorScheme="primary"
|
|
isDisabled={!csvData && !jsonData}
|
|
onClick={() => setStep(1)}
|
|
w={{ base: "100%", md: "auto" }}
|
|
>
|
|
Next
|
|
</Button>
|
|
</Flex>
|
|
</Flex>
|
|
</Container>
|
|
</Flex>
|
|
</Flex>
|
|
</>
|
|
) : (
|
|
<>
|
|
<Flex
|
|
align="center"
|
|
justify="space-between"
|
|
py={4}
|
|
w="100%"
|
|
mb={2}
|
|
>
|
|
<HStack>
|
|
<Icon
|
|
boxSize={5}
|
|
as={IoChevronBack}
|
|
color="gray.600"
|
|
onClick={() => setStep(0)}
|
|
cursor="pointer"
|
|
/>
|
|
<Heading size="title.md">
|
|
When will you reveal your NFTs?
|
|
</Heading>
|
|
</HStack>
|
|
</Flex>
|
|
<SelectReveal
|
|
contract={contract}
|
|
mergedData={mergedData}
|
|
onClose={_onClose}
|
|
/>
|
|
</>
|
|
)}
|
|
</Flex>
|
|
</Card>
|
|
</Container>
|
|
</Drawer>
|
|
);
|
|
};
|