feat: pass isBeeDesktop as Bee Dashboard component property (#510)

* feat: pass isBeeDesktop as Bee Dashboard component property

* chore: remove console log
This commit is contained in:
Vojtech Simetka
2022-08-02 09:53:50 +02:00
committed by GitHub
parent 72488fd5a3
commit 4c48657fca
13 changed files with 72 additions and 59 deletions
+10 -3
View File
@@ -1,6 +1,6 @@
import { Bee, BeeDebug } from '@ethersphere/bee-js'
import { providers } from 'ethers'
import { createContext, ReactChild, ReactElement, useEffect, useState } from 'react'
import { createContext, ReactNode, ReactElement, useEffect, useState } from 'react'
import { config as appConfig } from '../config'
import { useGetBeeConfig } from '../hooks/apiHooks'
import { restartBeeNode, setJsonRpcInDesktop } from '../utils/desktop'
@@ -26,6 +26,7 @@ interface ContextInterface {
setApiUrl: (url: string) => void
setDebugApiUrl: (url: string) => void
setAndPersistJsonRpcProvider: (url: string) => Promise<void>
isBeeDesktop: boolean
isLoading: boolean
error: Error | null
}
@@ -45,6 +46,7 @@ const initialValues: ContextInterface = {
cors: null,
dataDir: null,
ensResolver: null,
isBeeDesktop: false,
isLoading: true,
error: null,
}
@@ -53,10 +55,11 @@ export const Context = createContext<ContextInterface>(initialValues)
export const Consumer = Context.Consumer
interface Props {
children: ReactChild
children: ReactNode
beeApiUrl?: string
beeDebugApiUrl?: string
lockedApiSettings?: boolean
isBeeDesktop?: boolean
}
export function Provider({
@@ -64,6 +67,7 @@ export function Provider({
beeApiUrl,
beeDebugApiUrl,
lockedApiSettings: extLockedApiSettings,
isBeeDesktop: extIsBeeDesktop,
}: Props): ReactElement {
const [apiUrl, setApiUrl] = useState<string>(initialValues.apiUrl)
const [apiDebugUrl, setDebugApiUrl] = useState<string>(initialValues.apiDebugUrl)
@@ -74,13 +78,15 @@ export function Provider({
const [provider, setProvider] = useState(initialValues.provider)
const { config, isLoading, error } = useGetBeeConfig()
const isBeeDesktop = Boolean(extIsBeeDesktop ?? appConfig.BEE_DESKTOP_ENABLED)
async function setAndPersistJsonRpcProvider(providerUrl: string) {
try {
localStorage.setItem(LocalStorageKeys.providerUrl, providerUrl)
setProviderUrl(providerUrl)
setProvider(new providers.JsonRpcProvider(providerUrl))
if (appConfig.BEE_DESKTOP_ENABLED) {
if (isBeeDesktop) {
await setJsonRpcInDesktop(providerUrl)
await restartBeeNode()
}
@@ -146,6 +152,7 @@ export function Provider({
dataDir: config?.['data-dir'] ?? null,
ensResolver: config?.['resolver-options'] ?? null,
setAndPersistJsonRpcProvider,
isBeeDesktop,
isLoading,
error,
}}