Skip to content

Commit

Permalink
cleanup: remove unused posthog events
Browse files Browse the repository at this point in the history
  • Loading branch information
BrickheadJohnny committed Mar 5, 2025
1 parent 2941e9c commit 0b63311
Show file tree
Hide file tree
Showing 9 changed files with 20 additions and 134 deletions.
32 changes: 0 additions & 32 deletions src/components/[guild]/JoinModal/hooks/useMembershipUpdate.tsx
Original file line number Diff line number Diff line change
@@ -1,16 +1,12 @@
import { usePostHogContext } from "@/components/Providers/PostHogProvider"
import type { JoinJob } from "@guildxyz/types"
import useGuild from "components/[guild]/hooks/useGuild"
import useGuildPermission from "components/[guild]/hooks/useGuildPermission"
import useMembership from "components/explorer/hooks/useMembership"
import useCustomPosthogEvents from "hooks/useCustomPosthogEvents"
import { useFetcherWithSign } from "hooks/useFetcherWithSign"
import { useGetKeyForSWRWithOptionalAuth } from "hooks/useGetKeyForSWRWithOptionalAuth"
import useSubmit from "hooks/useSubmit"
import { UseSubmitOptions } from "hooks/useSubmit/types"
import { atom, useAtom } from "jotai"
import useUsersPoints from "rewards/Points/useUsersPoints"
import { getGuildPlatformsOfRoles } from "../utils/getGuildPlatformsOfRoles"
import { mapAccessJobState } from "../utils/mapAccessJobState"
import { useActiveMembershipUpdate } from "./useActiveMembershipUpdate"

