Skip to content

Commit

Permalink
fix: posthog is initialized twice
Browse files Browse the repository at this point in the history
  • Loading branch information
L03TJ3 committed Jan 9, 2024
1 parent 7c81308 commit c3f585e
Show file tree
Hide file tree
Showing 5 changed files with 14 additions and 42 deletions.
18 changes: 5 additions & 13 deletions src/components/common/dialogs/CustomDialog.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ import { useDialog } from '../../../lib/dialog/useDialog'
import CustomButton from '../buttons/CustomButton'
import ErrorAnimation from '../../common/animations/Error'

import { CustomPostHogProvider } from '../../../lib/contexts/CustomPosthogProvider'
import SuccessIcon from '../modal/SuccessIcon'
import LoadingIcon from '../modal/LoadingIcon'
import { InfoIcon } from '../modal/InfoIcon'
Expand All @@ -20,7 +19,6 @@ import Section from '../layout/Section'
import { GlobalTogglesContext } from '../../../lib/contexts/togglesContext'
import { DialogContext } from '../../../lib/dialog/dialogContext'
import { GoodWalletContext } from '../../../lib/wallet/GoodWalletProvider'
import Config from '../../../config/config'

export type DialogButtonProps = { color?: string, mode?: string, onPress?: Function => void, text: string, style?: any }
export type DialogProps = {
Expand Down Expand Up @@ -137,17 +135,11 @@ const CustomDialog = ({
// https://github.com/callstack/react-native-paper/blob/main/src/components/Portal/Portal.tsx#L54
// otherwise useContext(GlobalTogglesContext) will return undefined for
// any custom dialog component (e.g. ExplanationDialog and other ones)
<CustomPostHogProvider
apiKey={Config.posthogApiKey}
options={{ host: Config.posthogHost }}
autocapture={false}
>
<GlobalTogglesContext.Provider value={globalToggleState}>
<GoodWalletContext.Provider value={goodWalletState}>
<DialogContext.Provider value={dialogState}>{content}</DialogContext.Provider>
</GoodWalletContext.Provider>
</GlobalTogglesContext.Provider>
</CustomPostHogProvider>
<GlobalTogglesContext.Provider value={globalToggleState}>
<GoodWalletContext.Provider value={goodWalletState}>
<DialogContext.Provider value={dialogState}>{content}</DialogContext.Provider>
</GoodWalletContext.Provider>
</GlobalTogglesContext.Provider>
) : (
<>
{children}
Expand Down
9 changes: 2 additions & 7 deletions src/components/common/dialogs/TaskDialog.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import React, { useMemo } from 'react'
import React from 'react'
import { Platform, View } from 'react-native'
import { usePostHog } from 'posthog-react-native'

import TaskButton from '../../common/buttons/TaskButton'
import { Section, Text } from '../../common'
Expand Down Expand Up @@ -102,11 +101,7 @@ const dialogStyles = ({ theme }) => ({
},
})

const TaskDialog = ({ styles, theme }) => {
const posthog = usePostHog()
const payload = useMemo(() => (posthog ? posthog.getFeatureFlagPayload('next-tasks') : []), [posthog])
const { tasks } = payload || {}

const TaskDialog = ({ styles, theme, tasks }) => {
return (
<View>
{tasks
Expand Down
7 changes: 6 additions & 1 deletion src/components/dashboard/Claim.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import moment from 'moment'
import { assign, noop } from 'lodash'
import { t, Trans } from '@lingui/macro'

import { usePostHog } from 'posthog-react-native'
import AsyncStorage from '../../lib/utils/asyncStorage'
import { retry } from '../../lib/utils/async'

Expand Down Expand Up @@ -257,6 +258,10 @@ const Claim = props => {
const advanceClaimsCounter = useClaimCounter()
const [, , collectInviteBounty] = useInviteBonus()

const posthog = usePostHog()
const taskPayload = useMemo(() => (posthog ? posthog.getFeatureFlagPayload('next-tasks') : []), [posthog])
const { tasks } = taskPayload || {}

// format number of people who did claim today
const formattedNumberOfPeopleClaimedToday = useMemo(() => formatWithSIPrefix(peopleClaimed), [peopleClaimed])

Expand Down Expand Up @@ -496,7 +501,7 @@ const Claim = props => {

await showDialog({
image: <LoadingAnimation success speed={2} />,
content: <TaskDialog />,
content: <TaskDialog tasks={tasks} />,
title: t`You've claimed today!`,
titleStyle: { paddingTop: 0, marginTop: 0, minHeight: 'auto' },
onDismiss: noop,
Expand Down
20 changes: 0 additions & 20 deletions src/lib/contexts/CustomPosthogProvider.js

This file was deleted.

2 changes: 1 addition & 1 deletion src/lib/notifications/hooks/useNotifications.native.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ const { notificationTime, notificationSchedule } = Config
let bridge = null

const NOTIFICATION = {
title: "It's that time of the day 💸 💙",
title: "It's claim time! 💙",
message: 'Claim your free GoodDollars now. It takes 10 seconds.',
}

Expand Down

0 comments on commit c3f585e

Please sign in to comment.