Skip to content

Commit 67768ac

Browse files
committed
[TOOL-4208] Dashboard: Transfer tab improvements/fixes (#6784)
<!-- ## title your PR with this format: "[SDK/Dashboard/Portal] Feature/Fix: Concise title for the changes" If you did not copy the branch name from Linear, paste the issue tag here (format is TEAM-0000): ## Notes for the reviewer Anything important to call out? Be sure to also clarify these in your comments. ## How to test Unit tests, playground, etc. --> <!-- start pr-codex --> --- ## PR-Codex overview This PR focuses on enhancing the `TokenIdPage` components by adding `accountAddress` as a prop and updating several related functionalities to improve user experience and state management. ### Detailed summary - Added `accountAddress` prop to `TokenIdPageClient` and `TokenIdPage`. - Updated `Page` component to fetch `accountAddress` using `getAuthTokenWalletAddress`. - Modified `TransferTab` to use `sendTxAndConfirm` for transaction handling. - Updated ownership check in `useNFTDrawerTabs` to compare against `accountAddress`. > ✨ Ask PR-Codex anything about this PR by commenting with `/codex {your question}` <!-- end pr-codex -->
1 parent 8937d55 commit 67768ac

File tree

5 files changed

+30
-18
lines changed

5 files changed

+30
-18
lines changed

apps/dashboard/src/app/(dashboard)/(chain)/[chain_id]/[contractAddress]/nfts/[tokenId]/TokenIdPage.client.tsx

+2
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ export function TokenIdPageClient(props: {
1010
contract: ThirdwebContract;
1111
tokenId: string;
1212
isLoggedIn: boolean;
13+
accountAddress: string | undefined;
1314
}) {
1415
const { contract } = props;
1516
const metadataQuery = useContractPageMetadata(props.contract);
@@ -34,6 +35,7 @@ export function TokenIdPageClient(props: {
3435
isErc721={supportedERCs.isERC721}
3536
tokenId={props.tokenId}
3637
isLoggedIn={props.isLoggedIn}
38+
accountAddress={props.accountAddress}
3739
/>
3840
);
3941
}

apps/dashboard/src/app/(dashboard)/(chain)/[chain_id]/[contractAddress]/nfts/[tokenId]/components/transfer-tab.tsx

+12-4
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
"use client";
22

3+
import { GenericLoadingPage } from "@/components/blocks/skeletons/GenericLoadingPage";
34
import { FormControl, Input } from "@chakra-ui/react";
45
import { TransactionButton } from "components/buttons/TransactionButton";
56
import { SolidityInput } from "contract-ui/components/solidity-inputs";
@@ -45,7 +46,11 @@ const TransferTab: React.FC<TransferTabProps> = ({
4546
{ contract },
4647
);
4748

48-
const { mutate, isPending } = useSendAndConfirmTransaction();
49+
const sendTxAndConfirm = useSendAndConfirmTransaction();
50+
51+
if (checking1155) {
52+
return <GenericLoadingPage />;
53+
}
4954

5055
return (
5156
<div className="flex w-full flex-col gap-2">
@@ -71,7 +76,7 @@ const TransferTab: React.FC<TransferTabProps> = ({
7176
tokenId: BigInt(tokenId),
7277
from: account?.address ?? "",
7378
});
74-
mutate(transaction, {
79+
sendTxAndConfirm.mutate(transaction, {
7580
onSuccess: () => {
7681
trackEvent({
7782
category: "nft",
@@ -128,11 +133,14 @@ const TransferTab: React.FC<TransferTabProps> = ({
128133
isLoggedIn={isLoggedIn}
129134
txChainID={contract.chain.id}
130135
transactionCount={1}
131-
isPending={isPending || checking1155}
136+
isPending={sendTxAndConfirm.isPending}
132137
type="submit"
133138
className="self-end"
134139
disabled={
135-
!form.formState.isDirty || checking1155 || isPending || !account
140+
!form.formState.isDirty ||
141+
checking1155 ||
142+
sendTxAndConfirm.isPending ||
143+
!account
136144
}
137145
>
138146
Transfer

apps/dashboard/src/app/(dashboard)/(chain)/[chain_id]/[contractAddress]/nfts/[tokenId]/page.tsx

+7-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import { notFound, redirect } from "next/navigation";
22
import { localhost } from "thirdweb/chains";
33
import { getRawAccount } from "../../../../../../account/settings/getAccount";
4+
import { getAuthTokenWalletAddress } from "../../../../../../api/lib/getAuthToken";
45
import { getContractPageParamsInfo } from "../../_utils/getContractFromParams";
56
import { getContractPageMetadata } from "../../_utils/getContractPageMetadata";
67
import { TokenIdPageClient } from "./TokenIdPage.client";
@@ -24,7 +25,10 @@ export default async function Page(props: {
2425
redirect(`/${params.chain_id}/${params.contractAddress}/nfts`);
2526
}
2627

27-
const account = await getRawAccount();
28+
const [accountAddress, account] = await Promise.all([
29+
getAuthTokenWalletAddress(),
30+
getRawAccount(),
31+
]);
2832

2933
const { contract } = info;
3034
if (contract.chain.id === localhost.id) {
@@ -33,6 +37,7 @@ export default async function Page(props: {
3337
contract={contract}
3438
tokenId={params.tokenId}
3539
isLoggedIn={!!account}
40+
accountAddress={accountAddress || undefined}
3641
/>
3742
);
3843
}
@@ -49,6 +54,7 @@ export default async function Page(props: {
4954
isErc721={supportedERCs.isERC721}
5055
tokenId={params.tokenId}
5156
isLoggedIn={!!account}
57+
accountAddress={accountAddress || undefined}
5258
/>
5359
);
5460
}

apps/dashboard/src/app/(dashboard)/(chain)/[chain_id]/[contractAddress]/nfts/[tokenId]/token-id.tsx

+3
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,7 @@ interface TokenIdPageProps {
5252
contract: ThirdwebContract;
5353
isErc721: boolean;
5454
isLoggedIn: boolean;
55+
accountAddress: string | undefined;
5556
}
5657

5758
// TODO: verify the entire nft object with zod schema and display an error message
@@ -61,6 +62,7 @@ export const TokenIdPage: React.FC<TokenIdPageProps> = ({
6162
tokenId,
6263
isErc721,
6364
isLoggedIn,
65+
accountAddress,
6466
}) => {
6567
const [tab, setTab] = useState("Details");
6668
const router = useDashboardRouter();
@@ -71,6 +73,7 @@ export const TokenIdPage: React.FC<TokenIdPageProps> = ({
7173
contract,
7274
tokenId,
7375
isLoggedIn,
76+
accountAddress,
7477
});
7578

7679
const client = useThirdwebClient();

apps/dashboard/src/app/(dashboard)/(chain)/[chain_id]/[contractAddress]/nfts/[tokenId]/useNftDrawerTabs.tsx

+6-13
Original file line numberDiff line numberDiff line change
@@ -5,13 +5,14 @@ import { useMemo } from "react";
55
import type { ThirdwebContract } from "thirdweb";
66
import * as ERC721Ext from "thirdweb/extensions/erc721";
77
import * as ERC1155Ext from "thirdweb/extensions/erc1155";
8-
import { useActiveAccount, useReadContract } from "thirdweb/react";
8+
import { useReadContract } from "thirdweb/react";
99
import type { NFTDrawerTab } from "./types";
1010

1111
type UseNFTDrawerTabsParams = {
1212
contract: ThirdwebContract;
1313
tokenId: string;
1414
isLoggedIn: boolean;
15+
accountAddress: string | undefined;
1516
};
1617

1718
const TransferTab = dynamic(() => import("./components/transfer-tab"));
@@ -32,10 +33,10 @@ export function useNFTDrawerTabs({
3233
contract,
3334
tokenId,
3435
isLoggedIn,
36+
accountAddress,
3537
}: UseNFTDrawerTabsParams): NFTDrawerTab[] {
3638
const functionSelectorQuery = useContractFunctionSelectors(contract);
3739
const functionSelectors = functionSelectorQuery.data || [];
38-
const address = useActiveAccount()?.address;
3940

4041
const isERC721Query = useReadContract(ERC721Ext.isERC721, { contract });
4142

@@ -45,13 +46,6 @@ export function useNFTDrawerTabs({
4546
: isERC721Query.data || false;
4647
const isERC1155 = isERC721Query.isPending ? false : !isERC721;
4748

48-
const balanceOfQuery = useReadContract(ERC1155Ext.balanceOf, {
49-
contract,
50-
owner: address || "",
51-
tokenId: BigInt(tokenId || 0),
52-
queryOptions: { enabled: isERC1155 },
53-
});
54-
5549
const { data: nft } = useReadContract(
5650
isERC721 ? ERC721Ext.getNFT : ERC1155Ext.getNFT,
5751
{
@@ -111,10 +105,10 @@ export function useNFTDrawerTabs({
111105

112106
const isOwner = (() => {
113107
if (isERC1155) {
114-
return balanceOfQuery?.data ? balanceOfQuery.data > 0n : false;
108+
return true;
115109
}
116110
if (isERC721) {
117-
return nft?.owner === address;
111+
return nft?.owner === accountAddress;
118112
}
119113
return false;
120114
})();
@@ -241,10 +235,9 @@ export function useNFTDrawerTabs({
241235
return tabs;
242236
}, [
243237
isERC1155,
244-
balanceOfQuery?.data,
245238
isERC721,
246239
nft,
247-
address,
240+
accountAddress,
248241
tokenId,
249242
isMinterRole,
250243
contract,

0 commit comments

Comments
 (0)