remove activityCenter from provider.tsx

This commit is contained in:
Felicio Mununga 2022-08-24 14:16:34 +02:00
parent 373a8beae2
commit 2457c43bbe
No known key found for this signature in database
GPG Key ID: 0EB8D75C775AB6F1
2 changed files with 6 additions and 18 deletions

View File

@ -4,20 +4,13 @@ import { createClient } from '@status-im/js'
import { Loading } from '../components/loading' import { Loading } from '../components/loading'
import type { import type { Account, Client, ClientOptions, Community } from '@status-im/js'
Account,
ActivityCenter,
Client,
ClientOptions,
Community,
} from '@status-im/js'
const Context = createContext<State | undefined>(undefined) const Context = createContext<State | undefined>(undefined)
type State = { type State = {
loading: boolean loading: boolean
client: Client | undefined client: Client | undefined
activityCenter: ActivityCenter | undefined
community: Community['description'] | undefined community: Community['description'] | undefined
account: Account | undefined account: Account | undefined
dispatch?: React.Dispatch<Action> dispatch?: React.Dispatch<Action>
@ -42,7 +35,6 @@ const reducer = (state: State, action: Action): State => {
...state, ...state,
loading: false, loading: false,
client, client,
activityCenter: client.activityCenter,
community: client.community.description, community: client.community.description,
} }
} }
@ -64,7 +56,6 @@ export const ProtocolProvider = (props: Props) => {
const [state, dispatch] = useReducer(reducer, { const [state, dispatch] = useReducer(reducer, {
loading: true, loading: true,
client: undefined, client: undefined,
activityCenter: undefined,
community: undefined, community: undefined,
account: undefined, account: undefined,
dispatch: undefined, dispatch: undefined,
@ -112,7 +103,6 @@ export function useProtocol() {
// we enforce initialization of client before rendering children // we enforce initialization of client before rendering children
return context as State & { return context as State & {
client: Client client: Client
activityCenter: ActivityCenter
community: Community['description'] community: Community['description']
dispatch: React.Dispatch<Action> dispatch: React.Dispatch<Action>
} }

View File

@ -5,25 +5,23 @@ import { useProtocol } from './provider'
import type { ActivityCenterLatest } from '@status-im/js' import type { ActivityCenterLatest } from '@status-im/js'
export const useActivityCenter = () => { export const useActivityCenter = () => {
const { activityCenter } = useProtocol() const { client } = useProtocol()
const [latest, setData] = useState<ActivityCenterLatest>(() => const [latest, setData] = useState<ActivityCenterLatest>(() =>
activityCenter.getLatest() client.activityCenter.getLatest()
) )
useEffect(() => { useEffect(() => {
setData(activityCenter.getLatest()) setData(client.activityCenter.getLatest())
const handleUpdate = (latest: ActivityCenterLatest) => { const handleUpdate = (latest: ActivityCenterLatest) => {
setData(latest) setData(latest)
} }
return activityCenter.onChange(handleUpdate) return client.activityCenter.onChange(handleUpdate)
// todo?: add latest.unreadChats and latest.notifications, will it render unnecessarily }, [client.activityCenter])
}, [activityCenter])
return { return {
activityCenter,
unreadChats: latest.unreadChats, unreadChats: latest.unreadChats,
} }
} }