Skip to content

Commit 4480e45

Browse files
committed
refactor: clean up pay analytics ftux
1 parent 2f14419 commit 4480e45

File tree

5 files changed

+59
-38
lines changed

5 files changed

+59
-38
lines changed

apps/dashboard/src/@/api/analytics.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -425,7 +425,7 @@ export async function getUniversalBridgeWalletUsage(args: {
425425
console.error(
426426
`Failed to fetch universal bridge wallet stats: ${res?.status} - ${res.statusText} - ${reason}`,
427427
);
428-
return null;
428+
return [];
429429
}
430430

431431
const json = await res.json();

apps/dashboard/src/@/components/ui/code/code.server.tsx

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,13 +6,17 @@ export type CodeProps = {
66
code: string;
77
lang: BundledLanguage;
88
className?: string;
9+
ignoreFormattingErrors?: boolean;
910
};
1011

1112
export const CodeServer: React.FC<CodeProps> = async ({
1213
code,
1314
lang,
1415
className,
16+
ignoreFormattingErrors,
1517
}) => {
16-
const { html, formattedCode } = await getCodeHtml(code, lang);
18+
const { html, formattedCode } = await getCodeHtml(code, lang, {
19+
ignoreFormattingErrors,
20+
});
1721
return <RenderCode code={formattedCode} html={html} className={className} />;
1822
};

apps/dashboard/src/@/components/ui/code/getCodeHtml.tsx

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -23,21 +23,21 @@ export async function getCodeHtml(
2323
const estreePlugin = await import("prettier/plugins/estree");
2424
const formattedCode = isPrettierSupportedLang(lang)
2525
? await format(code, {
26-
parser: "babel-ts",
27-
plugins: [parserBabel, estreePlugin.default],
28-
printWidth: 60,
29-
}).catch((e) => {
30-
if (!options?.ignoreFormattingErrors) {
31-
console.error(e);
32-
console.error("Failed to format code");
33-
console.log({
34-
code,
35-
lang,
36-
});
37-
}
26+
parser: "babel-ts",
27+
plugins: [parserBabel, estreePlugin.default],
28+
printWidth: 60,
29+
}).catch((e) => {
30+
if (!options?.ignoreFormattingErrors) {
31+
console.error(e);
32+
console.error("Failed to format code");
33+
console.log({
34+
code,
35+
lang,
36+
});
37+
}
3838

39-
return code;
40-
})
39+
return code;
40+
})
4141
: code;
4242

