import { createContext , ReactChild , ReactElement , useEffect , useState } from 'react' ; export type IdentityType = 'V3' | 'PRIVATE_KEY' ; export interface Identity { uuid : string ; name : string ; feedHash ? : string ; identity : string ; address : string ; type : IdentityType ; } interface ContextInterface { identities : Identity [ ] ; setIdentities : ( identities : Identity [ ] ) => void ; } const initialValues = { identities : [ ] , setIdentities : ( ) => { } , } ; export const Context = createContext < ContextInterface > ( initialValues ) ; export const Consumer = Context . Consumer ; interface Props { children : ReactChild ; } export function Provider ( { children } ) { const [ identities , setIdentities ] = useState < Identity [ ] > ( initialValues . identities ) ; useEffect ( ( ) => { try { setIdentities ( JSON . parse ( localStorage . getItem ( 'feeds' ) || '[]' ) ) ; } catch { setIdentities ( [ ] ) ; } } , [ ] ) ; return < Context . Provider value = { { identities , setIdentities } } > { children } < /Context.Provider>; }