Expand Down Expand Up @@ -50,16 +46,6 @@ const useMembershipUpdate = ({
const [currentlyCheckedRoleIds, setCurrentlyCheckedRoleIds] = useAtom(
currentlyCheckedRoleIdsAtom
)
const { captureEvent } = usePostHogContext()
const { rewardGranted } = useCustomPosthogEvents()
const posthogOptions = {
guild: guild.urlName,
}

const { roleIds: accessedRoleIds } = useMembership()
const accessedGuildPlatformIds = new Set(
getGuildPlatformsOfRoles(accessedRoleIds, guild).map(({ id }) => id)
)

const getKeyForSWRWithOptionalAuth = useGetKeyForSWRWithOptionalAuth()

Expand Down Expand Up @@ -95,23 +81,6 @@ const useMembershipUpdate = ({
correlationId: res.correlationId,
})

if (res?.updateMembershipResult?.newMembershipRoleIds?.length > 0) {
const grantedGuildPlatforms = getGuildPlatformsOfRoles(
res.updateMembershipResult.newMembershipRoleIds,
guild
)

const newGuildPlatforms = grantedGuildPlatforms.filter(
({ id }) => !accessedGuildPlatformIds.has(id)
)

if (newGuildPlatforms.length > 0) {
newGuildPlatforms.forEach((newGuildPlatform) => {
rewardGranted(newGuildPlatform.platformId)
})
}
}

if (res?.roleAccesses?.some((role) => !!role.access)) {
// mutate guild in case the user sees more entities due to visibilities
if (!isAdmin) guild.mutateGuild()
Expand All @@ -136,7 +105,6 @@ const useMembershipUpdate = ({
},
onError: (error) => {
setIsGettingJob(false)
captureEvent(`Guild join error`, { ...posthogOptions, error })
onError?.(error)
},
})
Expand Down
26 changes: 0 additions & 26 deletions src/components/[guild]/JoinModal/utils/getGuildPlatformsOfRoles.ts

This file was deleted.

5 changes: 0 additions & 5 deletions src/components/[guild]/forms/FillForm.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,12 @@ import Button from "components/common/Button"
import Card from "components/common/Card"
import FormErrorMessage from "components/common/FormErrorMessage"
import DynamicDevTool from "components/create-guild/DynamicDevTool"
import useCustomPosthogEvents from "hooks/useCustomPosthogEvents"
import useShowErrorToast from "hooks/useShowErrorToast"
import { useSubmitWithSign } from "hooks/useSubmit"
import useToast from "hooks/useToast"
import { useState } from "react"
import { Controller, FormProvider, UseFormProps, useForm } from "react-hook-form"
import { useUserFormSubmission } from "rewards/Forms/hooks/useFormSubmissions"
import { PlatformType } from "types"
import fetcher from "utils/fetcher"
import { useMembershipUpdate } from "../JoinModal/hooks/useMembershipUpdate"
import useGuild from "../hooks/useGuild"
Expand Down Expand Up @@ -49,8 +47,6 @@ const FillForm = ({ form, method = "POST", ...config }: Props) => {
const { mutate: mutateSubmission } = useUserFormSubmission(form)
const { triggerMembershipUpdate } = useMembershipUpdate()

const { rewardClaimed } = useCustomPosthogEvents()

const toast = useToast()
const showErrorToast = useShowErrorToast()
const { onSubmit, isLoading } = useSubmitWithSign(
Expand All @@ -64,7 +60,6 @@ const FillForm = ({ form, method = "POST", ...config }: Props) => {
),
{
onSuccess: (res) => {
rewardClaimed(PlatformType.FORM)
toast({
status: "success",
title: "Successfully submitted form",
Expand Down
36 changes: 15 additions & 21 deletions src/hooks/useCustomPosthogEvents.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,28 +24,22 @@ export default function useCustomPosthogEvents() {
})
},

rewardGranted(platformId: number) {
captureEvent("reward granted", {
platformName: PlatformType[platformId],
guild: urlName,
userId: id,
})
},

rewardClaimed(platformId: number) {
captureEvent("reward claimed", {
platformName: PlatformType[platformId],
guild: urlName,
userId: id,
...(platformId === PlatformType.CONTRACT_CALL
? {
$set: {
mintedReward: true,
mintedNFT: true,
},
}
: {}),
})
if (platformId === PlatformType.CONTRACT_CALL) {
captureEvent("reward claimed", {
platformName: PlatformType[platformId],
guild: urlName,
userId: id,
...(platformId === PlatformType.CONTRACT_CALL
? {
$set: {
mintedReward: true,
mintedNFT: true,
},
}
: {}),
})
}
},
} as const
}
8 changes: 0 additions & 8 deletions src/hooks/useSetKeyPair.ts
Original file line number Diff line number Diff line change
Expand Up @@ -180,14 +180,6 @@ const useSetKeyPair = (submitOptions?: UseSubmitOptions) => {
...submitOptions,
onError: (error) => {
console.error("setKeyPair error", error)
if (
error?.code !== RPC_INTERNAL_ERROR_CODE &&
error?.code !== "ACTION_REJECTED"
) {
const trace = error?.stack || new Error().stack
captureEvent(`Failed to set keypair`, { error, trace })
}

submitOptions?.onError?.(error)
},
onSuccess: () => {
Expand Down
4 changes: 0 additions & 4 deletions src/rewards/Gather/hooks/useClaimGather.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,10 @@ import { useDisclosure } from "@chakra-ui/react"
import useGuild from "components/[guild]/hooks/useGuild"
import useJsConfetti from "components/create-guild/hooks/useJsConfetti"
import { useClaimedReward } from "hooks/useClaimedReward"
import useCustomPosthogEvents from "hooks/useCustomPosthogEvents"
import useShowErrorToast from "hooks/useShowErrorToast"
import { SignedValidation, useSubmitWithSign } from "hooks/useSubmit"
import { useSWRConfig } from "swr"
import useSWRImmutable from "swr/immutable"
import { PlatformType } from "types"
import fetcher from "utils/fetcher"

type ClaimResponse = {
Expand All @@ -26,7 +24,6 @@ const useClaimGather = (rolePlatformId: number) => {

const triggerConfetti = useJsConfetti()
const showErrorToast = useShowErrorToast()
const { rewardClaimed } = useCustomPosthogEvents()

const endpoint = `/v2/guilds/${guildId}/roles/${roleId}/role-platforms/${rolePlatformId}/claim`
const { data: responseFromCache, mutate: mutateCachedResponse } = useSWRImmutable(
Expand All @@ -43,7 +40,6 @@ const useClaimGather = (rolePlatformId: number) => {
const { onSubmit: onClaimGatherSubmit, ...claim } =
useSubmitWithSign<ClaimResponse>(claimFetcher, {
onSuccess: (response) => {
rewardClaimed(PlatformType.GATHER_TOWN)
triggerConfetti()
/**
* Saving in SWR cache so we don't need to re-claim the reward if the user
Expand Down
13 changes: 1 addition & 12 deletions src/rewards/SecretText/hooks/useClaimText.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ import useGuild from "components/[guild]/hooks/useGuild"
import ErrorAlert from "components/common/ErrorAlert"
import { Modal } from "components/common/Modal"
import useJsConfetti from "components/create-guild/hooks/useJsConfetti"
import useCustomPosthogEvents from "hooks/useCustomPosthogEvents"
import useShowErrorToast from "hooks/useShowErrorToast"
import { SignedValidation, useSubmitWithSign } from "hooks/useSubmit"
import { PropsWithChildren } from "react"
Expand All @@ -33,21 +32,14 @@ type ClaimResponse = {
const useClaimText = (rolePlatformId: number) => {
const { cache } = useSWRConfig()
const { uniqueValue } = useClaimedReward(rolePlatformId)
const { rewardClaimed } = useCustomPosthogEvents()

const { isOpen, onOpen, onClose } = useDisclosure()

const { id: guildId, roles, mutateGuild, guildPlatforms } = useGuild()
const { id: guildId, roles, mutateGuild } = useGuild()
const roleId = roles.find((role) =>
role.rolePlatforms.some((rp) => rp.id === rolePlatformId)
)?.id

const guildPlatformId = roles
.find((role) => role.id === roleId)
?.rolePlatforms?.find(({ id }) => id === rolePlatformId)?.guildPlatformId

const guildPlatform = guildPlatforms.find(({ id }) => id === guildPlatformId)

const triggerConfetti = useJsConfetti()
const showErrorToast = useShowErrorToast()

Expand All @@ -67,9 +59,6 @@ const useClaimText = (rolePlatformId: number) => {
claimFetcher,
{
onSuccess: (response) => {
if (guildPlatform) {
rewardClaimed(guildPlatform.platformId)
}
triggerConfetti()
/**
* Saving in SWR cache so we don't need to re-claim the reward if the user
Expand Down
6 changes: 0 additions & 6 deletions src/rewards/Token/hooks/useCollectToken.tsx
Original file line number Diff line number Diff line change
@@ -1,13 +1,11 @@
import { usePostHogContext } from "@/components/Providers/PostHogProvider"
import useGuild from "components/[guild]/hooks/useGuild"
import useCustomPosthogEvents from "hooks/useCustomPosthogEvents"
import { useFetcherWithSign } from "hooks/useFetcherWithSign"
import useShowErrorToast from "hooks/useShowErrorToast"
import useSubmit from "hooks/useSubmit"
import { useToastWithShareButtons } from "hooks/useToastWithShareButtons"
import { useState } from "react"
import tokenRewardPoolAbi from "static/abis/tokenRewardPool"
import { PlatformType } from "types"
import { ERC20_CONTRACTS } from "utils/guildCheckout/constants"
import processViemContractError from "utils/processViemContractError"
import { TransactionReceipt, WriteContractParameters } from "viem"
Expand Down Expand Up @@ -41,7 +39,6 @@ const useCollectToken = (
const fetcherWithSign = useFetcherWithSign()
const publicClient = usePublicClient()
const { data: walletClient } = useWalletClient()
const { rewardClaimed } = useCustomPosthogEvents()

const collect = async () => {
setLoadingText("Getting signature...")
Expand All @@ -67,9 +64,6 @@ const useCollectToken = (
return
})
.then((res) => {
if (res) {
rewardClaimed(PlatformType.ERC20)
}
const data: ClaimResponse = res.data
// eslint-disable-next-line @typescript-eslint/naming-convention
const [_poolId, _rolePlatformId, _amount, _signedAt, _userId, _signature] =
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import { usePostHogContext } from "@/components/Providers/PostHogProvider"
import {
Accordion,
AccordionContent,
Expand Down Expand Up @@ -70,7 +69,6 @@ const ConnectFarcasterButton = ({
children,
...props
}: ButtonProps & { onSuccess?: () => void; isReconnection?: boolean }) => {
const { captureEvent } = usePostHogContext()
const { farcasterProfiles, id: userId, mutate } = useUser()
const { isOpen, onOpen, onClose } = useDisclosure()
const { toast } = useToast()
Expand All @@ -80,7 +78,6 @@ const ConnectFarcasterButton = ({
const getKeyForSWRWithOptionalAuth = useGetKeyForSWRWithOptionalAuth()

const onApprove = () => {
captureEvent("[farcaster] request approved")
onClose()
toast({
variant: "success",
Expand Down Expand Up @@ -163,13 +160,10 @@ const ConnectFarcasterButton = ({

useEffect(() => {
if (seconds > 0) return

captureEvent("[farcaster] deadline hit")
onRegenerate()
}, [seconds, resetCountdown, captureEvent, onRegenerate])
}, [seconds, resetCountdown, onRegenerate])

const handleOnClose = () => {
captureEvent("[farcaster] connect modal closed")
stop()
signedKeyRequest.reset()
if (pollInterval) {
Expand All @@ -186,10 +180,7 @@ const ConnectFarcasterButton = ({
return (
<>
<Button
onClick={() => {
captureEvent("[farcaster] connect button clicked")
signedKeyRequest.onSubmit()
}}
onClick={() => signedKeyRequest.onSubmit()}
size="sm"
disabled={farcasterProfiles?.length > 0}
isLoading={signedKeyRequest.isLoading}
Expand Down Expand Up @@ -258,10 +249,7 @@ const ConnectFarcasterButton = ({
disabled={!shouldEnableRegenerateButton}
isLoading={signedKeyRequest.isLoading}
aria-label="Regenerate Farcaster QR code"
onClick={() => {
captureEvent("[farcaster] manual qr regeneration")
onRegenerate()
}}
onClick={() => onRegenerate()}
icon={<ArrowCounterClockwise weight="bold" />}
/>
</TooltipTrigger>
Expand Down Expand Up @@ -321,7 +309,6 @@ const ConnectFarcasterButton = ({
}

const DisconnectFarcasterButton = () => {
const { captureEvent } = usePostHogContext()
const disclosure = useDisclosure()
const { farcasterProfiles, id, mutate } = useUser()
const fetcherWithSign = useFetcherWithSign()
Expand Down Expand Up @@ -352,10 +339,7 @@ const DisconnectFarcasterButton = () => {
},
}
)
const onConfirm = () => {
captureEvent("[farcaster] disconnect button clicked")
onSubmit(farcasterProfiles?.[0]?.fid)
}
const onConfirm = () => onSubmit(farcasterProfiles?.[0]?.fid)

return (
<DisconnectAccountButton
Expand Down

0 comments on commit 0b63311

Please sign in to comment.