Skip to content

Commit

Permalink
added plausible events for common actions
Browse files Browse the repository at this point in the history
  • Loading branch information
NoahSaso committed Nov 26, 2024
1 parent ecf3df0 commit 898f16f
Show file tree
Hide file tree
Showing 17 changed files with 506 additions and 89 deletions.
14 changes: 13 additions & 1 deletion packages/stateful/components/dao/CreateDaoForm.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import clsx from 'clsx'
import cloneDeep from 'lodash.clonedeep'
import merge from 'lodash.merge'
import { nanoid } from 'nanoid'
import { usePlausible } from 'next-plausible'
import { useEffect, useMemo, useState } from 'react'
import {
FormProvider,
Expand Down Expand Up @@ -53,6 +54,7 @@ import {
DaoTabId,
GovernanceProposalActionData,
NewDao,
PlausibleEvents,
ProposalModuleAdapter,
SecretModuleInstantiateInfo,
} from '@dao-dao/types'
Expand Down Expand Up @@ -177,6 +179,7 @@ export const InnerCreateDaoForm = ({
const { t } = useTranslation()
const dao = useDaoIfAvailable()
const queryClient = useQueryClient()
const plausible = usePlausible<PlausibleEvents>()

const chainContext = useSupportedChainContext()
const {
Expand Down Expand Up @@ -777,7 +780,7 @@ export const InnerCreateDaoForm = ({
],
} as Partial<GovernanceProposalActionData>),
})
} else if (isWalletConnected) {
} else if (isWalletConnected && walletAddress) {
setCreating(true)
try {
const coreAddress = await toast.promise(doCreateDao(), {
Expand All @@ -801,6 +804,15 @@ export const InnerCreateDaoForm = ({
},
})

plausible('daoCreate', {
props: {
chainId,
dao: coreAddress,
daoType: values.creator.id,
walletAddress,
},
})

const { info } = await queryClient
.fetchQuery(
contractQueries.info(queryClient, {
Expand Down
54 changes: 38 additions & 16 deletions packages/stateful/hooks/useProposalActionState.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import { toUtf8 } from '@cosmjs/encoding'
import { OfflineSigner } from '@cosmjs/proto-signing'
import { CancelOutlined, Key, Send } from '@mui/icons-material'
import { useQueryClient } from '@tanstack/react-query'
import { usePlausible } from 'next-plausible'
import { useCallback, useEffect, useState } from 'react'
import toast from 'react-hot-toast'
import { useTranslation } from 'react-i18next'
Expand All @@ -16,12 +17,12 @@ import {
ProposalCrossChainRelayStatus,
ProposalStatusAndInfoProps,
TextInput,
useConfiguredChainContext,
useDao,
} from '@dao-dao/stateless'
import {
ChainId,
LoadingData,
PlausibleEvents,
PreProposeModuleType,
ProposalStatusEnum,
ProposalStatusKey,
Expand Down Expand Up @@ -72,14 +73,8 @@ export const useProposalActionState = ({
onCloseSuccess,
}: UseProposalActionStateOptions): UseProposalActionStateReturn => {
const { t } = useTranslation()
const {
chain: { chainId, chainName },
} = useConfiguredChainContext()
const queryClient = useQueryClient()
const {
coreAddress,
info: { items },
} = useDao()
const dao = useDao()
const {
options: { proposalNumber },
proposalModule,
Expand All @@ -92,10 +87,11 @@ export const useProposalActionState = ({
getOfflineSigner,
} = useWallet()
const { isMember = false } = useMembership()
const plausible = usePlausible<PlausibleEvents>()

const config = useRecoilValue(
DaoProposalSingleCommonSelectors.configSelector({
chainId,
chainId: proposalModule.chainId,
contractAddress: proposalModule.address,
})
)
Expand All @@ -113,7 +109,7 @@ export const useProposalActionState = ({
// execution transaction, unless a memo is already set in the metadata.
const allowMemoOnExecute = metadata?.memo
? false
: !!items[DAO_CORE_ALLOW_MEMO_ON_EXECUTE_ITEM_KEY]
: !!dao.info.items[DAO_CORE_ALLOW_MEMO_ON_EXECUTE_ITEM_KEY]
const [memo, setMemo] = useState('')

const onExecute = useCallback(async () => {
Expand Down Expand Up @@ -144,9 +140,11 @@ export const useProposalActionState = ({

signingClientGetter = async () =>
await SigningCosmWasmClient.connectWithSigner(
getRpcForChainId(chainId),
getRpcForChainId(proposalModule.chainId),
signer,
makeGetSignerOptions(queryClient)(chainName)
makeGetSignerOptions(queryClient)(
proposalModule.dao.chain.chainName
)
)
} catch (err) {
console.error(
Expand Down Expand Up @@ -178,6 +176,17 @@ export const useProposalActionState = ({
),
})

plausible('daoProposalExecute', {
props: {
chainId: dao.chainId,
dao: dao.coreAddress,
walletAddress,
proposalModule: proposalModule.address,
proposalModuleType: proposalModule.contractName,
proposalNumber: proposalNumber,
},
})

await onExecuteSuccess()
} catch (err) {
console.error(err)
Expand All @@ -200,10 +209,10 @@ export const useProposalActionState = ({
onExecuteSuccess,
getOfflineSignerDirect,
getOfflineSigner,
chainId,
queryClient,
chainName,
t,
plausible,
dao,
])

const onClose = useCallback(async () => {
Expand All @@ -220,6 +229,17 @@ export const useProposalActionState = ({
sender: walletAddress,
})

plausible('daoProposalClose', {
props: {
chainId: dao.chainId,
dao: dao.coreAddress,
walletAddress,
proposalModule: proposalModule.address,
proposalModuleType: proposalModule.contractName,
proposalNumber: proposalNumber,
},
})

await onCloseSuccess()
} catch (err) {
console.error(err)
Expand All @@ -237,6 +257,8 @@ export const useProposalActionState = ({
getSigningClient,
walletAddress,
onCloseSuccess,
plausible,
dao,
])

const showRelayStatus =
Expand Down Expand Up @@ -269,8 +291,8 @@ export const useProposalActionState = ({
: statusKey === ProposalStatusEnum.Rejected &&
// Don't show for Neutron overrule proposals.
!(
chainId === ChainId.NeutronMainnet &&
coreAddress === NEUTRON_GOVERNANCE_DAO &&
dao.chainId === ChainId.NeutronMainnet &&
dao.coreAddress === NEUTRON_GOVERNANCE_DAO &&
proposalModule.prePropose?.type ===
PreProposeModuleType.NeutronOverruleSingle
)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { FlagOutlined, Timelapse } from '@mui/icons-material'
import { usePlausible } from 'next-plausible'
import { useFormContext } from 'react-hook-form'
import toast from 'react-hot-toast'
import { useTranslation } from 'react-i18next'
Expand All @@ -15,10 +16,13 @@ import {
NewProposalProps as StatelessNewProposalProps,
useActionsContext,
useCachedLoadable,
useChain,
useDao,
} from '@dao-dao/stateless'
import { BaseNewProposalProps, IProposalModuleBase } from '@dao-dao/types'
import {
BaseNewProposalProps,
IProposalModuleBase,
PlausibleEvents,
} from '@dao-dao/types'
import {
MAX_NUM_PROPOSAL_CHOICES,
convertExpirationToDate,
Expand Down Expand Up @@ -52,14 +56,13 @@ export const NewProposal = ({
...props
}: NewProposalProps) => {
const { t } = useTranslation()
const { chainId } = useChain()
const {
name: daoName,
imageUrl: daoImageUrl,
coreAddress,
info: { isActive, activeThreshold },
} = useDao()
const { isWalletConnecting, isWalletConnected, getStargateClient } =
const { address, isWalletConnecting, isWalletConnected, getStargateClient } =
useWallet()

const { watch } = useFormContext<NewProposalForm>()
Expand All @@ -73,7 +76,7 @@ export const NewProposal = ({
// re-renders.
const pauseInfo = useCachedLoadable(
DaoDaoCoreSelectors.pauseInfoSelector({
chainId,
chainId: proposalModule.chainId,
contractAddress: coreAddress,
params: [],
})
Expand All @@ -86,7 +89,7 @@ export const NewProposal = ({

const blocksPerYearLoadable = useRecoilValueLoadable(
blocksPerYearSelector({
chainId,
chainId: proposalModule.chainId,
})
)

Expand All @@ -98,10 +101,11 @@ export const NewProposal = ({
simulationBypassExpiration,
} = usePublishProposal()

const plausible = usePlausible<PlausibleEvents>()
const createProposal = useRecoilCallback(
({ snapshot }) =>
async (newProposalData: NewProposalData) => {
if (!isWalletConnected) {
if (!isWalletConnected || !address) {
toast.error(t('error.logInToContinue'))
return
}
Expand All @@ -122,6 +126,19 @@ export const NewProposal = ({
}
)

plausible('daoProposalCreate', {
props: {
chainId: proposalModule.chainId,
dao: proposalModule.dao.coreAddress,
walletAddress: address,
proposalModule: proposalModule.address,
proposalModuleType: proposalModule.contractName,
proposalNumber,
proposalId,
approval: false,
},
})

const proposalInfo = await makeGetProposalInfo({
chain: proposalModule.dao.chain,
coreAddress: proposalModule.dao.coreAddress,
Expand All @@ -141,7 +158,7 @@ export const NewProposal = ({
const proposal = (
await snapshot.getPromise(
DaoProposalMultipleSelectors.proposalSelector({
chainId,
chainId: proposalModule.chainId,
contractAddress: proposalModule.address,
params: [
{
Expand Down Expand Up @@ -204,12 +221,13 @@ export const NewProposal = ({
proposalModule,
blocksPerYearLoadable,
getStargateClient,
chainId,
processQ,
onCreateSuccess,
daoName,
coreAddress,
daoImageUrl,
plausible,
address,
]
)

Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
import { usePlausible } from 'next-plausible'
import { useCallback, useEffect, useState } from 'react'
import toast from 'react-hot-toast'

import { PlausibleEvents } from '@dao-dao/types'
import { MultipleChoiceVote } from '@dao-dao/types/contracts/DaoProposalMultiple'
import { processError } from '@dao-dao/utils'

Expand All @@ -18,6 +20,7 @@ export const useCastVote = (onSuccess?: () => void | Promise<void>) => {
address: walletAddress = '',
getSigningClient,
} = useWallet()
const plausible = usePlausible<PlausibleEvents>()

const [castingVote, setCastingVote] = useState(false)

Expand Down Expand Up @@ -49,6 +52,17 @@ export const useCastVote = (onSuccess?: () => void | Promise<void>) => {
sender: walletAddress,
})

plausible('daoProposalVote', {
props: {
chainId: proposalModule.chainId,
dao: proposalModule.dao.coreAddress,
walletAddress,
proposalModule: proposalModule.address,
proposalModuleType: proposalModule.contractName,
proposalNumber,
},
})

await onSuccess?.()
} catch (err) {
console.error(err)
Expand All @@ -67,6 +81,7 @@ export const useCastVote = (onSuccess?: () => void | Promise<void>) => {
getSigningClient,
walletAddress,
onSuccess,
plausible,
]
)

Expand Down
Loading

0 comments on commit 898f16f

Please sign in to comment.