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

View File

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