Skip to content

Commit a3d336c

Browse files
MananTankjnsdls
authored andcommitted
Fix CodeServer used in client component
1 parent aabb96a commit a3d336c

File tree

3 files changed

+86
-67
lines changed

3 files changed

+86
-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
@@ -3,7 +3,9 @@ import {
33
getUniversalBridgeUsage,
44
getUniversalBridgeWalletUsage,
55
} from "@/api/analytics";
6+
import { CodeServer } from "@/components/ui/code/code.server";
67
import type { Range } from "../../analytics/date-range-selector";
8+
import { apiCode, embedCode, sdkCode } from "./code-examples";
79
import { PayCustomersTable } from "./components/PayCustomersTable";
810
import { PaymentHistory } from "./components/PaymentHistory";
911
import { PaymentsSuccessRate } from "./components/PaymentsSuccessRate";
@@ -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+
api: (
72+
<CodeServer
73+
className="bg-background"
74+
code={apiCode(props.projectClientId)}
75+
lang="bash"
76+
/>
77+
),
78+
embed: (
79+
<CodeServer
80+
className="bg-background"
81+
code={embedCode(props.projectClientId)}
82+
lang="tsx"
83+
/>
84+
),
85+
sdk: (
86+
<CodeServer
87+
className="bg-background"
88+
code={sdkCode(props.projectClientId)}
89+
lang="ts"
90+
/>
91+
),
92+
} as const
93+
}
94+
/>
95+
);
6496
}
6597

6698
return (
Lines changed: 18 additions & 66 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,31 @@
11
"use client";
2+
23
import { ExternalLinkIcon } from "lucide-react";
34
import Link from "next/link";
45
import { useState } from "react";
56
import { Button } from "@/components/ui/button";
6-
import { CodeServer } from "@/components/ui/code/code.server";
77
import { TabButtons } from "@/components/ui/tabs";
88

9-
export function PayEmbedFTUX(props: { clientId: string }) {
10-
const [tab, setTab] = useState("embed");
9+
type Tab = "embed" | "sdk" | "api";
10+
11+
export function PayEmbedFTUX(props: {
12+
clientId: string;
13+
codeExamples: {
14+
embed: React.ReactNode;
15+
sdk: React.ReactNode;
16+
api: React.ReactNode;
17+
};
18+
}) {
19+
const [tab, setTab] = useState<Tab>("embed");
1120
return (
1221
<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">
22+
<div className="border-b border-dashed p-4">
23+
<h2 className="font-semibold text-lg tracking-tight">
1524
Start Monetizing Your App
1625
</h2>
1726
</div>
1827

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

66-
<div className="flex flex-col gap-3 border-t p-4 lg:flex-row lg:items-center lg:justify-between lg:p-6">
54+
<div className="flex flex-col gap-3 border-t p-4 lg:flex-row lg:items-center lg:justify-between">
6755
<div className="flex gap-3">
6856
<Button asChild size="sm" variant="outline">
6957
<Link
@@ -81,39 +69,3 @@ export function PayEmbedFTUX(props: { clientId: string }) {
8169
</div>
8270
);
8371
}
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)