Skip to content

Commit 9c420c0

Browse files
authored
[SDK] Feature: Update PayEmbed to use new widgets (#7394)
1 parent ffea73c commit 9c420c0

File tree

5 files changed

+76
-32
lines changed

5 files changed

+76
-32
lines changed

.changeset/wide-books-ring.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"thirdweb": minor
3+
---
4+
5+
Updated PayEmbed UI

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

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ export function UniversalBridgeEmbed({
1010
chainId,
1111
token,
1212
amount,
13-
}: { chainId?: number; token: TokenInfo | undefined; amount: string }) {
13+
}: { chainId?: number; token: TokenInfo | undefined; amount?: string }) {
1414
const { theme } = useTheme();
1515
const chain = useV5DashboardChain(chainId || 1);
1616

@@ -19,11 +19,14 @@ export function UniversalBridgeEmbed({
1919
client={bridgeAppThirdwebClient}
2020
payOptions={{
2121
mode: "fund_wallet",
22-
prefillBuy: {
23-
chain,
24-
token,
25-
amount,
26-
},
22+
prefillBuy:
23+
chainId && token
24+
? {
25+
chain,
26+
token,
27+
amount,
28+
}
29+
: undefined,
2730
}}
2831
theme={getSDKTheme(theme === "light" ? "light" : "dark")}
2932
/>

apps/dashboard/src/app/bridge/page.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ export default async function BridgePage({
6060
}
6161
: undefined
6262
}
63-
amount={(amount || "0.01") as string}
63+
amount={amount as string}
6464
/>
6565
</main>
6666

apps/playground-web/src/app/connect/sign-in/button/RightSection.tsx

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import { useEffect, useState } from "react";
55
import {
66
arbitrumSepolia,
77
baseSepolia,
8+
defineChain,
89
optimismSepolia,
910
sepolia,
1011
} from "thirdweb/chains";
@@ -119,7 +120,13 @@ export function RightSection(props: {
119120
showThirdwebBranding: connectOptions.ShowThirdwebBranding,
120121
requireApproval: connectOptions.requireApproval,
121122
}}
122-
chains={[sepolia, baseSepolia, optimismSepolia, arbitrumSepolia]}
123+
chains={[
124+
defineChain(578),
125+
sepolia,
126+
baseSepolia,
127+
optimismSepolia,
128+
arbitrumSepolia,
129+
]}
123130
wallets={wallets}
124131
auth={connectOptions.enableAuth ? playgroundAuth : undefined}
125132
accountAbstraction={

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

Lines changed: 53 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
import { useEffect, useState } from "react";
44
import type { Chain } from "../../../chains/types.js";
55
import type { ThirdwebClient } from "../../../client/client.js";
6+
import type { Address } from "../../../utils/address.js";
67
import type { Wallet } from "../../../wallets/interfaces/wallet.js";
78
import type { SmartWalletOptions } from "../../../wallets/smart/types.js";
89
import type { AppMetadata } from "../../../wallets/types.js";
@@ -22,11 +23,12 @@ import { useActiveWallet } from "../../core/hooks/wallets/useActiveWallet.js";
2223
import { useConnectionManager } from "../../core/providers/connection-manager.js";
2324
import type { SupportedTokens } from "../../core/utils/defaultTokens.js";
2425
import { AutoConnect } from "../../web/ui/AutoConnect/AutoConnect.js";
25-
import { webWindowAdapter } from "../adapters/WindowAdapter.js";
26+
import { BuyWidget } from "./Bridge/BuyWidget.js";
27+
import { CheckoutWidget } from "./Bridge/CheckoutWidget.js";
28+
import { TransactionWidget } from "./Bridge/TransactionWidget.js";
2629
import { EmbedContainer } from "./ConnectWallet/Modal/ConnectEmbed.js";
2730
import { useConnectLocale } from "./ConnectWallet/locale/getConnectLocale.js";
2831
import BuyScreen from "./ConnectWallet/screens/Buy/BuyScreen.js";
29-
import { ExecutingTxScreen } from "./TransactionButton/ExecutingScreen.js";
3032
import { DynamicHeight } from "./components/DynamicHeight.js";
3133
import { Spinner } from "./components/Spinner.js";
3234
import type { LocaleId } from "./types.js";
@@ -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)