Skip to content

Commit a440621

Browse files
committed
Dashboard: Reduce useThirdwebClient hook usage #2 (#7224)
<!-- ## 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 functionality of various components by integrating a `client` prop of type `ThirdwebClient` into multiple files. This change improves the interaction with the Thirdweb SDK across the application. ### Detailed summary - Added `client` prop to components like `IconUpload`, `SolidityInput`, and `CustomConnectWallet`. - Updated hooks and functions to accept `client` for better SDK integration. - Modified forms to utilize the `client` for storage uploads and contract deployments. - Enhanced `AddChainToWallet` and `EcosystemHeader` to support `client`. - Updated various fieldsets to include `client`, improving data handling and validation. > ✨ 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** - Components and forms now consistently accept and require a `client` prop, providing improved client context across wallet connection, contract deployment, network configuration, and NFT interactions. - **Refactor** - Updated numerous components and hooks to require explicit passing of the `client` instance, replacing previous internal retrieval methods. - Prop types and interfaces were extended to include the new `client` property, ensuring consistent usage throughout the app. - **Bug Fixes** - Addressed missing `client` props in several components to prevent potential issues with client-dependent functionality. <!-- end of auto-generated comment: release notes by coderabbit.ai -->
1 parent 0262763 commit a440621

File tree

35 files changed

+174
-43
lines changed

35 files changed

+174
-43
lines changed

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

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
"use client";
22

