Skip to content

Commit 10de271

Browse files
committed
[Dashboard] Remove useClaimNFT; use erc1155/claimTo (#4102)
The component in this PR is meant for Edition Drop only <!-- start pr-codex --> --- ## PR-Codex overview The focus of this PR is to update the `ClaimTab` component to support ERC1155 contracts and improve transaction handling. ### Detailed summary - Renamed `ClaimTab` component to `ClaimTabERC1155`. - Updated `ClaimTabERC1155` to work with ERC1155 contracts. - Improved transaction handling in `ClaimTabERC1155`. - Removed unnecessary imports and updated dependencies. > ✨ Ask PR-Codex anything about this PR by commenting with `/codex {your question}` <!-- end pr-codex -->
1 parent 0ca1a79 commit 10de271

File tree

2 files changed

+34
-24
lines changed

2 files changed

+34
-24
lines changed

apps/dashboard/src/contract-ui/tabs/nfts/components/claim-tab.tsx

Lines changed: 25 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,45 +1,47 @@
11
import { Flex, FormControl, Input } from "@chakra-ui/react";
2-
import { type DropContract, useClaimNFT } from "@thirdweb-dev/react";
32
import { TransactionButton } from "components/buttons/TransactionButton";
43
import { useTrack } from "hooks/analytics/useTrack";
54
import { useTxNotifications } from "hooks/useTxNotifications";
65
import { thirdwebClient } from "lib/thirdweb-client";
76
import { useV5DashboardChain } from "lib/v5-adapter";
87
import { useForm } from "react-hook-form";
98
import { ZERO_ADDRESS, getContract } from "thirdweb";
10-
import { useActiveAccount } from "thirdweb/react";
9+
import { claimTo } from "thirdweb/extensions/erc1155";
10+
import { useActiveAccount, useSendAndConfirmTransaction } from "thirdweb/react";
1111
import { FormErrorMessage, FormHelperText, FormLabel } from "tw-components";
1212

1313
interface ClaimTabProps {
14-
contract: DropContract;
14+
contractAddress: string;
15+
chainId: number;
1516
tokenId: string;
1617
}
1718

18-
const ClaimTab: React.FC<ClaimTabProps> = ({ contract, tokenId }) => {
19+
const ClaimTabERC1155: React.FC<ClaimTabProps> = ({
20+
contractAddress,
21+
chainId,
22+
tokenId,
23+
}) => {
1924
const trackEvent = useTrack();
2025
const address = useActiveAccount()?.address;
2126
const form = useForm<{ to: string; amount: string }>({
2227
defaultValues: { amount: "1", to: address },
2328
});
29+
const chain = useV5DashboardChain(chainId);
2430

25-
const claim = useClaimNFT(contract);
26-
const chain = useV5DashboardChain(contract?.chainId);
27-
28-
const contractV5 =
29-
contract && chain
30-
? getContract({
31-
address: contract.getAddress(),
32-
chain: chain,
33-
client: thirdwebClient,
34-
})
35-
: null;
31+
const contract = getContract({
32+
address: contractAddress,
33+
chain: chain,
34+
client: thirdwebClient,
35+
});
3636

3737
const { onSuccess, onError } = useTxNotifications(
3838
"Claimed successfully",
3939
"Failed to claim",
40-
contractV5,
40+
contract,
4141
);
4242

43+
const mutation = useSendAndConfirmTransaction();
44+
4345
return (
4446
<Flex
4547
w="full"
@@ -53,11 +55,13 @@ const ClaimTab: React.FC<ClaimTabProps> = ({ contract, tokenId }) => {
5355
});
5456

5557
try {
56-
await claim.mutateAsync({
57-
tokenId,
58-
quantity: data.amount,
58+
const transaction = claimTo({
59+
contract,
60+
tokenId: BigInt(tokenId),
61+
quantity: BigInt(data.amount),
5962
to: data.to,
6063
});
64+
await mutation.mutateAsync(transaction);
6165
trackEvent({
6266
category: "nft",
6367
action: "claim",
@@ -115,7 +119,7 @@ const ClaimTab: React.FC<ClaimTabProps> = ({ contract, tokenId }) => {
115119

116120
<TransactionButton
117121
transactionCount={1}
118-
isLoading={claim.isLoading || form.formState.isSubmitting}
122+
isLoading={mutation.isPending || form.formState.isSubmitting}
119123
type="submit"
120124
colorScheme="primary"
121125
alignSelf="flex-end"
@@ -127,4 +131,4 @@ const ClaimTab: React.FC<ClaimTabProps> = ({ contract, tokenId }) => {
127131
);
128132
};
129133

130-
export default ClaimTab;
134+
export default ClaimTabERC1155;

apps/dashboard/src/core-ui/nft-drawer/useNftDrawerTabs.tsx

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ const ClaimConditionTab = dynamic(() =>
3939
({ ClaimConditions }) => ClaimConditions,
4040
),
4141
);
42-
const ClaimTab = dynamic(
42+
const ClaimTabERC1155 = dynamic(
4343
() => import("contract-ui/tabs/nfts/components/claim-tab"),
4444
);
4545
const UpdateMetadataTab = dynamic(
@@ -216,12 +216,18 @@ export function useNFTDrawerTabs({
216216
},
217217
]);
218218
}
219-
if (isClaimable && isERC1155) {
219+
if (isClaimable && isERC1155 && oldContract) {
220220
tabs = tabs.concat([
221221
{
222222
title: "Claim",
223223
isDisabled: false,
224-
children: <ClaimTab contract={oldContract} tokenId={tokenId} />,
224+
children: (
225+
<ClaimTabERC1155
226+
contractAddress={oldContract.getAddress()}
227+
chainId={oldContract.chainId}
228+
tokenId={tokenId}
229+
/>
230+
),
225231
},
226232
]);
227233
}

0 commit comments

Comments
 (0)