Skip to content

Commit 800503d

Browse files
committed
[MNY-345] Portal: Add Checkout widget iframe docs (#8581)
<!-- ## title your PR with this format: "[SDK/Dashboard/Portal] Feature/Fix: Concise title for the changes" If you did not copy the branch name from Linear, paste the issue tag here (format is TEAM-0000): ## Notes for the reviewer Anything important to call out? Be sure to also clarify these in your comments. ## How to test Unit tests, playground, etc. --> <!-- start pr-codex --> --- ## PR-Codex overview This PR focuses on updating the `Checkout Widget` and `Swap Widget` components to enhance their functionality and improve user experience, including new image formats, additional features, and documentation updates. ### Detailed summary - Replaced `.png` images with `.jpg` for `swap-dark` and `swap-light`. - Added `IframeCodePreview` component for iframe integration in `Checkout Widget`. - Updated `sendMessageToParent` function to use a single object parameter. - Enhanced sidebar with new links for `Checkout Widget` and `Swap Widget`. - Expanded documentation for `Checkout Widget` and `Swap Widget` with features, examples, and API references. > ✨ Ask PR-Codex anything about this PR by commenting with `/codex {your question}` <!-- end pr-codex --> <!-- This is an auto-generated comment: release notes by coderabbit.ai --> ## Summary by CodeRabbit * **New Features** * Added an iframe code-preview component with "Code" and "Preview" tabs for live iframe examples. * **Documentation** * New Checkout Widget docs (React + iframe) with integration guides, examples, options, and event-listening examples. * New Swap Widget docs with usage examples and API reference. * Swap page asset updates (image format changes). * **Improvements** * Reorganized sidebar to surface Widgets (Bridge, Checkout, Swap). * Updated widget postMessage event payload shape — consumers should verify event format. <sub>✏️ Tip: You can customize this high-level summary in your review settings.</sub> <!-- end of auto-generated comment: release notes by coderabbit.ai -->
1 parent 0ff8b9f commit 800503d

File tree

14 files changed

+566
-23
lines changed

14 files changed

+566
-23
lines changed

apps/dashboard/src/app/bridge/checkout-widget/CheckoutWidgetEmbed.client.tsx

Lines changed: 10 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -83,31 +83,26 @@ export function CheckoutWidgetEmbed({
8383
wallets: bridgeWallets,
8484
appMetadata,
8585
}}
86-
onSuccess={(data) => {
87-
sendMessageToParent("success", data);
86+
onSuccess={() => {
87+
sendMessageToParent({
88+
source: "checkout-widget",
89+
type: "success",
90+
});
8891
}}
8992
onError={(error) => {
90-
sendMessageToParent("error", {
93+
sendMessageToParent({
94+
source: "checkout-widget",
95+
type: "error",
9196
message: error.message,
9297
});
9398
}}
9499
/>
95100
);
96101
}
97102

98-
function sendMessageToParent(
99-
type: "success" | "error",
100-
data: object | undefined,
101-
) {
103+
function sendMessageToParent(content: object) {
102104
try {
103-
window.parent.postMessage(
104-
{
105-
source: "checkout-widget",
106-
type,
107-
data,
108-
},
109-
"*",
110-
);
105+
window.parent.postMessage(content, "*");
111106
} catch (error) {
112107
console.error("Failed to send post message to parent window");
113108
console.error(error);
186 KB
Loading
188 KB
Loading
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
import { CodeBlock, Tabs, TabsContent, TabsList, TabsTrigger } from "@doc";
2+
3+
export function IframeCodePreview(props: { src: string }) {
4+
return (
5+
<Tabs defaultValue="code">
6+
<TabsList>
7+
<TabsTrigger value="code">Code</TabsTrigger>
8+
<TabsTrigger value="preview">Preview</TabsTrigger>
9+
</TabsList>
10+
<TabsContent value="code">
11+
<CodeBlock
12+
code={`\
13+
<iframe
14+
src="${props.src}"
15+
height="700px"
16+
width="100%"
17+
style="border: 0;"
18+
/>`}
19+
lang="html"
20+
/>
21+
</TabsContent>
22+
<TabsContent value="preview">
23+
<iframe
24+
title="Checkout widget iframe"
25+
src={props.src}
26+
height="700px"
27+
className="rounded-xl"
28+
width="100%"
29+
style={{ border: 0 }}
30+
/>
31+
</TabsContent>
32+
</Tabs>
33+
);
34+
}
Lines changed: 162 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,162 @@
1+
import {
2+
ArticleIconCard,
3+
Details,
4+
createMetadata,
5+
DocImage,
6+
} from "@doc";
7+
import { IframeCodePreview } from "./iframe-code-preview";
8+
import { PlayIcon } from "lucide-react";
9+
import checkoutWidgetDark from "../checkout-widget-dark.jpg";
10+
import checkoutWidgetLight from "../checkout-widget.jpg";
11+
12+
export const metadata = createMetadata({
13+
image: {
14+
title: "Checkout widget iframe",
15+
icon: "payments",
16+
},
17+
title: "Checkout widget iframe",
18+
description: "Add a widget to accept crypto and fiat payments in your app using an iframe",
19+
});
20+
21+
# Checkout widget iframe
22+
23+
The Checkout widget iframe makes it easy to accept crypto and fiat payments in your app. Just add an iframe to your HTML and get a fully customizable checkout widget - no build setup required.
24+
25+
<div className='dark-only'>
26+
<DocImage src={checkoutWidgetDark} />
27+
</div>
28+
<div className='light-only'>
29+
<DocImage src={checkoutWidgetLight} />
30+
</div>
31+
32+
## Features
33+
34+
- Accept payments in crypto or fiat (credit/debit cards)
35+
- Cross-chain payment support across 85+ blockchains
36+
- Display product information (name, description, image)
37+
- Dark and light mode support
38+
- Display fiat values in multiple currencies
39+
40+
## Iframe Integration
41+
42+
The checkout widget requires below minimum parameters to be set:
43+
44+
- `chain` - The chain ID where you want to receive payment (e.g., 8453 for Base)
45+
- `tokenAddress` (optional) - The token address to accept as payment. If this parameter is not set, payment will be accepted in the native token of the specified chain.
46+
- `amount` - The amount to charge (as a decimal string, e.g., "0.01")
47+
- `seller` - The wallet address that will receive the payment
48+
49+
### Example
50+
51+
Accept 0.1 USDC on Base as payment to seller (`0xdd99b75f095d0c4d5112aCe938e4e6ed962fb024`)
52+
53+
<IframeCodePreview src="https://thirdweb.com/bridge/checkout-widget?chain=8453&tokenAddress=0x833589fcd6edb6e08f4c7c32d4f71b54bda02913&amount=0.1&seller=0xdd99b75f095d0c4d5112aCe938e4e6ed962fb024" />
54+
55+
## Try it out
56+
57+
<ArticleIconCard
58+
title="Checkout Widget Playground"
59+
description="Try out the Checkout Widget in our live playground"
60+
icon={PlayIcon}
61+
href="https://playground.thirdweb.com/bridge/checkout-widget?tab=iframe"
62+
/>
63+
64+
## Options
65+
66+
You can customize the checkout widget using query parameters as mentioned below.
67+
68+
69+
### Theme
70+
71+
By default the widget uses the "dark" theme. You can set the light theme by passing the `theme=light` query parameter.
72+
73+
<IframeCodePreview src="https://thirdweb.com/bridge/checkout-widget?chain=8453&amount=0.01&seller=0xdd99b75f095d0c4d5112aCe938e4e6ed962fb024&theme=light" />
74+
75+
76+
### Product Information
77+
78+
You can display product information by passing `title`, `description`, and `image` query parameters. Each of these parameters are optional.
79+
80+
Make sure to URI encode the parameters if they contain special characters
81+
82+
<Details summary="Example">
83+
84+
* title: `"Something"`
85+
* description: `"Description of something goes here"`
86+
* image: `"https://picsum.photos/600/300"`
87+
* price: 0.01 ETH on Base
88+
89+
<IframeCodePreview src="https://thirdweb.com/bridge/checkout-widget?chain=8453&amount=0.01&seller=0xdd99b75f095d0c4d5112aCe938e4e6ed962fb024&title=Something&description=Description%20of%20something%20goes%20here&image=https%3A%2F%2Fpicsum.photos%2F600%2F300" />
90+
91+
</Details>
92+
93+
94+
### Currency
95+
96+
By default the fiat value of the token amounts is displayed in USD. You can change the currency by setting the `currency` query parameter.
97+
98+
<Details summary="Supported Currencies">
99+
100+
- `USD` - US Dollar (default)
101+
- `EUR` - Euro
102+
- `GBP` - British Pound
103+
- `JPY` - Japanese Yen
104+
- `KRW` - Korean Won
105+
- `CNY` - Chinese Yuan
106+
- `INR` - Indian Rupee
107+
- `NOK` - Norwegian Krone
108+
- `SEK` - Swedish Krona
109+
- `CHF` - Swiss Franc
110+
- `AUD` - Australian Dollar
111+
- `CAD` - Canadian Dollar
112+
- `NZD` - New Zealand Dollar
113+
- `MXN` - Mexican Peso
114+
- `BRL` - Brazilian Real
115+
- `CLP` - Chilean Peso
116+
- `CZK` - Czech Koruna
117+
- `DKK` - Danish Krone
118+
- `HKD` - Hong Kong Dollar
119+
- `HUF` - Hungarian Forint
120+
- `IDR` - Indonesian Rupiah
121+
- `ILS` - Israeli New Sheqel
122+
- `ISK` - Icelandic Krona
123+
124+
</Details>
125+
126+
#### Example
127+
128+
Show fiat values in Euro (EUR) in the widget.
129+
130+
<IframeCodePreview src="https://thirdweb.com/bridge/checkout-widget?chain=8453&amount=0.01&seller=0xdd99b75f095d0c4d5112aCe938e4e6ed962fb024&currency=EUR" />
131+
132+
### thirdweb branding
133+
134+
By default, the widget displays thirdweb branding at the bottom. You can hide this by setting the `showThirdwebBranding` query parameter to `false`.
135+
136+
<IframeCodePreview src="https://thirdweb.com/bridge/checkout-widget?chain=8453&amount=0.01&seller=0xdd99b75f095d0c4d5112aCe938e4e6ed962fb024&showThirdwebBranding=false" />
137+
138+
## Listening for Events
139+
140+
The checkout widget iframe sends events to the parent window using `postMessage` when a purchase succeeds or fails.
141+
142+
You can listen for these events to handle the purchase result in your application.
143+
144+
```js
145+
window.addEventListener("message", (event) => {
146+
147+
// verify that message is from thirdweb checkout widget iframe
148+
if (
149+
event.origin === "https://thirdweb.com" && event.data.source === "checkout-widget"
150+
) {
151+
152+
if (event.data.type === "success") {
153+
console.log("Purchase successful!");
154+
}
155+
156+
if (event.data.type === "error") {
157+
console.error("Purchase failed with error:", event.data.message);
158+
}
159+
}
160+
161+
});
162+
```
Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
1+
import {
2+
Details,
3+
createMetadata,
4+
DocImage,
5+
} from "@doc";
6+
import { ArticleIconCard } from "@doc";
7+
import { FrameIcon, PlayIcon } from "lucide-react";
8+
import { ReactIcon } from "@/icons";
9+
import checkoutWidgetDark from "./checkout-widget-dark.jpg";
10+
import checkoutWidgetLight from "./checkout-widget.jpg";
11+
12+
export const metadata = createMetadata({
13+
image: {
14+
title: "Checkout widget",
15+
icon: "payments",
16+
},
17+
title: "Checkout widget",
18+
description: "Add a widget to accept crypto and fiat payments in your app",
19+
});
20+
21+
# Checkout widget
22+
23+
The Checkout widget makes it easy to accept crypto and fiat payments directly to your wallet. It supports cross-chain payments, fiat onramp via credit/debit cards, and provides a seamless checkout experience for your users.
24+
25+
<div className='dark-only'>
26+
<DocImage src={checkoutWidgetDark} />
27+
</div>
28+
<div className='light-only'>
29+
<DocImage src={checkoutWidgetLight} />
30+
</div>
31+
32+
## Features
33+
34+
- Accept payments in crypto or fiat (credit/debit cards)
35+
- Cross-chain payment support across 85+ blockchains
36+
- Display product information (name, description, image)
37+
- Customizable UI with dark and light mode support
38+
- Display fiat values in multiple currencies
39+
- Event callbacks to track purchase status (success, error, cancel)
40+
41+
## Get Started
42+
43+
You can integrate the checkout widget into your website using an iframe or a React component.
44+
45+
<div className="space-y-4">
46+
47+
<ArticleIconCard
48+
title="Iframe"
49+
icon={FrameIcon}
50+
description="Integrate checkout widget into your website using an iframe"
51+
href="/bridge/checkout-widget/iframe"
52+
/>
53+
54+
<ArticleIconCard
55+
title="React Component"
56+
icon={ReactIcon}
57+
description="Integrate checkout widget into your app using a React component"
58+
href="/bridge/checkout-widget/react"
59+
/>
60+
61+
</div>
62+
63+
## Try it out
64+
65+
<ArticleIconCard
66+
title="Checkout Widget Playground"
67+
description="Try out the Checkout Widget in our live playground"
68+
icon={PlayIcon}
69+
href="https://playground.thirdweb.com/bridge/checkout-widget"
70+
/>
71+

0 commit comments

Comments
 (0)