Skip to content

Commit

Permalink
feat(analytics): add tracking for trade input size toggle (#830)
Browse files Browse the repository at this point in the history
  • Loading branch information
moo-onthelawn authored Jul 19, 2024
1 parent 0d884b3 commit 4884872
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 7 deletions.
5 changes: 5 additions & 0 deletions src/constants/analytics.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import type { SupportedLocales } from './localization';
import type { DydxNetwork } from './networks';
import { TransferNotificationTypes } from './notifications';
import type { TradeTypes } from './trade';
import { TradeToggleSizeInput } from './trade';
import type { DydxAddress, EvmAddress, WalletConnectionType, WalletType } from './wallets';

export type AnalyticsEventTrackMeta<T extends AnalyticsEventTypes> = {
Expand Down Expand Up @@ -197,6 +198,10 @@ export const AnalyticsEvents = unionize(
TradeOrderTypeSelected: ofType<{
type: TradeTypes;
}>(),
TradeAmountToggleClick: ofType<{
newInput: TradeToggleSizeInput;
market: string;
}>(),
TradePlaceOrder: ofType<
HumanReadablePlaceOrderPayload & {
isClosePosition: boolean;
Expand Down
2 changes: 2 additions & 0 deletions src/constants/trade.ts
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,8 @@ export enum TradeSizeInput {
Usdc = 'size.usdcSize',
}

export type TradeToggleSizeInput = TradeSizeInput.Size | TradeSizeInput.Usdc;

export enum TradeBoxKeys {
LimitPrice = 'price.limitPrice',
TrailingPercent = 'price.trailingPercent',
Expand Down
26 changes: 19 additions & 7 deletions src/views/forms/TradeForm/TradeSizeInputs.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import { shallowEqual } from 'react-redux';
import styled from 'styled-components';

import { TradeInputField } from '@/constants/abacus';
import { AnalyticsEvents } from '@/constants/analytics';
import { ButtonShape, ButtonSize } from '@/constants/buttons';
import { STRING_KEYS } from '@/constants/localization';
import { TOKEN_DECIMALS, USD_DECIMALS } from '@/constants/numbers';
Expand Down Expand Up @@ -35,6 +36,7 @@ import { getSelectedLocale } from '@/state/localizationSelectors';
import { getCurrentMarketConfig } from '@/state/perpetualsSelectors';

import abacusStateManager from '@/lib/abacus';
import { track } from '@/lib/analytics';
import { MustBigNumber } from '@/lib/numbers';

import { MarketLeverageInput } from './MarketLeverageInput';
Expand Down Expand Up @@ -108,13 +110,23 @@ export const TradeSizeInputs = () => {
});
};

const onUsdcToggle = useCallback((isPressed: boolean) => {
setShowUSDCInput(isPressed);
abacusStateManager.setTradeValue({
field: TradeInputField.lastInput,
value: isPressed ? TradeInputField.usdcSize.rawValue : TradeInputField.size.rawValue,
});
}, []);
const onUsdcToggle = useCallback(
(isPressed: boolean) => {
setShowUSDCInput(isPressed);
abacusStateManager.setTradeValue({
field: TradeInputField.lastInput,
value: isPressed ? TradeInputField.usdcSize.rawValue : TradeInputField.size.rawValue,
});

track(
AnalyticsEvents.TradeAmountToggleClick({
newInput: isPressed ? TradeSizeInput.Usdc : TradeSizeInput.Size,
market: id ?? '',
})
);
},
[id]
);

const inputToggleButton = () => {
const slotTooltip =
Expand Down

0 comments on commit 4884872

Please sign in to comment.