Skip to content

Commit 8d4b6a1

Browse files
committed
[MNY-356] Add tokenEditable and amountEditable props on BuyWidget (#8621)
<!-- ## 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 introduces two new properties, `amountEditable` and `tokenEditable`, to enhance the `BuyWidget` component, allowing control over editing options for token selection and amount. This improves user experience by providing flexibility in the widget's functionality. ### Detailed summary - Added `amountEditable` and `tokenEditable` properties to `BuyWidget`. - Updated `BuyPlayground.tsx`, `CheckoutPlayground.tsx`, and `TransactionPlayground.tsx` to use new props. - Modified `CodeGen.tsx` to incorporate editability options. - Updated URL generation in `buildBuyIframeUrl.ts` for new props. - Added editability options in `LeftSection.tsx`. - Enhanced `BuyWidgetEmbed` to accept new props. - Implemented stories in `BuyWidget.stories.tsx` for editable and non-editable states. - Added documentation in `iframe/page.mdx` for new features. - Adjusted `FundWallet.tsx` and `TokenSection.tsx` to respect new editability options. > ✨ 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 ## Release Notes * **New Features** * Added `amountEditable` and `tokenEditable` props to the BuyWidget component, allowing developers to disable token selection and/or amount editing in the buy flow. * Enhanced UI controls to prevent interaction with locked fields when these options are disabled. * Updated documentation with examples of how to use the new editability options. * **Tests** * Added story variants demonstrating token and amount lock scenarios. <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 49b80fe commit 8d4b6a1

17 files changed

Lines changed: 246 additions & 45 deletions

File tree

.changeset/dirty-breads-swim.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"thirdweb": patch
3+
---
4+
5+
Add `amountEditable` and `tokenEditable` props on `BuyWidget` component to disable token selection and token amount editing

apps/dashboard/src/app/bridge/buy-widget/BuyWidgetEmbed.client.tsx

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,8 @@ export function BuyWidgetEmbed({
2020
buttonLabel,
2121
receiverAddress,
2222
country,
23+
amountEditable,
24+
tokenEditable,
2325
}: {
2426
chainId?: number;
2527
tokenAddress?: Address;
@@ -34,6 +36,8 @@ export function BuyWidgetEmbed({
3436
buttonLabel?: string;
3537
receiverAddress?: Address;
3638
country?: string;
39+
amountEditable?: boolean;
40+
tokenEditable?: boolean;
3741
}) {
3842
const client = useMemo(
3943
() =>
@@ -68,6 +72,8 @@ export function BuyWidgetEmbed({
6872
buttonLabel={buttonLabel}
6973
receiverAddress={receiverAddress}
7074
country={country}
75+
amountEditable={amountEditable}
76+
tokenEditable={tokenEditable}
7177
onSuccess={() => {
7278
sendMessageToParent({
7379
source: "buy-widget",

apps/dashboard/src/app/bridge/buy-widget/page.tsx

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,14 @@ export default async function Page(props: {
7373
const receiverAddress = parseQueryParams(searchParams.receiver, onlyAddress);
7474
const country = parseQueryParams(searchParams.country, (v) => v);
7575

76+
// Editable params
77+
const amountEditable = parseQueryParams(searchParams.amountEditable, (v) =>
78+
v === "false" ? false : undefined,
79+
);
80+
const tokenEditable = parseQueryParams(searchParams.tokenEditable, (v) =>
81+
v === "false" ? false : undefined,
82+
);
83+
7684
return (
7785
<BridgeProvidersLite forcedTheme={theme}>
7886
<div className="flex min-h-screen items-center justify-center bg-background px-4 py-8">
@@ -90,6 +98,8 @@ export default async function Page(props: {
9098
buttonLabel={buttonLabel}
9199
receiverAddress={receiverAddress}
92100
country={country}
101+
amountEditable={amountEditable}
102+
tokenEditable={tokenEditable}
93103
/>
94104
</div>
95105
</BridgeProvidersLite>

apps/playground-web/src/app/bridge/buy-widget/BuyPlayground.tsx

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,8 @@ const defaultOptions: BridgeComponentsPlaygroundOptions = {
2424
transactionData: "",
2525
currency: "USD",
2626
showThirdwebBranding: true,
27+
amountEditable: true,
28+
tokenEditable: true,
2729
},
2830
theme: {
2931
darkColorOverrides: {},

apps/playground-web/src/app/bridge/checkout-widget/CheckoutPlayground.tsx

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,8 @@ const defaultOptions: BridgeComponentsPlaygroundOptions = {
2424
receiverAddress: undefined,
2525
currency: "USD",
2626
showThirdwebBranding: true,
27+
amountEditable: true,
28+
tokenEditable: true,
2729
},
2830
theme: {
2931
darkColorOverrides: {},

apps/playground-web/src/app/bridge/components/CodeGen.tsx

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -160,6 +160,14 @@ tokenId: 2n,
160160
? quotes(options.payOptions.buttonLabel)
161161
: undefined,
162162
transaction: transaction,
163+
amountEditable:
164+
widget === "buy" && options.payOptions.amountEditable === false
165+
? false
166+
: undefined,
167+
tokenEditable:
168+
widget === "buy" && options.payOptions.tokenEditable === false
169+
? false
170+
: undefined,
163171
};
164172

165173
return `\

apps/playground-web/src/app/bridge/components/LeftSection.tsx

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -259,6 +259,46 @@ export function LeftSection(props: {
259259
</div>
260260
</div>
261261
</div>
262+
263+
{/* Editability Options */}
264+
<div className="flex flex-col gap-3">
265+
<Label>Editability Options</Label>
266+
<div className="flex gap-4">
267+
<div className="flex items-center space-x-2">
268+
<Checkbox
269+
checked={payOptions.tokenEditable}
270+
id="token-editable"
271+
onCheckedChange={(checked) => {
272+
setOptions((v) => ({
273+
...v,
274+
payOptions: {
275+
...v.payOptions,
276+
tokenEditable: checked === true,
277+
},
278+
}));
279+
}}
280+
/>
281+
<Label htmlFor="token-editable">Token Editable</Label>
282+
</div>
283+
284+
<div className="flex items-center space-x-2">
285+
<Checkbox
286+
checked={payOptions.amountEditable}
287+
id="amount-editable"
288+
onCheckedChange={(checked) => {
289+
setOptions((v) => ({
290+
...v,
291+
payOptions: {
292+
...v.payOptions,
293+
amountEditable: checked === true,
294+
},
295+
}));
296+
}}
297+
/>
298+
<Label htmlFor="amount-editable">Amount Editable</Label>
299+
</div>
300+
</div>
301+
</div>
262302
</div>
263303
)}
264304

apps/playground-web/src/app/bridge/components/RightSection.tsx

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,8 @@ export function RightSection(props: {
7070
currency={props.options.payOptions.currency}
7171
showThirdwebBranding={props.options.payOptions.showThirdwebBranding}
7272
receiverAddress={props.options.payOptions.receiverAddress}
73+
amountEditable={props.options.payOptions.amountEditable}
74+
tokenEditable={props.options.payOptions.tokenEditable}
7375
key={JSON.stringify({
7476
amount: props.options.payOptions.buyTokenAmount,
7577
chain: props.options.payOptions.buyTokenChain,

apps/playground-web/src/app/bridge/components/buildBuyIframeUrl.ts

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,5 +68,14 @@ export function buildBuyIframeUrl(options: BridgeComponentsPlaygroundOptions) {
6868
);
6969
}
7070

71+
// Editability options
72+
if (options.payOptions.amountEditable === false) {
73+
url.searchParams.set("amountEditable", "false");
74+
}
75+
76+
if (options.payOptions.tokenEditable === false) {
77+
url.searchParams.set("tokenEditable", "false");
78+
}
79+
7180
return url.toString();
7281
}

apps/playground-web/src/app/bridge/components/types.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,5 +59,9 @@ export type BridgeComponentsPlaygroundOptions = {
5959
currency?: SupportedFiatCurrency;
6060

6161
showThirdwebBranding: boolean;
62+
63+
// Editability options
64+
amountEditable: boolean;
65+
tokenEditable: boolean;
6266
};
6367
};

0 commit comments

Comments
 (0)