Skip to content

Commit 6ae54dd

Browse files
committed
Dashboard: Remove useThirdwebClient hook (#7228)
<!-- ## 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 integrating the `ThirdwebClient` into various components and functions across the application, enhancing the client functionality for better interaction with smart contracts and improving the overall architecture. ### Detailed summary - Added `client` prop to multiple components for better contract interactions. - Updated functions to utilize the `contract.client` instead of a generic client. - Removed redundant imports of `useThirdwebClient`. - Enhanced several UI components to accept and use the `client` prop. - Modified API calls to pass the `client` where necessary for fetching data. - Improved handling of ENS queries by passing the `client` directly. > The following files were skipped due to too many changes: `apps/dashboard/src/components/contract-components/hooks.ts`, `apps/dashboard/src/app/(app)/team/[team_slug]/[project_slug]/(sidebar)/connect/account-abstraction/factories/page.tsx`, `apps/dashboard/src/components/embedded-wallets/Configure/index.tsx`, `apps/dashboard/src/components/contract-components/contract-publish-form/index.tsx`, `apps/dashboard/src/components/contract-components/contract-deploy-form/custom-contract.tsx` > ✨ Ask PR-Codex anything about this PR by commenting with `/codex {your question}` <!-- end pr-codex --> <!-- This is an auto-generated comment: release notes by coderabbit.ai --> ## Summary by CodeRabbit - **New Features** - Many components now accept a client instance as a prop, enabling more explicit and flexible client management throughout the dashboard. - **Refactor** - Shifted from internal client initialization to explicit client prop injection across the app, affecting forms, tables, media components, contract publishing, and wallet settings. - Updated hooks and utility functions to require a client parameter instead of relying on internal context. - **Chores** - Removed unused files and internal hooks related to client management. - **Bug Fixes** - Improved consistency and reliability when handling authentication and client context in user flows. <!-- end of auto-generated comment: release notes by coderabbit.ai -->
1 parent 8245c06 commit 6ae54dd

File tree

85 files changed

+423
-284
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

85 files changed

+423
-284
lines changed

apps/dashboard/src/@/constants/thirdweb.client.ts

Lines changed: 0 additions & 51 deletions
This file was deleted.

apps/dashboard/src/@3rdweb-sdk/react/components/connect-wallet/index.tsx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -198,6 +198,7 @@ export const CustomConnectWallet = (props: {
198198
open={isNetworkConfigModalOpen}
199199
onOpenChange={setIsNetworkConfigModalOpen}
200200
editChain={editChain}
201+
client={client}
201202
/>
202203
</>
203204
);

apps/dashboard/src/app/(app)/(dashboard)/(chain)/[chain_id]/[contractAddress]/(marketplace)/components/list-form.tsx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -559,6 +559,7 @@ export const CreateListingsForm: React.FC<CreateListingsFormProps> = ({
559559
width="140px"
560560
height="140px"
561561
requireInteraction
562+
client={contract.client}
562563
/>
563564
</Box>
564565
</Tooltip>

apps/dashboard/src/app/(app)/(dashboard)/(chain)/[chain_id]/[contractAddress]/(marketplace)/components/listing-drawer.tsx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,7 @@ export const ListingDrawer: React.FC<NFTDrawerProps> = ({
5151
<div className="flex flex-row gap-6">
5252
<NFTMediaWithEmptyState
5353
metadata={renderData.asset.metadata}
54+
client={contract.client}
5455
requireInteraction
5556
width="150px"
5657
height="150px"

apps/dashboard/src/app/(app)/(dashboard)/(chain)/[chain_id]/[contractAddress]/(marketplace)/components/marketplace-table.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,7 @@ export const MarketplaceTable: React.FC<MarketplaceTableProps> = ({
9999
Header: "Media",
100100
accessor: (row) => row.asset.metadata,
101101
// biome-ignore lint/suspicious/noExplicitAny: FIXME
102-
Cell: (cell: any) => <MediaCell cell={cell} />,
102+
Cell: (cell: any) => <MediaCell cell={cell} client={contract.client} />,
103103
},
104104
{
105105
Header: "Name",

apps/dashboard/src/app/(app)/(dashboard)/(chain)/[chain_id]/[contractAddress]/_components/NFTCards.tsx

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import { SkeletonContainer } from "@/components/ui/skeleton";
22
import { TrackedLinkTW } from "@/components/ui/tracked-link";
33
import { useMemo } from "react";
4-
import { type NFT, ZERO_ADDRESS } from "thirdweb";
4+
import { type NFT, type ThirdwebClient, ZERO_ADDRESS } from "thirdweb";
55
import { NFTMediaWithEmptyState } from "tw-components/nft-media";
66
import type { ProjectMeta } from "../../../../../team/[team_slug]/[project_slug]/contract/[chainIdOrSlug]/[contractAddress]/types";
77
import { buildContractPagePath } from "../_utils/contract-page-path";
@@ -32,6 +32,7 @@ interface NFTCardsProps {
3232
isPending: boolean;
3333
allNfts?: boolean;
3434
projectMeta: ProjectMeta | undefined;
35+
client: ThirdwebClient;
3536
}
3637

3738
export const NFTCards: React.FC<NFTCardsProps> = ({
@@ -40,6 +41,7 @@ export const NFTCards: React.FC<NFTCardsProps> = ({
4041
isPending,
4142
allNfts,
4243
projectMeta,
44+
client,
4345
}) => {
4446
const dummyData = useMemo(() => {
4547
return Array.from({
@@ -73,6 +75,7 @@ export const NFTCards: React.FC<NFTCardsProps> = ({
7375
requireInteraction
7476
width="100%"
7577
height="100%"
78+
client={client}
7679
/>
7780
);
7881
}}

apps/dashboard/src/app/(app)/(dashboard)/(chain)/[chain_id]/[contractAddress]/_components/claim-conditions/claim-conditions-form/index.tsx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -528,6 +528,7 @@ export const ClaimConditionsForm: React.FC<ClaimConditionsFormProps> = ({
528528
form.setValue(`phases.${index}.snapshot`, snapshot)
529529
}
530530
isDisabled={!canEditForm}
531+
client={contract.client}
531532
/>
532533

533534
<ClaimsConditionFormContext.Provider

apps/dashboard/src/app/(app)/(dashboard)/(chain)/[chain_id]/[contractAddress]/_components/claim-conditions/snapshot-upload.tsx

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ import { useCsvUpload } from "hooks/useCsvUpload";
1414
import { CircleAlertIcon, DownloadIcon, UploadIcon } from "lucide-react";
1515
import { useRef } from "react";
1616
import type { Column } from "react-table";
17-
import { ZERO_ADDRESS } from "thirdweb";
17+
import { type ThirdwebClient, ZERO_ADDRESS } from "thirdweb";
1818
import { CsvDataTable } from "../csv-data-table";
1919

2020
interface SnapshotAddressInput {
@@ -30,6 +30,7 @@ interface SnapshotUploadProps {
3030
isDisabled: boolean;
3131
value?: SnapshotAddressInput[] | undefined;
3232
onClose: () => void;
33+
client: ThirdwebClient;
3334
}
3435

3536
const csvParser = (items: SnapshotAddressInput[]): SnapshotAddressInput[] => {
@@ -49,6 +50,7 @@ const SnapshotViewerSheetContent: React.FC<SnapshotUploadProps> = ({
4950
isDisabled,
5051
value,
5152
onClose,
53+
client,
5254
}) => {
5355
const {
5456
normalizeQuery,
@@ -59,7 +61,11 @@ const SnapshotViewerSheetContent: React.FC<SnapshotUploadProps> = ({
5961
noCsv,
6062
reset,
6163
removeInvalid,
62-
} = useCsvUpload<SnapshotAddressInput>({ csvParser, defaultRawData: value });
64+
} = useCsvUpload<SnapshotAddressInput>({
65+
csvParser,
66+
defaultRawData: value,
67+
client,
68+
});
6369

6470
const paginationPortalRef = useRef<HTMLDivElement>(null);
6571
const normalizeData = normalizeQuery.data;

apps/dashboard/src/app/(app)/(dashboard)/(chain)/[chain_id]/[contractAddress]/_layout/ConfigureCustomChain.tsx

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,11 @@ import { ConfigureNetworks } from "components/configure-networks/ConfigureNetwor
66
import { CheckIcon, CircleAlertIcon, RotateCcwIcon } from "lucide-react";
77
import { useState } from "react";
88
import { addChainOverrides } from "stores/chainStores";
9+
import type { ThirdwebClient } from "thirdweb";
910

1011
export function ConfigureCustomChain(props: {
1112
chainSlug: string;
13+
client: ThirdwebClient;
1214
}) {
1315
const { chainSlug } = props;
1416
const isSlugNumber = Number.isInteger(Number(chainSlug));
@@ -61,6 +63,7 @@ export function ConfigureCustomChain(props: {
6163
}
6264
}}
6365
editChain={undefined}
66+
client={props.client}
6467
/>
6568
</div>
6669
</div>

apps/dashboard/src/app/(app)/(dashboard)/(chain)/[chain_id]/[contractAddress]/_layout/contract-metadata.tsx

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,6 @@ export async function getContractMetadataHeaderData(
4343
fetchDashboardContractMetadata(contract),
4444
fetchPublishedContractsFromDeploy({
4545
contract,
46-
client: contract.client,
4746
}),
4847
]);
4948

apps/dashboard/src/app/(app)/(dashboard)/(chain)/[chain_id]/[contractAddress]/account/components/nfts-owned.tsx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ export const NftsOwned: React.FC<NftsOwnedProps> = ({
2727

2828
return nfts.length !== 0 ? (
2929
<NFTCards
30+
client={contract.client}
3031
projectMeta={projectMeta}
3132
nfts={nfts.map((nft) => ({
3233
id: BigInt(nft.id),

apps/dashboard/src/app/(app)/(dashboard)/(chain)/[chain_id]/[contractAddress]/cross-chain/shared-cross-chain-page.tsx

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -183,7 +183,6 @@ export async function SharedCrossChainPage(props: {
183183
coreMetadata = (
184184
await fetchPublishedContractsFromDeploy({
185185
contract: serverContract,
186-
client: serverContract.client,
187186
})
188187
).at(-1) as FetchDeployMetadataResult;
189188
} catch {}
@@ -256,7 +255,6 @@ export async function SharedCrossChainPage(props: {
256255
client: serverContract.client,
257256
address: m,
258257
}),
259-
client: serverContract.client,
260258
})
261259
).at(-1),
262260
),

apps/dashboard/src/app/(app)/(dashboard)/(chain)/[chain_id]/[contractAddress]/layout.tsx

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import type { Metadata } from "next";
2+
import { getAuthToken } from "../../../../api/lib/getAuthToken";
23
import {
34
SharedContractLayout,
45
generateContractLayoutMetadata,
@@ -11,12 +12,13 @@ export default async function Layout(props: {
1112
}>;
1213
children: React.ReactNode;
1314
}) {
14-
const params = await props.params;
15+
const [params, authToken] = await Promise.all([props.params, getAuthToken()]);
1516
return (
1617
<SharedContractLayout
1718
contractAddress={params.contractAddress}
1819
chainIdOrSlug={params.chain_id}
1920
projectMeta={undefined}
21+
authToken={authToken}
2022
>
2123
{props.children}
2224
</SharedContractLayout>

apps/dashboard/src/app/(app)/(dashboard)/(chain)/[chain_id]/[contractAddress]/modules/components/ModuleForm.tsx

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -69,9 +69,10 @@ export const InstallModuleForm = (props: InstallModuleFormProps) => {
6969
const { contract, account } = props;
7070
const { errors } = formState;
7171

72-
const { data, isPending, isFetching } = usePublishedContractsQuery(
73-
watch("publisherAddress"),
74-
);
72+
const { data, isPending, isFetching } = usePublishedContractsQuery({
73+
client: contract.client,
74+
address: watch("publisherAddress"),
75+
});
7576

7677
// filter out all the contracts that AREN'T modules
7778
const modulesOnly = useMemo(() => {
@@ -88,6 +89,7 @@ export const InstallModuleForm = (props: InstallModuleFormProps) => {
8889
const allVersions = useAllVersions(
8990
watch("publisherAddress"),
9091
watch("moduleContract"),
92+
contract.client,
9193
);
9294

9395
const installMutation = useMutation({

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -135,6 +135,7 @@ const AirdropTab: React.FC<AirdropTabProps> = ({
135135
</SheetTitle>
136136
</SheetHeader>
137137
<AirdropUpload
138+
client={contract.client}
138139
onClose={() => setOpen(false)}
139140
setAirdrop={(value) =>
140141
setValue("addresses", value, { shouldDirty: true })

apps/dashboard/src/app/(app)/(dashboard)/(chain)/[chain_id]/[contractAddress]/nfts/[tokenId]/components/update-metadata-form.tsx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -252,6 +252,7 @@ export const UpdateNftMetadata: React.FC<UpdateNftMetadataForm> = ({
252252
<div className="flex flex-row flex-wrap gap-3">
253253
{nft?.metadata && !mediaFileUrl && (
254254
<NFTMediaWithEmptyState
255+
client={contract.client}
255256
metadata={{
256257
name: nft.metadata.name,
257258
animation_url:

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

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -126,7 +126,11 @@ export const TokenIdPage: React.FC<TokenIdPageProps> = ({
126126
{/* border */}
127127
<div className="absolute inset-0 z-0 rounded-lg border" />
128128
{/* media */}
129-
<NFTMediaWithEmptyState metadata={nftMetadata} className="z-10" />
129+
<NFTMediaWithEmptyState
130+
metadata={nftMetadata}
131+
className="z-10"
132+
client={contract.client}
133+
/>
130134
</div>
131135

132136
<div className="flex w-full flex-col gap-6">

apps/dashboard/src/app/(app)/(dashboard)/(chain)/[chain_id]/[contractAddress]/nfts/components/table.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ export const NFTGetAllTable: React.FC<ContractOverviewNFTGetAllProps> = ({
7575
Header: "Media",
7676
accessor: (row) => row.metadata,
7777
Cell: (cell: CellProps<NFT, NFT["metadata"]>) => (
78-
<MediaCell cell={cell} />
78+
<MediaCell cell={cell} client={contract.client} />
7979
),
8080
},
8181
{

apps/dashboard/src/app/(app)/(dashboard)/(chain)/[chain_id]/[contractAddress]/overview/components/MarketplaceDetails.tsx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -344,6 +344,7 @@ const ListingCards: React.FC<ListingCardsProps> = ({
344344
render={(v) => {
345345
return (
346346
<NFTMediaWithEmptyState
347+
client={client}
347348
metadata={v}
348349
requireInteraction
349350
width="100%"

apps/dashboard/src/app/(app)/(dashboard)/(chain)/[chain_id]/[contractAddress]/overview/components/NFTDetails.tsx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,7 @@ export function NFTDetails({
6767
{/* cards */}
6868
<div className="p-6">
6969
<NFTCards
70+
client={contract.client}
7071
projectMeta={projectMeta}
7172
nfts={displayableNFTs.map((t) => ({
7273
...t,

apps/dashboard/src/app/(app)/(dashboard)/(chain)/[chain_id]/[contractAddress]/overview/components/published-by-ui.tsx

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import { fetchPublishedContractsFromDeploy } from "components/contract-component
22
import { ContractCard } from "components/explore/contract-card";
33
import { THIRDWEB_DEPLOYER_ADDRESS } from "constants/addresses";
44
import { resolveEns } from "lib/ens";
5-
import type { ThirdwebClient, ThirdwebContract } from "thirdweb";
5+
import type { ThirdwebContract } from "thirdweb";
66
import { polygon } from "thirdweb/chains";
77
import { getBytecode, getContract } from "thirdweb/contract";
88
import { getPublishedUriFromCompilerUri } from "thirdweb/extensions/thirdweb";
@@ -20,13 +20,11 @@ type ModuleMetadataPickedKeys = {
2020
export async function getPublishedByCardProps(params: {
2121
address: string | null;
2222
contract: ThirdwebContract;
23-
client: ThirdwebClient;
2423
}) {
25-
const { address, contract, client } = params;
24+
const { address, contract } = params;
2625

2726
const publishedContractsFromDeploy = await fetchPublishedContractsFromDeploy({
2827
contract,
29-
client,
3028
});
3129

3230
const reversedPublishedContractsFromDeploy = [
@@ -54,7 +52,10 @@ export async function getPublishedByCardProps(params: {
5452
let publisherAddressOrEns = publishedContractToShow.publisher;
5553
if (!isValidENSName(publishedContractToShow.publisher)) {
5654
try {
57-
const res = await resolveEns(publishedContractToShow.publisher, client);
55+
const res = await resolveEns(
56+
publishedContractToShow.publisher,
57+
contract.client,
58+
);
5859
if (res.ensName) {
5960
publisherAddressOrEns = res.ensName;
6061
}

apps/dashboard/src/app/(app)/(dashboard)/(chain)/[chain_id]/[contractAddress]/overview/components/published-by.server.tsx

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@ export const PublishedBy: React.FC<PublishedByProps> = async ({ contract }) => {
1111
const props = await getPublishedByCardProps({
1212
address,
1313
contract,
14-
client: contract.client,
1514
});
1615

1716
if (!props) {

apps/dashboard/src/app/(app)/(dashboard)/(chain)/[chain_id]/[contractAddress]/shared-layout.tsx

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import { getProjects } from "@/api/projects";
22
import { getTeams } from "@/api/team";
3+
import { getClientThirdwebClient } from "@/constants/thirdweb-client.client";
34
import type { MinimalTeamsAndProjects } from "components/contract-components/contract-deploy-form/add-to-project-card";
45
import { resolveFunctionSelectors } from "lib/selectors";
56
import type { Metadata } from "next";
@@ -27,6 +28,7 @@ export async function SharedContractLayout(props: {
2728
chainIdOrSlug: string;
2829
projectMeta: ProjectMeta | undefined;
2930
children: React.ReactNode;
31+
authToken: string | undefined | null;
3032
}) {
3133
if (!isAddress(props.contractAddress)) {
3234
return notFound();
@@ -43,7 +45,15 @@ export async function SharedContractLayout(props: {
4345
]);
4446

4547
if (!info) {
46-
return <ConfigureCustomChain chainSlug={props.chainIdOrSlug} />;
48+
return (
49+
<ConfigureCustomChain
50+
chainSlug={props.chainIdOrSlug}
51+
client={getClientThirdwebClient({
52+
jwt: props.authToken,
53+
teamId: props.projectMeta?.teamId,
54+
})}
55+
/>
56+
);
4757
}
4858

4959
const { clientContract, serverContract, chainMetadata, isLocalhostChain } =

apps/dashboard/src/app/(app)/(dashboard)/(chain)/[chain_id]/[contractAddress]/tokens/components/airdrop-form.tsx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -97,6 +97,7 @@ export const TokenAirdropForm: React.FC<TokenAirdropFormProps> = ({
9797
<div className="mb-3 flex w-full flex-col gap-6 md:flex-row">
9898
{airdropFormOpen ? (
9999
<AirdropUpload
100+
client={contract.client}
100101
onClose={() => setAirdropFormOpen(false)}
101102
setAirdrop={(value) =>
102103
setValue("addresses", value, { shouldDirty: true })

0 commit comments

Comments
 (0)