Skip to content

Commit

Permalink
plausible add position
Browse files Browse the repository at this point in the history
  • Loading branch information
saml33 committed Aug 7, 2024
1 parent 4d44f11 commit 646d148
Show file tree
Hide file tree
Showing 3 changed files with 42 additions and 5 deletions.
17 changes: 17 additions & 0 deletions components/DepositForm.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ import Decimal from 'decimal.js'
import useIpAddress from 'hooks/useIpAddress'
import { walletBalanceForToken } from './StakeForm'
import { ClientContextKeys } from 'utils/constants'
import { usePlausible } from 'next-plausible'

const set = mangoStore.getState().set

Expand Down Expand Up @@ -63,6 +64,7 @@ function DespositForm({ token: selectedToken, clientContext }: StakeFormProps) {
const submitting = mangoStore((s) => s.submittingBoost)
const [refreshingWalletTokens, setRefreshingWalletTokens] = useState(false)
const { maxSolDeposit } = useSolBalance()
const plausible = usePlausible()
const { usedTokens, totalTokens } = useMangoAccountAccounts()
const { jlpGroup } = useMangoGroup()
const groupLoaded = mangoStore((s) => s.groupLoaded)
Expand Down Expand Up @@ -113,6 +115,7 @@ function DespositForm({ token: selectedToken, clientContext }: StakeFormProps) {

if (!group || !depositBank || !publicKey) return

plausible('PositionEntryStart')
set((state) => {
state.submittingBoost = true
})
Expand All @@ -139,6 +142,14 @@ function DespositForm({ token: selectedToken, clientContext }: StakeFormProps) {
})
setInputAmount('')
setSizePercentage('')
plausible('PositionEntrySuccess', {
props: {
description: `${publicKey.toString()} ${inputAmount} ${
depositBank.name
}`,
wallet: publicKey.toString(),
},
})
await sleep(500)
if (!mangoAccount) {
await actions.fetchMangoAccounts(publicKey)
Expand All @@ -150,6 +161,12 @@ function DespositForm({ token: selectedToken, clientContext }: StakeFormProps) {
set((state) => {
state.submittingBoost = false
})
plausible('PositionEntryError', {
props: {
error: `${e}`,
wallet: publicKey.toString(),
},
})
if (!isMangoError(e)) return
notify({
title: 'Transaction failed',
Expand Down
17 changes: 17 additions & 0 deletions components/StakeForm.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ import useQuoteRoutes from 'hooks/useQuoteRoutes'
import { YIELD_BUTTON_CLASSES } from './Stake'
import { useTheme } from 'next-themes'
import usePositions from 'hooks/usePositions'
import { usePlausible } from 'next-plausible'

export const MIN_SOL_BALANCE_FOR_ACCOUNT = 0.045

Expand Down Expand Up @@ -110,6 +111,7 @@ export const walletBalanceForToken = (
function StakeForm({ token: selectedToken, clientContext }: StakeFormProps) {
const { theme } = useTheme()
const { positions } = usePositions()
const plausible = usePlausible()
const { t } = useTranslation(['common', 'account'])
const [depositToken, setDepositToken] = useState(selectedToken)
const [inputAmount, setInputAmount] = useState('')
Expand Down Expand Up @@ -315,6 +317,7 @@ function StakeForm({ token: selectedToken, clientContext }: StakeFormProps) {
set((state) => {
state.submittingBoost = true
})
plausible('PositionEntryStart')
try {
// const newAccountfNum = getNextAccountNumber(mangoAccounts)
let stakeAmount = parseFloat(inputAmount)
Expand Down Expand Up @@ -363,6 +366,14 @@ function StakeForm({ token: selectedToken, clientContext }: StakeFormProps) {
})
setInputAmount('')
setSizePercentage('')
plausible('PositionEntrySuccess', {
props: {
description: `${publicKey.toString()} ${inputAmount} ${
stakeBank.name
} ${leverage}x`,
wallet: publicKey.toString(),
},
})
await sleep(500)
if (!mangoAccount) {
await actions.fetchMangoAccounts(publicKey)
Expand All @@ -374,6 +385,12 @@ function StakeForm({ token: selectedToken, clientContext }: StakeFormProps) {
set((state) => {
state.submittingBoost = false
})
plausible('PositionEntryError', {
props: {
error: `${e}`,
wallet: publicKey.toString(),
},
})
if (!isMangoError(e)) return
notify({
title: 'Transaction failed',
Expand Down
13 changes: 8 additions & 5 deletions pages/_app.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import '../styles/globals.css'
import 'react-range-slider-input/dist/style.css'

import type { AppProps } from 'next/app'
import { useCallback, useEffect, useMemo, useState } from 'react'
import { ReactNode, useCallback, useEffect, useMemo, useState } from 'react'
import {
Adapter,
WalletAdapterNetwork,
Expand Down Expand Up @@ -132,9 +132,10 @@ function MyApp({ Component, pageProps }: AppProps) {
>
<MangoProvider />
<ThemeProvider defaultTheme="Light" storageKey={THEME_KEY}>
<Telemetry />
<Layout>
<Component {...pageProps} />
<Telemetry>
<Component {...pageProps} />
</Telemetry>
</Layout>
<TransactionNotification />
</ThemeProvider>
Expand All @@ -152,7 +153,7 @@ type TelemetryProps = {
walletConnected: string
}

const Telemetry = () => {
const Telemetry = ({ children }: { children: ReactNode }) => {
const { wallet } = useWallet()
const [telemetryProps, setTelemetryProps] = useState<
TelemetryProps | undefined
Expand Down Expand Up @@ -183,6 +184,8 @@ const Telemetry = () => {
scriptProps={{ id: 'plausible' }}
pageviewProps={telemetryProps}
trackOutboundLinks={true}
/>
>
{children}
</PlausibleProvider>
)
}

0 comments on commit 646d148

Please sign in to comment.