add protocol provider

This commit is contained in:
Pavel Prichodko 2022-06-10 14:16:06 +02:00 committed by Felicio Mununga
parent 5b7c3cbb5a
commit f72476e248
No known key found for this signature in database
GPG Key ID: 0EB8D75C775AB6F1
1 changed files with 15 additions and 13 deletions

View File

@ -1,15 +1,17 @@
import React, { import React, {
useEffect,
createContext, createContext,
useContext, useContext,
useEffect,
useMemo, useMemo,
useState, useState,
} from 'react' } from 'react'
import type { Config } from '~/src/types/config'
import {Loading} from '~/src/components/loading'
import { createClient } from '@status-im/js' import { createClient } from '@status-im/js'
import type { Client, ClientOptions, Community , Account} from '@status-im/js'
import { Loading } from '~/src/components/loading'
import type { Account, Client, ClientOptions, Community } from '@status-im/js'
import type { Config } from '~/src/types/config'
const Context = createContext<Client | undefined>(undefined) const Context = createContext<Client | undefined>(undefined)
const CommunityContext = createContext< const CommunityContext = createContext<
@ -58,11 +60,12 @@ export const ClientProvider = (props: ClientProviderProps) => {
const loadClient = async () => { const loadClient = async () => {
// setLoading(true) // setLoading(true)
const client = await createClient({ publicKey: props.options.publicKey }) const client = await createClient({ publicKey: props.options.publicKey })
console.log('starting')
await client.start()
console.log('init', client) console.log('init', client)
setCommunity(client.community.communityMetadata) setCommunity(client.community.communityMetadata)
console.log("file: provider.tsx > line 64 > loadClient > client.community.communityMetadata", client.community.communityMetadata) console.log(
'file: provider.tsx > line 64 > loadClient > client.community.communityMetadata',
client.community.communityMetadata
)
setClient(client) setClient(client)
setLoading(false) setLoading(false)
@ -76,7 +79,10 @@ console.log('starting')
console.log('useEffect subscribe') console.log('useEffect subscribe')
return client.community.onCommunityUpdate(community => { return client.community.onCommunityUpdate(community => {
setCommunity(community) setCommunity(community)
console.log("file: provider.tsx > line 75 > useEffect > community", community) console.log(
'file: provider.tsx > line 75 > useEffect > community',
community
)
}) })
} }
}, [client]) }, [client])
@ -88,11 +94,7 @@ console.log('starting')
return ( return (
<Context.Provider value={client}> <Context.Provider value={client}>
<CommunityContext.Provider value={community}> <CommunityContext.Provider value={community}>
{loading ? ( {loading ? <Loading /> : children}
<Loading />
) : (
children
)}
</CommunityContext.Provider> </CommunityContext.Provider>
</Context.Provider> </Context.Provider>
) )