Skip to content

Commit 621c1de

Browse files
[SDK] Add buttonLabel prop to checkout widgets (#7805)
Co-authored-by: Cursor Agent <[email protected]>
1 parent 8bb2b0a commit 621c1de

File tree

17 files changed

+205
-8
lines changed

17 files changed

+205
-8
lines changed

.changeset/upset-pears-unite.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 ability to override button label for all payment widgets

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ function Example() {
7171
<${componentName}
7272
client={client}
7373
chain={defineChain(${options.payOptions.buyTokenChain.id})}
74-
amount="${options.payOptions.buyTokenAmount}"${options.payOptions.buyTokenAddress ? `\n\t tokenAddress="${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.paymentMethods && options.payOptions.paymentMethods.length > 0 ? `\n\t paymentMethods={${JSON.stringify(options.payOptions.paymentMethods)}}` : ""}${options.payOptions.currency ? `\n\t currency="${options.payOptions.currency}"` : ""}${
74+
amount="${options.payOptions.buyTokenAmount}"${options.payOptions.buyTokenAddress ? `\n\t tokenAddress="${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.buttonLabel ? `\n\t buttonLabel="${options.payOptions.buttonLabel}"` : ""}${options.payOptions.paymentMethods && options.payOptions.paymentMethods.length > 0 ? `\n\t paymentMethods={${JSON.stringify(options.payOptions.paymentMethods)}}` : ""}${options.payOptions.currency ? `\n\t currency="${options.payOptions.currency}"` : ""}${
7575
options.payOptions.widget === "transaction"
7676
? `\n\t transaction={claimTo({
7777
contract: nftContract,

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@ export type BridgeComponentsPlaygroundOptions = {
4141
title: string | undefined;
4242
image: string | undefined;
4343
description: string | undefined;
44+
buttonLabel: string | undefined;
4445

4546
buyTokenAddress?: Address;
4647
buyTokenAmount: string;

apps/playground-web/src/app/payments/embed/LeftSection.tsx

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,7 @@ export function LeftSection(props: {
7373
const modalTitleId = useId();
7474
const modalTitleIconId = useId();
7575
const modalDescriptionId = useId();
76+
const buttonLabelId = useId();
7677
const themeId = useId();
7778
const cryptoPaymentId = useId();
7879
const cardPaymentId = useId();
@@ -486,6 +487,26 @@ export function LeftSection(props: {
486487
value={options.payOptions.description}
487488
/>
488489
</div>
490+
491+
{/* Button Label */}
492+
<div className="flex flex-col gap-2">
493+
<Label htmlFor={buttonLabelId}>Button Label</Label>
494+
<Input
495+
className="bg-card"
496+
id={buttonLabelId}
497+
onChange={(e) =>
498+
setOptions((v) => ({
499+
...v,
500+
payOptions: {
501+
...payOptions,
502+
buttonLabel: e.target.value,
503+
},
504+
}))
505+
}
506+
placeholder="Custom button text (optional)"
507+
value={options.payOptions.buttonLabel}
508+
/>
509+
</div>
489510
</div>
490511
</CollapsibleSection>
491512

apps/playground-web/src/app/payments/embed/RightSection.tsx

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,9 @@ export function RightSection(props: {
6666
tokenAddress={props.options.payOptions.buyTokenAddress}
6767
currency={props.options.payOptions.currency}
6868
showThirdwebBranding={props.options.payOptions.showThirdwebBranding}
69+
{...(props.options.payOptions.buttonLabel && {
70+
buttonLabel: props.options.payOptions.buttonLabel,
71+
})}
6972
/>
7073
);
7174
}
@@ -91,6 +94,9 @@ export function RightSection(props: {
9194
tokenAddress={props.options.payOptions.buyTokenAddress}
9295
currency={props.options.payOptions.currency}
9396
showThirdwebBranding={props.options.payOptions.showThirdwebBranding}
97+
{...(props.options.payOptions.buttonLabel && {
98+
buttonLabel: props.options.payOptions.buttonLabel,
99+
})}
94100
/>
95101
);
96102
}
@@ -112,6 +118,9 @@ export function RightSection(props: {
112118
})}
113119
currency={props.options.payOptions.currency}
114120
showThirdwebBranding={props.options.payOptions.showThirdwebBranding}
121+
{...(props.options.payOptions.buttonLabel && {
122+
buttonLabel: props.options.payOptions.buttonLabel,
123+
})}
115124
/>
116125
);
117126
}

apps/playground-web/src/app/payments/embed/page.tsx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ const defaultConnectOptions: BridgeComponentsPlaygroundOptions = {
1313
buyTokenChain: arbitrum,
1414
description: "",
1515
image: "",
16+
buttonLabel: "",
1617
paymentMethods: ["crypto", "card"],
1718
sellerAddress: "0x0000000000000000000000000000000000000000",
1819
title: "",

packages/thirdweb/src/react/web/ui/Bridge/BridgeOrchestrator.tsx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@ export type UIOptions = Prettify<
4242
image?: string;
4343
};
4444
currency?: SupportedFiatCurrency;
45+
buttonLabel?: string;
4546
} & (
4647
| {
4748
mode: "fund_wallet";

packages/thirdweb/src/react/web/ui/Bridge/BuyWidget.tsx

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -180,6 +180,11 @@ export type BuyWidgetProps = {
180180
* @default "USD"
181181
*/
182182
currency?: SupportedFiatCurrency;
183+
184+
/**
185+
* Custom label for the main action button.
186+
*/
187+
buttonLabel?: string;
183188
};
184189

185190
// Enhanced UIOptions to handle unsupported token state
@@ -335,6 +340,7 @@ export function BuyWidget(props: BuyWidgetProps) {
335340
},
336341
mode: "fund_wallet",
337342
currency: props.currency || "USD",
343+
buttonLabel: props.buttonLabel,
338344
},
339345
type: "success",
340346
};
@@ -364,6 +370,8 @@ export function BuyWidget(props: BuyWidgetProps) {
364370
title: props.title,
365371
},
366372
mode: "fund_wallet",
373+
currency: props.currency || "USD",
374+
buttonLabel: props.buttonLabel,
367375
},
368376
type: "success",
369377
};

packages/thirdweb/src/react/web/ui/Bridge/CheckoutWidget.tsx

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -186,6 +186,11 @@ export type CheckoutWidgetProps = {
186186
* @default "USD"
187187
*/
188188
currency?: SupportedFiatCurrency;
189+
190+
/**
191+
* Custom label for the main action button.
192+
*/
193+
buttonLabel?: string;
189194
};
190195

191196
// Enhanced UIOptions to handle unsupported token state
@@ -310,6 +315,7 @@ export function CheckoutWidget(props: CheckoutWidgetProps) {
310315
},
311316
mode: "direct_payment",
312317
currency: props.currency || "USD",
318+
buttonLabel: props.buttonLabel,
313319
paymentInfo: {
314320
amount: props.amount,
315321
feePayer: props.feePayer === "seller" ? "receiver" : "sender",

packages/thirdweb/src/react/web/ui/Bridge/DirectPayment.tsx

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,11 @@ export function DirectPayment({
6464
);
6565
};
6666

67-
const buyNow = (
67+
const buyNow = uiOptions.buttonLabel ? (
68+
<Text color="primaryButtonText" size="md">
69+
{uiOptions.buttonLabel}
70+
</Text>
71+
) : (
6872
<Container flex="row" gap="3xs">
6973
<Text color="primaryButtonText" size="md">
7074
Buy Now ·

0 commit comments

Comments
 (0)