33
import { Button } from "@/components/ui/button";
4-
import { useThirdwebClient } from "@/constants/thirdweb.client";
54
import { useStore } from "@/lib/reactive";
65
import { getSDKTheme } from "app/(app)/components/sdk-component-theme";
76
import { CustomChainRenderer } from "components/selects/CustomChainRenderer";
@@ -12,7 +11,7 @@ import Image from "next/image";
1211
import Link from "next/link";
1312
import { usePathname } from "next/navigation";
1413
import { useCallback, useMemo, useState } from "react";
15-
import type { Chain } from "thirdweb";
14+
import type { Chain, ThirdwebClient } from "thirdweb";
1615
import {
1716
ConnectButton,
1817
type NetworkSelectorProps,
@@ -36,9 +35,11 @@ export const CustomConnectWallet = (props: {
3635
signInLinkButtonClassName?: string;
3736
detailsButtonClassName?: string;
3837
chain?: Chain;
38+
client: ThirdwebClient;
3939
isLoggedIn: boolean;
4040
}) => {
41-
const thirdwebClient = useThirdwebClient();
41+
const client = props.client;
42+
4243
const loginRequired =
4344
props.loginRequired === undefined ? true : props.loginRequired;
4445

@@ -140,7 +141,7 @@ export const CustomConnectWallet = (props: {
140141
<>
141142
<ConnectButton
142143
theme={getSDKTheme(t)}
143-
client={thirdwebClient}
144+
client={client}
144145
connectModal={{
145146
privacyPolicyUrl: "/privacy-policy",
146147
termsOfServiceUrl: "/terms",
@@ -175,7 +176,7 @@ export const CustomConnectWallet = (props: {
175176
renderChain(props) {
176177
return (
177178
<CustomChainRenderer
178-
client={thirdwebClient}
179+
client={client}
179180
{...props}
180181
openEditChainModal={(c) => {
181182
setIsNetworkConfigModalOpen(true);
@@ -276,12 +277,11 @@ function ConnectWalletWelcomeScreen(props: {
276277
export function useCustomConnectModal() {
277278
const { connect } = useConnectModal();
278279
const { theme } = useTheme();
279-
const thirdwebClient = useThirdwebClient();
280280

281281
return useCallback(
282-
(options?: { chain?: Chain }) => {
282+
(options: { chain?: Chain; client: ThirdwebClient }) => {
283283
return connect({
284-
client: thirdwebClient,
284+
client: options.client,
285285
appMetadata: {
286286
name: "thirdweb",
287287
logoUrl: "https://thirdweb.com/favicon.ico",
@@ -299,7 +299,7 @@ export function useCustomConnectModal() {
299299
theme: getSDKTheme(theme === "light" ? "light" : "dark"),
300300
});
301301
},
302-
[connect, theme, thirdwebClient],
302+
[connect, theme],
303303
);
304304
}
305305

apps/dashboard/src/@3rdweb-sdk/react/hooks/useDashboardStorageUpload.tsx

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,17 @@
1-
import { useThirdwebClient } from "@/constants/thirdweb.client";
21
import { useMutation } from "@tanstack/react-query";
2+
import type { ThirdwebClient } from "thirdweb";
33
import { upload } from "thirdweb/storage";
44

55
type DashboardUploadOptions = {
66
uploadWithoutDirectory?: boolean;
77
metadata?: Record<string, string>;
8+
client: ThirdwebClient;
89
};
910

10-
export function useDashboardStorageUpload(options?: DashboardUploadOptions) {
11-
const thirdwebClient = useThirdwebClient();
11+
export function useDashboardStorageUpload(options: DashboardUploadOptions) {
1212
return useMutation({
1313
mutationFn: async (files: Array<File | string>): Promise<string[]> => {
1414
const uris = await upload({
15-
client: thirdwebClient,
1615
files,
1716
...options,
1817
});

apps/dashboard/src/app/(app)/(dashboard)/(chain)/[chain_id]/(chainPage)/components/client/FaucetButton.tsx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -407,6 +407,7 @@ function SendFundsToFaucetModalContent(props: {
407407
isLoggedIn={props.isLoggedIn}
408408
connectButtonClassName="!w-full"
409409
detailsButtonClassName="!w-full"
410+
client={props.client}
410411
/>
411412
)}
412413

apps/dashboard/src/app/(app)/(dashboard)/(chain)/[chain_id]/(chainPage)/components/client/add-chain-to-wallet.tsx

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ import { ToolTipLabel } from "@/components/ui/tooltip";
66
import { useCustomConnectModal } from "@3rdweb-sdk/react/components/connect-wallet";
77
import { useMutation } from "@tanstack/react-query";
88
import { toast } from "sonner";
9-
import type { Chain } from "thirdweb";
9+
import type { Chain, ThirdwebClient } from "thirdweb";
1010
import {
1111
useActiveAccount,
1212
useActiveWalletChain,
@@ -16,6 +16,7 @@ import { useDebounce } from "use-debounce";
1616

1717
type AddChainToWalletProps = {
1818
chain: Chain;
19+
client: ThirdwebClient;
1920
};
2021

2122
export const AddChainToWallet: React.FC<AddChainToWalletProps> = (props) => {
@@ -49,7 +50,10 @@ export const AddChainToWallet: React.FC<AddChainToWalletProps> = (props) => {
4950
onClick={() => {
5051
// Connect directly to this chain
5152
if (!account) {
52-
return customConnectModal({ chain: props.chain });
53+
return customConnectModal({
54+
chain: props.chain,
55+
client: props.client,
56+
});
5357
}
5458

5559
// switch to this chain

apps/dashboard/src/app/(app)/(dashboard)/(chain)/[chain_id]/(chainPage)/components/server/chain-header.tsx

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import { Button } from "@/components/ui/button";
22
import { cn } from "@/lib/utils";
33
import Link from "next/link";
4+
import type { ThirdwebClient } from "thirdweb";
45
import type { ChainMetadata } from "thirdweb/chains";
56
import { mapV4ChainToV5Chain } from "../../../../../../../../contexts/map-chains";
67
import { ChainIcon } from "../../../../components/server/chain-icon";
@@ -10,6 +11,7 @@ type ChainHeaderProps = {
1011
headerImageUrl?: string;
1112
logoUrl?: string;
1213
chain: ChainMetadata;
14+
client: ThirdwebClient;
1315
};
1416

1517
// TODO: improve the behavior when clicking "Get started with thirdweb", currently just redirects to the dashboard
@@ -51,6 +53,7 @@ export function ChainHeader(props: ChainHeaderProps) {
5153
{/* Desktop only */}
5254
<div className="hidden flex-row gap-2 lg:flex">
5355
<AddChainToWallet
56+
client={props.client}
5457
chain={
5558
// Do not include chain overrides for chain pages
5659
// eslint-disable-next-line no-restricted-syntax

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -164,6 +164,7 @@ The following is the user's message:
164164
headerImageUrl={chainMetadata?.headerImgUrl}
165165
logoUrl={chain.icon?.url}
166166
chain={chain}
167+
client={client}
167168
/>
168169

169170
<div className="h-4 md:h-8" />
@@ -210,6 +211,7 @@ The following is the user's message:
210211
<div className="w-full sm:hidden">
211212
<div className="grid grid-cols-2 gap-2">
212213
<AddChainToWallet
214+
client={client}
213215
chain={
214216
// Do not include chain overrides for chain pages
215217
// eslint-disable-next-line no-restricted-syntax

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
@@ -485,6 +485,7 @@ export const CreateListingsForm: React.FC<CreateListingsFormProps> = ({
485485
>
486486
<FormLabel>Contract address</FormLabel>
487487
<SolidityInput
488+
client={contract.client}
488489
solidityType="address"
489490
formContext={form}
490491
{...form.register("selected.contractAddress", {

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -103,6 +103,7 @@ const TransferTab: React.FC<TransferTabProps> = ({
103103
<FormControl isRequired isInvalid={!!form.formState.errors.to}>
104104
<FormLabel>To Address</FormLabel>
105105
<SolidityInput
106+
client={contract.client}
106107
solidityType="address"
107108
formContext={form}
108109
placeholder={ZERO_ADDRESS}

apps/dashboard/src/app/(app)/(dashboard)/(chain)/[chain_id]/[contractAddress]/settings/components/platform-fees.tsx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -129,6 +129,7 @@ export const SettingsPlatformFees = ({
129129
>
130130
<FormLabel>Recipient Address</FormLabel>
131131
<SolidityInput
132+
client={contract.client}
132133
solidityType="address"
133134
formContext={form}
134135
{...form.register("platform_fee_recipient")}

apps/dashboard/src/app/(app)/(dashboard)/(chain)/[chain_id]/[contractAddress]/settings/components/primary-sale.tsx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -127,6 +127,7 @@ export const SettingsPrimarySale = ({
127127
>
128128
<FormLabel>Recipient Address</FormLabel>
129129
<SolidityInput
130+
client={contract.client}
130131
disabled={mutation.isPending || !address}
131132
solidityType="address"
132133
formContext={form}

0 commit comments

Comments
 (0)