4343
const html = await codeToHtml(formattedCode, {

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

Lines changed: 29 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,9 @@ export function PayEmbedFTUX(props: { clientId: string }) {
1111
return (
1212
<div className="rounded-lg border bg-card">
1313
<div className="border-b px-4 py-4 lg:px-6">
14-
<h2 className="font-semibold text-xl tracking-tight">Integrate Pay</h2>
14+
<h2 className="font-semibold text-xl tracking-tight">
15+
Start Monetizing Your App
16+
</h2>
1517
</div>
1618

1719
<div className="px-4 py-6 lg:p-6">
@@ -44,13 +46,19 @@ export function PayEmbedFTUX(props: { clientId: string }) {
4446
/>
4547
)}
4648
{tab === "sdk" && (
47-
<CodeServer code={sdkCode} lang="ts" className="bg-background" />
49+
<CodeServer
50+
code={sdkCode(props.clientId)}
51+
lang="ts"
52+
className="bg-background"
53+
ignoreFormattingErrors
54+
/>
4855
)}
4956
{tab === "api" && (
5057
<CodeServer
5158
code={apiCode(props.clientId)}
5259
lang="bash"
5360
className="bg-background"
61+
ignoreFormattingErrors
5462
/>
5563
)}
5664
</div>
@@ -75,7 +83,7 @@ export function PayEmbedFTUX(props: { clientId: string }) {
7583
);
7684
}
7785

78-
const embedCode = (clientId: string) => `
86+
const embedCode = (clientId: string) => `\
7987
import { createThirdwebClient } from "thirdweb";
8088
import { PayEmbed } from "thirdweb/react";
8189
@@ -85,25 +93,28 @@ const client = createThirdwebClient({
8593
8694
export default function App() {
8795
return <PayEmbed client={client} />;
88-
}
89-
`;
96+
}`;
9097

91-
const sdkCode = `
92-
import { Bridge, NATIVE_TOKEN_ADDRESS } from "thirdweb";
98+
const sdkCode = (clientId: string) => `\
99+
import { Bridge, NATIVE_TOKEN_ADDRESS, createThirdwebClient, toWei } from "thirdweb";
100+
101+
const client = createThirdwebClient({
102+
clientId: "${clientId}",
103+
});
93104
94105
const quote = await Bridge.Buy.prepare({
95106
originChainId: 1,
96-
originTokenAddress: NATIVE_TOKEN_ADDRESS,
107+
originTokenAddress: "0xEeeeeEeeeEeEeeEeEeEeeEEEeeeeEeeeeeeeEEeE",
97108
destinationChainId: 10,
98-
destinationTokenAddress: NATIVE_TOKEN_ADDRESS,
109+
destinationTokenAddress: "0xEeeeeEeeeEeEeeEeEeEeeEEEeeeeEeeeeeeeEEeE",
99110
amount: toWei("0.01"),
100-
client: thirdwebClient,
101-
});
102-
`;
111+
sender: "0x2a4f24F935Eb178e3e7BA9B53A5Ee6d8407C0709",
112+
receiver: "0x2a4f24F935Eb178e3e7BA9B53A5Ee6d8407C0709",
113+
client,
114+
});`;
103115

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-
`;
116+
const apiCode = (clientId: string) => `\
117+
curl -X POST https://pay.thirdweb.com/v1/buy/prepare
118+
-H "Content-Type: application/json"
119+
-H "x-client-id: ${clientId}"
120+
-d '{"originChainId":"1","originTokenAddress":"0x...","destinationChainId":"10","destinationTokenAddress":"0x...","amount":"0.01"}'`;

packages/thirdweb/src/bridge/Buy.ts

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -164,13 +164,13 @@ export declare namespace quote {
164164
client: ThirdwebClient;
165165
maxSteps?: number;
166166
} & (
167-
| {
167+
| {
168168
buyAmountWei: bigint;
169169
}
170-
| {
170+
| {
171171
amount: bigint;
172172
}
173-
);
173+
);
174174

175175
type Result = Quote & {
176176
intent: {
@@ -197,6 +197,8 @@ export declare namespace quote {
197197
* destinationChainId: 10,
198198
* destinationTokenAddress: NATIVE_TOKEN_ADDRESS,
199199
* amount: toWei("0.01"),
200+
* sender: "0x...",
201+
* receiver: "0x...",
200202
* client: thirdwebClient,
201203
* });
202204
* ```
@@ -282,6 +284,8 @@ export declare namespace quote {
282284
* destinationChainId: 10,
283285
* destinationTokenAddress: NATIVE_TOKEN_ADDRESS,
284286
* amount: toWei("0.01"),
287+
* sender: "0x...",
288+
* receiver: "0x...",
285289
* purchaseData: {
286290
* size: "large",
287291
* shippingAddress: "123 Main St, New York, NY 10001",
@@ -299,6 +303,8 @@ export declare namespace quote {
299303
* destinationChainId: 10,
300304
* destinationTokenAddress: NATIVE_TOKEN_ADDRESS,
301305
* amount: toWei("0.01"),
306+
* sender: "0x...",
307+
* receiver: "0x...",
302308
* maxSteps: 2, // Will only return a quote for routes with 2 or fewer steps
303309
* client: thirdwebClient,
304310
* });
@@ -312,7 +318,7 @@ export declare namespace quote {
312318
* @param options.amount - The amount of the destination token to receive.
313319
* @param options.sender - The address of the sender.
314320
* @param options.receiver - The address of the recipient.
315-
* @param options.purchaseData - Arbitrary data to be passed to the purchase function and included with any webhooks or status calls.
321+
* @param [options.purchaseData] - Arbitrary data to be passed to the purchase function and included with any webhooks or status calls.
316322
* @param [options.maxSteps] - Limit the number of total steps in the route.
317323
* @param options.client - Your thirdweb client.
318324
*

0 commit comments

Comments
 (0)