Skip to content

Commit

Permalink
feat(mobile): track wallet events (#305)
Browse files Browse the repository at this point in the history
  • Loading branch information
duongdev committed Sep 11, 2024
1 parent 6f1424c commit 964c4ed
Showing 1 changed file with 23 additions and 0 deletions.
23 changes: 23 additions & 0 deletions apps/mobile/stores/wallet/hooks.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import type { WalletFormValues } from '@6pm/validation'
import { createId } from '@paralleldrive/cuid2'
import { useMutation, useQuery, useQueryClient } from '@tanstack/react-query'
import { keyBy } from 'lodash-es'
import { usePostHog } from 'posthog-react-native'
import { useMemo } from 'react'
import type { StoreHookQueryOptions } from '../core/stores'
import { useCreateTransaction } from '../transaction/hooks'
Expand Down Expand Up @@ -48,6 +49,7 @@ export const useWallet = (walletId: string) => {
}

export const useUpdateWallet = () => {
const posthog = usePostHog()
const updateWalletInStore = useWalletStore((state) => state.updateWallet)
const { walletsDict } = useWalletList()
const { mutateAsync: mutateCreateTransaction } = useCreateTransaction()
Expand Down Expand Up @@ -115,6 +117,14 @@ export const useUpdateWallet = () => {

updateWalletInStore(wallet)

posthog.capture('wallet_updated', {
wallet_id: wallet.id,
wallet_name: wallet.name,
wallet_currency: wallet.preferredCurrency,
wallet_balance: wallet.balance,
wallet_icon: wallet.icon,
})

return wallet
},
},
Expand All @@ -125,6 +135,7 @@ export const useUpdateWallet = () => {
}

export const useCreateWallet = () => {
const posthog = usePostHog()
const { data: userData } = useMeQuery()
const updateWalletInStore = useWalletStore((state) => state.updateWallet)

Expand Down Expand Up @@ -177,6 +188,14 @@ export const useCreateWallet = () => {

updateWalletInStore(wallet)

posthog.capture('wallet_created', {
wallet_id: wallet.id,
wallet_name: wallet.name,
wallet_currency: wallet.preferredCurrency,
wallet_balance: wallet.balance,
wallet_icon: wallet.icon,
})

return wallet
},
})
Expand All @@ -185,6 +204,7 @@ export const useCreateWallet = () => {
}

export const useDeleteWallet = () => {
const posthog = usePostHog()
const removeWalletInStore = useWalletStore((state) => state.removeWallet)

const mutation = useMutation({
Expand All @@ -196,6 +216,9 @@ export const useDeleteWallet = () => {
},
onMutate(walletId) {
removeWalletInStore(walletId)
posthog.capture('wallet_deleted', {
wallet_id: walletId,
})
},
})

Expand Down

0 comments on commit 964c4ed

Please sign in to comment.