Skip to content

Commit 356dee5

Browse files
committed
[Dashboard] improve pay analytics FTUX
1 parent 4d38a7e commit 356dee5

File tree

2 files changed

+116
-0
lines changed

2 files changed

+116
-0
lines changed

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

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import {
33
getUniversalBridgeWalletUsage,
44
} from "@/api/analytics";
55
import type { Range } from "../../analytics/date-range-selector";
6+
import { PayEmbedFTUX } from "./PayEmbedFTUX";
67
import { PayCustomersTable } from "./components/PayCustomersTable";
78
import { PayNewCustomers } from "./components/PayNewCustomers";
89
import { PaymentHistory } from "./components/PaymentHistory";
@@ -54,6 +55,12 @@ export async function PayAnalytics(props: {
5455
walletDataPromise,
5556
]);
5657

58+
const hasVolume = volumeData.some((d) => d.amountUsdCents > 0);
59+
const hasWallet = walletData.some((d) => d.count > 0);
60+
if (!hasVolume && !hasWallet) {
61+
return <PayEmbedFTUX clientId={props.clientId} />;
62+
}
63+
5764
return (
5865
<div className="flex flex-col gap-10 lg:gap-6">
5966
<GridWithSeparator>
Lines changed: 109 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,109 @@
1+
"use client";
2+
import { Button } from "@/components/ui/button";
3+
import { CodeServer } from "@/components/ui/code/code.server";
4+
import { TabButtons } from "@/components/ui/tabs";
5+
import { TrackedLinkTW } from "@/components/ui/tracked-link";
6+
import { ExternalLinkIcon } from "lucide-react";
7+
import { useState } from "react";
8+
9+
export function PayEmbedFTUX(props: { clientId: string }) {
10+
const [tab, setTab] = useState("embed");
11+
return (
12+
<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">Integrate Pay</h2>
15+
</div>
16+
17+
<div className="px-4 py-6 lg:p-6">
18+
<TabButtons
19+
tabClassName="!text-sm"
20+
tabs={[
21+
{
22+
name: "Embed",
23+
onClick: () => setTab("embed"),
24+
isActive: tab === "embed",
25+
},
26+
{
27+
name: "SDK",
28+
onClick: () => setTab("sdk"),
29+
isActive: tab === "sdk",
30+
},
31+
{
32+
name: "API",
33+
onClick: () => setTab("api"),
34+
isActive: tab === "api",
35+
},
36+
]}
37+
/>
38+
<div className="h-2" />
39+
{tab === "embed" && (
40+
<CodeServer
41+
code={embedCode(props.clientId)}
42+
lang="tsx"
43+
className="bg-background"
44+
/>
45+
)}
46+
{tab === "sdk" && (
47+
<CodeServer code={sdkCode} lang="ts" className="bg-background" />
48+
)}
49+
{tab === "api" && (
50+
<CodeServer
51+
code={apiCode(props.clientId)}
52+
lang="bash"
53+
className="bg-background"
54+
/>
55+
)}
56+
</div>
57+
58+
<div className="flex flex-col gap-3 border-t p-4 lg:flex-row lg:items-center lg:justify-between lg:p-6">
59+
<div className="flex gap-3">
60+
<Button asChild variant="outline" size="sm">
61+
<TrackedLinkTW
62+
href="https://portal.thirdweb.com/connect/pay/embed"
63+
target="_blank"
64+
className="gap-2"
65+
category="pay-ftux"
66+
label="docs"
67+
>
68+
View Docs
69+
<ExternalLinkIcon className="size-4 text-muted-foreground" />
70+
</TrackedLinkTW>
71+
</Button>
72+
</div>
73+
</div>
74+
</div>
75+
);
76+
}
77+
78+
const embedCode = (clientId: string) => `
79+
import { createThirdwebClient } from "thirdweb";
80+
import { PayEmbed } from "thirdweb/react";
81+
82+
const client = createThirdwebClient({
83+
clientId: "${clientId}",
84+
});
85+
86+
export default function App() {
87+
return <PayEmbed client={client} />;
88+
}
89+
`;
90+
91+
const sdkCode = `
92+
import { Bridge, NATIVE_TOKEN_ADDRESS } from "thirdweb";
93+
94+
const quote = await Bridge.Buy.prepare({
95+
originChainId: 1,
96+
originTokenAddress: NATIVE_TOKEN_ADDRESS,
97+
destinationChainId: 10,
98+
destinationTokenAddress: NATIVE_TOKEN_ADDRESS,
99+
amount: toWei("0.01"),
100+
client: thirdwebClient,
101+
});
102+
`;
103+
104+
const apiCode = (clientId: string) => `
105+
curl -X POST https://pay.thirdweb.com/v1/buy/quote \
106+
-H "Content-Type: application/json" \
107+
-H "x-client-id: ${clientId}" \
108+
-d '{"originChainId":1,"originTokenAddress":"0x...","destinationChainId":10,"destinationTokenAddress":"0x...","amount":"0.01"}'
109+
`;

0 commit comments

Comments
 (0)