Skip to content

Commit

Permalink
Add position management events
Browse files Browse the repository at this point in the history
  • Loading branch information
riordanp committed Dec 5, 2023
1 parent 6834fc3 commit fd30c65
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 0 deletions.
16 changes: 16 additions & 0 deletions components/StakeForm.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,8 @@ import SheenLoader from './shared/SheenLoader'
import useLeverageMax from 'hooks/useLeverageMax'
import { STAKEABLE_TOKENS_DATA } from 'utils/constants'
import { sleep } from 'utils'
import { usePlausible } from 'next-plausible'
import { TelemetryEvents } from 'utils/telemetry'

const set = mangoStore.getState().set

Expand Down Expand Up @@ -97,6 +99,7 @@ function StakeForm({ token: selectedToken }: StakeFormProps) {
estimatedNetAPY,
} = useBankRates(selectedToken, leverage)
const leverageMax = useLeverageMax(selectedToken)
const telemetry = usePlausible<TelemetryEvents>()

const stakeBank = useMemo(() => {
return group?.banksMapByName.get(selectedToken)?.[0]
Expand Down Expand Up @@ -175,6 +178,19 @@ function StakeForm({ token: selectedToken }: StakeFormProps) {
parseFloat(inputAmount),
tokenNum || 0,
)
if (mangoAccount !== undefined) {
telemetry('positionCreate', {
props: {
token: selectedToken,
},
})
} else {
telemetry('positionIncrease', {
props: {
token: selectedToken,
},
})
}
notify({
title: 'Transaction confirmed',
type: 'success',
Expand Down
8 changes: 8 additions & 0 deletions components/UnstakeForm.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,8 @@ import ButtonGroup from './forms/ButtonGroup'
import Decimal from 'decimal.js'
import { Disclosure } from '@headlessui/react'
import { sleep } from 'utils'
import { usePlausible } from 'next-plausible'
import { TelemetryEvents } from 'utils/telemetry'

const set = mangoStore.getState().set

Expand Down Expand Up @@ -79,6 +81,7 @@ function UnstakeForm({ token: selectedToken }: UnstakeFormProps) {
const { usedTokens, totalTokens } = useMangoAccountAccounts()
const { group } = useMangoGroup()
const { mangoAccount } = useMangoAccount()
const telemetry = usePlausible<TelemetryEvents>()

const stakeBank = useMemo(() => {
return group?.banksMapByName.get(selectedToken)?.[0]
Expand Down Expand Up @@ -197,6 +200,11 @@ function UnstakeForm({ token: selectedToken }: UnstakeFormProps) {
await sleep(500)
await actions.fetchMangoAccounts(mangoAccount.owner)
await actions.fetchWalletTokens(publicKey)
telemetry('positionReduce', {
props: {
token: selectedToken,
},
})
} catch (e) {
console.error('Error depositing:', e)
setSubmitting(false)
Expand Down
5 changes: 5 additions & 0 deletions utils/telemetry.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
export type TelemetryEvents = {
positionCreate: { token: string }
positionIncrease: { token: string }
positionReduce: { token: string }
}

0 comments on commit fd30c65

Please sign in to comment.