feat(react): add static protocol layer base

This commit is contained in:
Pavel Prichodko 2022-04-11 21:05:08 +02:00
parent 5c0f785b2d
commit bbd2f19b89
No known key found for this signature in database
GPG Key ID: 0EB8D75C775AB6F1
8 changed files with 120 additions and 0 deletions

View File

@ -0,0 +1,37 @@
import React, { createContext, useContext, useMemo } from 'react'
import type { Config } from '~/src/types/config'
// import { createClient } from '@status-im/core'
// import type { Client } from '@status-im/core'
interface ClientContext {
client: Config
}
const Context = createContext<ClientContext | undefined>(undefined)
export function useClient() {
const context = useContext(Context)
if (!context) {
throw new Error(`useClient must be used within a ClientProvider`)
}
return context
}
interface ClientProviderProps {
config: Config
children: React.ReactNode
}
export const ClientProvider = (props: ClientProviderProps) => {
const { config, children } = props
const client = useMemo(() => {
// return createClient({ ...config })
return { client: config }
}, [config])
return <Context.Provider value={client}>{children}</Context.Provider>
}

View File

@ -0,0 +1,5 @@
import { useClient } from './provider'
export const useChannels = () => {
const client = useClient()
}

View File

@ -0,0 +1,16 @@
interface Chat {
type: 'channel' | 'group-chat' | 'chat'
}
const chats: Record<string, Chat> = {
welcome: { type: 'channel' },
general: { type: 'channel' },
random: { type: 'channel' },
'vitalik.eth': { type: 'chat' },
'pvl.eth': { type: 'chat' },
'Climate Change': { type: 'group-chat' },
}
export const useChat = (id: string) => {
return chats[id]
}

View File

@ -0,0 +1,9 @@
import { useClient } from './provider'
interface Chat {
type: 'channel' | 'group-chat' | 'chat'
}
export const useChats = (id: string) => {
const client = useClient()
}

View File

@ -0,0 +1,11 @@
export const useCommunity = () => {
return {
name: 'CryptoKitties',
description: 'A community of cat lovers, meow!',
publicKey: '0x2Ef1907d50926...6cEbd975aC5E0Ba',
imageUrl:
'https://images.unsplash.com/photo-1592194996308-7b43878e84a6?ixlib=rb-1.2.1&ixid=MnwxMjA3fDB8MHxwaG90by1wYWdlfHx8fGVufDB8fHx8&auto=format&fit=crop&w=987&q=80',
membersCount: 182,
requestNeeded: true,
}
}

View File

@ -0,0 +1,3 @@
export const useContacts = () => {
return []
}

View File

@ -0,0 +1,31 @@
import { useEffect, useRef, useState } from 'react'
import { useClient } from './provider'
interface State {
fetching: boolean
stale: boolean
data?: any
error?: Error
}
export const useMembers = (): State => {
const isMounted = useRef(true)
const client = useClient()
const [state, setState] = useState<State>({
fetching: false,
stale: false,
data: undefined,
error: undefined,
})
useEffect(() => {
isMounted.current = true
return () => {
isMounted.current = false
}
}, [])
return state
}

View File

@ -0,0 +1,8 @@
export const useProfile = () => {
return {
name: 'Satoshi',
publicKey: '71C7656EC7ab88b098defB751B7401B5f6d8976F',
imageUrl:
'https://images.unsplash.com/photo-1546776310-eef45dd6d63c?ixlib=rb-1.2.1&ixid=MnwxMjA3fDB8MHxwaG90by1wYWdlfHx8fGVufDB8fHx8&auto=format&fit=crop&w=1620&q=80',
}
}