Skip to content

Commit e814248

Browse files
committed
[TOOL-4898] Dashboard: Replace PayEmbed with BuyWidget in asset page, add tracking (#7459)
<!-- ## title your PR with this format: "[SDK/Dashboard/Portal] Feature/Fix: Concise title for the changes" If you did not copy the branch name from Linear, paste the issue tag here (format is TEAM-0000): ## Notes for the reviewer Anything important to call out? Be sure to also clarify these in your comments. ## How to test Unit tests, playground, etc. --> <!-- start pr-codex --> --- ## PR-Codex overview This PR focuses on updating the `PayEmbed` component to `BuyWidget` in the `BuyTokenEmbed` function, enhancing the functionality with error reporting and success tracking for asset purchases. ### Detailed summary - Replaced `PayEmbed` with `BuyWidget` in `BuyTokenEmbed`. - Added `amount`, `chain`, and `className` props to `BuyWidget`. - Implemented `onError` and `onSuccess` callbacks for analytics reporting. - Updated the token address prop to ensure correct type. - Modified chart className in `contract-analytics.tsx`. > ✨ Ask PR-Codex anything about this PR by commenting with `/codex {your question}` <!-- end pr-codex --> <!-- This is an auto-generated comment: release notes by coderabbit.ai --> ## Summary by CodeRabbit * **New Features** * Updated the buy token section to use an improved widget with enhanced error and success handling, including dynamic titles and analytics reporting. * **Style** * Adjusted the chart's aspect ratio for better display across different screen sizes. <!-- end of auto-generated comment: release notes by coderabbit.ai -->
1 parent d7a0613 commit e814248

File tree

3 files changed

+27
-27
lines changed

3 files changed

+27
-27
lines changed

apps/dashboard/src/app/(app)/(dashboard)/(chain)/[chain_id]/[contractAddress]/public-pages/erc20/_components/PayEmbedSection.tsx

Lines changed: 26 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -2,45 +2,47 @@
22

33
import { useTheme } from "next-themes";
44
import type { Chain, ThirdwebClient } from "thirdweb";
5-
import { PayEmbed } from "thirdweb/react";
6-
import { getSDKTheme } from "../../../../../../../../../@/utils/sdk-component-theme";
5+
import { BuyWidget } from "thirdweb/react";
6+
import {
7+
reportAssetBuyFailed,
8+
reportAssetBuySuccessful,
9+
} from "@/analytics/report";
10+
import { parseError } from "@/utils/errorParser";
11+
import { getSDKTheme } from "@/utils/sdk-component-theme";
712

813
export function BuyTokenEmbed(props: {
914
client: ThirdwebClient;
1015
chain: Chain;
11-
tokenSymbol: string;
12-
tokenName: string;
1316
tokenAddress: string;
1417
}) {
1518
const { theme } = useTheme();
1619
return (
17-
<PayEmbed
20+
<BuyWidget
21+
amount="1"
22+
chain={props.chain}
1823
className="!rounded-xl !w-full"
1924
client={props.client}
2025
connectOptions={{
2126
autoConnect: false,
2227
}}
23-
payOptions={{
24-
metadata: {
25-
name: `Buy ${props.tokenSymbol}`,
26-
},
27-
mode: "fund_wallet",
28-
prefillBuy: {
29-
allowEdits: {
30-
amount: true,
31-
chain: false,
32-
token: false,
33-
},
34-
amount: "1",
35-
chain: props.chain,
36-
token: {
37-
address: props.tokenAddress,
38-
name: props.tokenName,
39-
symbol: props.tokenSymbol,
40-
},
41-
},
28+
onError={(e) => {
29+
const errorMessage = parseError(e);
30+
reportAssetBuyFailed({
31+
assetType: "coin",
32+
chainId: props.chain.id,
33+
contractType: "DropERC20",
34+
error: errorMessage,
35+
});
36+
}}
37+
onSuccess={() => {
38+
reportAssetBuySuccessful({
39+
assetType: "coin",
40+
chainId: props.chain.id,
41+
contractType: "DropERC20",
42+
});
4243
}}
4344
theme={getSDKTheme(theme === "light" ? "light" : "dark")}
45+
tokenAddress={props.tokenAddress as `0x${string}`}
4446
/>
4547
);
4648
}

apps/dashboard/src/app/(app)/(dashboard)/(chain)/[chain_id]/[contractAddress]/public-pages/erc20/_components/contract-analytics/contract-analytics.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ export function ContractAnalyticsOverview(props: {
3939
</div>
4040
<ThirdwebAreaChart
4141
cardContentClassName="p-0"
42-
chartClassName="aspect-[1.5] lg:aspect-[3]"
42+
chartClassName="aspect-[1.2] lg:aspect-[2.6]"
4343
className="border-none bg-background p-0"
4444
config={{
4545
events: {

apps/dashboard/src/app/(app)/(dashboard)/(chain)/[chain_id]/[contractAddress]/public-pages/erc20/erc20.tsx

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -152,8 +152,6 @@ function BuyEmbed(props: {
152152
chain={props.clientContract.chain}
153153
client={props.clientContract.client}
154154
tokenAddress={props.clientContract.address}
155-
tokenName={props.tokenName}
156-
tokenSymbol={props.tokenSymbol}
157155
/>
158156
);
159157
}

0 commit comments

Comments
 (0)