Skip to content

Commit 51f10c4

Browse files
add playground example
1 parent c516ec5 commit 51f10c4

File tree

2 files changed

+28
-2
lines changed

2 files changed

+28
-2
lines changed

apps/playground-web/src/components/pay/transaction-button.tsx

Lines changed: 24 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,8 @@
22

33
import { useTheme } from "next-themes";
44
import { getContract } from "thirdweb";
5-
import { base, polygon } from "thirdweb/chains";
5+
import { prepareTransaction } from "thirdweb";
6+
import { base, baseSepolia, polygon } from "thirdweb/chains";
67
import { transfer } from "thirdweb/extensions/erc20";
78
import { claimTo, getNFT } from "thirdweb/extensions/erc1155";
89
import {
@@ -12,6 +13,7 @@ import {
1213
useActiveAccount,
1314
useReadContract,
1415
} from "thirdweb/react";
16+
import { toWei } from "thirdweb/utils";
1517
import { THIRDWEB_CLIENT } from "../../lib/client";
1618
import { StyledConnectButton } from "../styled-connect-button";
1719

@@ -99,6 +101,27 @@ export function PayTransactionButtonPreview() {
99101
>
100102
Buy VIP Pass
101103
</TransactionButton>
104+
<div className="h-10" />
105+
<div className="flex items-center gap-2">Price: 0.1 ETH</div>
106+
<TransactionButton
107+
transaction={() => {
108+
if (!account) throw new Error("No active account");
109+
return prepareTransaction({
110+
chain: baseSepolia,
111+
client: THIRDWEB_CLIENT,
112+
to: account.address,
113+
value: toWei("0.1"),
114+
});
115+
}}
116+
onError={(e) => {
117+
console.error(e);
118+
}}
119+
payModal={{
120+
theme: theme === "light" ? "light" : "dark",
121+
}}
122+
>
123+
Send 0.1 ETH
124+
</TransactionButton>
102125
</div>
103126
)}
104127
</>

packages/thirdweb/src/react/web/ui/TransactionButton/TransactionModal.tsx

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,10 @@ export function TransactionModal(props: ModalProps) {
5252
toToken: props.tx.erc20Value
5353
? (await resolvePromisedValue(props.tx.erc20Value))?.tokenAddress
5454
: undefined,
55-
event: "open_pay_transaction_modal",
55+
event:
56+
props.modalMode === "buy"
57+
? "open_pay_transaction_modal"
58+
: "open_pay_deposit_modal",
5659
});
5760

5861
return null;

0 commit comments

Comments
 (0)