Skip to content

[TOOL-4621] New ERC20 public contract page #7177

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
May 29, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions apps/dashboard/src/@/actions/getWalletNFTs.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import type { WalletNFT } from "lib/wallet/nfts/types";
import { getVercelEnv } from "../../lib/vercel-utils";
import { isAlchemySupported } from "../../lib/wallet/nfts/isAlchemySupported";
import { isMoralisSupported } from "../../lib/wallet/nfts/isMoralisSupported";
import { NET_PUBLIC_DASHBOARD_THIRDWEB_CLIENT_ID } from "../constants/public-envs";
import { NEXT_PUBLIC_DASHBOARD_CLIENT_ID } from "../constants/public-envs";
import { MORALIS_API_KEY } from "../constants/server-envs";

type WalletNFTApiReturn =
Expand Down Expand Up @@ -149,7 +149,7 @@ async function getWalletNFTsFromInsight(params: {

const response = await fetch(url, {
headers: {
"x-client-id": NET_PUBLIC_DASHBOARD_THIRDWEB_CLIENT_ID,
"x-client-id": NEXT_PUBLIC_DASHBOARD_CLIENT_ID,
},
});

Expand Down
10 changes: 5 additions & 5 deletions apps/dashboard/src/@/components/blocks/UpsellBannerCard.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ type UpsellBannerCardProps = {
cta: {
text: React.ReactNode;
icon?: React.ReactNode;
target?: "_blank";
link: string;
};
trackingCategory: string;
Expand All @@ -55,7 +56,7 @@ export function UpsellBannerCard(props: UpsellBannerCardProps) {
return (
<div
className={cn(
"relative overflow-hidden rounded-lg border bg-gradient-to-r p-5",
"relative overflow-hidden rounded-lg border bg-gradient-to-r p-4 lg:p-6",
color.border,
color.bgFrom,
)}
Expand All @@ -73,7 +74,7 @@ export function UpsellBannerCard(props: UpsellBannerCardProps) {
{props.icon ? (
<div
className={cn(
"mt-0.5 flex h-9 w-9 shrink-0 items-center justify-center rounded-full",
"mt-0.5 hidden h-9 w-9 shrink-0 items-center justify-center rounded-full lg:flex",
color.iconBg,
)}
>
Expand All @@ -90,9 +91,7 @@ export function UpsellBannerCard(props: UpsellBannerCardProps) {
>
{props.title}
</h3>
<p className={cn("mt-0.5 text-sm", color.desc)}>
{props.description}
</p>
<p className={cn("text-sm", color.desc)}>{props.description}</p>
</div>
</div>

Expand All @@ -108,6 +107,7 @@ export function UpsellBannerCard(props: UpsellBannerCardProps) {
href={props.cta.link}
category={props.trackingCategory}
label={props.trackingLabel}
target={props.cta.target}
>
{props.cta.text}
{props.cta.icon && <span className="ml-2">{props.cta.icon}</span>}
Expand Down
15 changes: 12 additions & 3 deletions apps/dashboard/src/@/components/blocks/charts/area-chart.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -46,8 +46,12 @@ type ThirdwebAreaChartProps<TConfig extends ChartConfig> = {
// chart className
chartClassName?: string;
isPending: boolean;
className?: string;
cardContentClassName?: string;
hideLabel?: boolean;
toolTipLabelFormatter?: (label: string, payload: unknown) => React.ReactNode;
toolTipValueFormatter?: (value: unknown) => React.ReactNode;
emptyChartState?: React.ReactElement;
};

export function ThirdwebAreaChart<TConfig extends ChartConfig>(
Expand All @@ -56,7 +60,7 @@ export function ThirdwebAreaChart<TConfig extends ChartConfig>(
const configKeys = useMemo(() => Object.keys(props.config), [props.config]);

return (
<Card>
<Card className={props.className}>
{props.header && (
<CardHeader>
<CardTitle className={cn("mb-2", props.header.titleClassName)}>
Expand All @@ -70,12 +74,16 @@ export function ThirdwebAreaChart<TConfig extends ChartConfig>(

{props.customHeader && props.customHeader}

<CardContent className={cn(!props.header && "pt-6")}>
<CardContent
className={cn(!props.header && "pt-6", props.cardContentClassName)}
>
<ChartContainer config={props.config} className={props.chartClassName}>
{props.isPending ? (
<LoadingChartState />
) : props.data.length === 0 ? (
<EmptyChartState />
<EmptyChartState type="area">
{props.emptyChartState}
</EmptyChartState>
) : (
<AreaChart accessibilityLayer data={props.data}>
<CartesianGrid vertical={false} />
Expand All @@ -100,6 +108,7 @@ export function ThirdwebAreaChart<TConfig extends ChartConfig>(
props.hideLabel !== undefined ? props.hideLabel : true
}
labelFormatter={props.toolTipLabelFormatter}
valueFormatter={props.toolTipValueFormatter}
/>
}
/>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,9 @@ export function ThirdwebBarChart<TConfig extends ChartConfig>(
{props.isPending ? (
<LoadingChartState />
) : props.data.length === 0 ? (
<EmptyChartState>{props.emptyChartState}</EmptyChartState>
<EmptyChartState type="bar">
{props.emptyChartState}
</EmptyChartState>
) : (
<BarChart accessibilityLayer data={props.data}>
<CartesianGrid vertical={false} />
Expand Down
10 changes: 10 additions & 0 deletions apps/dashboard/src/@/components/ui/LoadingDots.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
export function LoadingDots() {
return (
<div className="fade-in-0 flex animate-in gap-2 duration-300">
<span className="sr-only">Loading...</span>
<div className="size-4 animate-bounce rounded-full bg-foreground [animation-delay:-0.3s]" />
<div className="size-4 animate-bounce rounded-full bg-foreground [animation-delay:-0.15s]" />
<div className="size-4 animate-bounce rounded-full bg-foreground" />
</div>
);
}
35 changes: 35 additions & 0 deletions apps/dashboard/src/@/components/ui/decimal-input.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
import { Input } from "./input";
export function DecimalInput(props: {
value: string;
onChange: (value: string) => void;
maxValue?: number;
id?: string;
className?: string;
}) {
return (
<Input
id={props.id}
type="text"
value={props.value}
className={props.className}
inputMode="decimal"
onChange={(e) => {
const number = Number(e.target.value);
// ignore if string becomes invalid number
if (Number.isNaN(number)) {
return;
}
if (props.maxValue && number > props.maxValue) {
return;
}
// replace leading multiple zeros with single zero
let cleanedValue = e.target.value.replace(/^0+/, "0");
// replace leading zero before decimal point
if (!cleanedValue.includes(".")) {
cleanedValue = cleanedValue.replace(/^0+/, "");
}
props.onChange(cleanedValue || "0");
}}
/>
);
}
2 changes: 1 addition & 1 deletion apps/dashboard/src/@/constants/public-envs.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
export const NET_PUBLIC_DASHBOARD_THIRDWEB_CLIENT_ID =
export const NEXT_PUBLIC_DASHBOARD_CLIENT_ID =
process.env.NEXT_PUBLIC_DASHBOARD_CLIENT_ID || "";

export const NEXT_PUBLIC_NEBULA_APP_CLIENT_ID =
Expand Down
4 changes: 2 additions & 2 deletions apps/dashboard/src/@/constants/thirdweb.server.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import {
NET_PUBLIC_DASHBOARD_THIRDWEB_CLIENT_ID,
NEXT_PUBLIC_DASHBOARD_CLIENT_ID,
NEXT_PUBLIC_IPFS_GATEWAY_URL,
} from "@/constants/public-envs";
import {
Expand Down Expand Up @@ -76,7 +76,7 @@ export function getConfiguredThirdwebClient(options: {
return createThirdwebClient({
teamId: options.teamId,
secretKey: options.secretKey,
clientId: NET_PUBLIC_DASHBOARD_THIRDWEB_CLIENT_ID,
clientId: NEXT_PUBLIC_DASHBOARD_CLIENT_ID,
config: {
storage: {
gatewayUrl: NEXT_PUBLIC_IPFS_GATEWAY_URL,
Expand Down
16 changes: 16 additions & 0 deletions apps/dashboard/src/app/(app)/(dashboard)/(bridge)/layout.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
import { TeamHeader } from "../../team/components/TeamHeader/team-header";

export default function Layout({
children,
}: {
children: React.ReactNode;
}) {
return (
<div className="flex grow flex-col">
<div className="border-border border-b bg-card">
<TeamHeader />
</div>
{children}
</div>
);
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { CopyTextButton } from "@/components/ui/CopyTextButton";
import { Skeleton } from "@/components/ui/skeleton";
import { ToolTipLabel } from "@/components/ui/tooltip";
import { isProd } from "@/constants/env-utils";
import { NET_PUBLIC_DASHBOARD_THIRDWEB_CLIENT_ID } from "@/constants/public-envs";
import { NEXT_PUBLIC_DASHBOARD_CLIENT_ID } from "@/constants/public-envs";
import { useQuery } from "@tanstack/react-query";
import { CircleCheckIcon, XIcon } from "lucide-react";
import { hostnameEndsWith } from "utils/url";
Expand All @@ -14,7 +14,7 @@ function useChainStatswithRPC(_rpcUrl: string) {
let rpcUrl = _rpcUrl.replace(
// eslint-disable-next-line no-template-curly-in-string
"${THIRDWEB_API_KEY}",
NET_PUBLIC_DASHBOARD_THIRDWEB_CLIENT_ID,
NEXT_PUBLIC_DASHBOARD_CLIENT_ID,
);

// based on the environment hit dev or production
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ import {
getAuthToken,
getAuthTokenWalletAddress,
} from "../../../../api/lib/getAuthToken";
import { TeamHeader } from "../../../../team/components/TeamHeader/team-header";
import { StarButton } from "../../components/client/star-button";
import { getChain, getChainMetadata } from "../../utils";
import { AddChainToWallet } from "./components/client/add-chain-to-wallet";
Expand Down Expand Up @@ -95,7 +96,10 @@ The following is the user's message:
}

return (
<>
<div className="flex grow flex-col">
<div className="border-border border-b bg-card">
<TeamHeader />
</div>
<NebulaChatButton
isLoggedIn={!!authToken}
networks={chain.testnet ? "testnet" : "mainnet"}
Expand Down Expand Up @@ -225,7 +229,7 @@ The following is the user's message:
{children}
</div>
</div>
</>
</div>
);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -82,21 +82,19 @@ export const MetadataHeader: React.FC<MetadataHeaderProps> = ({
</h1>
)}

{chain && (
<Link
href={`/${chain.slug}`}
className="flex w-fit shrink-0 items-center gap-2 rounded-3xl border border-border bg-card px-2.5 py-1.5 hover:bg-accent"
>
<ChainIconClient
src={chain.icon?.url}
client={client}
className="size-4"
/>
{cleanedChainName && (
<span className="text-xs">{cleanedChainName}</span>
)}
</Link>
)}
<Link
href={`/${chain.slug}`}
className="flex w-fit shrink-0 items-center gap-2 rounded-3xl border border-border bg-card px-2.5 py-1.5 hover:bg-accent"
>
<ChainIconClient
src={chain.icon?.url}
client={client}
className="size-4"
/>
{cleanedChainName && (
<span className="text-xs">{cleanedChainName}</span>
)}
</Link>
</div>
)}

Expand All @@ -115,7 +113,7 @@ export const MetadataHeader: React.FC<MetadataHeaderProps> = ({
<CopyAddressButton
address={address}
copyIconPosition="left"
className="bg-card text-xs"
className="bg-card px-2.5 py-1.5 text-xs"
variant="outline"
/>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,17 @@ export const PrimaryDashboardButton: React.FC<AddToDashboardCardProps> = ({

// if user is on a project page
if (projectMeta) {
return null;
return (
<Button variant="default" asChild>
<Link
href={`/${contractInfo.chainSlug}/${contractAddress}`}
target="_blank"
className="gap-2"
>
View Asset Page <ExternalLinkIcon className="size-3.5" />
</Link>
</Button>
);
}

return (
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
import { resolveFunctionSelectors } from "lib/selectors";
import type { ThirdwebContract } from "thirdweb";
import { isERC20 } from "thirdweb/extensions/erc20";

export type NewPublicPageType = "erc20";

export async function shouldRenderNewPublicPage(
contract: ThirdwebContract,
): Promise<false | { type: NewPublicPageType }> {
try {
const functionSelectors = await resolveFunctionSelectors(contract).catch(
() => undefined,
);

if (!functionSelectors) {
return false;
}

const isERC20Contract = isERC20(functionSelectors);

if (isERC20Contract) {
return {
type: "erc20",
};
}

return false;
} catch {
return false;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import type { ProjectMeta } from "../../../../../team/[team_slug]/[project_slug]
import { redirectToContractLandingPage } from "../../../../../team/[team_slug]/[project_slug]/contract/[chainIdOrSlug]/[contractAddress]/utils";
import { getContractPageParamsInfo } from "../_utils/getContractFromParams";
import { getContractPageMetadata } from "../_utils/getContractPageMetadata";
import { shouldRenderNewPublicPage } from "../_utils/newPublicPage";
import { ContractAnalyticsPage } from "./ContractAnalyticsPage";

export async function SharedAnalyticsPage(props: {
Expand All @@ -22,6 +23,18 @@ export async function SharedAnalyticsPage(props: {
notFound();
}

// new public page can't show /analytics page
if (!props.projectMeta) {
const shouldHide = await shouldRenderNewPublicPage(info.serverContract);
if (shouldHide) {
redirectToContractLandingPage({
contractAddress: props.contractAddress,
chainIdOrSlug: props.chainIdOrSlug,
projectMeta: props.projectMeta,
});
}
}

const [
{ eventSelectorToName, writeFnSelectorToName },
{ isInsightSupported },
Expand Down
Loading
Loading