Skip to content

Commit

Permalink
[Dashboard]: Migrate major NFT features to v5 (#3998)
Browse files Browse the repository at this point in the history
# High level changes
- `mint-form.tsx` is "over-abstracted" (not sure if that's the right word) - it's being used for too many different NFT features, making the code hard-to-migrate.
- solution: breaking it down to different component which makes it much easier to remove v4 code

# to test
- [x] UpdateMetadataForm
  - [x] Drop contracts
  - [x] Collection contracts
- [x] SharedMetadataForm
- [x] NFTMintForm
- [x] LazyMintForm

<!-- start pr-codex -->

---

## PR-Codex overview
This PR introduces NFT extensions for ERC721 and ERC1155 contracts, adds a new `updateTokenURI` function, and updates components for NFT minting and metadata management.

### Detailed summary
- Added NFT extension with `updateTokenURI` function for ERC721 and ERC1155 contracts
- Updated components for NFT minting and metadata management

> The following files were skipped due to too many changes: `apps/dashboard/src/contract-ui/tabs/permissions/components/contract-permission.tsx`, `packages/thirdweb/src/extensions/erc721/write/updateTokenURI.ts`, `packages/thirdweb/src/extensions/erc1155/write/updateTokenURI.ts`, `apps/dashboard/src/contract-ui/tabs/nfts/components/shared-metadata-form.tsx`, `apps/dashboard/src/contract-ui/tabs/nfts/components/lazy-mint-form.tsx`, `apps/dashboard/src/contract-ui/tabs/nfts/components/update-metadata-form.tsx`, `apps/dashboard/src/contract-ui/tabs/nfts/components/mint-form.tsx`

> ✨ Ask PR-Codex anything about this PR by commenting with `/codex {your question}`

<!-- end pr-codex -->
  • Loading branch information
kien-ngo committed Aug 13, 2024
1 parent 2d4a5c3 commit db8695d
Show file tree
Hide file tree
Showing 18 changed files with 1,431 additions and 424 deletions.
5 changes: 5 additions & 0 deletions .changeset/calm-llamas-pretend.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"thirdweb": patch
---

Add NFT extension: updateTokenURI
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ interface ListForm
quantity: string;
}

type NFTMintForm = {
type CreateListingsFormProps = {
contract: ThirdwebContract;
formId: string;
type?: "direct-listings" | "english-auctions";
Expand All @@ -80,7 +80,7 @@ const auctionTimes = [
{ label: "1 year", value: 60 * 60 * 24 * 365 },
];

export const CreateListingsForm: React.FC<NFTMintForm> = ({
export const CreateListingsForm: React.FC<CreateListingsFormProps> = ({
contract,
formId,
type,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,36 +1,21 @@
import { MinterOnly } from "@3rdweb-sdk/react/components/roles/minter-only";
import { Icon, useDisclosure } from "@chakra-ui/react";
import { type useContract, useLazyMint } from "@thirdweb-dev/react";
import { thirdwebClient } from "lib/thirdweb-client";
import { useV5DashboardChain } from "lib/v5-adapter";
import { FiPlus } from "react-icons/fi";
import { getContract } from "thirdweb";
import type { ThirdwebContract } from "thirdweb";
import { Button, Drawer } from "tw-components";
import { NFTMintForm } from "./mint-form";
import { LazyMintNftForm } from "./lazy-mint-form";

interface NFTLazyMintButtonProps {
contractQuery: ReturnType<typeof useContract>;
contract: ThirdwebContract;
isErc721: boolean;
}

export const NFTLazyMintButton: React.FC<NFTLazyMintButtonProps> = ({
contractQuery,
contract,
isErc721,
...restButtonProps
}) => {
const contractV4 = contractQuery.contract;
const chain = useV5DashboardChain(contractV4?.chainId);
const contract =
contractV4 && chain
? getContract({
address: contractV4.getAddress(),
chain: chain,
client: thirdwebClient,
})
: null;
const { isOpen, onOpen, onClose } = useDisclosure();
const mutation = useLazyMint(contractV4);
if (!contract) {
return null;
}
return (
<MinterOnly contract={contract}>
<Drawer
Expand All @@ -40,7 +25,7 @@ export const NFTLazyMintButton: React.FC<NFTLazyMintButtonProps> = ({
onClose={onClose}
isOpen={isOpen}
>
<NFTMintForm contract={contractV4} lazyMintMutation={mutation} />
<LazyMintNftForm contract={contract} isErc721={isErc721} />
</Drawer>
<Button
colorScheme="primary"
Expand Down
Loading

0 comments on commit db8695d

Please sign in to comment.