Skip to content

Commit b386d39

Browse files
committed
feat: adds BuyEmbed
1 parent 76c0e00 commit b386d39

File tree

8 files changed

+700
-211
lines changed

8 files changed

+700
-211
lines changed

apps/playground-web/src/app/connect/pay/fund-wallet/page.tsx

Lines changed: 13 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import { PageLayout } from "@/components/blocks/APIHeader";
22
import { CodeExample } from "@/components/code/code-example";
3-
import { StyledPayEmbedPreview } from "@/components/pay/embed";
43
import ThirdwebProvider from "@/components/thirdweb-provider";
4+
import { StyledBuyWidgetPreview } from "@/components/universal-bridge/buy";
55
import { metadataBase } from "@/lib/constants";
66
import type { Metadata } from "next";
77

@@ -25,17 +25,17 @@ export default function Page() {
2525
}
2626
docsLink="https://portal.thirdweb.com/connect/pay/get-started?utm_source=playground"
2727
>
28-
<StyledPayEmbed />
28+
<StyledPayWidget />
2929
</PageLayout>
3030
</ThirdwebProvider>
3131
);
3232
}
3333

34-
function StyledPayEmbed() {
34+
function StyledPayWidget() {
3535
return (
3636
<CodeExample
3737
header={{
38-
title: " Buy Crypto",
38+
title: "Buy Crypto",
3939
description: (
4040
<>
4141
Inline component that allows users to buy any currency.
@@ -44,26 +44,19 @@ function StyledPayEmbed() {
4444
</>
4545
),
4646
}}
47-
preview={<StyledPayEmbedPreview />}
47+
preview={<StyledBuyWidgetPreview />}
4848
code={`\
49-
import { PayEmbed } from "thirdweb/react";
49+
import { BuyWidget } from "thirdweb/react";
5050
5151
function App() {
5252
return (
53-
<PayEmbed
54-
client={client}
55-
payOptions={{
56-
mode: "fund_wallet",
57-
metadata: {
58-
name: "Get funds",
59-
},
60-
prefillBuy: {
61-
chain: base,
62-
amount: "0.01",
63-
},
64-
// ... theme, currency, amounts, payment methods, etc.
65-
}}
66-
/>
53+
<BuyWidget
54+
client={THIRDWEB_CLIENT}
55+
title="Get Funds"
56+
tokenAddress={NATIVE_TOKEN_ADDRESS}
57+
chain={arbitrum}
58+
amount={toWei("0.002")}
59+
/>
6760
);
6861
}`}
6962
lang="tsx"
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
"use client";
2+
3+
import { THIRDWEB_CLIENT } from "@/lib/client";
4+
import { useTheme } from "next-themes";
5+
import { NATIVE_TOKEN_ADDRESS, toWei } from "thirdweb";
6+
import { arbitrum } from "thirdweb/chains";
7+
import { BuyWidget } from "thirdweb/react";
8+
9+
export function StyledBuyWidgetPreview() {
10+
const { theme } = useTheme();
11+
12+
return (
13+
<div className="flex flex-col items-center justify-center">
14+
<div className="h-10" />
15+
<BuyWidget
16+
client={THIRDWEB_CLIENT}
17+
theme={theme === "light" ? "light" : "dark"}
18+
title="Get Funds"
19+
tokenAddress={NATIVE_TOKEN_ADDRESS}
20+
chain={arbitrum}
21+
amount={toWei("0.002")}
22+
/>
23+
</div>
24+
);
25+
}

packages/thirdweb/src/exports/react.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -130,6 +130,10 @@ export type { AutoConnectProps } from "../wallets/connection/types.js";
130130
// auth
131131
export type { SiweAuthOptions } from "../react/core/hooks/auth/useSiweAuth.js";
132132

133+
export {
134+
BuyWidget,
135+
type BuyWidgetProps,
136+
} from "../react/web/ui/Bridge/BuyWidget.js";
133137
export {
134138
PayEmbed,
135139
type PayEmbedProps,

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

Lines changed: 22 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -40,20 +40,20 @@ export type UIOptions = Prettify<
4040
};
4141
} & (
4242
| {
43-
mode: "fund_wallet";
44-
destinationToken: Token;
45-
initialAmount?: string;
46-
presetOptions?: [number, number, number];
47-
}
43+
mode: "fund_wallet";
44+
destinationToken: Token;
45+
initialAmount?: string;
46+
presetOptions?: [number, number, number];
47+
}
4848
| {
49-
mode: "direct_payment";
50-
paymentInfo: {
51-
sellerAddress: Address;
52-
token: Token;
53-
amount: string;
54-
feePayer?: "sender" | "receiver";
55-
};
56-
}
49+
mode: "direct_payment";
50+
paymentInfo: {
51+
sellerAddress: Address;
52+
token: Token;
53+
amount: string;
54+
feePayer?: "sender" | "receiver";
55+
};
56+
}
5757
| { mode: "transaction"; transaction: PreparedTransaction }
5858
)
5959
>;
@@ -67,7 +67,7 @@ export interface BridgeOrchestratorProps {
6767
/**
6868
* The receiver address, defaults to the connected wallet address
6969
*/
70-
receiverAddress?: Address;
70+
receiverAddress: Address | undefined;
7171

7272
/**
7373
* ThirdwebClient for blockchain interactions
@@ -77,42 +77,42 @@ export interface BridgeOrchestratorProps {
7777
/**
7878
* Called when the flow is completed successfully
7979
*/
80-
onComplete?: () => void;
80+
onComplete: () => void;
8181

8282
/**
8383
* Called when the flow encounters an error
8484
*/
85-
onError?: (error: Error) => void;
85+
onError: (error: Error) => void;
8686

8787
/**
8888
* Called when the user cancels the flow
8989
*/
90-
onCancel?: () => void;
90+
onCancel: () => void;
9191

9292
/**
9393
* Connect options for wallet connection
9494
*/
95-
connectOptions?: PayEmbedConnectOptions;
95+
connectOptions: PayEmbedConnectOptions | undefined;
9696

9797
/**
9898
* Locale for connect UI
9999
*/
100-
connectLocale?: ConnectLocale;
100+
connectLocale: ConnectLocale | undefined;
101101

102102
/**
103103
* Optional purchase data for the payment
104104
*/
105-
purchaseData?: object;
105+
purchaseData: object | undefined;
106106

107107
/**
108108
* Optional payment link ID for the payment
109109
*/
110-
paymentLinkId?: string;
110+
paymentLinkId: string | undefined;
111111

112112
/**
113113
* Quick buy amounts
114114
*/
115-
presetOptions?: [number, number, number];
115+
presetOptions: [number, number, number] | undefined;
116116
}
117117

118118
export function BridgeOrchestrator({

0 commit comments

Comments
 (0)