Skip to content

Commit ae7c499

Browse files
committed
[MNY-193] Dashboard: Update Client Ids for Buy and Swap widgets in chain, bridge and asset pages
1 parent b37ed57 commit ae7c499

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,
@@ -14,16 +14,23 @@ import {
1414
reportTokenSwapSuccessful,
1515
} from "@/analytics/report";
1616
import { Button } from "@/components/ui/button";
17+
import {
18+
NEXT_PUBLIC_ASSET_PAGE_CLIENT_ID,
19+
NEXT_PUBLIC_BRIDGE_PAGE_CLIENT_ID,
20+
NEXT_PUBLIC_CHAIN_PAGE_CLIENT_ID,
21+
} from "@/constants/public-envs";
1722
import { cn } from "@/lib/utils";
1823
import { parseError } from "@/utils/errorParser";
1924
import { getSDKTheme } from "@/utils/sdk-component-theme";
25+
import { getConfiguredThirdwebClient } from "../../constants/thirdweb.server";
26+
27+
type PageType = "asset" | "bridge" | "chain";
2028

2129
export function BuyAndSwapEmbed(props: {
22-
client: ThirdwebClient;
2330
chain: Chain;
2431
tokenAddress: string | undefined;
2532
buyAmount: string | undefined;
26-
pageType: "asset" | "bridge" | "chain";
33+
pageType: PageType;
2734
}) {
2835
const { theme } = useTheme();
2936
const [tab, setTab] = useState<"buy" | "swap">("swap");
@@ -41,6 +48,21 @@ export function BuyAndSwapEmbed(props: {
4148
});
4249
}, [props.pageType]);
4350

51+
const client = useMemo(() => {
52+
return getConfiguredThirdwebClient({
53+
clientId:
54+
props.pageType === "asset"
55+
? NEXT_PUBLIC_ASSET_PAGE_CLIENT_ID
56+
: props.pageType === "bridge"
57+
? NEXT_PUBLIC_BRIDGE_PAGE_CLIENT_ID
58+
: props.pageType === "chain"
59+
? NEXT_PUBLIC_CHAIN_PAGE_CLIENT_ID
60+
: undefined,
61+
secretKey: undefined,
62+
teamId: undefined,
63+
});
64+
}, [props.pageType]);
65+
4466
return (
4567
<div className="bg-card rounded-2xl border overflow-hidden flex flex-col relative z-10">
4668
<div className="flex gap-2.5 p-4 border-b border-dashed">
@@ -62,7 +84,7 @@ export function BuyAndSwapEmbed(props: {
6284
chain={props.chain}
6385
className="!rounded-2xl !w-full !border-none"
6486
title=""
65-
client={props.client}
87+
client={client}
6688
connectOptions={{
6789
autoConnect: false,
6890
}}
@@ -103,7 +125,7 @@ export function BuyAndSwapEmbed(props: {
103125

104126
{tab === "swap" && (
105127
<SwapWidget
106-
client={props.client}
128+
client={client}
107129
theme={themeObj}
108130
className="!rounded-2xl !border-none !w-full"
109131
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)