Skip to content

Commit b84db12

Browse files
committed
Dashboard: Reduce useThirdwebClient hook usage #3 (#7226)
<!-- ## 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 primarily focuses on updating the usage of the `client` prop throughout various components in the application, replacing instances of `useThirdwebClient` with a more consistent approach using `getClientThirdwebClient`. ### Detailed summary - Added `client` prop to multiple components including `AccountPage`, `DeployedContractsPage`, and `FaucetButton`. - Replaced `useThirdwebClient` with `getClientThirdwebClient` in various files. - Ensured consistency in passing the `client` prop across components. - Updated the `ProfileHeader`, `PayModalButton`, and `SendTestTransaction` to accept `client` as a prop. - Modified forms and sections to utilize the `client` prop for better integration with Thirdweb services. > ✨ 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 - **Refactor** - Updated various components to receive a client instance as a prop instead of obtaining it internally, improving consistency and making client usage more explicit throughout the app. - Enhanced component interfaces to require a client prop where necessary, ensuring proper client context is passed across the dashboard. - Adjusted authentication and layout flows to support explicit client instantiation and propagation. <!-- end of auto-generated comment: release notes by coderabbit.ai -->
1 parent a440621 commit b84db12

File tree

36 files changed

+186
-77
lines changed

36 files changed

