Skip to content

Commit 66fd195

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

File tree

5 files changed

+31
-12
lines changed

5 files changed

+31
-12
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: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -71,14 +71,10 @@ export function RightSection(props: {
7171
amount={props.options.payOptions.buyTokenAmount}
7272
chain={props.options.payOptions.buyTokenChain}
7373
client={THIRDWEB_CLIENT}
74-
name={props.options.payOptions.title}
74+
name={props.options.payOptions.title || "Your Product Name"}
75+
description={props.options.payOptions.description || "Your Product Description"}
76+
image={props.options.payOptions.image || getDefaultImage(props.options.theme.type)}
7577
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-
}}
8278
seller={props.options.payOptions.sellerAddress}
8379
theme={themeObj}
8480
tokenAddress={props.options.payOptions.buyTokenAddress}
@@ -181,3 +177,10 @@ function TabButtons(props: {
181177
</div>
182178
);
183179
}
180+
181+
182+
function getDefaultImage(theme: "dark" | "light") {
183+
return theme === "dark"
184+
? "https://placehold.co/600x400/1d1d23/7c7a85?text=Your%20Product%20Here&font=roboto"
185+
: "https://placehold.co/600x400/f2eff3/6f6d78?text=Your%20Product%20Here&font=roboto";
186+
}

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

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

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

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -27,10 +27,10 @@ export function WithHeader({
2727
style={{
2828
aspectRatio: "16/9",
2929
backgroundColor: theme.colors.tertiaryBg,
30-
backgroundImage: `url(${resolveScheme({
30+
backgroundImage: `url(${getUrl(
3131
client,
32-
uri: uiOptions.metadata.image,
33-
})})`,
32+
uiOptions.metadata.image,
33+
)})`,
3434
backgroundPosition: "center",
3535
backgroundSize: "cover",
3636
borderRadius: `${radius.md} ${radius.md} 0 0`,
@@ -63,3 +63,13 @@ export function WithHeader({
6363
</Container>
6464
);
6565
}
66+
67+
function getUrl(client: ThirdwebClient, uri: string) {
68+
if (!uri.startsWith("ipfs://")) {
69+
return uri;
70+
}
71+
return resolveScheme({
72+
client,
73+
uri,
74+
});
75+
}

0 commit comments

Comments
 (0)