Skip to content

Commit 871cea4

Browse files
committed
Fix CodeServer used in client component
1 parent 1a2acd3 commit 871cea4

File tree

3 files changed

+85
-67
lines changed

3 files changed

+85
-67
lines changed

apps/dashboard/src/components/pay/PayAnalytics/PayAnalytics.tsx

Lines changed: 33 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,11 @@ import {
22
getUniversalBridgeUsage,
33
getUniversalBridgeWalletUsage,
44
} from "@/api/analytics";
5+
import { CodeServer } from "@/components/ui/code/code.server";
56
import type { ThirdwebClient } from "thirdweb";
67
import type { Range } from "../../analytics/date-range-selector";
78
import { PayEmbedFTUX } from "./PayEmbedFTUX";
9+
import { apiCode, embedCode, sdkCode } from "./code-examples";
810
import { PayCustomersTable } from "./components/PayCustomersTable";
911
import { PayNewCustomers } from "./components/PayNewCustomers";
1012
import { PaymentHistory } from "./components/PaymentHistory";
@@ -59,8 +61,38 @@ export async function PayAnalytics(props: {
5961

6062
const hasVolume = volumeData.some((d) => d.amountUsdCents > 0);
6163
const hasWallet = walletData.some((d) => d.count > 0);
64+
6265
if (!hasVolume && !hasWallet) {
63-
return <PayEmbedFTUX clientId={props.projectClientId} />;
66+
return (
67+
<PayEmbedFTUX
68+
clientId={props.projectClientId}
69+
codeExamples={
70+
{
71+
embed: (
72+
<CodeServer
73+
code={embedCode(props.projectClientId)}
74+
lang="tsx"
75+
className="bg-background"
76+
/>
77+
),
78+
sdk: (
79+
<CodeServer
80+
code={sdkCode(props.projectClientId)}
81+
lang="ts"
82+
className="bg-background"
83+
/>
84+
),
85+
api: (
86+
<CodeServer
87+
code={apiCode(props.projectClientId)}
88+
lang="bash"
89+
className="bg-background"
90+
/>
91+
),
92+
} as const
93+
}
94+
/>
95+
);
6496
}
6597

6698
return (
Lines changed: 17 additions & 66 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,30 @@
11
"use client";
22
import { Button } from "@/components/ui/button";
3-
import { CodeServer } from "@/components/ui/code/code.server";
43
import { TabButtons } from "@/components/ui/tabs";
54
import { ExternalLinkIcon } from "lucide-react";
65
import Link from "next/link";
76
import { useState } from "react";
87

9-
export function PayEmbedFTUX(props: { clientId: string }) {
10-
const [tab, setTab] = useState("embed");
8+
type Tab = "embed" | "sdk" | "api";
9+
10+
export function PayEmbedFTUX(props: {
11+
clientId: string;
12+
codeExamples: {
13+
embed: React.ReactNode;
14+
sdk: React.ReactNode;
15+
api: React.ReactNode;
16+
};
17+
}) {
18+
const [tab, setTab] = useState<Tab>("embed");
1119
return (
1220
<div className="rounded-lg border bg-card">
13-
<div className="border-b px-4 py-4 lg:px-6">
14-
<h2 className="font-semibold text-xl tracking-tight">
21+
<div className="border-b border-dashed p-4">
22+
<h2 className="font-semibold text-lg tracking-tight">
1523
Start Monetizing Your App
1624
</h2>
1725
</div>
1826

19-
<div className="px-4 py-6 lg:p-6">
27+
<div className="p-4 pt-2">
2028
<TabButtons
2129
tabClassName="!text-sm"
2230
tabs={[
@@ -38,32 +46,11 @@ export function PayEmbedFTUX(props: { clientId: string }) {
3846
]}
3947
/>
4048
<div className="h-2" />
41-
{tab === "embed" && (
42-
<CodeServer
43-
code={embedCode(props.clientId)}
44-
lang="tsx"
45-
className="bg-background"
46-
/>
47-
)}
48-
{tab === "sdk" && (
49-
<CodeServer
50-
code={sdkCode(props.clientId)}
51-
lang="ts"
52-
className="bg-background"
53-
ignoreFormattingErrors
54-
/>
55-
)}
56-
{tab === "api" && (
57-
<CodeServer
58-
code={apiCode(props.clientId)}
59-
lang="bash"
60-
className="bg-background"
61-
ignoreFormattingErrors
62-
/>
63-
)}
49+
50+
{props.codeExamples[tab]}
6451
</div>
6552

66-
<div className="flex flex-col gap-3 border-t p-4 lg:flex-row lg:items-center lg:justify-between lg:p-6">
53+
<div className="flex flex-col gap-3 border-t p-4 lg:flex-row lg:items-center lg:justify-between">
6754
<div className="flex gap-3">
6855
<Button asChild variant="outline" size="sm">
6956
<Link
@@ -81,39 +68,3 @@ export function PayEmbedFTUX(props: { clientId: string }) {
8168
</div>
8269
);
8370
}
84-
85-
const embedCode = (clientId: string) => `\
86-
import { createThirdwebClient } from "thirdweb";
87-
import { PayEmbed } from "thirdweb/react";
88-
89-
const client = createThirdwebClient({
90-
clientId: "${clientId}",
91-
});
92-
93-
export default function App() {
94-
return <PayEmbed client={client} />;
95-
}`;
96-
97-
const sdkCode = (clientId: string) => `\
98-
import { Bridge, NATIVE_TOKEN_ADDRESS, createThirdwebClient, toWei } from "thirdweb";
99-
100-
const client = createThirdwebClient({
101-
clientId: "${clientId}",
102-
});
103-
104-
const quote = await Bridge.Buy.prepare({
105-
originChainId: 1,
106-
originTokenAddress: "0xEeeeeEeeeEeEeeEeEeEeeEEEeeeeEeeeeeeeEEeE",
107-
destinationChainId: 10,
108-
destinationTokenAddress: "0xEeeeeEeeeEeEeeEeEeEeeEEEeeeeEeeeeeeeEEeE",
109-
amount: toWei("0.01"),
110-
sender: "0x2a4f24F935Eb178e3e7BA9B53A5Ee6d8407C0709",
111-
receiver: "0x2a4f24F935Eb178e3e7BA9B53A5Ee6d8407C0709",
112-
client,
113-
});`;
114-
115-
const apiCode = (clientId: string) => `\
116-
curl -X POST https://pay.thirdweb.com/v1/buy/prepare
117-
-H "Content-Type: application/json"
118-
-H "x-client-id: ${clientId}"
119-
-d '{"originChainId":"1","originTokenAddress":"0x...","destinationChainId":"10","destinationTokenAddress":"0x...","amount":"0.01"}'`;
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
export const embedCode = (clientId: string) => `\
2+
import { createThirdwebClient } from "thirdweb";
3+
import { PayEmbed } from "thirdweb/react";
4+
5+
const client = createThirdwebClient({
6+
clientId: "${clientId}",
7+
});
8+
9+
export default function App() {
10+
return <PayEmbed client={client} />;
11+
}`;
12+
13+
export const sdkCode = (clientId: string) => `\
14+
import { Bridge, NATIVE_TOKEN_ADDRESS, createThirdwebClient, toWei } from "thirdweb";
15+
16+
const client = createThirdwebClient({
17+
clientId: "${clientId}",
18+
});
19+
20+
const quote = await Bridge.Buy.prepare({
21+
originChainId: 1,
22+
originTokenAddress: "0xEeeeeEeeeEeEeeEeEeEeeEEEeeeeEeeeeeeeEEeE",
23+
destinationChainId: 10,
24+
destinationTokenAddress: "0xEeeeeEeeeEeEeeEeEeEeeEEEeeeeEeeeeeeeEEeE",
25+
amount: toWei("0.01"),
26+
sender: "0x2a4f24F935Eb178e3e7BA9B53A5Ee6d8407C0709",
27+
receiver: "0x2a4f24F935Eb178e3e7BA9B53A5Ee6d8407C0709",
28+
client,
29+
});`;
30+
31+
export const apiCode = (clientId: string) => `\
32+
curl -X POST https://pay.thirdweb.com/v1/buy/prepare
33+
-H "Content-Type: application/json"
34+
-H "x-client-id: ${clientId}"
35+
-d '{"originChainId":"1","originTokenAddress":"0x...","destinationChainId":"10","destinationTokenAddress":"0x...","amount":"0.01"}'`;

0 commit comments

Comments
 (0)