From e568bcea60b88dd1ed4abd5a4c1a67b89b8dac00 Mon Sep 17 00:00:00 2001 From: MananTank Date: Mon, 22 Sep 2025 23:41:35 +0000 Subject: [PATCH] [MNY-193] Dashboard: Update Client Ids for Buy and Swap widgets in chain, bridge and asset pages (#8101) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ## 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}` ## 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 --- .../@/components/blocks/BuyAndSwapEmbed.tsx | 34 +++++++++++++++---- apps/dashboard/src/@/constants/public-envs.ts | 9 +++++ .../src/@/constants/thirdweb.server.ts | 4 ++- .../components/client/BuyFundsSection.tsx | 7 +--- .../(chain)/[chain_id]/(chainPage)/page.tsx | 2 +- .../public-pages/erc20/erc20.tsx | 1 - .../client/UniversalBridgeEmbed.tsx | 2 -- 7 files changed, 42 insertions(+), 17 deletions(-) diff --git a/apps/dashboard/src/@/components/blocks/BuyAndSwapEmbed.tsx b/apps/dashboard/src/@/components/blocks/BuyAndSwapEmbed.tsx index ab67e638b6c..0ad2382fb9c 100644 --- a/apps/dashboard/src/@/components/blocks/BuyAndSwapEmbed.tsx +++ b/apps/dashboard/src/@/components/blocks/BuyAndSwapEmbed.tsx @@ -1,8 +1,8 @@ "use client"; import { useTheme } from "next-themes"; -import { useEffect, useRef, useState } from "react"; -import type { Chain, ThirdwebClient } from "thirdweb"; +import { useEffect, useMemo, useRef, useState } from "react"; +import type { Chain } from "thirdweb"; import { BuyWidget, SwapWidget } from "thirdweb/react"; import { reportAssetBuyCancelled, @@ -17,16 +17,23 @@ import { reportTokenSwapSuccessful, } from "@/analytics/report"; import { Button } from "@/components/ui/button"; +import { + NEXT_PUBLIC_ASSET_PAGE_CLIENT_ID, + NEXT_PUBLIC_BRIDGE_PAGE_CLIENT_ID, + NEXT_PUBLIC_CHAIN_PAGE_CLIENT_ID, +} from "@/constants/public-envs"; import { cn } from "@/lib/utils"; import { parseError } from "@/utils/errorParser"; import { getSDKTheme } from "@/utils/sdk-component-theme"; +import { getConfiguredThirdwebClient } from "../../constants/thirdweb.server"; + +type PageType = "asset" | "bridge" | "chain"; export function BuyAndSwapEmbed(props: { - client: ThirdwebClient; chain: Chain; tokenAddress: string | undefined; buyAmount: string | undefined; - pageType: "asset" | "bridge" | "chain"; + pageType: PageType; }) { const { theme } = useTheme(); const [tab, setTab] = useState<"buy" | "swap">("swap"); @@ -44,6 +51,21 @@ export function BuyAndSwapEmbed(props: { }); }, [props.pageType]); + const client = useMemo(() => { + return getConfiguredThirdwebClient({ + clientId: + props.pageType === "asset" + ? NEXT_PUBLIC_ASSET_PAGE_CLIENT_ID + : props.pageType === "bridge" + ? NEXT_PUBLIC_BRIDGE_PAGE_CLIENT_ID + : props.pageType === "chain" + ? NEXT_PUBLIC_CHAIN_PAGE_CLIENT_ID + : undefined, + secretKey: undefined, + teamId: undefined, + }); + }, [props.pageType]); + return (
@@ -65,7 +87,7 @@ export function BuyAndSwapEmbed(props: { chain={props.chain} className="!rounded-2xl !w-full !border-none" title="" - client={props.client} + client={client} connectOptions={{ autoConnect: false, }} @@ -155,7 +177,7 @@ export function BuyAndSwapEmbed(props: { {tab === "swap" && ( ) : chain.services.find((c) => c.service === "pay" && c.enabled) ? ( - + ) : null} {/* Chain Overview */} diff --git a/apps/dashboard/src/app/(app)/(dashboard)/(chain)/[chain_id]/[contractAddress]/public-pages/erc20/erc20.tsx b/apps/dashboard/src/app/(app)/(dashboard)/(chain)/[chain_id]/[contractAddress]/public-pages/erc20/erc20.tsx index 11b8da95484..9330d9a3254 100644 --- a/apps/dashboard/src/app/(app)/(dashboard)/(chain)/[chain_id]/[contractAddress]/public-pages/erc20/erc20.tsx +++ b/apps/dashboard/src/app/(app)/(dashboard)/(chain)/[chain_id]/[contractAddress]/public-pages/erc20/erc20.tsx @@ -173,7 +173,6 @@ function BuyEmbed(props: { return (