Skip to content

Commit ac8b09f

Browse files
committed
Dashboard: Add team id to thirdweb client (#6775)
<!-- ## 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 updating the usage of the `getThirdwebClient` function throughout the codebase, transitioning to using an options object that includes `jwt` and `teamId`. This change enhances client initialization consistency and improves the handling of team-related functionality. ### Detailed summary - Updated `getThirdwebClient` to accept an options object with `jwt` and `teamId`. - Modified several components to pass the new client structure. - Added constants for `LAST_USED_PROJECT_ID` and `LAST_USED_TEAM_ID`. - Enhanced various components to include `client` as a prop, improving flexibility. - Adjusted several pages and components to handle team IDs better. - Improved cookie management for storing and retrieving the last used team ID. - Updated storybook examples to utilize the new client structure. > The following files were skipped due to too many changes: `apps/dashboard/src/app/team/[team_slug]/(team)/~/usage/overview/components/SponsoredTransactionsTableUI.stories.tsx`, `apps/dashboard/src/app/(dashboard)/profile/[addressOrEns]/components/published-contracts.tsx`, `apps/dashboard/src/app/team/[team_slug]/[project_slug]/components/Transactions/index.tsx`, `apps/dashboard/src/components/configure-networks/ConfigureNetworkForm.tsx`, `apps/dashboard/src/components/contract-components/contract-table/index.tsx`, `apps/dashboard/src/app/(dashboard)/(chain)/[chain_id]/(chainPage)/page.tsx`, `apps/dashboard/src/app/(dashboard)/(bridge)/routes/components/server/routelist-card.tsx`, `apps/dashboard/src/app/(dashboard)/(bridge)/routes/components/server/routes-table.tsx`, `apps/dashboard/src/app/(dashboard)/profile/[addressOrEns]/page.tsx`, `apps/dashboard/src/app/(dashboard)/profile/[addressOrEns]/resolveAddressAndEns.tsx`, `apps/dashboard/src/app/team/components/TeamHeader/TeamSelectorMobileMenuButton.tsx`, `apps/dashboard/src/app/team/components/TeamHeader/TeamHeaderUI.stories.tsx`, `apps/dashboard/src/app/(dashboard)/contracts/deploy/[compiler_uri]/page.tsx`, `apps/dashboard/src/app/(dashboard)/(bridge)/routes/components/server/routelist-row.tsx`, `apps/dashboard/src/components/contract-components/contract-deploy-form/custom-contract.tsx`, `apps/dashboard/src/app/team/[team_slug]/(team)/~/settings/members/TeamMembersSettingsPage.stories.tsx`, `apps/dashboard/src/app/(dashboard)/published-contract/[publisher]/[contract_id]/page.tsx`, `apps/dashboard/src/components/contract-components/contract-publish-form/index.tsx`, `apps/dashboard/src/app/nebula-app/(app)/components/ExecuteTransactionCard.stories.tsx`, `apps/dashboard/src/lib/wallet/nfts/alchemy.ts`, `apps/dashboard/src/lib/wallet/nfts/moralis.ts`, `apps/dashboard/src/app/(dashboard)/contracts/publish/[publish_uri]/page.tsx`, `apps/dashboard/src/app/(dashboard)/(chain)/[chain_id]/[contractAddress]/_layout/metadata-header.tsx`, `apps/dashboard/src/app/team/components/TeamHeader/team-header-logged-in.client.tsx`, `apps/dashboard/src/components/contract-components/fetchPublishedContracts.ts`, `apps/dashboard/src/app/(dashboard)/(chain)/[chain_id]/[contractAddress]/modules/components/getModuleInstalledParams.ts`, `apps/dashboard/src/app/nebula-app/(app)/components/Chats.stories.tsx`, `apps/dashboard/src/components/explore/contract-card/index.tsx`, `apps/dashboard/src/app/(dashboard)/(chain)/[chain_id]/(chainPage)/layout.tsx`, `apps/dashboard/src/app/(dashboard)/(chain)/chainlist/components/server/chainlist-row.tsx`, `apps/dashboard/src/app/(dashboard)/profile/[addressOrEns]/components/PublishedContractTable.tsx`, `apps/dashboard/src/app/(dashboard)/(chain)/chainlist/components/server/chainlist-card.tsx`, `apps/dashboard/src/app/(dashboard)/profile/[addressOrEns]/ProfileUI.tsx`, `apps/dashboard/src/components/contract-components/fetch-contracts-with-versions.ts`, `apps/dashboard/src/app/team/[team_slug]/(team)/layout.tsx`, `apps/dashboard/src/@/components/blocks/Avatars/ProjectAvatar.stories.tsx`, `apps/dashboard/src/app/(dashboard)/published-contract/components/publish-based-deploy.tsx`, `apps/dashboard/src/app/team/components/TeamHeader/team-header.tsx`, `apps/dashboard/src/app/team/[team_slug]/[project_slug]/components/Transactions/TransactionCharts.tsx`, `apps/dashboard/src/app/team/[team_slug]/[project_slug]/layout.tsx`, `apps/dashboard/src/app/(dashboard)/(chain)/[chain_id]/[contractAddress]/cross-chain/data-table.tsx`, `apps/dashboard/src/app/(dashboard)/published-contract/[publisher]/[contract_id]/utils/getPublishedContractsWithPublisherMapping.ts`, `apps/dashboard/src/app/(dashboard)/published-contract/[publisher]/[contract_id]/[version]/page.tsx`, `apps/dashboard/src/@/components/blocks/Avatars/GradientAvatar.stories.tsx`, `apps/dashboard/src/app/team/[team_slug]/[project_slug]/page.tsx`, `apps/dashboard/src/components/contract-components/hooks.ts` > ✨ Ask PR-Codex anything about this PR by commenting with `/codex {your question}` <!-- end pr-codex -->
1 parent f7f179c commit ac8b09f

File tree

142 files changed

+768
-353
lines changed

Some content is hidden

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

142 files changed

+768
-353
lines changed

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,8 @@
11
"use server";
2-
3-
import { getThirdwebClient } from "@/constants/thirdweb.server";
42
import { defineDashboardChain } from "lib/defineDashboardChain";
53
import { ZERO_ADDRESS, isAddress, toTokens } from "thirdweb";
64
import { getWalletBalance } from "thirdweb/wallets";
5+
import { getUserThirdwebClient } from "../../app/api/lib/getAuthToken";
76

87
type BalanceQueryResponse = Array<{
98
balance: string;
@@ -24,6 +23,7 @@ export async function getTokenBalancesFromMoralis(params: {
2423
error: string;
2524
}
2625
> {
26+
const client = await getUserThirdwebClient();
2727
const { contractAddress, chainId } = params;
2828

2929
if (!isAddress(contractAddress)) {
@@ -39,7 +39,7 @@ export async function getTokenBalancesFromMoralis(params: {
3939
const balance = await getWalletBalance({
4040
address: contractAddress,
4141
chain,
42-
client: getThirdwebClient(),
42+
client,
4343
});
4444
return [
4545
{

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,16 +2,16 @@
22

33
import {
44
generateAlchemyUrl,
5-
isAlchemySupported,
65
transformAlchemyResponseToNFT,
76
} from "lib/wallet/nfts/alchemy";
87
import {
98
generateMoralisUrl,
10-
isMoralisSupported,
119
transformMoralisResponseToNFT,
1210
} from "lib/wallet/nfts/moralis";
1311
import type { WalletNFT } from "lib/wallet/nfts/types";
1412
import { getVercelEnv } from "../../lib/vercel-utils";
13+
import { isAlchemySupported } from "../../lib/wallet/nfts/isAlchemySupported";
14+
import { isMoralisSupported } from "../../lib/wallet/nfts/isMoralisSupported";
1515
import { DASHBOARD_THIRDWEB_CLIENT_ID } from "../constants/env";
1616

1717
type WalletNFTApiReturn =

apps/dashboard/src/@/components/blocks/Avatars/GradientAvatar.stories.tsx

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
11
import type { Meta, StoryObj } from "@storybook/react";
22
import { useState } from "react";
3-
import { BadgeContainer } from "../../../../stories/utils";
4-
import { getThirdwebClient } from "../../../constants/thirdweb.server";
3+
import {
4+
BadgeContainer,
5+
storybookThirdwebClient,
6+
} from "../../../../stories/utils";
57
import { Button } from "../../ui/button";
68
import { GradientAvatar } from "./GradientAvatar";
79

@@ -17,8 +19,6 @@ export const Variants: Story = {
1719
args: {},
1820
};
1921

20-
const client = getThirdwebClient();
21-
2222
function Story() {
2323
return (
2424
<div className="container flex max-w-6xl flex-col gap-10 py-10">
@@ -29,7 +29,7 @@ function Story() {
2929
id={undefined}
3030
src={undefined}
3131
className="size-20"
32-
client={client}
32+
client={storybookThirdwebClient}
3333
/>
3434
</BadgeContainer>
3535

@@ -38,7 +38,7 @@ function Story() {
3838
id={"foo"}
3939
src={undefined}
4040
className="size-20"
41-
client={client}
41+
client={storybookThirdwebClient}
4242
/>
4343
</BadgeContainer>
4444

@@ -47,7 +47,7 @@ function Story() {
4747
id={"foo"}
4848
src={""}
4949
className="size-20"
50-
client={client}
50+
client={storybookThirdwebClient}
5151
/>
5252
</BadgeContainer>
5353

@@ -56,7 +56,7 @@ function Story() {
5656
id={"bar"}
5757
src={""}
5858
className="size-20"
59-
client={client}
59+
client={storybookThirdwebClient}
6060
/>
6161
</BadgeContainer>
6262

@@ -65,7 +65,7 @@ function Story() {
6565
src="invalid-src"
6666
id={undefined}
6767
className="size-20"
68-
client={client}
68+
client={storybookThirdwebClient}
6969
/>
7070
</BadgeContainer>
7171

@@ -74,7 +74,7 @@ function Story() {
7474
src="https://picsum.photos/200/300"
7575
id={undefined}
7676
className="size-20"
77-
client={client}
77+
client={storybookThirdwebClient}
7878
/>
7979
</BadgeContainer>
8080

@@ -83,7 +83,7 @@ function Story() {
8383
src="ipfs://QmZbeJYEs7kCJHyQxjxU2SJUtjSAr4m87wzJFJUyWomKdj/Smily.svg"
8484
id={undefined}
8585
className="size-20"
86-
client={client}
86+
client={storybookThirdwebClient}
8787
/>
8888
</BadgeContainer>
8989

@@ -123,7 +123,7 @@ function ToggleTest() {
123123
src={data?.src}
124124
id={data?.id}
125125
className="size-20"
126-
client={client}
126+
client={storybookThirdwebClient}
127127
/>
128128
</BadgeContainer>
129129

@@ -132,7 +132,7 @@ function ToggleTest() {
132132
className="size-20"
133133
src={data ? "invalid-src" : undefined}
134134
id={undefined}
135-
client={client}
135+
client={storybookThirdwebClient}
136136
/>
137137
</BadgeContainer>
138138
</div>

apps/dashboard/src/@/components/blocks/Avatars/ProjectAvatar.stories.tsx

Lines changed: 20 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
11
import type { Meta, StoryObj } from "@storybook/react";
22
import { useState } from "react";
3-
import { BadgeContainer } from "../../../../stories/utils";
4-
import { getThirdwebClient } from "../../../constants/thirdweb.server";
3+
import {
4+
BadgeContainer,
5+
storybookThirdwebClient,
6+
} from "../../../../stories/utils";
57
import { Button } from "../../ui/button";
68
import { ProjectAvatar } from "./ProjectAvatar";
79

@@ -18,19 +20,25 @@ export const Variants: Story = {
1820
args: {},
1921
};
2022

21-
const client = getThirdwebClient();
22-
2323
function Story() {
2424
return (
2525
<div className="container flex max-w-6xl flex-col gap-10 py-10">
2626
<p> All images below are set with size-6 className </p>
2727

2828
<BadgeContainer label="No Src - Skeleton">
29-
<ProjectAvatar src={undefined} className="size-6" client={client} />
29+
<ProjectAvatar
30+
src={undefined}
31+
className="size-6"
32+
client={storybookThirdwebClient}
33+
/>
3034
</BadgeContainer>
3135

3236
<BadgeContainer label="Invalid/Empty Src - BoxIcon Fallback">
33-
<ProjectAvatar src={""} className="size-6" client={client} />
37+
<ProjectAvatar
38+
src={""}
39+
className="size-6"
40+
client={storybookThirdwebClient}
41+
/>
3442
</BadgeContainer>
3543

3644
<ToggleTest />
@@ -65,14 +73,18 @@ function ToggleTest() {
6573
<p> Src+Name is: {data ? "set" : "not set"} </p>
6674

6775
<BadgeContainer label="Valid Src">
68-
<ProjectAvatar src={data?.src} className="size-6" client={client} />
76+
<ProjectAvatar
77+
src={data?.src}
78+
className="size-6"
79+
client={storybookThirdwebClient}
80+
/>
6981
</BadgeContainer>
7082

7183
<BadgeContainer label="invalid Src">
7284
<ProjectAvatar
7385
src={data ? "invalid-src" : undefined}
7486
className="size-6"
75-
client={client}
87+
client={storybookThirdwebClient}
7688
/>
7789
</BadgeContainer>
7890
</div>

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

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,16 @@ import { useQuery } from "@tanstack/react-query";
22
import { useMemo } from "react";
33
import { useActiveAccount } from "thirdweb/react";
44
import type { GetAuthTokenResponse } from "../../app/api/auth/get-auth-token/route";
5+
import { LAST_USED_TEAM_ID } from "../../constants/cookies";
6+
import { getCookie } from "../../lib/cookie";
57
import { getThirdwebClient } from "./thirdweb.server";
68

79
// returns a thirdweb client with optional JWT passed i
810

911
export function useThirdwebClient(jwt?: string) {
1012
const account = useActiveAccount();
13+
const lastUsedTeamId = getCookie(LAST_USED_TEAM_ID);
14+
1115
const query = useQuery({
1216
queryKey: ["jwt", account?.address],
1317
// only enable the query if there is an account and no JWT is passed in directly
@@ -33,8 +37,12 @@ export function useThirdwebClient(jwt?: string) {
3337

3438
return useMemo(
3539
// prefer jwt from props over the one from the token query if it exists
36-
() => getThirdwebClient(jwt || query.data),
37-
[jwt, query.data],
40+
() =>
41+
getThirdwebClient({
42+
jwt: jwt || query.data,
43+
teamId: lastUsedTeamId,
44+
}),
45+
[jwt, query.data, lastUsedTeamId],
3846
);
3947
}
4048

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

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,14 @@ import { getZkPaymasterData } from "thirdweb/wallets/smart";
2323
import { getVercelEnv } from "../../lib/vercel-utils";
2424

2525
// returns a thirdweb client with optional JWT passed in
26-
export function getThirdwebClient(jwt?: string) {
26+
export function getThirdwebClient(
27+
options:
28+
| {
29+
jwt: string | null | undefined;
30+
teamId: string | undefined;
31+
}
32+
| undefined,
33+
) {
2734
if (getVercelEnv() !== "production") {
2835
// if not on production: run this when creating a client to set the domains
2936
setThirdwebDomains({
@@ -71,7 +78,8 @@ export function getThirdwebClient(jwt?: string) {
7178
}
7279

7380
return createThirdwebClient({
74-
secretKey: jwt ? jwt : DASHBOARD_THIRDWEB_SECRET_KEY,
81+
teamId: options?.teamId,
82+
secretKey: options?.jwt ? options.jwt : DASHBOARD_THIRDWEB_SECRET_KEY,
7583
clientId: DASHBOARD_THIRDWEB_CLIENT_ID,
7684
config: {
7785
storage: {

apps/dashboard/src/app/(dashboard)/(bridge)/bridge/components/client/UniversalBridgeEmbed.tsx

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,21 @@
11
"use client";
2-
import { getThirdwebClient } from "@/constants/thirdweb.server";
2+
33
import { getSDKTheme } from "app/components/sdk-component-theme";
44
import { useV5DashboardChain } from "lib/v5-adapter";
55
import { useTheme } from "next-themes";
6+
import type { ThirdwebClient } from "thirdweb";
67
import { PayEmbed } from "thirdweb/react";
78

8-
export function UniversalBridgeEmbed({ chainId }: { chainId?: number }) {
9+
export function UniversalBridgeEmbed({
10+
chainId,
11+
client,
12+
}: { chainId?: number; client: ThirdwebClient }) {
913
const { theme } = useTheme();
1014
const chain = useV5DashboardChain(chainId || 1);
1115

1216
return (
1317
<PayEmbed
14-
client={getThirdwebClient()}
18+
client={client}
1519
payOptions={{
1620
mode: "fund_wallet",
1721
prefillBuy: {

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

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import { getThirdwebClient } from "@/constants/thirdweb.server";
12
import type { Metadata } from "next";
23
import { UniversalBridgeEmbed } from "./components/client/UniversalBridgeEmbed";
34

@@ -18,10 +19,14 @@ export default async function RoutesPage({
1819
searchParams,
1920
}: { searchParams: Record<string, string | string[]> }) {
2021
const { chainId } = searchParams;
22+
const client = getThirdwebClient(undefined);
2123
return (
2224
<div className="relative mx-auto flex h-screen w-full flex-col items-center justify-center overflow-hidden border py-10">
2325
<main className="container z-10 flex justify-center">
24-
<UniversalBridgeEmbed chainId={chainId ? Number(chainId) : undefined} />
26+
<UniversalBridgeEmbed
27+
chainId={chainId ? Number(chainId) : undefined}
28+
client={client}
29+
/>
2530
</main>
2631

2732
{/* eslint-disable-next-line @next/next/no-img-element */}

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

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { Card, CardContent, CardHeader } from "@/components/ui/card";
2-
import { getThirdwebClient } from "@/constants/thirdweb.server";
32
import { resolveSchemeWithErrorHandler } from "@/lib/resolveSchemeWithErrorHandler";
3+
import type { ThirdwebClient } from "thirdweb";
44
import { defineChain } from "thirdweb";
55
import { getChainMetadata } from "thirdweb/chains";
66

@@ -15,6 +15,7 @@ type RouteListCardProps = {
1515
destinationTokenIconUri?: string | null;
1616
destinationTokenSymbol: string;
1717
destinationTokenName: string;
18+
client: ThirdwebClient;
1819
};
1920

2021
export async function RouteListCard({
@@ -26,6 +27,7 @@ export async function RouteListCard({
2627
destinationTokenAddress,
2728
destinationTokenIconUri,
2829
destinationTokenName,
30+
client,
2931
}: RouteListCardProps) {
3032
const [
3133
originChain,
@@ -40,13 +42,13 @@ export async function RouteListCard({
4042
originTokenIconUri
4143
? resolveSchemeWithErrorHandler({
4244
uri: originTokenIconUri,
43-
client: getThirdwebClient(),
45+
client,
4446
})
4547
: undefined,
4648
destinationTokenIconUri
4749
? resolveSchemeWithErrorHandler({
4850
uri: destinationTokenIconUri,
49-
client: getThirdwebClient(),
51+
client,
5052
})
5153
: undefined,
5254
]);

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

Lines changed: 5 additions & 3 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 { getThirdwebClient } from "@/constants/thirdweb.server";
43
import { resolveSchemeWithErrorHandler } from "@/lib/resolveSchemeWithErrorHandler";
4+
import type { ThirdwebClient } from "thirdweb";
55
import { defineChain, getChainMetadata } from "thirdweb/chains";
66

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

2021
export async function RouteListRow({
@@ -26,6 +27,7 @@ export async function RouteListRow({
2627
destinationTokenAddress,
2728
destinationTokenIconUri,
2829
destinationTokenSymbol,
30+
client,
2931
}: RouteListRowProps) {
3032
const [
3133
originChain,
@@ -40,13 +42,13 @@ export async function RouteListRow({
4042
originTokenIconUri
4143
? resolveSchemeWithErrorHandler({
4244
uri: originTokenIconUri,
43-
client: getThirdwebClient(),
45+
client,
4446
})
4547
: undefined,
4648
destinationTokenIconUri
4749
? resolveSchemeWithErrorHandler({
4850
uri: destinationTokenIconUri,
49-
client: getThirdwebClient(),
51+
client,
5052
})
5153
: undefined,
5254
]);

0 commit comments

Comments
 (0)