Skip to content

Commit 5e73246

Browse files
committed
lint
1 parent 1ce2227 commit 5e73246

File tree

2 files changed

+37
-35
lines changed

2 files changed

+37
-35
lines changed

apps/playground-web/src/app/connect/pay/components/CodeGen.tsx

Lines changed: 36 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
1+
import { THIRDWEB_CLIENT } from "@/lib/client";
2+
import { useQuery } from "@tanstack/react-query";
13
import { Suspense, lazy } from "react";
4+
import { defineChain, getContract, toUnits } from "thirdweb";
5+
import { getCurrencyMetadata } from "thirdweb/extensions/erc20";
26
import { CodeLoading } from "../../../../components/code/code.client";
37
import type { BridgeComponentsPlaygroundOptions } from "./types";
4-
import { useQuery } from "@tanstack/react-query";
5-
import { getCurrencyMetadata } from "thirdweb/extensions/erc20";
6-
import { defineChain, getContract, toUnits } from "thirdweb";
7-
import { THIRDWEB_CLIENT } from "@/lib/client";
88

99
const CodeClient = lazy(
1010
() => import("../../../../components/code/code.client"),
@@ -13,11 +13,36 @@ const CodeClient = lazy(
1313
export function CodeGen(props: {
1414
options: BridgeComponentsPlaygroundOptions;
1515
}) {
16+
const { options } = props;
17+
const { data: amount } = useQuery({
18+
queryKey: [
19+
"amount",
20+
options.payOptions.buyTokenAmount,
21+
options.payOptions.buyTokenChain,
22+
options.payOptions.buyTokenAddress,
23+
],
24+
queryFn: async () => {
25+
if (!options.payOptions.buyTokenAmount) {
26+
return;
27+
}
28+
const contract = getContract({
29+
chain: defineChain(options.payOptions.buyTokenChain.id),
30+
address: options.payOptions.buyTokenAddress,
31+
client: THIRDWEB_CLIENT,
32+
});
33+
const token = await getCurrencyMetadata({
34+
contract,
35+
});
36+
37+
return toUnits(options.payOptions.buyTokenAmount, token.decimals);
38+
},
39+
});
40+
1641
return (
1742
<div className="flex w-full grow flex-col">
1843
<Suspense fallback={<CodeLoading />}>
1944
<CodeClient
20-
code={getCode(props.options)}
45+
code={getCode(props.options, amount)}
2146
lang="tsx"
2247
loader={<CodeLoading />}
2348
className="grow"
@@ -27,7 +52,7 @@ export function CodeGen(props: {
2752
);
2853
}
2954

30-
function getCode(options: BridgeComponentsPlaygroundOptions) {
55+
function getCode(options: BridgeComponentsPlaygroundOptions, amount?: bigint) {
3156
const imports = {
3257
react: ["PayEmbed"] as string[],
3358
thirdweb: [] as string[],
@@ -48,30 +73,6 @@ function getCode(options: BridgeComponentsPlaygroundOptions) {
4873
imports.chains.push("base");
4974
}
5075

51-
const { data: amount } = useQuery({
52-
queryKey: [
53-
"amount",
54-
options.payOptions.buyTokenAmount,
55-
options.payOptions.buyTokenChain,
56-
options.payOptions.buyTokenAddress,
57-
],
58-
queryFn: async () => {
59-
if (!options.payOptions.buyTokenAmount) {
60-
return;
61-
}
62-
const contract = getContract({
63-
chain: defineChain(options.payOptions.buyTokenChain.id),
64-
address: options.payOptions.buyTokenAddress,
65-
client: THIRDWEB_CLIENT,
66-
});
67-
const token = await getCurrencyMetadata({
68-
contract,
69-
});
70-
71-
return toUnits(options.payOptions.buyTokenAmount, token.decimals);
72-
},
73-
});
74-
7576
imports.wallets.push("createWallet");
7677

7778
const componentName = (() => {
@@ -103,15 +104,16 @@ function Example() {
103104
<${componentName}
104105
client={client}
105106
chain={defineChain(${options.payOptions.buyTokenChain.id})}
106-
amount={${amount}n}${options.payOptions.buyTokenAddress ? `\n\t token="${options.payOptions.buyTokenAddress}"` : ""}${options.payOptions.sellerAddress ? `\n\t seller="${options.payOptions.sellerAddress}"` : ""}${options.payOptions.title ? `\n\t ${options.payOptions.widget === "checkout" ? "name" : "title"}="${options.payOptions.title}"` : ""}${options.payOptions.image ? `\n\t image="${options.payOptions.image}"` : ""}${options.payOptions.description ? `\n\t description="${options.payOptions.description}"` : ""}${options.payOptions.widget === "transaction"
107-
? `\n\t transaction={claimTo({
107+
amount={${amount}n}${options.payOptions.buyTokenAddress ? `\n\t token="${options.payOptions.buyTokenAddress}"` : ""}${options.payOptions.sellerAddress ? `\n\t seller="${options.payOptions.sellerAddress}"` : ""}${options.payOptions.title ? `\n\t ${options.payOptions.widget === "checkout" ? "name" : "title"}="${options.payOptions.title}"` : ""}${options.payOptions.image ? `\n\t image="${options.payOptions.image}"` : ""}${options.payOptions.description ? `\n\t description="${options.payOptions.description}"` : ""}${
108+
options.payOptions.widget === "transaction"
109+
? `\n\t transaction={claimTo({
108110
contract: nftContract,
109111
quantity: 1n,
110112
tokenId: 2n,
111113
to: account?.address || "",
112114
})}`
113-
: ""
114-
}
115+
: ""
116+
}
115117
/>
116118
);
117119
}`;

apps/playground-web/src/app/connect/pay/embed/LeftSection.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ import {
1313
import Link from "next/link";
1414
import type React from "react";
1515
import { useState } from "react";
16-
import { type Address, isAddress } from "thirdweb";
16+
import type { Address } from "thirdweb";
1717
import { defineChain } from "thirdweb/chains";
1818
import { cn } from "../../../../lib/utils";
1919
import { CollapsibleSection } from "../../sign-in/components/CollapsibleSection";

0 commit comments

Comments
 (0)