Skip to content

Commit

Permalink
(Swap tool) Add top gainer ampli event and add feature flag (#3962)
Browse files Browse the repository at this point in the history
  • Loading branch information
JoseRFelix authored Nov 21, 2024
1 parent 3d3c557 commit 8419dea
Show file tree
Hide file tree
Showing 5 changed files with 31 additions and 15 deletions.
3 changes: 2 additions & 1 deletion packages/types/src/feature-flags-types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,4 +22,5 @@ export type AvailableFlags =
| "sqsActiveOrders"
| "alloyedAssets"
| "bridgeDepositAddress"
| "nomicWithdrawAmount";
| "nomicWithdrawAmount"
| "swapToolTopGainers";
33 changes: 20 additions & 13 deletions packages/web/components/assets/highlights-categories.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -145,6 +145,7 @@ export const AssetHighlights: FunctionComponent<
isLoading?: boolean;
disableLinking?: boolean;
highlight: Highlight;
onClickAsset?: (asset: HighlightAsset) => void;
} & CustomClasses
> = ({
title,
Expand All @@ -154,6 +155,7 @@ export const AssetHighlights: FunctionComponent<
isLoading = false,
className,
highlight,
onClickAsset,
}) => {
const { t } = useTranslation();

Expand Down Expand Up @@ -192,6 +194,7 @@ export const AssetHighlights: FunctionComponent<
asset={asset}
extraInfo={extraInfo}
highlight={highlight}
onClick={onClickAsset}
/>
))}
</>
Expand All @@ -201,21 +204,21 @@ export const AssetHighlights: FunctionComponent<
);
};

type HighlightAsset = {
coinDenom: string;
coinName: string;
coinImageUrl?: string;
href?: string;
externalLink?: boolean;
};

const AssetHighlightRow: FunctionComponent<{
asset: {
coinDenom: string;
coinName: string;
coinImageUrl?: string;
href?: string;
externalLink?: boolean;
};
asset: HighlightAsset;
extraInfo: ReactNode;
highlight: Highlight;
}> = ({
asset: { coinDenom, coinName, coinImageUrl, href, externalLink },
extraInfo,
highlight,
}) => {
onClick?: (asset: HighlightAsset) => void;
}> = ({ asset, extraInfo, highlight, onClick }) => {
const { coinDenom, coinName, coinImageUrl, href, externalLink } = asset;
const { logEvent } = useAmplitudeAnalytics();

const AssetContent = (
Expand All @@ -234,7 +237,10 @@ const AssetHighlightRow: FunctionComponent<{
);

return !href ? (
<div className="-mx-2 flex items-center justify-between gap-4 rounded-lg p-2">
<div
className="-mx-2 flex items-center justify-between gap-4 rounded-lg p-2"
onClick={() => onClick?.(asset)}
>
{AssetContent}
</div>
) : (
Expand All @@ -245,6 +251,7 @@ const AssetHighlightRow: FunctionComponent<{
className="-mx-2 flex items-center justify-between gap-4 rounded-lg p-2 transition-colors duration-200 ease-in-out hover:cursor-pointer hover:bg-osmoverse-850"
onClick={() => {
logEvent([EventName.Assets.assetClicked, { coinDenom, highlight }]);
onClick?.(asset);
}}
>
{AssetContent}
Expand Down
2 changes: 2 additions & 0 deletions packages/web/config/analytics-events.ts
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,7 @@ export type EventProperties = {
section: string;
tokenIn: string;
tokenOut: string;
token: string;
option: string;
numberOfValidators: number;
validatorNames: string[];
Expand Down Expand Up @@ -114,6 +115,7 @@ export const EventName = {
swapCompleted: "Swap: Swap completed",
swapFailed: "Swap: Swap failed",
dropdownAssetSelected: "Swap: Dropdown asset selected",
checkTopGainers: "Swap: Check Top Gainers",
},
// Events in Sidebar UI
Sidebar: {
Expand Down
1 change: 1 addition & 0 deletions packages/web/hooks/use-feature-flags.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ const defaultFlags: Record<AvailableFlags, boolean> = {
alloyedAssets: false,
bridgeDepositAddress: false,
nomicWithdrawAmount: false,
swapToolTopGainers: false,
};

export function useFeatureFlags() {
Expand Down
7 changes: 6 additions & 1 deletion packages/web/pages/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ const Home = () => {
setPreviousTrade={setPreviousTrade}
/>
</ClientOnly>
<TopGainers />
{featureFlags.swapToolTopGainers && <TopGainers />}
</div>
</div>
</div>
Expand All @@ -72,6 +72,7 @@ const Home = () => {
const TopGainers = () => {
const { t } = useTranslation();
const router = useRouter();
const { logEvent } = useAmplitudeAnalytics();

const { data: topGainerAssets, isLoading: isTopGainerAssetsLoading } =
api.edge.assets.getTopGainerAssets.useQuery({
Expand All @@ -86,8 +87,12 @@ const TopGainers = () => {
isLoading={isTopGainerAssetsLoading}
assets={(topGainerAssets ?? []).map(highlightPrice24hChangeAsset)}
onClickSeeAll={() => {
logEvent([EventName.Swap.checkTopGainers, { token: "All" }]);
router.push(`/assets?category=topGainers`);
}}
onClickAsset={(asset) => {
logEvent([EventName.Swap.checkTopGainers, { token: asset.coinDenom }]);
}}
highlight="topGainers"
/>
);
Expand Down

0 comments on commit 8419dea

Please sign in to comment.