Skip to content

Commit f0c4fc8

Browse files
committed
cleanup
1 parent 1405e11 commit f0c4fc8

File tree

3 files changed

+54
-41
lines changed

3 files changed

+54
-41
lines changed

apps/dashboard/src/@/analytics/report.ts

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -320,6 +320,26 @@ export function reportAssetBuyFailed(properties: {
320320
});
321321
}
322322

323+
/**
324+
* ### Why do we need to report this event?
325+
* - To track number of cancelled asset purchases from the token page
326+
* - To track the errors that users encounter when trying to purchase an asset
327+
*
328+
* ### Who is responsible for this event?
329+
* @MananTank
330+
*/
331+
export function reportAssetBuyCancelled(properties: {
332+
chainId: number;
333+
contractType: AssetContractType;
334+
assetType: "nft" | "coin";
335+
}) {
336+
posthog.capture("asset buy cancelled", {
337+
assetType: properties.assetType,
338+
chainId: properties.chainId,
339+
contractType: properties.contractType,
340+
});
341+
}
342+
323343
// Assets Landing Page ----------------------------
324344

325345
/**

apps/dashboard/src/@/components/blocks/BuyAndSwapEmbed.tsx

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import { useState } from "react";
55
import type { Chain, ThirdwebClient } from "thirdweb";
66
import { BuyWidget, SwapWidget } from "thirdweb/react";
77
import {
8+
reportAssetBuyCancelled,
89
reportAssetBuyFailed,
910
reportAssetBuySuccessful,
1011
reportTokenSwapCancelled,
@@ -62,6 +63,15 @@ export function BuyAndSwapEmbed(props: {
6263
});
6364
}
6465
}}
66+
onCancel={() => {
67+
if (props.pageType === "asset") {
68+
reportAssetBuyCancelled({
69+
assetType: "coin",
70+
chainId: props.chain.id,
71+
contractType: "DropERC20",
72+
});
73+
}
74+
}}
6575
onSuccess={() => {
6676
if (props.pageType === "asset") {
6777
reportAssetBuySuccessful({
@@ -92,8 +102,9 @@ export function BuyAndSwapEmbed(props: {
92102
},
93103
}}
94104
onError={(error, quote) => {
105+
const errorMessage = parseError(error);
95106
reportTokenSwapFailed({
96-
errorMessage: error.message,
107+
errorMessage: errorMessage,
97108
buyTokenChainId: quote.intent.destinationChainId,
98109
buyTokenAddress: quote.intent.destinationTokenAddress,
99110
sellTokenChainId: quote.intent.originChainId,

packages/thirdweb/src/react/web/ui/Bridge/swap-widget/SwapWidget.tsx

Lines changed: 22 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -263,48 +263,30 @@ export function SwapWidgetContainer(props: {
263263
);
264264
}
265265

266+
type SelectionInfo = {
267+
preparedQuote: SwapPreparedQuote;
268+
request: BridgePrepareRequest;
269+
quote: Buy.quote.Result | Sell.quote.Result;
270+
buyToken: TokenWithPrices;
271+
sellToken: TokenWithPrices;
272+
sellTokenBalance: bigint;
273+
mode: "buy" | "sell";
274+
};
275+
276+
type Join<T, U> = T & U;
277+
266278
type SwapWidgetScreen =
267279
| { id: "1:swap-ui" }
268-
| {
269-
id: "2:loading-quote";
270-
quote: Buy.quote.Result | Sell.quote.Result;
271-
buyToken: TokenWithPrices;
272-
sellToken: TokenWithPrices;
273-
sellTokenBalance: bigint;
274-
mode: "buy" | "sell";
275-
}
276-
| {
277-
id: "2:preview";
278-
preparedQuote: SwapPreparedQuote;
279-
request: BridgePrepareRequest;
280-
quote: Buy.quote.Result | Sell.quote.Result;
281-
buyToken: TokenWithPrices;
282-
sellToken: TokenWithPrices;
283-
sellTokenBalance: bigint;
284-
mode: "buy" | "sell";
285-
}
286-
| {
287-
id: "3:execute";
288-
request: BridgePrepareRequest;
289-
quote: Buy.quote.Result | Sell.quote.Result;
290-
preparedQuote: SwapPreparedQuote;
291-
buyToken: TokenWithPrices;
292-
sellToken: TokenWithPrices;
293-
sellTokenBalance: bigint;
294-
mode: "buy" | "sell";
295-
}
296-
| {
297-
id: "4:success";
298-
completedStatuses: CompletedStatusResult[];
299-
preparedQuote: SwapPreparedQuote;
300-
buyToken: TokenWithPrices;
301-
sellToken: TokenWithPrices;
302-
}
303-
| {
304-
id: "error";
305-
preparedQuote: SwapPreparedQuote;
306-
error: Error;
307-
};
280+
| Join<{ id: "2:preview" }, SelectionInfo>
281+
| Join<{ id: "3:execute" }, SelectionInfo>
282+
| Join<
283+
{
284+
id: "4:success";
285+
completedStatuses: CompletedStatusResult[];
286+
},
287+
SelectionInfo
288+
>
289+
| { id: "error"; error: Error; preparedQuote: SwapPreparedQuote };
308290

309291
function SwapWidgetContent(props: SwapWidgetProps) {
310292
const [screen, setScreen] = useState<SwapWidgetScreen>({ id: "1:swap-ui" });

0 commit comments

Comments
 (0)