@@ -245,7 +237,7 @@ export function LeftSection(props: {
)}
{/* Checkout Mode - Seller Address, Price and Payment Methods */}
- {effectiveWidget === "checkout" && (
+ {props.widget === "checkout" && (
@@ -347,7 +339,7 @@ export function LeftSection(props: {
)}
{/* Transaction Mode Options */}
- {effectiveWidget === "transaction" && (
+ {props.widget === "transaction" && (
@@ -495,26 +487,6 @@ export function LeftSection(props: {
-
-
-
-
-
- Abstract away gas fees for users of your app by enabling ERC-4337
- Account Abstraction
-
-
-
- Learn more about Account Abstraction
-
-
-
-
-
);
}
diff --git a/apps/playground-web/src/app/payments/components/RightSection.tsx b/apps/playground-web/src/app/payments/components/RightSection.tsx
index 36b76a8a215..3285ac4a5bc 100644
--- a/apps/playground-web/src/app/payments/components/RightSection.tsx
+++ b/apps/playground-web/src/app/payments/components/RightSection.tsx
@@ -29,7 +29,7 @@ type Tab = "ui" | "code";
export function RightSection(props: {
options: BridgeComponentsPlaygroundOptions;
tab?: string;
- lockedWidget?: "buy" | "checkout" | "transaction";
+ widget: "buy" | "checkout" | "transaction";
}) {
const pathname = usePathname();
const [previewTab, _setPreviewTab] = useState
(() => {
@@ -52,10 +52,8 @@ export function RightSection(props: {
colors: props.options.theme.lightColorOverrides,
});
- const effectiveWidget = props.lockedWidget || props.options.payOptions.widget;
-
let embed: React.ReactNode;
- if (effectiveWidget === "buy") {
+ if (props.widget === "buy") {
embed = (
}
+ {previewTab === "code" && (
+
+ )}
);
diff --git a/apps/playground-web/src/app/payments/components/types.ts b/apps/playground-web/src/app/payments/components/types.ts
index 6b8f6b57137..aef999010a8 100644
--- a/apps/playground-web/src/app/payments/components/types.ts
+++ b/apps/playground-web/src/app/payments/components/types.ts
@@ -37,7 +37,6 @@ export type BridgeComponentsPlaygroundOptions = {
lightColorOverrides: ThemeOverrides["colors"];
};
payOptions: {
- widget?: "buy" | "checkout" | "transaction";
title: string | undefined;
image: string | undefined;
description: string | undefined;
diff --git a/apps/playground-web/src/app/payments/fund-wallet/BuyPlayground.tsx b/apps/playground-web/src/app/payments/fund-wallet/BuyPlayground.tsx
index c96863a39f5..a942c9d074b 100644
--- a/apps/playground-web/src/app/payments/fund-wallet/BuyPlayground.tsx
+++ b/apps/playground-web/src/app/payments/fund-wallet/BuyPlayground.tsx
@@ -18,7 +18,6 @@ const defaultOptions: BridgeComponentsPlaygroundOptions = {
sellerAddress: "0x0000000000000000000000000000000000000000",
title: "",
transactionData: "",
- widget: "buy",
currency: "USD",
showThirdwebBranding: true,
},
@@ -36,13 +35,9 @@ export function BuyPlayground() {
return (
);
}
diff --git a/apps/playground-web/src/app/payments/transactions/TransactionPlayground.tsx b/apps/playground-web/src/app/payments/transactions/TransactionPlayground.tsx
index 4b0a9959f39..1b598964ea2 100644
--- a/apps/playground-web/src/app/payments/transactions/TransactionPlayground.tsx
+++ b/apps/playground-web/src/app/payments/transactions/TransactionPlayground.tsx
@@ -18,7 +18,6 @@ const defaultOptions: BridgeComponentsPlaygroundOptions = {
sellerAddress: "0x0000000000000000000000000000000000000000",
title: "",
transactionData: "",
- widget: "transaction",
currency: "USD",
showThirdwebBranding: true,
},
@@ -37,12 +36,12 @@ export function TransactionPlayground() {
);
}
diff --git a/apps/playground-web/src/app/wallets/sign-in/components/CodeGen.tsx b/apps/playground-web/src/app/wallets/sign-in/components/CodeGen.tsx
index 408b14d8ce0..58ee78ad0d0 100644
--- a/apps/playground-web/src/app/wallets/sign-in/components/CodeGen.tsx
+++ b/apps/playground-web/src/app/wallets/sign-in/components/CodeGen.tsx
@@ -1,4 +1,10 @@
import { lazy, Suspense } from "react";
+import {
+ quotes,
+ stringifyIgnoreFalsy,
+ stringifyImports,
+ stringifyProps,
+} from "@/lib/code-gen";
import { LoadingDots } from "../../../../components/ui/LoadingDots";
import type { ConnectPlaygroundOptions } from "./types";
@@ -34,10 +40,10 @@ export function CodeGen(props: { connectOptions: ConnectPlaygroundOptions }) {
function getCode(connectOptions: ConnectPlaygroundOptions) {
const walletCodes: string[] = [];
const imports = {
- chains: [] as string[],
- react: [] as string[],
- thirdweb: [] as string[],
- wallets: [] as string[],
+ "thirdweb/chains": [] as string[],
+ "thirdweb/react": ["ConnectButton"] as string[],
+ thirdweb: ["createThirdwebClient"] as string[],
+ "thirdweb/wallets": [] as string[],
};
if (
@@ -49,7 +55,7 @@ function getCode(connectOptions: ConnectPlaygroundOptions) {
options: ${JSON.stringify(connectOptions.inAppWallet.methods)},
},
})`);
- imports.wallets.push("inAppWallet");
+ imports["thirdweb/wallets"].push("inAppWallet");
}
for (const wallet of connectOptions.walletIds) {
@@ -57,7 +63,7 @@ function getCode(connectOptions: ConnectPlaygroundOptions) {
}
if (connectOptions.walletIds.length > 0) {
- imports.wallets.push("createWallet");
+ imports["thirdweb/wallets"].push("createWallet");
}
let themeProp: string | undefined;
@@ -68,7 +74,7 @@ function getCode(connectOptions: ConnectPlaygroundOptions) {
themeProp = `darkTheme({
colors: ${JSON.stringify(connectOptions.theme.darkColorOverrides)},
})`;
- imports.react.push("darkTheme");
+ imports["thirdweb/react"].push("darkTheme");
}
if (connectOptions.theme.type === "light") {
@@ -78,14 +84,14 @@ function getCode(connectOptions: ConnectPlaygroundOptions) {
themeProp = `lightTheme({
colors: ${JSON.stringify(connectOptions.theme.lightColorOverrides)},
})`;
- imports.react.push("lightTheme");
+ imports["thirdweb/react"].push("lightTheme");
} else {
themeProp = quotes("light");
}
}
if (connectOptions.enableAccountAbstraction) {
- imports.chains.push("ethereum");
+ imports["thirdweb/chains"].push("ethereum");
}
const props: Record
= {
@@ -118,11 +124,7 @@ function getCode(connectOptions: ConnectPlaygroundOptions) {
};
return `\
-import { createThirdwebClient } from "thirdweb";
-import { ConnectButton } from "thirdweb/react";
-${imports.react.length > 0 ? `import { ${imports.react.join(", ")} } from "thirdweb/react";` : ""}
-${imports.wallets.length > 0 ? `import { ${imports.wallets.join(", ")} } from "thirdweb/wallets";` : ""}
-${imports.chains.length > 0 ? `import { ${imports.chains.join(", ")} } from "thirdweb/chains";` : ""}
+${stringifyImports(imports)}
const client = createThirdwebClient({
clientId: "....",
@@ -160,35 +162,3 @@ const accountAbstractCode = `\
sponsorGas: true
}
`;
-
-function stringifyIgnoreFalsy(
- value: Record,
-) {
- const _value: Record = {};
-
- for (const key in value) {
- if (value[key] !== undefined && value[key] !== "") {
- _value[key] = value[key];
- }
- }
-
- return JSON.stringify(_value);
-}
-
-function stringifyProps(props: Record) {
- const _props: Record = {};
-
- for (const key in props) {
- if (props[key] !== undefined && props[key] !== "") {
- _props[key] = props[key];
- }
- }
-
- return Object.entries(_props)
- .map(([key, value]) => `${key}={${value}}`)
- .join("\n");
-}
-
-function quotes(value: string) {
- return `"${value}"`;
-}
diff --git a/apps/playground-web/src/lib/code-gen.ts b/apps/playground-web/src/lib/code-gen.ts
new file mode 100644
index 00000000000..16df909fd32
--- /dev/null
+++ b/apps/playground-web/src/lib/code-gen.ts
@@ -0,0 +1,43 @@
+export function stringifyProps(
+ props: Record,
+) {
+ const _props: Record = {};
+
+ for (const key in props) {
+ if (props[key] !== undefined && props[key] !== "") {
+ _props[key] = props[key];
+ }
+ }
+
+ return Object.entries(_props)
+ .map(([key, value]) => `${key}={${value}}`)
+ .join("\n");
+}
+
+export function quotes(value: string) {
+ return `"${value}"`;
+}
+
+export function stringifyImports(imports: Record) {
+ let code = "";
+ for (const key in imports) {
+ if (imports[key].length > 0) {
+ code += `import { ${imports[key].join(", ")} } from "${key}";\n`;
+ }
+ }
+ return code;
+}
+
+export function stringifyIgnoreFalsy(
+ value: Record,
+) {
+ const _value: Record = {};
+
+ for (const key in value) {
+ if (value[key] !== undefined && value[key] !== "") {
+ _value[key] = value[key];
+ }
+ }
+
+ return JSON.stringify(_value);
+}
diff --git a/packages/ui/src/components/code/getCodeHtml.tsx b/packages/ui/src/components/code/getCodeHtml.tsx
index 768e1e2934e..0283309b333 100644
--- a/packages/ui/src/components/code/getCodeHtml.tsx
+++ b/packages/ui/src/components/code/getCodeHtml.tsx
@@ -25,7 +25,7 @@ export async function getCodeHtml(
? await format(code, {
parser: "typescript",
plugins: [estreePlugin, typescriptPlugin],
- printWidth: 60,
+ printWidth: 80,
}).catch((e) => {
if (!options?.ignoreFormattingErrors) {
console.error(e);