Skip to content

Commit

Permalink
plausible position exit
Browse files Browse the repository at this point in the history
  • Loading branch information
saml33 committed Aug 8, 2024
1 parent 3fd7c07 commit 1f9aee8
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 0 deletions.
3 changes: 3 additions & 0 deletions components/StakeForm.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -286,6 +286,7 @@ function StakeForm({ token: selectedToken, clientContext }: StakeFormProps) {
borrowBank?.uiPrice,
clientContext,
leverage,
uiOutAmount,
])

const availableVaultBalance = useMemo(() => {
Expand Down Expand Up @@ -413,11 +414,13 @@ function StakeForm({ token: selectedToken, clientContext }: StakeFormProps) {
publicKey,
clientContext,
inputAmount,
leverage,
bestRoute,
isSwapMode,
amountToBorrow,
connection,
wallet,
plausible,
])

const showInsufficientBalance =
Expand Down
18 changes: 18 additions & 0 deletions components/UnstakeForm.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ import {
JLP_BORROW_TOKEN,
LST_BORROW_TOKEN,
} from 'utils/constants'
import { usePlausible } from 'next-plausible'

const set = mangoStore.getState().set

Expand All @@ -59,6 +60,7 @@ function UnstakeForm({
clientContext,
}: UnstakeFormProps) {
const { t } = useTranslation(['common', 'account'])
const plausible = usePlausible()
const [inputAmount, setInputAmount] = useState('')
const [submitting, setSubmitting] = useState(false)
const [refreshingWalletTokens, setRefreshingWalletTokens] = useState(false)
Expand Down Expand Up @@ -173,6 +175,7 @@ function UnstakeForm({

if (!group || !mangoAccount) return

plausible('PositionExitStart')
setSubmitting(true)
try {
if (mangoAccount.getTokenBalanceUi(borrowBank) < 0) {
Expand Down Expand Up @@ -223,6 +226,14 @@ function UnstakeForm({
type: 'success',
txid: tx2,
})
plausible('PositionExitSuccess', {
props: {
description: `${publicKey.toString()} ${inputAmount} ${
stakeBank.name
} ${leverage}x`,
wallet: publicKey.toString(),
},
})
setSubmitting(false)
setInputAmount('')
setSizePercentage('')
Expand All @@ -237,6 +248,12 @@ function UnstakeForm({
description: `${e}`,
type: 'error',
})
plausible('PositionExitError', {
props: {
error: `${e}`,
wallet: publicKey.toString(),
},
})
setSubmitting(false)
if (!isMangoError(e)) return
notify({
Expand All @@ -254,6 +271,7 @@ function UnstakeForm({
inputAmount,
leverage,
clientContext,
plausible,
])

const maxWithdraw = useMemo(() => {
Expand Down

0 comments on commit 1f9aee8

Please sign in to comment.