Skip to content

Commit 2221dcf

Browse files
committed
feat: enable passing quickOptions
1 parent 224e2af commit 2221dcf

File tree

5 files changed

+50
-36
lines changed

5 files changed

+50
-36
lines changed

packages/thirdweb/src/react/core/hooks/connection/ConnectButtonProps.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -165,6 +165,7 @@ export type FundWalletOptions = {
165165
token: boolean;
166166
chain: boolean;
167167
};
168+
quickOptions?: [number, number, number];
168169
};
169170
};
170171

packages/thirdweb/src/react/web/ui/Bridge/BridgeOrchestrator.tsx

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ export type UIOptions =
3131
mode: "fund_wallet";
3232
destinationToken: Token;
3333
initialAmount?: string;
34+
quickOptions?: [number, number, number];
3435
}
3536
| {
3637
mode: "direct_payment";
@@ -98,6 +99,11 @@ export interface BridgeOrchestratorProps {
9899
* Optional payment link ID for the payment
99100
*/
100101
paymentLinkId?: string;
102+
103+
/**
104+
* Quick buy amounts
105+
*/
106+
quickOptions?: [number, number, number];
101107
}
102108

103109
export function BridgeOrchestrator({
@@ -111,6 +117,7 @@ export function BridgeOrchestrator({
111117
connectLocale,
112118
purchaseData,
113119
paymentLinkId,
120+
quickOptions,
114121
}: BridgeOrchestratorProps) {
115122
// Initialize adapters
116123
const adapters = useMemo(
@@ -206,6 +213,7 @@ export function BridgeOrchestrator({
206213
client={client}
207214
onContinue={handleRequirementsResolved}
208215
connectOptions={connectOptions}
216+
quickOptions={quickOptions ?? [5, 10, 20]}
209217
/>
210218
)}
211219

packages/thirdweb/src/react/web/ui/Bridge/FundWallet.tsx

Lines changed: 21 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,11 @@ export interface FundWalletProps {
4949
*/
5050
onContinue: (amount: string, token: Token, receiverAddress: Address) => void;
5151

52+
/**
53+
* Quick buy amounts
54+
*/
55+
quickOptions?: [number, number, number];
56+
5257
/**
5358
* Connect options for wallet connection
5459
*/
@@ -61,6 +66,7 @@ export function FundWallet({
6166
receiverAddress,
6267
initialAmount = "",
6368
onContinue,
69+
quickOptions,
6470
connectOptions,
6571
}: FundWalletProps) {
6672
const [amount, setAmount] = useState(initialAmount);
@@ -232,42 +238,21 @@ export function FundWallet({
232238
justifyContent: "space-evenly",
233239
}}
234240
>
235-
<Button
236-
variant="outline"
237-
onClick={() => handleQuickAmount(5)}
238-
style={{
239-
padding: `${spacing.sm} ${spacing.md}`,
240-
fontSize: fontSize.sm,
241-
flex: 1,
242-
backgroundColor: theme.colors.tertiaryBg,
243-
}}
244-
>
245-
$5
246-
</Button>
247-
<Button
248-
variant="outline"
249-
onClick={() => handleQuickAmount(10)}
250-
style={{
251-
padding: `${spacing.sm} ${spacing.md}`,
252-
fontSize: fontSize.sm,
253-
flex: 1,
254-
backgroundColor: theme.colors.tertiaryBg,
255-
}}
256-
>
257-
$10
258-
</Button>
259-
<Button
260-
variant="outline"
261-
onClick={() => handleQuickAmount(20)}
262-
style={{
263-
padding: `${spacing.sm} ${spacing.md}`,
264-
fontSize: fontSize.sm,
265-
flex: 1,
266-
backgroundColor: theme.colors.tertiaryBg,
267-
}}
268-
>
269-
$20
270-
</Button>
241+
{quickOptions?.map((amount) => (
242+
<Button
243+
variant="outline"
244+
onClick={() => handleQuickAmount(Number(amount))}
245+
key={amount}
246+
style={{
247+
padding: `${spacing.sm} ${spacing.md}`,
248+
fontSize: fontSize.sm,
249+
flex: 1,
250+
backgroundColor: theme.colors.tertiaryBg,
251+
}}
252+
>
253+
${amount}
254+
</Button>
255+
))}
271256
</Container>
272257

273258
<Spacer y="md" />

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

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ import type { Theme } from "../../core/design-system/index.js";
1717
import type { SiweAuthOptions } from "../../core/hooks/auth/useSiweAuth.js";
1818
import type {
1919
ConnectButton_connectModalOptions,
20+
FundWalletOptions,
2021
PayUIOptions,
2122
} from "../../core/hooks/connection/ConnectButtonProps.js";
2223
import type { SupportedTokens } from "../../core/utils/defaultTokens.js";
@@ -467,6 +468,9 @@ export function PayEmbed(props: PayEmbedProps) {
467468
connectLocale={localeQuery.data}
468469
purchaseData={props.payOptions?.purchaseData}
469470
paymentLinkId={props.paymentLinkId}
471+
quickOptions={
472+
(props.payOptions as FundWalletOptions)?.prefillBuy?.quickOptions
473+
}
470474
/>
471475
);
472476
}

packages/thirdweb/src/stories/Bridge/BridgeOrchestrator.stories.tsx

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,10 @@ const meta = {
7272
options: ["light", "dark"],
7373
description: "Theme for the component",
7474
},
75+
quickOptions: {
76+
control: "object",
77+
description: "Quick buy options",
78+
},
7579
onComplete: { action: "flow completed" },
7680
onError: { action: "error occurred" },
7781
onCancel: { action: "flow cancelled" },
@@ -224,3 +228,15 @@ export const TransactionLight: Story = {
224228
},
225229
},
226230
};
231+
232+
export const CustomQuickOptions: Story = {
233+
args: {
234+
theme: "dark",
235+
uiOptions: {
236+
mode: "fund_wallet",
237+
destinationToken: ETH,
238+
initialAmount: "1",
239+
},
240+
quickOptions: [1, 2, 3],
241+
},
242+
};

0 commit comments

Comments
 (0)