Skip to content

Commit

Permalink
chore: add Mixpanel enum
Browse files Browse the repository at this point in the history
  • Loading branch information
0xApotheosis committed Jan 9, 2024
1 parent bb54423 commit 5598f72
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 5 deletions.
5 changes: 3 additions & 2 deletions src/components/SelectPair.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@ import { useCallback, useMemo } from 'react'
import { FaArrowRightArrowLeft } from 'react-icons/fa6'
import { useNavigate } from 'react-router-dom'
import { BTCImage, ETHImage } from 'lib/const'
import { getMixPanel } from 'lib/mixpanelSingleton'
import { getMixPanel } from 'lib/mixpanel/mixpanelSingleton'
import { MixPanelEvent } from 'lib/mixpanel/types'

import { AssetSelection } from './AssetSelection'

Expand All @@ -12,7 +13,7 @@ export const SelectPair = () => {
const navigate = useNavigate()
const switchIcon = useMemo(() => <FaArrowRightArrowLeft />, [])
const handleSubmit = useCallback(() => {
mixpanel?.track('Pair selected', {
mixpanel?.track(MixPanelEvent.PairSelected, {
'some key': 'some val',
})

Expand Down
8 changes: 7 additions & 1 deletion src/components/TradeInput.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -19,18 +19,24 @@ import { useCallback, useMemo } from 'react'
import { FaArrowRightArrowLeft } from 'react-icons/fa6'
import { useNavigate } from 'react-router-dom'
import { BTCImage, ETHImage } from 'lib/const'
import { getMixPanel } from 'lib/mixpanel/mixpanelSingleton'
import { MixPanelEvent } from 'lib/mixpanel/types'

import { Amount } from './Amount/Amount'

export const TradeInput = () => {
const mixpanel = getMixPanel()
const navigate = useNavigate()
const Divider = useMemo(() => <StackDivider borderColor='border.base' />, [])
const FromAssetIcon = useMemo(() => <Avatar size='sm' src={BTCImage} />, [])
const ToAssetIcon = useMemo(() => <Avatar size='sm' src={ETHImage} />, [])
const SwitchIcon = useMemo(() => <FaArrowRightArrowLeft />, [])
const handleSubmit = useCallback(() => {
mixpanel?.track(MixPanelEvent.StartTransaction, {
'some key': 'some val',
})
navigate('/status')
}, [navigate])
}, [mixpanel, navigate])

const handleFromAssetClick = useCallback(() => {
console.info('asset click')
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import Mixpanel from 'mixpanel-browser'

export type MixPanelType = typeof Mixpanel
import type { MixPanelType } from './types'

// don't export me, access me through the getter
let _mixPanel: typeof Mixpanel | undefined = undefined
let _mixPanel: MixPanelType | undefined = undefined

// we need to be able to access this outside react
export const getMixPanel = (): MixPanelType | undefined => {
Expand All @@ -13,6 +13,7 @@ export const getMixPanel = (): MixPanelType | undefined => {
const mixpanelToken = import.meta.env.VITE_MIXPANEL_TOKEN
Mixpanel.init(mixpanelToken)
_mixPanel = Mixpanel // identify once per session
_mixPanel.set_config({ persistence: 'localStorage' })
_mixPanel.identify()
return _mixPanel
}
8 changes: 8 additions & 0 deletions src/lib/mixpanel/types.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
import type Mixpanel from 'mixpanel-browser'

export type MixPanelType = typeof Mixpanel

export enum MixPanelEvent {
PairSelected = 'Pair Selected',
StartTransaction = 'Start Transaction',
}

0 comments on commit 5598f72

Please sign in to comment.