Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add position management events #4

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 }
}
Loading