Skip to content

Commit 6776d08

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

File tree

5 files changed

+34
-13
lines changed

5 files changed

+34
-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: 15 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,7 @@ 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}
6162
theme={themeObj}
6263
title={props.options.payOptions.title}
6364
tokenAddress={props.options.payOptions.buyTokenAddress}
@@ -71,14 +72,15 @@ export function RightSection(props: {
7172
amount={props.options.payOptions.buyTokenAmount}
7273
chain={props.options.payOptions.buyTokenChain}
7374
client={THIRDWEB_CLIENT}
74-
name={props.options.payOptions.title}
75+
description={
76+
props.options.payOptions.description || "Your Product Description"
77+
}
78+
image={
79+
props.options.payOptions.image ||
80+
getDefaultImage(props.options.theme.type)
81+
}
82+
name={props.options.payOptions.title || "Your Product Name"}
7583
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-
}}
8284
seller={props.options.payOptions.sellerAddress}
8385
theme={themeObj}
8486
tokenAddress={props.options.payOptions.buyTokenAddress}
@@ -181,3 +183,9 @@ function TabButtons(props: {
181183
</div>
182184
);
183185
}
186+
187+
function getDefaultImage(theme: "dark" | "light") {
188+
return theme === "dark"
189+
? "https://placehold.co/600x400/1d1d23/7c7a85?text=Your%20Product%20Here&font=roboto"
190+
: "https://placehold.co/600x400/f2eff3/6f6d78?text=Your%20Product%20Here&font=roboto";
191+
}

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/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)