Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/fluffy-cows-swim.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"thirdweb": patch
---

Handle non urls for metadata images in payment widgets
Original file line number Diff line number Diff line change
Expand Up @@ -277,7 +277,7 @@ export function LeftSection(props: {
<div className="grid grid-cols-1 gap-6 md:grid-cols-2 md:gap-4">
{/* Modal title */}
<div className="flex flex-col gap-2">
<Label htmlFor={modalTitleId}>Title</Label>
<Label htmlFor={modalTitleId}>Name</Label>
<Input
className="bg-card"
id={modalTitleId}
Expand Down Expand Up @@ -318,7 +318,7 @@ export function LeftSection(props: {

{/* Modal description */}
<div className="flex flex-col gap-2">
<Label htmlFor={modalDescriptionId}>Image</Label>
<Label htmlFor={modalDescriptionId}>Description</Label>
<Input
className="bg-card"
id={modalDescriptionId}
Expand Down
23 changes: 16 additions & 7 deletions apps/playground-web/src/app/connect/pay/embed/RightSection.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,8 @@ export function RightSection(props: {
amount={props.options.payOptions.buyTokenAmount}
chain={props.options.payOptions.buyTokenChain}
client={THIRDWEB_CLIENT}
description={props.options.payOptions.description}
image={props.options.payOptions.image}
theme={themeObj}
title={props.options.payOptions.title}
tokenAddress={props.options.payOptions.buyTokenAddress}
Expand All @@ -71,14 +73,15 @@ export function RightSection(props: {
amount={props.options.payOptions.buyTokenAmount}
chain={props.options.payOptions.buyTokenChain}
client={THIRDWEB_CLIENT}
name={props.options.payOptions.title}
description={
props.options.payOptions.description || "Your Product Description"
}
image={
props.options.payOptions.image ||
getDefaultImage(props.options.theme.type)
}
name={props.options.payOptions.title || "Your Product Name"}
presetOptions={[1, 2, 3]}
purchaseData={{
description: "Size L | Ships worldwide.",
image:
"https://placehold.co/600x400/1d1d23/7c7a85?text=Your%20Product%20Here&font=roboto",
name: "Black Hoodie",
}}
seller={props.options.payOptions.sellerAddress}
theme={themeObj}
tokenAddress={props.options.payOptions.buyTokenAddress}
Expand Down Expand Up @@ -181,3 +184,9 @@ function TabButtons(props: {
</div>
);
}

function getDefaultImage(theme: "dark" | "light") {
return theme === "dark"
? "https://placehold.co/600x400/1d1d23/7c7a85?text=Your%20Product%20Here&font=roboto"
: "https://placehold.co/600x400/f2eff3/6f6d78?text=Your%20Product%20Here&font=roboto";
}
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ export function BuyMerchPreview() {
client={THIRDWEB_CLIENT}
description="Size L | Ships worldwide."
feePayer="seller"
image="/drip-hoodie.png"
name="Black Hoodie"
seller="0xEb0effdFB4dC5b3d5d3aC6ce29F3ED213E95d675"
theme="light"
Expand Down
17 changes: 17 additions & 0 deletions packages/thirdweb/src/react/web/ui/Bridge/BuyWidget.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,16 @@
*/
title?: string;

/**
* The description to display in the widget.
*/
description?: string;

/**
* The image to display in the widget.
*/
image?: string;

/**
* Preset fiat amounts to display in the UI. Defaults to [5, 10, 20].
*/
Expand Down Expand Up @@ -275,6 +285,11 @@
data: {
destinationToken: ETH,
initialAmount: props.amount,
metadata: {
description: props.description,
image: props.image,
title: props.title,
},

Check warning on line 292 in packages/thirdweb/src/react/web/ui/Bridge/BuyWidget.tsx

View check run for this annotation

Codecov / codecov/patch

packages/thirdweb/src/react/web/ui/Bridge/BuyWidget.tsx#L288-L292

Added lines #L288 - L292 were not covered by tests
mode: "fund_wallet",
},
type: "success",
Expand All @@ -300,6 +315,8 @@
destinationToken: token,
initialAmount: props.amount,
metadata: {
description: props.description,
image: props.image,

Check warning on line 319 in packages/thirdweb/src/react/web/ui/Bridge/BuyWidget.tsx

View check run for this annotation

Codecov / codecov/patch

packages/thirdweb/src/react/web/ui/Bridge/BuyWidget.tsx#L318-L319

Added lines #L318 - L319 were not covered by tests
title: props.title,
},
mode: "fund_wallet",
Expand Down
15 changes: 11 additions & 4 deletions packages/thirdweb/src/react/web/ui/Bridge/common/WithHeader.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -27,10 +27,7 @@
style={{
aspectRatio: "16/9",
backgroundColor: theme.colors.tertiaryBg,
backgroundImage: `url(${resolveScheme({
client,
uri: uiOptions.metadata.image,
})})`,
backgroundImage: `url(${getUrl(client, uiOptions.metadata.image)})`,

Check warning on line 30 in packages/thirdweb/src/react/web/ui/Bridge/common/WithHeader.tsx

View check run for this annotation

Codecov / codecov/patch

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

Added line #L30 was not covered by tests
backgroundPosition: "center",
backgroundSize: "cover",
borderRadius: `${radius.md} ${radius.md} 0 0`,
Expand Down Expand Up @@ -63,3 +60,13 @@
</Container>
);
}

function getUrl(client: ThirdwebClient, uri: string) {
if (!uri.startsWith("ipfs://")) {
return uri;
}
return resolveScheme({
client,
uri,
});
}

Check warning on line 72 in packages/thirdweb/src/react/web/ui/Bridge/common/WithHeader.tsx

View check run for this annotation

Codecov / codecov/patch

packages/thirdweb/src/react/web/ui/Bridge/common/WithHeader.tsx#L64-L72

Added lines #L64 - L72 were not covered by tests
Loading