Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit e568bce

Browse files
committed
[MNY-193] Dashboard: Update Client Ids for Buy and Swap widgets in chain, bridge and asset pages (#8101)
<!-- ## 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 refactoring components and updating environment variable handling for the `BuyAndSwapEmbed` and `BuyFundsSection` components in a dashboard application. It enhances the usage of client IDs and improves the structure of props. ### Detailed summary - Removed `client` prop from `BuyAndSwapEmbed` and `BuyFundsSection`. - Introduced `clientId` handling in `getConfiguredThirdwebClient`. - Updated `BuyAndSwapEmbed` to use `useMemo` for client configuration based on `pageType`. - Added multiple `NEXT_PUBLIC_*_CLIENT_ID` constants in `public-envs.ts`. - Cleaned up imports and types in various files for better clarity. > ✨ 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 - Auto-configured client selection per page type (asset/bridge/chain) for Buy, Swap, and Bridge embeds, improving reliability without manual setup. - Refactor - Simplified components by removing the need to pass a client prop; widgets now use an internal, memoized client. - Chores - Added new public environment variables for page-specific client IDs to enable tailored configuration: - NEXT_PUBLIC_ASSET_PAGE_CLIENT_ID - NEXT_PUBLIC_BRIDGE_PAGE_CLIENT_ID - NEXT_PUBLIC_CHAIN_PAGE_CLIENT_ID <!-- end of auto-generated comment: release notes by coderabbit.ai -->
1 parent a94f229 commit e568bce

File tree

7 files changed

+42
-17
lines changed

7 files changed

+42
-17
lines changed

apps/dashboard/src/@/components/blocks/BuyAndSwapEmbed.tsx

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

33
import { useTheme } from "next-themes";
4-
import { useEffect, useRef, useState } from "react";
5-
import type { Chain, ThirdwebClient } from "thirdweb";
4+
import { useEffect, useMemo, useRef, useState } from "react";
5+
import type { Chain } from "thirdweb";
66
import { BuyWidget, SwapWidget } from "thirdweb/react";
77
import {
88
reportAssetBuyCancelled,
@@ -17,16 +17,23 @@ import {
1717
reportTokenSwapSuccessful,
1818
} from "@/analytics/report";
1919
import { Button } from "@/components/ui/button";
20+
import {
21+
NEXT_PUBLIC_ASSET_PAGE_CLIENT_ID,
22+
NEXT_PUBLIC_BRIDGE_PAGE_CLIENT_ID,
23+
NEXT_PUBLIC_CHAIN_PAGE_CLIENT_ID,
24+
} from "@/constants/public-envs";
2025
import { cn } from "@/lib/utils";
2126
import { parseError } from "@/utils/errorParser";
2227
import { getSDKTheme } from "@/utils/sdk-component-theme";
28+
import { getConfiguredThirdwebClient } from "../../constants/thirdweb.server";
29+
30+
type PageType = "asset" | "bridge" | "chain";
2331

2432
export function BuyAndSwapEmbed(props: {
25-
client: ThirdwebClient;
2633
chain: Chain;
2734
tokenAddress: string | undefined;
2835
buyAmount: string | undefined;
29-
pageType: "asset" | "bridge" | "chain";
36+
pageType: PageType;
3037
}) {
3138
const { theme } = useTheme();
3239
const [tab, setTab] = useState<"buy" | "swap">("swap");
@@ -44,6 +51,21 @@ export function BuyAndSwapEmbed(props: {
4451
});
4552
}, [props.pageType]);
4653

54+
const client = useMemo(() => {
55+
return getConfiguredThirdwebClient({
56+
clientId:
57+
props.pageType === "asset"
58+
? NEXT_PUBLIC_ASSET_PAGE_CLIENT_ID
59+
: props.pageType === "bridge"
60+
? NEXT_PUBLIC_BRIDGE_PAGE_CLIENT_ID
61+
: props.pageType === "chain"
62+
? NEXT_PUBLIC_CHAIN_PAGE_CLIENT_ID
63+
: undefined,
64+
secretKey: undefined,
65+
teamId: undefined,
66+
});
67+
}, [props.pageType]);
68+
4769
return (
4870
<div className="bg-card rounded-2xl border overflow-hidden flex flex-col relative z-10">
4971
<div className="flex gap-2.5 p-4 border-b border-dashed">
@@ -65,7 +87,7 @@ export function BuyAndSwapEmbed(props: {
6587
chain={props.chain}
6688
className="!rounded-2xl !w-full !border-none"
6789
title=""
68-
client={props.client}
90+
client={client}
6991
connectOptions={{
7092
autoConnect: false,
7193
}}
@@ -155,7 +177,7 @@ export function BuyAndSwapEmbed(props: {
155177

156178
{tab === "swap" && (
157179
<SwapWidget
158-
client={props.client}
180+
client={client}
159181
theme={themeObj}
160182
className="!rounded-2xl !border-none !w-full"
161183
prefill={{

apps/dashboard/src/@/constants/public-envs.ts

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,3 +32,12 @@ export const NEXT_PUBLIC_DEMO_ENGINE_URL =
3232

3333
export const NEXT_PUBLIC_THIRDWEB_AI_HOST =
3434
process.env.NEXT_PUBLIC_THIRDWEB_AI_HOST || "https://nebula-api.thirdweb.com";
35+
36+
export const NEXT_PUBLIC_BRIDGE_PAGE_CLIENT_ID =
37+
process.env.NEXT_PUBLIC_BRIDGE_PAGE_CLIENT_ID;
38+
39+
export const NEXT_PUBLIC_CHAIN_PAGE_CLIENT_ID =
40+
process.env.NEXT_PUBLIC_CHAIN_PAGE_CLIENT_ID;
41+
42+
export const NEXT_PUBLIC_ASSET_PAGE_CLIENT_ID =
43+
process.env.NEXT_PUBLIC_ASSET_PAGE_CLIENT_ID;

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

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ import { getVercelEnv } from "@/utils/vercel";
2525
export function getConfiguredThirdwebClient(options: {
2626
secretKey: string | undefined;
2727
teamId: string | undefined;
28+
clientId?: string;
2829
}): ThirdwebClient {
2930
if (getVercelEnv() !== "production") {
3031
// if not on production: run this when creating a client to set the domains
@@ -77,7 +78,8 @@ export function getConfiguredThirdwebClient(options: {
7778
}
7879

7980
// During build time, provide fallbacks if credentials are missing
80-
const clientId = NEXT_PUBLIC_DASHBOARD_CLIENT_ID || "dummy-build-client";
81+
const clientId =
82+
options.clientId || NEXT_PUBLIC_DASHBOARD_CLIENT_ID || "dummy-build-client";
8183
const secretKey = options.secretKey || undefined;
8284

8385
return createThirdwebClient({

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

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,13 @@
11
"use client";
2-
import type { ThirdwebClient } from "thirdweb";
32
import type { ChainMetadata } from "thirdweb/chains";
43
import { BuyAndSwapEmbed } from "@/components/blocks/BuyAndSwapEmbed";
54
import { GridPatternEmbedContainer } from "@/components/blocks/grid-pattern-embed-container";
65
import { defineDashboardChain } from "@/lib/defineDashboardChain";
76

8-
export function BuyFundsSection(props: {
9-
chain: ChainMetadata;
10-
client: ThirdwebClient;
11-
}) {
7+
export function BuyFundsSection(props: { chain: ChainMetadata }) {
128
return (
139
<GridPatternEmbedContainer>
1410
<BuyAndSwapEmbed
15-
client={props.client}
1611
// eslint-disable-next-line no-restricted-syntax
1712
chain={defineDashboardChain(props.chain.chainId, props.chain)}
1813
buyAmount={undefined}

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ export default async function Page(props: {
4444
{chain.testnet ? (
4545
<FaucetSection chain={chain} client={client} isLoggedIn={!!account} />
4646
) : chain.services.find((c) => c.service === "pay" && c.enabled) ? (
47-
<BuyFundsSection chain={chain} client={client} />
47+
<BuyFundsSection chain={chain} />
4848
) : null}
4949

5050
{/* Chain Overview */}

apps/dashboard/src/app/(app)/(dashboard)/(chain)/[chain_id]/[contractAddress]/public-pages/erc20/erc20.tsx

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -173,7 +173,6 @@ function BuyEmbed(props: {
173173
return (
174174
<BuyAndSwapEmbed
175175
chain={props.clientContract.chain}
176-
client={props.clientContract.client}
177176
tokenAddress={props.clientContract.address}
178177
buyAmount={undefined}
179178
pageType="asset"

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

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33
import type { TokenInfo } from "thirdweb/react";
44
import { BuyAndSwapEmbed } from "@/components/blocks/BuyAndSwapEmbed";
55
import { useV5DashboardChain } from "@/hooks/chains/v5-adapter";
6-
import { bridgeAppThirdwebClient } from "../../constants";
76

87
export function UniversalBridgeEmbed({
98
chainId,
@@ -19,7 +18,6 @@ export function UniversalBridgeEmbed({
1918
return (
2019
<div className="w-full lg:w-[400px]">
2120
<BuyAndSwapEmbed
22-
client={bridgeAppThirdwebClient}
2321
chain={chain}
2422
buyAmount={amount}
2523
tokenAddress={token?.address}

0 commit comments

Comments
 (0)