-
Notifications
You must be signed in to change notification settings - Fork 634
[MNY-346] Playground: Add CheckoutWidget iframe #8591
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -15,6 +15,7 @@ import { | |
| import { Button } from "../../../components/ui/button"; | ||
| import { THIRDWEB_CLIENT } from "../../../lib/client"; | ||
| import { cn } from "../../../lib/utils"; | ||
| import { buildCheckoutIframeUrl } from "./buildCheckoutIframeUrl"; | ||
| import { CodeGen } from "./CodeGen"; | ||
| import type { BridgeComponentsPlaygroundOptions } from "./types"; | ||
|
|
||
|
|
@@ -156,7 +157,22 @@ export function RightSection(props: { | |
| > | ||
| <BackgroundPattern /> | ||
|
|
||
| {previewTab === "ui" && embed} | ||
| {previewTab === "ui" && | ||
| (props.widget === "checkout" && | ||
| props.options.integrationType === "iframe" ? ( | ||
| <iframe | ||
| src={buildCheckoutIframeUrl(props.options)} | ||
| height="700px" | ||
| width="100%" | ||
| title="Checkout Widget" | ||
| className="fade-in-0 animate-in rounded-xl duration-500" | ||
| style={{ | ||
| border: "0", | ||
| }} | ||
| /> | ||
| ) : ( | ||
| embed | ||
| ))} | ||
|
Comment on lines
+160
to
+175
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🛠️ Refactor suggestion | 🟠 Major Replace inline style with Tailwind class. The inline 🔎 Proposed fix <iframe
src={buildCheckoutIframeUrl(props.options)}
height="700px"
width="100%"
title="Checkout Widget"
- className="fade-in-0 animate-in rounded-xl duration-500"
- style={{
- border: "0",
- }}
+ className="fade-in-0 animate-in rounded-xl border-0 duration-500"
/>Based on coding guidelines, inline styles should be avoided in favor of Tailwind utility classes. 🤖 Prompt for AI Agents |
||
|
|
||
| {previewTab === "code" && ( | ||
| <CodeGen widget={props.widget} options={props.options} /> | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,65 @@ | ||
| import type { BridgeComponentsPlaygroundOptions } from "./types"; | ||
|
|
||
| const CHECKOUT_WIDGET_IFRAME_BASE_URL = | ||
| "https://thirdweb.com/bridge/checkout-widget"; | ||
|
|
||
| export function buildCheckoutIframeUrl( | ||
| options: BridgeComponentsPlaygroundOptions, | ||
| ) { | ||
MananTank marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| const url = new URL(CHECKOUT_WIDGET_IFRAME_BASE_URL); | ||
|
|
||
| // Required params | ||
| url.searchParams.set("chain", String(options.payOptions.buyTokenChain.id)); | ||
| url.searchParams.set("amount", options.payOptions.buyTokenAmount); | ||
| url.searchParams.set("seller", options.payOptions.sellerAddress); | ||
|
|
||
| // Token address (optional - if not set, native token is used) | ||
| if (options.payOptions.buyTokenAddress) { | ||
| url.searchParams.set("tokenAddress", options.payOptions.buyTokenAddress); | ||
| } | ||
|
|
||
| // Theme (only add if light, dark is default) | ||
| if (options.theme.type === "light") { | ||
| url.searchParams.set("theme", "light"); | ||
| } | ||
|
|
||
| // Currency (only add if not USD, USD is default) | ||
| if (options.payOptions.currency && options.payOptions.currency !== "USD") { | ||
| url.searchParams.set("currency", options.payOptions.currency); | ||
| } | ||
|
|
||
| // Branding | ||
| if (options.payOptions.showThirdwebBranding === false) { | ||
| url.searchParams.set("showThirdwebBranding", "false"); | ||
| } | ||
|
|
||
| // Product info | ||
| if (options.payOptions.title) { | ||
| url.searchParams.set("title", options.payOptions.title); | ||
| } | ||
|
|
||
| if (options.payOptions.description) { | ||
| url.searchParams.set("description", options.payOptions.description); | ||
| } | ||
|
|
||
| if (options.payOptions.image) { | ||
| url.searchParams.set("image", options.payOptions.image); | ||
| } | ||
|
|
||
| if (options.payOptions.buttonLabel) { | ||
| url.searchParams.set("buttonLabel", options.payOptions.buttonLabel); | ||
| } | ||
|
|
||
| // Payment methods | ||
| if ( | ||
| options.payOptions.paymentMethods && | ||
| options.payOptions.paymentMethods.length === 1 | ||
| ) { | ||
| url.searchParams.set( | ||
| "paymentMethods", | ||
| options.payOptions.paymentMethods[0], | ||
| ); | ||
| } | ||
|
|
||
| return url.toString(); | ||
| } | ||
Uh oh!
There was an error while loading. Please reload this page.