diff --git a/.changeset/fluffy-cows-swim.md b/.changeset/fluffy-cows-swim.md new file mode 100644 index 00000000000..17bfdb30e58 --- /dev/null +++ b/.changeset/fluffy-cows-swim.md @@ -0,0 +1,5 @@ +--- +"thirdweb": patch +--- + +Handle non urls for metadata images in payment widgets diff --git a/apps/playground-web/src/app/connect/pay/embed/LeftSection.tsx b/apps/playground-web/src/app/connect/pay/embed/LeftSection.tsx index 8a268a2ced4..bce6ea14a98 100644 --- a/apps/playground-web/src/app/connect/pay/embed/LeftSection.tsx +++ b/apps/playground-web/src/app/connect/pay/embed/LeftSection.tsx @@ -277,7 +277,7 @@ export function LeftSection(props: {
{/* Modal title */}
- + - + ); } + +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"; +} diff --git a/apps/playground-web/src/components/pay/direct-payment.tsx b/apps/playground-web/src/components/pay/direct-payment.tsx index b6d7302fdd9..ae2968b56d2 100644 --- a/apps/playground-web/src/components/pay/direct-payment.tsx +++ b/apps/playground-web/src/components/pay/direct-payment.tsx @@ -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" diff --git a/packages/thirdweb/src/react/web/ui/Bridge/BuyWidget.tsx b/packages/thirdweb/src/react/web/ui/Bridge/BuyWidget.tsx index 87fa8629bc3..10b2b3e5c74 100644 --- a/packages/thirdweb/src/react/web/ui/Bridge/BuyWidget.tsx +++ b/packages/thirdweb/src/react/web/ui/Bridge/BuyWidget.tsx @@ -120,6 +120,16 @@ export type BuyWidgetProps = { */ 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]. */ @@ -275,6 +285,11 @@ export function BuyWidget(props: BuyWidgetProps) { data: { destinationToken: ETH, initialAmount: props.amount, + metadata: { + description: props.description, + image: props.image, + title: props.title, + }, mode: "fund_wallet", }, type: "success", @@ -300,6 +315,8 @@ export function BuyWidget(props: BuyWidgetProps) { destinationToken: token, initialAmount: props.amount, metadata: { + description: props.description, + image: props.image, title: props.title, }, mode: "fund_wallet", diff --git a/packages/thirdweb/src/react/web/ui/Bridge/common/WithHeader.tsx b/packages/thirdweb/src/react/web/ui/Bridge/common/WithHeader.tsx index 1d15290b8f4..85cb46fdd06 100644 --- a/packages/thirdweb/src/react/web/ui/Bridge/common/WithHeader.tsx +++ b/packages/thirdweb/src/react/web/ui/Bridge/common/WithHeader.tsx @@ -27,10 +27,7 @@ export function WithHeader({ style={{ aspectRatio: "16/9", backgroundColor: theme.colors.tertiaryBg, - backgroundImage: `url(${resolveScheme({ - client, - uri: uiOptions.metadata.image, - })})`, + backgroundImage: `url(${getUrl(client, uiOptions.metadata.image)})`, backgroundPosition: "center", backgroundSize: "cover", borderRadius: `${radius.md} ${radius.md} 0 0`, @@ -63,3 +60,13 @@ export function WithHeader({ ); } + +function getUrl(client: ThirdwebClient, uri: string) { + if (!uri.startsWith("ipfs://")) { + return uri; + } + return resolveScheme({ + client, + uri, + }); +}