Skip to content

Commit

Permalink
add tracking
Browse files Browse the repository at this point in the history
  • Loading branch information
nguyenhoaidanh committed Oct 28, 2023
1 parent bea3425 commit 4bdb097
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 4 deletions.
2 changes: 1 addition & 1 deletion .nvmrc
Original file line number Diff line number Diff line change
@@ -1 +1 @@
v18.15.0
v20.9.0
12 changes: 11 additions & 1 deletion src/components/SwapForm/GasPriceNote.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import { Text } from 'rebass'
import PriceImpactNote from 'components/SwapForm/PriceImpactNote'
import WarningNote from 'components/WarningNote'
import { useActiveWeb3React } from 'hooks'
import useMixpanel, { MIXPANEL_TYPE } from 'hooks/useMixpanel'
import useTheme from 'hooks/useTheme'
import { useSwitchPairToLimitOrder } from 'state/swap/hooks'
import { checkPriceImpact } from 'utils/prices'
Expand All @@ -22,14 +23,23 @@ const GasFeeAndPriceImpactNote: FC<Props> = ({ gasUsd = 0, priceImpact, isDegenM
const { chainId } = useActiveWeb3React()
const switchToLimitOrder = useSwitchPairToLimitOrder()
const { isHigh, isVeryHigh } = checkPriceImpact(priceImpact)
const { mixpanelHandler } = useMixpanel()

if (+gasUsd < GAS_USD_THRESHOLD || chainId !== ChainId.MAINNET)
return <PriceImpactNote priceImpact={priceImpact} isDegenMode={isDegenMode} showLimitOrderLink />

const limitOrderLink = (
<Trans>
Do you want to make a{' '}
<Text as="span" sx={{ cursor: 'pointer', fontWeight: 'bold' }} color={theme.primary} onClick={switchToLimitOrder}>
<Text
as="span"
sx={{ cursor: 'pointer', fontWeight: 'bold' }}
color={theme.primary}
onClick={() => {
mixpanelHandler(MIXPANEL_TYPE.LO_CLICK_WARNING_IN_SWAP)
switchToLimitOrder()
}}
>
Limit Order
</Text>{' '}
instead?
Expand Down
14 changes: 12 additions & 2 deletions src/components/SwapForm/PriceImpactNote.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import styled from 'styled-components'
import Column from 'components/Column'
import Row from 'components/Row'
import WarningNote from 'components/WarningNote'
import useMixpanel, { MIXPANEL_TYPE } from 'hooks/useMixpanel'
import useTheme from 'hooks/useTheme'
import { useSwitchPairToLimitOrder } from 'state/swap/hooks'
import { checkPriceImpact } from 'utils/prices'
Expand Down Expand Up @@ -38,6 +39,7 @@ const PriceImpactNote: FC<Props> = ({ isDegenMode, priceImpact, showLimitOrderLi
const priceImpactResult = checkPriceImpact(priceImpact)
const theme = useTheme()
const switchToLimitOrder = useSwitchPairToLimitOrder()
const { mixpanelHandler } = useMixpanel()

if (typeof priceImpact !== 'number') {
return null
Expand Down Expand Up @@ -81,7 +83,15 @@ const PriceImpactNote: FC<Props> = ({ isDegenMode, priceImpact, showLimitOrderLi
<Text>
<Trans>
Do you want to make a{' '}
<Text as="b" sx={{ cursor: 'pointer' }} color={theme.primary} onClick={switchToLimitOrder}>
<Text
as="b"
sx={{ cursor: 'pointer' }}
color={theme.primary}
onClick={() => {
mixpanelHandler(MIXPANEL_TYPE.LO_CLICK_WARNING_IN_SWAP)
switchToLimitOrder()
}}
>
Limit Order
</Text>{' '}
instead?
Expand All @@ -108,6 +118,7 @@ const PriceImpactNote: FC<Props> = ({ isDegenMode, priceImpact, showLimitOrderLi
}
longText={
<Column gap="4px">
{limitOrderNote}
<Text>
{isDegenMode ? (
<Trans>
Expand All @@ -120,7 +131,6 @@ const PriceImpactNote: FC<Props> = ({ isDegenMode, priceImpact, showLimitOrderLi
</Trans>
)}
</Text>
{limitOrderNote}
</Column>
}
/>
Expand Down
5 changes: 5 additions & 0 deletions src/hooks/useMixpanel.ts
Original file line number Diff line number Diff line change
Expand Up @@ -206,6 +206,7 @@ export enum MIXPANEL_TYPE {
LO_CLICK_CANCEL_TYPE,
LO_CLICK_UPDATE_TYPE,
LO_CLICK_GET_STARTED,
LO_CLICK_WARNING_IN_SWAP,

// Wallet UI
WUI_WALLET_CLICK,
Expand Down Expand Up @@ -1138,6 +1139,10 @@ export default function useMixpanel(currencies?: { [field in Field]?: Currency }
mixpanel.track('Limit Order - Get Started Click', payload)
break
}
case MIXPANEL_TYPE.LO_CLICK_WARNING_IN_SWAP: {
mixpanel.track('Limit Order - Warning in Swap Click', payload)
break
}

case MIXPANEL_TYPE.WUI_WALLET_CLICK: {
mixpanel.track('Wallet UI - Wallet Click')
Expand Down

0 comments on commit 4bdb097

Please sign in to comment.