Skip to content

Commit 3de47ce

Browse files
committed
feat: use new components in PayEmbed
1 parent 6177e11 commit 3de47ce

File tree

2 files changed

+62
-42
lines changed

2 files changed

+62
-42
lines changed

apps/dashboard/src/app/bridge/components/client/UniversalBridgeEmbed.tsx

Lines changed: 9 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,10 @@
11
"use client";
22

33
import { useTheme } from "next-themes";
4-
import { BuyWidget, PayEmbed, type TokenInfo } from "thirdweb/react";
4+
import { PayEmbed, type TokenInfo } from "thirdweb/react";
55
import { getSDKTheme } from "../../../(app)/components/sdk-component-theme";
66
import { useV5DashboardChain } from "../../../../lib/v5-adapter";
77
import { bridgeAppThirdwebClient } from "../../constants";
8-
import type { Address } from "thirdweb";
98

109
export function UniversalBridgeEmbed({
1110
chainId,
@@ -15,27 +14,19 @@ export function UniversalBridgeEmbed({
1514
const { theme } = useTheme();
1615
const chain = useV5DashboardChain(chainId || 1);
1716

18-
if (chainId && token) {
19-
return (
20-
<BuyWidget
21-
client={bridgeAppThirdwebClient}
22-
chain={chain}
23-
tokenAddress={token.address as Address}
24-
amount={amount ?? "1"}
25-
/>
26-
);
27-
}
28-
2917
return (
3018
<PayEmbed
3119
client={bridgeAppThirdwebClient}
3220
payOptions={{
3321
mode: "fund_wallet",
34-
prefillBuy: {
35-
chain,
36-
token,
37-
amount,
38-
},
22+
prefillBuy:
23+
chainId && token
24+
? {
25+
chain,
26+
token,
27+
amount,
28+
}
29+
: undefined,
3930
}}
4031
theme={getSDKTheme(theme === "light" ? "light" : "dark")}
4132
/>

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

Lines changed: 53 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -22,14 +22,16 @@ import { useActiveWallet } from "../../core/hooks/wallets/useActiveWallet.js";
2222
import { useConnectionManager } from "../../core/providers/connection-manager.js";
2323
import type { SupportedTokens } from "../../core/utils/defaultTokens.js";
2424
import { AutoConnect } from "../../web/ui/AutoConnect/AutoConnect.js";
25-
import { webWindowAdapter } from "../adapters/WindowAdapter.js";
2625
import { EmbedContainer } from "./ConnectWallet/Modal/ConnectEmbed.js";
2726
import { useConnectLocale } from "./ConnectWallet/locale/getConnectLocale.js";
2827
import BuyScreen from "./ConnectWallet/screens/Buy/BuyScreen.js";
29-
import { ExecutingTxScreen } from "./TransactionButton/ExecutingScreen.js";
3028
import { DynamicHeight } from "./components/DynamicHeight.js";
3129
import { Spinner } from "./components/Spinner.js";
3230
import type { LocaleId } from "./types.js";
31+
import { BuyWidget } from "./Bridge/BuyWidget.js";
32+
import type { Address } from "../../../utils/address.js";
33+
import { CheckoutWidget } from "./Bridge/CheckoutWidget.js";
34+
import { TransactionWidget } from "./Bridge/TransactionWidget.js";
3335

3436
/**
3537
* Props of [`PayEmbed`](https://portal.thirdweb.com/references/typescript/v5/PayEmbed) component
@@ -345,6 +347,55 @@ export function PayEmbed(props: PayEmbedProps) {
345347
? props.payOptions.metadata
346348
: null;
347349

350+
if (
351+
props.payOptions?.mode === "fund_wallet" &&
352+
props.payOptions?.prefillBuy
353+
) {
354+
return (
355+
<BuyWidget
356+
title={metadata?.name || "Buy"}
357+
chain={props.payOptions.prefillBuy.chain}
358+
amount={props.payOptions.prefillBuy.amount || "0.01"}
359+
tokenAddress={
360+
props.payOptions.prefillBuy.token?.address as Address | undefined
361+
}
362+
client={props.client}
363+
theme={theme}
364+
/>
365+
);
366+
}
367+
368+
if (props.payOptions?.mode === "direct_payment") {
369+
return (
370+
<CheckoutWidget
371+
name={metadata?.name || "Checkout"}
372+
description={metadata?.description}
373+
image={metadata?.image}
374+
chain={props.payOptions.paymentInfo.chain}
375+
tokenAddress={
376+
props.payOptions.paymentInfo.token?.address as Address | undefined
377+
}
378+
amount={(props.payOptions.paymentInfo as { amount: string }).amount}
379+
seller={props.payOptions.paymentInfo.sellerAddress as Address}
380+
client={props.client}
381+
theme={theme}
382+
/>
383+
);
384+
}
385+
386+
if (props.payOptions?.mode === "transaction") {
387+
return (
388+
<TransactionWidget
389+
title={metadata?.name}
390+
description={metadata?.description}
391+
image={metadata?.image}
392+
transaction={props.payOptions.transaction}
393+
client={props.client}
394+
theme={theme}
395+
/>
396+
);
397+
}
398+
348399
if (!localeQuery.data) {
349400
content = (
350401
<div
@@ -386,28 +437,6 @@ export function PayEmbed(props: PayEmbedProps) {
386437
onBack={undefined}
387438
/>
388439
)}
389-
390-
{screen === "execute-tx" &&
391-
props.payOptions?.mode === "transaction" &&
392-
props.payOptions.transaction && (
393-
<ExecutingTxScreen
394-
tx={props.payOptions.transaction}
395-
closeModal={() => {
396-
setScreen("buy");
397-
}}
398-
onBack={() => {
399-
setScreen("buy");
400-
}}
401-
onTxSent={(data) => {
402-
props.payOptions?.onPurchaseSuccess?.({
403-
type: "transaction",
404-
chainId: data.chain.id,
405-
transactionHash: data.transactionHash,
406-
});
407-
}}
408-
windowAdapter={webWindowAdapter}
409-
/>
410-
)}
411440
</>
412441
);
413442
}

0 commit comments

Comments
 (0)