+186
-77
lines changed

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,6 @@ import {
2323
NEXT_PUBLIC_THIRDWEB_ENGINE_FAUCET_WALLET,
2424
NEXT_PUBLIC_TURNSTILE_SITE_KEY,
2525
} from "@/constants/public-envs";
26-
import { useThirdwebClient } from "@/constants/thirdweb.client";
2726
import { CustomConnectWallet } from "@3rdweb-sdk/react/components/connect-wallet";
2827
import { zodResolver } from "@hookform/resolvers/zod";
2928
import { Turnstile } from "@marsidev/react-turnstile";
@@ -77,13 +76,14 @@ export function FaucetButton({
7776
chain,
7877
amount,
7978
isLoggedIn,
79+
client,
8080
}: {
8181
chain: ChainMetadata;
8282
amount: number;
8383
isLoggedIn: boolean;
84+
client: ThirdwebClient;
8485
}) {
8586
const pathname = usePathname();
86-
const client = useThirdwebClient();
8787
const address = useActiveAccount()?.address;
8888
const chainId = chain.chainId;
8989
// do not include local overrides for chain pages

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

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,19 @@
11
"use client";
22
import { Button } from "@/components/ui/button";
33
import { Dialog, DialogContent, DialogTrigger } from "@/components/ui/dialog";
4-
import { useThirdwebClient } from "@/constants/thirdweb.client";
54
import { useTrack } from "hooks/analytics/useTrack";
65
import { defineDashboardChain } from "lib/defineDashboardChain";
76
import { useTheme } from "next-themes";
7+
import type { ThirdwebClient } from "thirdweb";
88
import { PayEmbed } from "thirdweb/react";
99
import { getSDKTheme } from "../../../../../../components/sdk-component-theme";
1010

11-
export function PayModalButton(props: { chainId: number; label: string }) {
11+
export function PayModalButton(props: {
12+
chainId: number;
13+
label: string;
14+
client: ThirdwebClient;
15+
}) {
1216
const { theme } = useTheme();
13-
const client = useThirdwebClient();
1417
const trackEvent = useTrack();
1518
return (
1619
<Dialog>
@@ -35,7 +38,7 @@ export function PayModalButton(props: { chainId: number; label: string }) {
3538
dialogCloseClassName="focus:ring-0"
3639
>
3740
<PayEmbed
38-
client={client}
41+
client={props.client}
3942
theme={getSDKTheme(theme === "dark" ? "dark" : "light")}
4043
className="!w-auto"
4144
payOptions={{

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

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import { ExternalLinkIcon } from "lucide-react";
22
import Link from "next/link";
3+
import type { ThirdwebClient } from "thirdweb";
34
import type { ChainMetadata } from "thirdweb/chains";
45
import { ChainIcon } from "../../../../components/server/chain-icon";
56
import { PayModalButton } from "../client/PayModal";
@@ -8,6 +9,7 @@ import { SectionTitle } from "./SectionTitle";
89

910
export function BuyFundsSection(props: {
1011
chain: ChainMetadata;
12+
client: ThirdwebClient;
1113
}) {
1214
const sanitizedChainName = props.chain.name.replace("Mainnet", "").trim();
1315

@@ -45,6 +47,7 @@ export function BuyFundsSection(props: {
4547
<PayModalButton
4648
chainId={props.chain.chainId}
4749
label={`Bridge to ${sanitizedChainName}`}
50+
client={props.client}
4851
/>
4952

5053
<div className="h-4" />

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

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import type { ThirdwebClient } from "thirdweb";
12
import type { ChainMetadata } from "thirdweb/chains";
23
import { getFaucetClaimAmount } from "../../../../../../api/testnet-faucet/claim/claim-amount";
34
import { ChainIcon } from "../../../../components/server/chain-icon";
@@ -8,8 +9,9 @@ import { SectionTitle } from "./SectionTitle";
89
export async function FaucetSection(props: {
910
chain: ChainMetadata;
1011
isLoggedIn: boolean;
12+
client: ThirdwebClient;
1113
}) {
12-
const { chain, isLoggedIn } = props;
14+
const { chain, isLoggedIn, client } = props;
1315

1416
// Check eligibility.
1517
const sanitizedChainName = chain.name.replace("Mainnet", "").trim();
@@ -44,6 +46,7 @@ export async function FaucetSection(props: {
4446
<div className="h-8" />
4547

4648
<FaucetButton
49+
client={client}
4750
chain={chain}
4851
amount={amountToGive}
4952
isLoggedIn={isLoggedIn}

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

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import { CircleAlertIcon } from "lucide-react";
2+
import { getClientThirdwebClient } from "../../../../../../@/constants/thirdweb-client.client";
23
import { getRawAccount } from "../../../../account/settings/getAccount";
34
import { getChain, getChainMetadata } from "../../utils";
45
import NextSteps from "./components/client/NextSteps";
@@ -16,6 +17,7 @@ export default async function Page(props: {
1617
const params = await props.params;
1718
const chain = await getChain(params.chain_id);
1819
const chainMetadata = await getChainMetadata(chain.chainId);
20+
const client = getClientThirdwebClient();
1921
const isDeprecated = chain.status === "deprecated";
2022

2123
const account = await getRawAccount();
@@ -42,9 +44,9 @@ export default async function Page(props: {
4244

4345
{/* Faucet / Buy Funds */}
4446
{chain.testnet ? (
45-
<FaucetSection chain={chain} isLoggedIn={!!account} />
47+
<FaucetSection chain={chain} isLoggedIn={!!account} client={client} />
4648
) : chain.services.find((c) => c.service === "pay" && c.enabled) ? (
47-
<BuyFundsSection chain={chain} />
49+
<BuyFundsSection chain={chain} client={client} />
4850
) : null}
4951

5052
{/* Chain Overview */}

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@ export const AccountPage: React.FC<AccountPageProps> = ({
4141
address={contract.address}
4242
symbol={symbol}
4343
chain={chainMetadata}
44+
client={contract.client}
4445
/>
4546
)}
4647

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

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

3-
import { useThirdwebClient } from "@/constants/thirdweb.client";
43
import { Input } from "@chakra-ui/react";
54
import { TransactionButton } from "components/buttons/TransactionButton";
65
import { useV5DashboardChain } from "lib/v5-adapter";
76
import { type ChangeEvent, useState } from "react";
87
import type { StoredChain } from "stores/chainStores";
9-
import { prepareTransaction, toWei } from "thirdweb";
8+
import { type ThirdwebClient, prepareTransaction, toWei } from "thirdweb";
109
import { useSendAndConfirmTransaction } from "thirdweb/react";
1110
import { Card } from "tw-components";
1211

@@ -15,15 +14,16 @@ interface DepositNativeProps {
1514
symbol: string;
1615
chain: StoredChain;
1716
isLoggedIn: boolean;
17+
client: ThirdwebClient;
1818
}
1919

2020
export const DepositNative: React.FC<DepositNativeProps> = ({
2121
address,
2222
symbol,
2323
chain,
2424
isLoggedIn,
25+
client,
2526
}) => {
26-
const client = useThirdwebClient();
2727
const { mutate: transfer, isPending } = useSendAndConfirmTransaction();
2828
const [amount, setAmount] = useState("");
2929
const handleChange = (e: ChangeEvent<HTMLInputElement>) => {

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

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

33
import { Spinner } from "@/components/ui/Spinner/Spinner";
4-
import { useThirdwebClient } from "@/constants/thirdweb.client";
54
import { FormControl, Input, Select, Skeleton, Spacer } from "@chakra-ui/react";
65
import { useMutation, useQuery } from "@tanstack/react-query";
76
import { TransactionButton } from "components/buttons/TransactionButton";
@@ -60,7 +59,6 @@ type InstallModuleFormProps = {
6059
export type InstallModuleForm = UseFormReturn<FormData>;
6160

6261
export const InstallModuleForm = (props: InstallModuleFormProps) => {
63-
const client = useThirdwebClient();
6462
const form = useForm<FormData>({
6563
defaultValues: {
6664
publisherAddress: "0xdd99b75f095d0c4d5112aCe938e4e6ed962fb024", // thirdweb publisher address
@@ -182,7 +180,7 @@ export const InstallModuleForm = (props: InstallModuleFormProps) => {
182180
moduleAddress.map(async (address) => {
183181
const result = await resolveImplementation(
184182
getContract({
185-
client,
183+
client: contract.client,
186184
address,
187185
chain: contract.chain,
188186
}),
@@ -231,7 +229,7 @@ export const InstallModuleForm = (props: InstallModuleFormProps) => {
231229
moduleInfo: {
232230
bytecodeUri: selectedModule.metadata.bytecodeUri,
233231
},
234-
client,
232+
client: contract.client,
235233
});
236234
},
237235
retry: false,
@@ -255,6 +253,7 @@ export const InstallModuleForm = (props: InstallModuleFormProps) => {
255253
const moduleInstallParams = useModuleInstallParams({
256254
module: selectedModuleMeta,
257255
isQueryEnabled: !!selectedModule && !!isModuleCompatibleQuery.data,
256+
client: contract.client,
258257
});
259258

260259
return (

apps/dashboard/src/app/(app)/(dashboard)/(chain)/[chain_id]/[contractAddress]/modules/components/install-module-params.tsx

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
1-
import { useThirdwebClient } from "@/constants/thirdweb.client";
21
import { FormControl } from "@chakra-ui/react";
32
import { useQuery } from "@tanstack/react-query";
43
import { SolidityInput } from "contract-ui/components/solidity-inputs";
4+
import type { ThirdwebClient } from "thirdweb";
55
import invariant from "tiny-invariant";
66
import { FormErrorMessage, FormLabel } from "tw-components";
77
import type { InstallModuleForm } from "./ModuleForm";
@@ -20,9 +20,9 @@ export type ModuleMeta = {
2020
export function useModuleInstallParams(props: {
2121
module?: ModuleMeta;
2222
isQueryEnabled: boolean;
23+
client: ThirdwebClient;
2324
}) {
24-
const client = useThirdwebClient();
25-
const { module, isQueryEnabled } = props;
25+
const { module, isQueryEnabled, client } = props;
2626
return useQuery({
2727
queryKey: ["useModuleInstallParams", module],
2828
queryFn: async () => {

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

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@ import { Button } from "@/components/ui/button";
1616
import { CodeClient } from "@/components/ui/code/code.client";
1717
import { TabButtons } from "@/components/ui/tabs";
1818
import { ToolTipLabel } from "@/components/ui/tooltip";
19-
import { useThirdwebClient } from "@/constants/thirdweb.client";
2019
import { resolveSchemeWithErrorHandler } from "@/lib/resolveSchemeWithErrorHandler";
2120
import { useChainSlug } from "hooks/chains/chainSlug";
2221
import { ExternalLinkIcon } from "lucide-react";
@@ -78,8 +77,6 @@ export const TokenIdPage: React.FC<TokenIdPageProps> = ({
7877
accountAddress,
7978
});
8079

81-
const client = useThirdwebClient();
82-
8380
const { data: nft, isPending } = useReadContract(
8481
isErc721 ? getErc721NFT : getErc1155NFT,
8582
{
@@ -175,7 +172,9 @@ export const TokenIdPage: React.FC<TokenIdPageProps> = ({
175172
/>
176173

177174
{/* tab contents */}
178-
{tab === "Details" && <NFTDetailsTab nft={nft} client={client} />}
175+
{tab === "Details" && (
176+
<NFTDetailsTab nft={nft} client={contract.client} />
177+
)}
179178

180179
{tabs.map((tb) => {
181180
return (

apps/dashboard/src/app/(app)/(dashboard)/profile/[addressOrEns]/ProfileUI.tsx

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,25 @@
11
import { Spinner } from "@/components/ui/Spinner/Spinner";
22
import { fetchPublishedContracts } from "components/contract-components/fetchPublishedContracts";
33
import { Suspense } from "react";
4+
import type { ThirdwebClient } from "thirdweb";
45
import { serverThirdwebClient } from "../../../../../@/constants/thirdweb-client.server";
56
import { ProfileHeader } from "./components/profile-header";
67
import { PublishedContracts } from "./components/published-contracts";
78

89
export function ProfileUI(props: {
910
profileAddress: string;
1011
ensName: string | undefined;
12+
client: ThirdwebClient;
1113
}) {
1214
const { profileAddress, ensName } = props;
1315

1416
return (
1517
<div className="container pt-8 pb-20">
16-
<ProfileHeader profileAddress={profileAddress} ensName={ensName} />
18+
<ProfileHeader
19+
profileAddress={profileAddress}
20+
ensName={ensName}
21+
client={props.client}
22+
/>
1723
<div className="h-8" />
1824

1925
<div>

apps/dashboard/src/app/(app)/(dashboard)/profile/[addressOrEns]/components/profile-header.tsx

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

33
import { Skeleton } from "@/components/ui/skeleton";
4-
import { useThirdwebClient } from "@/constants/thirdweb.client";
54
import { replaceDeployerAddress } from "lib/publisher-utils";
5+
import type { ThirdwebClient } from "thirdweb";
66
import {
77
AccountAddress,
88
AccountAvatar,
@@ -15,10 +15,10 @@ import { shortenIfAddress } from "utils/usedapp-external";
1515
export function ProfileHeader(props: {
1616
profileAddress: string;
1717
ensName: string | undefined;
18+
client: ThirdwebClient;
1819
}) {
19-
const client = useThirdwebClient();
2020
return (
21-
<AccountProvider address={props.profileAddress} client={client}>
21+
<AccountProvider address={props.profileAddress} client={props.client}>
2222
<div className="flex w-full flex-col items-center justify-between gap-4 border-border border-b pb-6 md:flex-row">
2323
<div className="flex w-full items-center gap-4">
2424
<AccountAvatar

apps/dashboard/src/app/(app)/(dashboard)/profile/[addressOrEns]/page.tsx

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
1+
import { getClientThirdwebClient } from "@/constants/thirdweb-client.client";
2+
import { serverThirdwebClient } from "@/constants/thirdweb-client.server";
13
import { replaceDeployerAddress } from "lib/publisher-utils";
24
import type { Metadata } from "next";
35
import { notFound } from "next/navigation";
46
import { shortenIfAddress } from "utils/usedapp-external";
5-
import { serverThirdwebClient } from "../../../../../@/constants/thirdweb-client.server";
67
import { ProfileUI } from "./ProfileUI";
78
import { resolveAddressAndEns } from "./resolveAddressAndEns";
89

@@ -27,6 +28,7 @@ export default async function Page(props: PageProps) {
2728
<ProfileUI
2829
ensName={replaceDeployerAddress(resolvedInfo.ensName || "")}
2930
profileAddress={resolvedInfo.address}
31+
client={getClientThirdwebClient()}
3032
/>
3133
);
3234
}

apps/dashboard/src/app/(app)/(dashboard)/tools/transaction-simulator/components/TransactionSimulator.tsx

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@ import { Input } from "@/components/ui/input";
88
import { Label } from "@/components/ui/label";
99
import { Textarea } from "@/components/ui/textarea";
1010
import { ToolTipLabel } from "@/components/ui/tooltip";
11-
import { useThirdwebClient } from "@/constants/thirdweb.client";
1211
import type { Abi, AbiFunction } from "abitype";
1312
import { useV5DashboardChain } from "lib/v5-adapter";
1413
import { ArrowDownIcon, WalletIcon } from "lucide-react";
@@ -25,6 +24,7 @@ import {
2524
import { resolveContractAbi } from "thirdweb/contract";
2625
import { useActiveAccount } from "thirdweb/react";
2726
import { parseAbiParams } from "thirdweb/utils";
27+
import { getClientThirdwebClient } from "../../../../../../@/constants/thirdweb-client.client";
2828
import { ShareButton } from "../../components/share";
2929

3030
export type SimulateTransactionForm = {
@@ -61,8 +61,7 @@ export const TransactionSimulator = (props: {
6161
const chain = useV5DashboardChain(
6262
Number.isInteger(Number(chainId)) ? chainId : undefined,
6363
);
64-
const client = useThirdwebClient();
65-
64+
const client = getClientThirdwebClient();
6665
async function handleSimulation(data: SimulateTransactionForm) {
6766
try {
6867
setIsPending(true);

0 commit comments

Comments
 (0)