Skip to content

Commit 7f11657

Browse files
committed
SDK: Fix PayEmbed not rendering anything when mode prop is not set (#7858)
<!-- ## title your PR with this format: "[SDK/Dashboard/Portal] Feature/Fix: Concise title for the changes" If you did not copy the branch name from Linear, paste the issue tag here (format is TEAM-0000): ## Notes for the reviewer Anything important to call out? Be sure to also clarify these in your comments. ## How to test Unit tests, playground, etc. --> <!-- start pr-codex --> --- ## PR-Codex overview This PR focuses on updating the `PayEmbed` component to default to a mode of "fund_wallet" with an amount of "0.01" and chain set to `ethereum` when no mode is specified. It also includes new story examples for the `PayEmbed` component. ### Detailed summary - Deleted `PayEmbed.stories.ts` and test files. - Updated `PayEmbed` component to default `mode` to "fund_wallet" and `amount` to "0.01". - Added handling for `chain` defaulting to `ethereum`. - Created multiple story functions for various use cases of `PayEmbed`. - Included stories for different payment modes and configurations. > ✨ Ask PR-Codex anything about this PR by commenting with `/codex {your question}` <!-- end pr-codex --> <!-- This is an auto-generated comment: release notes by coderabbit.ai --> ## Summary by CodeRabbit * **Bug Fixes** * PayEmbed now defaults to a wallet-funding flow when mode is missing (amount 0.01; Ethereum chain) and tolerates partial prefill data. * **Enhancements** * Buy flow renders more flexibly when mode is omitted or set to fund_wallet. * **Documentation** * Storybook updated/reorganized with comprehensive PayEmbed examples: fund wallet, direct payments, transactions, ERC20, metadata, and theme variants. * **Chores** * Added a changeset for a patch release. <!-- end of auto-generated comment: release notes by coderabbit.ai -->
1 parent d227bc3 commit 7f11657

File tree

6 files changed

+227
-101
lines changed

6 files changed

+227
-101
lines changed

.changeset/cold-pigs-dress.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+
Fix PayEmbed UI when mode prop is not specified - Default to mode: "fund_wallet" with amount: "0.01" and chain: ethereum

packages/thirdweb/src/react/web/ui/PayEmbed-disconnected.test.tsx

Lines changed: 0 additions & 17 deletions
This file was deleted.

packages/thirdweb/src/react/web/ui/PayEmbed.test.tsx

Lines changed: 0 additions & 35 deletions
This file was deleted.

packages/thirdweb/src/react/web/ui/PayEmbed.tsx

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
"use client";
22

33
import { useEffect } from "react";
4+
import { ethereum } from "../../../chains/chain-definitions/ethereum.js";
45
import type { Chain } from "../../../chains/types.js";
56
import type { ThirdwebClient } from "../../../client/client.js";
67
import type { Address } from "../../../utils/address.js";
@@ -328,14 +329,11 @@ export function PayEmbed(props: PayEmbedProps) {
328329
? props.payOptions.metadata
329330
: null;
330331

331-
if (
332-
props.payOptions?.mode === "fund_wallet" &&
333-
props.payOptions?.prefillBuy
334-
) {
332+
if (!props.payOptions?.mode || props.payOptions?.mode === "fund_wallet") {
335333
return (
336334
<BuyWidget
337-
amount={props.payOptions.prefillBuy.amount || "0.01"}
338-
chain={props.payOptions.prefillBuy.chain}
335+
amount={props.payOptions?.prefillBuy?.amount || "0.01"}
336+
chain={props.payOptions?.prefillBuy?.chain || ethereum}
339337
client={props.client}
340338
onSuccess={() => props.payOptions?.onPurchaseSuccess?.()}
341339
paymentMethods={
@@ -349,7 +347,7 @@ export function PayEmbed(props: PayEmbedProps) {
349347
theme={theme}
350348
title={metadata?.name || "Buy"}
351349
tokenAddress={
352-
props.payOptions.prefillBuy.token?.address as Address | undefined
350+
props.payOptions?.prefillBuy?.token?.address as Address | undefined
353351
}
354352
/>
355353
);

packages/thirdweb/src/stories/PayEmbed.stories.ts

Lines changed: 0 additions & 42 deletions
This file was deleted.
Lines changed: 217 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,217 @@
1+
import type { Meta } from "@storybook/react-vite";
2+
import { base } from "../chains/chain-definitions/base.js";
3+
import { polygon } from "../chains/chain-definitions/polygon.js";
4+
import { lightTheme } from "../react/core/design-system/index.js";
5+
import { PayEmbed } from "../react/web/ui/PayEmbed.js";
6+
import { prepareTransaction } from "../transaction/prepare-transaction.js";
7+
import { toWei } from "../utils/units.js";
8+
import { storyClient } from "./utils.js";
9+
10+
const meta = {
11+
parameters: {
12+
layout: "centered",
13+
},
14+
tags: ["autodocs"],
15+
title: "Connect/PayEmbed",
16+
} satisfies Meta<typeof PayEmbed>;
17+
18+
export function BasicUsage() {
19+
return <PayEmbed client={storyClient} />;
20+
}
21+
22+
export function BasicUsageWithMetadata() {
23+
return (
24+
<PayEmbed
25+
client={storyClient}
26+
payOptions={{
27+
metadata: {
28+
name: "this is a title",
29+
// This is not shown in UI - TODO fix this
30+
description: "this is a description",
31+
},
32+
}}
33+
/>
34+
);
35+
}
36+
37+
export function FundWallet() {
38+
return (
39+
<PayEmbed
40+
client={storyClient}
41+
payOptions={{
42+
mode: "fund_wallet",
43+
}}
44+
/>
45+
);
46+
}
47+
48+
export function FundWalletWithMetadata() {
49+
return (
50+
<PayEmbed
51+
client={storyClient}
52+
payOptions={{
53+
mode: "fund_wallet",
54+
metadata: {
55+
name: "this is a title",
56+
// This is not shown in UI - TODO fix this
57+
description: "this is a description",
58+
},
59+
}}
60+
/>
61+
);
62+
}
63+
64+
export function FundWalletWithOptions() {
65+
return (
66+
<PayEmbed
67+
client={storyClient}
68+
payOptions={{
69+
mode: "fund_wallet",
70+
prefillBuy: {
71+
amount: "0.123",
72+
chain: polygon,
73+
},
74+
}}
75+
/>
76+
);
77+
}
78+
79+
export function FundWalletERC20() {
80+
return (
81+
<PayEmbed
82+
client={storyClient}
83+
payOptions={{
84+
mode: "fund_wallet",
85+
prefillBuy: {
86+
amount: "0.123",
87+
chain: base,
88+
token: {
89+
address: "0x833589fcd6edb6e08f4c7c32d4f71b54bda02913",
90+
name: "USDC",
91+
// This icon is not being used - TODO fix this, either remove this prop or use it
92+
icon: "https://picsum.photos/200/200",
93+
},
94+
},
95+
}}
96+
/>
97+
);
98+
}
99+
100+
export function DirectPayment() {
101+
return (
102+
<PayEmbed
103+
client={storyClient}
104+
payOptions={{
105+
mode: "direct_payment",
106+
paymentInfo: {
107+
amount: "0.123",
108+
chain: polygon,
109+
sellerAddress: "0x83Dd93fA5D8343094f850f90B3fb90088C1bB425",
110+
},
111+
}}
112+
/>
113+
);
114+
}
115+
116+
export function DirectPaymentERC20() {
117+
return (
118+
<PayEmbed
119+
client={storyClient}
120+
payOptions={{
121+
mode: "direct_payment",
122+
paymentInfo: {
123+
amount: "0.123",
124+
chain: base,
125+
sellerAddress: "0x83Dd93fA5D8343094f850f90B3fb90088C1bB425",
126+
token: {
127+
address: "0x833589fcd6edb6e08f4c7c32d4f71b54bda02913",
128+
name: "USDC",
129+
// This icon is not being used - TODO fix this, either remove this prop or use it
130+
icon: "https://coin-images.coingecko.com/coins/images/6319/large/usdc.png",
131+
},
132+
},
133+
}}
134+
/>
135+
);
136+
}
137+
138+
export function DirectPaymentWithMetadata() {
139+
return (
140+
<PayEmbed
141+
client={storyClient}
142+
payOptions={{
143+
mode: "direct_payment",
144+
paymentInfo: {
145+
amount: "0.123",
146+
chain: polygon,
147+
sellerAddress: "0x83Dd93fA5D8343094f850f90B3fb90088C1bB425",
148+
},
149+
metadata: {
150+
name: "this is a title",
151+
description: "this is a description",
152+
},
153+
}}
154+
/>
155+
);
156+
}
157+
158+
export function Transaction() {
159+
return (
160+
<PayEmbed
161+
client={storyClient}
162+
payOptions={{
163+
mode: "transaction",
164+
transaction: prepareTransaction({
165+
to: "0x83Dd93fA5D8343094f850f90B3fb90088C1bB425",
166+
chain: polygon,
167+
client: storyClient,
168+
value: toWei("0.123"),
169+
}),
170+
}}
171+
/>
172+
);
173+
}
174+
175+
export function TransactionWithMetadata() {
176+
return (
177+
<PayEmbed
178+
client={storyClient}
179+
payOptions={{
180+
metadata: {
181+
name: "this is a title",
182+
description: "this is a description",
183+
},
184+
mode: "transaction",
185+
transaction: prepareTransaction({
186+
to: "0x83Dd93fA5D8343094f850f90B3fb90088C1bB425",
187+
chain: polygon,
188+
client: storyClient,
189+
value: toWei("0.123"),
190+
}),
191+
}}
192+
/>
193+
);
194+
}
195+
196+
export function LightMode() {
197+
return <PayEmbed client={storyClient} theme="light" />;
198+
}
199+
200+
export function CustomLightTheme() {
201+
return (
202+
<PayEmbed
203+
client={storyClient}
204+
theme={lightTheme({
205+
colors: {
206+
modalBg: "#FFFFF0",
207+
tertiaryBg: "#DBE4C9",
208+
borderColor: "#8AA624",
209+
secondaryText: "#3E3F29",
210+
accentText: "#E43636",
211+
},
212+
})}
213+
/>
214+
);
215+
}
216+
217+
export default meta;

0 commit comments

Comments
 (0)