Skip to content

Commit 5b40f76

Browse files
authored
Dashboard: thirdweb client refactor (#6987)
1 parent ef1550c commit 5b40f76

File tree

85 files changed

+215
-320
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

+215
-320
lines changed

apps/dashboard/src/@/actions/getBalancesFromMoralis.ts

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
import { defineDashboardChain } from "lib/defineDashboardChain";
33
import { ZERO_ADDRESS, isAddress, toTokens } from "thirdweb";
44
import { getWalletBalance } from "thirdweb/wallets";
5-
import { getUserThirdwebClient } from "../../app/(app)/api/lib/getAuthToken";
5+
import { serverThirdwebClient } from "../constants/thirdweb-client.server";
66

77
type BalanceQueryResponse = Array<{
88
balance: string;
@@ -23,7 +23,6 @@ export async function getTokenBalancesFromMoralis(params: {
2323
error: string;
2424
}
2525
> {
26-
const client = await getUserThirdwebClient();
2726
const { contractAddress, chainId } = params;
2827

2928
if (!isAddress(contractAddress)) {
@@ -39,7 +38,7 @@ export async function getTokenBalancesFromMoralis(params: {
3938
const balance = await getWalletBalance({
4039
address: contractAddress,
4140
chain,
42-
client,
41+
client: serverThirdwebClient,
4342
});
4443
return [
4544
{
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
import { getConfiguredThirdwebClient } from "./thirdweb.server";
2+
3+
export function getClientThirdwebClient(params?: {
4+
jwt: string | undefined | null;
5+
teamId: string | undefined | null;
6+
}) {
7+
return getConfiguredThirdwebClient({
8+
secretKey: params?.jwt ?? undefined,
9+
teamId: params?.teamId ?? undefined,
10+
});
11+
}
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
import "server-only";
2+
3+
import { DASHBOARD_THIRDWEB_SECRET_KEY } from "./env";
4+
import { getConfiguredThirdwebClient } from "./thirdweb.server";
5+
6+
export const serverThirdwebClient = getConfiguredThirdwebClient({
7+
teamId: undefined,
8+
secretKey: DASHBOARD_THIRDWEB_SECRET_KEY,
9+
});

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import { useActiveAccount } from "thirdweb/react";
44
import type { GetAuthTokenResponse } from "../../app/(app)/api/auth/get-auth-token/route";
55
import { LAST_USED_TEAM_ID } from "../../constants/cookies";
66
import { getCookie } from "../../lib/cookie";
7-
import { getThirdwebClient } from "./thirdweb.server";
7+
import { getClientThirdwebClient } from "./thirdweb-client.client";
88

99
// returns a thirdweb client with optional JWT passed i
1010

@@ -38,7 +38,7 @@ export function useThirdwebClient(jwt?: string) {
3838
return useMemo(
3939
// prefer jwt from props over the one from the token query if it exists
4040
() =>
41-
getThirdwebClient({
41+
getClientThirdwebClient({
4242
jwt: jwt || query.data,
4343
teamId: lastUsedTeamId,
4444
}),

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

Lines changed: 7 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
import {
22
DASHBOARD_THIRDWEB_CLIENT_ID,
3-
DASHBOARD_THIRDWEB_SECRET_KEY,
43
IPFS_GATEWAY_URL,
54
} from "@/constants/env";
65
import {
@@ -12,7 +11,7 @@ import {
1211
THIRDWEB_SOCIAL_API_DOMAIN,
1312
THIRDWEB_STORAGE_DOMAIN,
1413
} from "constants/urls";
15-
import { createThirdwebClient } from "thirdweb";
14+
import { type ThirdwebClient, createThirdwebClient } from "thirdweb";
1615
import { populateEip712Transaction } from "thirdweb/transaction";
1716
import {
1817
getTransactionDecorator,
@@ -22,15 +21,10 @@ import {
2221
import { getZkPaymasterData } from "thirdweb/wallets/smart";
2322
import { getVercelEnv } from "../../lib/vercel-utils";
2423

25-
// returns a thirdweb client with optional JWT passed in
26-
export function getThirdwebClient(
27-
options:
28-
| {
29-
jwt: string | null | undefined;
30-
teamId: string | undefined;
31-
}
32-
| undefined,
33-
) {
24+
export function getConfiguredThirdwebClient(options: {
25+
secretKey: string | undefined;
26+
teamId: string | undefined;
27+
}): ThirdwebClient {
3428
if (getVercelEnv() !== "production") {
3529
// if not on production: run this when creating a client to set the domains
3630
setThirdwebDomains({
@@ -78,8 +72,8 @@ export function getThirdwebClient(
7872
}
7973

8074
return createThirdwebClient({
81-
teamId: options?.teamId,
82-
secretKey: options?.jwt ? options.jwt : DASHBOARD_THIRDWEB_SECRET_KEY,
75+
teamId: options.teamId,
76+
secretKey: options.secretKey,
8377
clientId: DASHBOARD_THIRDWEB_CLIENT_ID,
8478
config: {
8579
storage: {

apps/dashboard/src/app/(app)/(dashboard)/(bridge)/bridge/page.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
import { getThirdwebClient } from "@/constants/thirdweb.server";
21
import type { Metadata } from "next";
2+
import { getClientThirdwebClient } from "../../../../../@/constants/thirdweb-client.client";
33
import { UniversalBridgeEmbed } from "./components/client/UniversalBridgeEmbed";
44

55
const title = "Universal Bridge: Swap, Bridge, and On-Ramp";
@@ -19,7 +19,7 @@ export default async function RoutesPage({
1919
searchParams,
2020
}: { searchParams: Record<string, string | string[]> }) {
2121
const { chainId } = searchParams;
22-
const client = getThirdwebClient(undefined);
22+
const client = getClientThirdwebClient(undefined);
2323
return (
2424
<div className="relative mx-auto flex h-screen w-full flex-col items-center justify-center overflow-hidden border py-10">
2525
<main className="container z-10 flex justify-center">

apps/dashboard/src/app/(app)/(dashboard)/(bridge)/routes/components/server/routelist-card.tsx

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
import { Card, CardContent, CardHeader } from "@/components/ui/card";
22
import { resolveSchemeWithErrorHandler } from "@/lib/resolveSchemeWithErrorHandler";
3-
import type { ThirdwebClient } from "thirdweb";
43
import { defineChain } from "thirdweb";
54
import { getChainMetadata } from "thirdweb/chains";
5+
import { serverThirdwebClient } from "../../../../../../../@/constants/thirdweb-client.server";
66

77
type RouteListCardProps = {
88
originChainId: number;
@@ -15,7 +15,6 @@ type RouteListCardProps = {
1515
destinationTokenIconUri?: string | null;
1616
destinationTokenSymbol: string;
1717
destinationTokenName: string;
18-
client: ThirdwebClient;
1918
};
2019

2120
export async function RouteListCard({
@@ -27,7 +26,6 @@ export async function RouteListCard({
2726
destinationTokenAddress,
2827
destinationTokenIconUri,
2928
destinationTokenName,
30-
client,
3129
}: RouteListCardProps) {
3230
const [
3331
originChain,
@@ -42,13 +40,13 @@ export async function RouteListCard({
4240
originTokenIconUri
4341
? resolveSchemeWithErrorHandler({
4442
uri: originTokenIconUri,
45-
client,
43+
client: serverThirdwebClient,
4644
})
4745
: undefined,
4846
destinationTokenIconUri
4947
? resolveSchemeWithErrorHandler({
5048
uri: destinationTokenIconUri,
51-
client,
49+
client: serverThirdwebClient,
5250
})
5351
: undefined,
5452
]);

apps/dashboard/src/app/(app)/(dashboard)/(bridge)/routes/components/server/routelist-row.tsx

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import { CopyTextButton } from "@/components/ui/CopyTextButton";
22
import { TableCell, TableRow } from "@/components/ui/table";
3+
import { serverThirdwebClient } from "@/constants/thirdweb-client.server";
34
import { resolveSchemeWithErrorHandler } from "@/lib/resolveSchemeWithErrorHandler";
4-
import type { ThirdwebClient } from "thirdweb";
55
import { defineChain, getChainMetadata } from "thirdweb/chains";
66

77
type RouteListRowProps = {
@@ -15,7 +15,6 @@ type RouteListRowProps = {
1515
destinationTokenIconUri?: string | null;
1616
destinationTokenSymbol?: string;
1717
destinationTokenName?: string;
18-
client: ThirdwebClient;
1918
};
2019

2120
export async function RouteListRow({
@@ -27,7 +26,6 @@ export async function RouteListRow({
2726
destinationTokenAddress,
2827
destinationTokenIconUri,
2928
destinationTokenSymbol,
30-
client,
3129
}: RouteListRowProps) {
3230
const [
3331
originChain,
@@ -42,13 +40,13 @@ export async function RouteListRow({
4240
originTokenIconUri
4341
? resolveSchemeWithErrorHandler({
4442
uri: originTokenIconUri,
45-
client,
43+
client: serverThirdwebClient,
4644
})
4745
: undefined,
4846
destinationTokenIconUri
4947
? resolveSchemeWithErrorHandler({
5048
uri: destinationTokenIconUri,
51-
client,
49+
client: serverThirdwebClient,
5250
})
5351
: undefined,
5452
]);

apps/dashboard/src/app/(app)/(dashboard)/(bridge)/routes/components/server/routes-table.tsx

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@ import {
66
TableHeader,
77
TableRow,
88
} from "@/components/ui/table";
9-
import { getThirdwebClient } from "@/constants/thirdweb.server";
109
import type { Address } from "thirdweb";
1110
import { checksumAddress } from "thirdweb/utils";
1211
import { getRoutes } from "../../../utils";
@@ -137,7 +136,6 @@ export async function RoutesData(props: {
137136
const startIndex = (activePage - 1) * pageSize;
138137
const endIndex = startIndex + pageSize;
139138
const paginatedRoutes = routesToRender.slice(startIndex, endIndex);
140-
const client = getThirdwebClient(undefined);
141139

142140
return (
143141
<>
@@ -172,7 +170,6 @@ export async function RoutesData(props: {
172170
destinationTokenIconUri={route.destinationToken.iconUri}
173171
destinationTokenSymbol={route.destinationToken.symbol}
174172
destinationTokenName={route.destinationToken.name}
175-
client={client}
176173
/>
177174
))}
178175
</TableBody>
@@ -196,7 +193,6 @@ export async function RoutesData(props: {
196193
destinationTokenIconUri={route.destinationToken.iconUri}
197194
destinationTokenSymbol={route.destinationToken.symbol}
198195
destinationTokenName={route.destinationToken.name}
199-
client={client}
200196
/>
201197
</li>
202198
))}

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

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

109
export function BuyFundsSection(props: {
1110
chain: ChainMetadata;
12-
client: ThirdwebClient;
1311
}) {
1412
const sanitizedChainName = props.chain.name.replace("Mainnet", "").trim();
1513

@@ -22,7 +20,6 @@ export function BuyFundsSection(props: {
2220
<ChainIcon
2321
className="-mr-2 size-12 rounded-full border p-1"
2422
iconUrl={props.chain.icon?.url}
25-
client={props.client}
2623
/>
2724
<CreditCardIcon
2825
bg="hsl(var(--background))"

0 commit comments

Comments
 (0)