Skip to content

Commit d0ce77d

Browse files
Handle non-URLs for metadata images in payment widgets
1 parent 897bdc7 commit d0ce77d

File tree

6 files changed

+52
-13
lines changed

6 files changed

+52
-13
lines changed

.changeset/fluffy-cows-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+
Handle non urls for metadata images in payment widgets

apps/playground-web/src/app/connect/pay/embed/LeftSection.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -277,7 +277,7 @@ export function LeftSection(props: {
277277
<div className="grid grid-cols-1 gap-6 md:grid-cols-2 md:gap-4">
278278
{/* Modal title */}
279279
<div className="flex flex-col gap-2">
280-
<Label htmlFor={modalTitleId}>Title</Label>
280+
<Label htmlFor={modalTitleId}>Name</Label>
281281
<Input
282282
className="bg-card"
283283
id={modalTitleId}
@@ -318,7 +318,7 @@ export function LeftSection(props: {
318318

319319
{/* Modal description */}
320320
<div className="flex flex-col gap-2">
321-
<Label htmlFor={modalDescriptionId}>Image</Label>
321+
<Label htmlFor={modalDescriptionId}>Description</Label>
322322
<Input
323323
className="bg-card"
324324
id={modalDescriptionId}

apps/playground-web/src/app/connect/pay/embed/RightSection.tsx

Lines changed: 16 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,8 @@ export function RightSection(props: {
5858
amount={props.options.payOptions.buyTokenAmount}
5959
chain={props.options.payOptions.buyTokenChain}
6060
client={THIRDWEB_CLIENT}
61+
description={props.options.payOptions.description}
62+
image={props.options.payOptions.image}
6163
theme={themeObj}
6264
title={props.options.payOptions.title}
6365
tokenAddress={props.options.payOptions.buyTokenAddress}
@@ -71,14 +73,15 @@ export function RightSection(props: {
7173
amount={props.options.payOptions.buyTokenAmount}
7274
chain={props.options.payOptions.buyTokenChain}
7375
client={THIRDWEB_CLIENT}
74-
name={props.options.payOptions.title}
76+
description={
77+
props.options.payOptions.description || "Your Product Description"
78+
}
79+
image={
80+
props.options.payOptions.image ||
81+
getDefaultImage(props.options.theme.type)
82+
}
83+
name={props.options.payOptions.title || "Your Product Name"}
7584
presetOptions={[1, 2, 3]}
76-
purchaseData={{
77-
description: "Size L | Ships worldwide.",
78-
image:
79-
"https://placehold.co/600x400/1d1d23/7c7a85?text=Your%20Product%20Here&font=roboto",
80-
name: "Black Hoodie",
81-
}}
8285
seller={props.options.payOptions.sellerAddress}
8386
theme={themeObj}
8487
tokenAddress={props.options.payOptions.buyTokenAddress}
@@ -181,3 +184,9 @@ function TabButtons(props: {
181184
</div>
182185
);
183186
}
187+
188+
function getDefaultImage(theme: "dark" | "light") {
189+
return theme === "dark"
190+
? "https://placehold.co/600x400/1d1d23/7c7a85?text=Your%20Product%20Here&font=roboto"
191+
: "https://placehold.co/600x400/f2eff3/6f6d78?text=Your%20Product%20Here&font=roboto";
192+
}

apps/playground-web/src/components/pay/direct-payment.tsx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ export function BuyMerchPreview() {
1212
client={THIRDWEB_CLIENT}
1313
description="Size L | Ships worldwide."
1414
feePayer="seller"
15+
image="/drip-hoodie.png"
1516
name="Black Hoodie"
1617
seller="0xEb0effdFB4dC5b3d5d3aC6ce29F3ED213E95d675"
1718
theme="light"

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

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -120,6 +120,16 @@ export type BuyWidgetProps = {
120120
*/
121121
title?: string;
122122

123+
/**
124+
* The description to display in the widget.
125+
*/
126+
description?: string;
127+
128+
/**
129+
* The image to display in the widget.
130+
*/
131+
image?: string;
132+
123133
/**
124134
* Preset fiat amounts to display in the UI. Defaults to [5, 10, 20].
125135
*/
@@ -275,6 +285,11 @@ export function BuyWidget(props: BuyWidgetProps) {
275285
data: {
276286
destinationToken: ETH,
277287
initialAmount: props.amount,
288+
metadata: {
289+
description: props.description,
290+
image: props.image,
291+
title: props.title,
292+
},
278293
mode: "fund_wallet",
279294
},
280295
type: "success",
@@ -300,6 +315,8 @@ export function BuyWidget(props: BuyWidgetProps) {
300315
destinationToken: token,
301316
initialAmount: props.amount,
302317
metadata: {
318+
description: props.description,
319+
image: props.image,
303320
title: props.title,
304321
},
305322
mode: "fund_wallet",

packages/thirdweb/src/react/web/ui/Bridge/common/WithHeader.tsx

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -27,10 +27,7 @@ export function WithHeader({
2727
style={{
2828
aspectRatio: "16/9",
2929
backgroundColor: theme.colors.tertiaryBg,
30-
backgroundImage: `url(${resolveScheme({
31-
client,
32-
uri: uiOptions.metadata.image,
33-
})})`,
30+
backgroundImage: `url(${getUrl(client, uiOptions.metadata.image)})`,
3431
backgroundPosition: "center",
3532
backgroundSize: "cover",
3633
borderRadius: `${radius.md} ${radius.md} 0 0`,
@@ -63,3 +60,13 @@ export function WithHeader({
6360
</Container>
6461
);
6562
}
63+
64+
function getUrl(client: ThirdwebClient, uri: string) {
65+
if (!uri.startsWith("ipfs://")) {
66+
return uri;
67+
}
68+
return resolveScheme({
69+
client,
70+
uri,
71+
});
72+
}

0 commit comments

Comments
 (0)