fix: always set rpc to newly provided value in desktop (#591)
* fix: always set rpc to newly provided value in desktop * fix: always set new rpc and restart node * fix: disable version check in desktop mode * fix: only set rpc in desktop when in light mode * refactor: simplify code
This commit is contained in:
+2
-2
@@ -1,7 +1,7 @@
|
||||
import CssBaseline from '@material-ui/core/CssBaseline'
|
||||
import { ThemeProvider } from '@material-ui/core/styles'
|
||||
import { SnackbarProvider } from 'notistack'
|
||||
import React, { ReactElement } from 'react'
|
||||
import { ReactElement } from 'react'
|
||||
import { HashRouter as Router } from 'react-router-dom'
|
||||
import './App.css'
|
||||
import Dashboard from './layout/Dashboard'
|
||||
@@ -47,7 +47,7 @@ const App = ({
|
||||
desktopUrl={desktopUrl}
|
||||
>
|
||||
<TopUpProvider>
|
||||
<BeeProvider>
|
||||
<BeeProvider isDesktop={isDesktop}>
|
||||
<BalanceProvider>
|
||||
<StampsProvider>
|
||||
<FileProvider>
|
||||
|
||||
@@ -1,12 +1,11 @@
|
||||
import CircularProgress from '@material-ui/core/CircularProgress'
|
||||
import { useSnackbar } from 'notistack'
|
||||
import { ReactElement, useContext } from 'react'
|
||||
import ExpandableList from '../../components/ExpandableList'
|
||||
import ExpandableListItemInput from '../../components/ExpandableListItemInput'
|
||||
import { Context as BeeContext } from '../../providers/Bee'
|
||||
import { Context as SettingsContext } from '../../providers/Settings'
|
||||
import { useSnackbar } from 'notistack'
|
||||
import { restartBeeNode, setJsonRpcInDesktop } from '../../utils/desktop'
|
||||
import { BeeModes } from '@ethersphere/bee-js'
|
||||
import { getDesktopConfiguration, restartBeeNode, setJsonRpcInDesktop } from '../../utils/desktop'
|
||||
|
||||
export default function SettingsPage(): ReactElement {
|
||||
const {
|
||||
@@ -24,17 +23,17 @@ export default function SettingsPage(): ReactElement {
|
||||
desktopUrl,
|
||||
setAndPersistJsonRpcProvider,
|
||||
} = useContext(SettingsContext)
|
||||
const { refresh, nodeInfo } = useContext(BeeContext)
|
||||
const { refresh } = useContext(BeeContext)
|
||||
const { enqueueSnackbar, closeSnackbar } = useSnackbar()
|
||||
|
||||
async function handleSetRpcUrl(value: string) {
|
||||
try {
|
||||
setAndPersistJsonRpcProvider(value)
|
||||
|
||||
// We can't set the RPC URL to the `swap-endpoint` Bee config value unless the Bee node is already in
|
||||
// light mode as setting this config value, basically upgrades the node to light mode.
|
||||
if (isDesktop && nodeInfo?.beeMode === BeeModes.LIGHT) {
|
||||
await setJsonRpcInDesktop(desktopUrl, rpcProviderUrl)
|
||||
const shouldUpdateDesktop = isDesktop && (await getDesktopConfiguration(desktopUrl))['swap-endpoint']
|
||||
|
||||
if (shouldUpdateDesktop) {
|
||||
await setJsonRpcInDesktop(desktopUrl, value)
|
||||
const snackKey = enqueueSnackbar('RPC endpoint successfully changed, restarting Bee node...', {
|
||||
variant: 'success',
|
||||
})
|
||||
@@ -48,7 +47,7 @@ export default function SettingsPage(): ReactElement {
|
||||
await refresh()
|
||||
} catch (e) {
|
||||
console.error(e) //eslint-disable-line
|
||||
enqueueSnackbar(`Failed to change RPC endpoint. Error: ${e}`, { variant: 'error' })
|
||||
enqueueSnackbar(`Failed to change RPC endpoint. ${e}`, { variant: 'error' })
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
+12
-2
@@ -127,11 +127,12 @@ function getStatus(
|
||||
chequebookAddress: ChequebookAddressResponse | null,
|
||||
chequebookBalance: ChequebookBalance | null,
|
||||
error: Error | null,
|
||||
isDesktop: boolean,
|
||||
): Status {
|
||||
const status: Status = { ...initialValues.status }
|
||||
|
||||
// Version check
|
||||
status.version.isEnabled = true
|
||||
status.version.isEnabled = !isDesktop
|
||||
status.version.checkState =
|
||||
debugApiHealth &&
|
||||
semver.satisfies(debugApiHealth.version, PackageJson.engines.bee, {
|
||||
@@ -194,7 +195,15 @@ function determineOverallStatus(debugApiHealth: Health | null, debugApiReadiness
|
||||
// This does not need to be exposed and works much better as variable than state variable which may trigger some unnecessary re-renders
|
||||
let isRefreshing = false
|
||||
|
||||
export function Provider({ children }: Props): ReactElement {
|
||||
interface InitialSettings {
|
||||
isDesktop?: boolean
|
||||
}
|
||||
|
||||
interface Props extends InitialSettings {
|
||||
children: ReactChild
|
||||
}
|
||||
|
||||
export function Provider({ children, isDesktop }: Props): ReactElement {
|
||||
const { beeApi, beeDebugApi } = useContext(SettingsContext)
|
||||
const [apiHealth, setApiHealth] = useState<boolean>(false)
|
||||
const [debugApiHealth, setDebugApiHealth] = useState<Health | null>(null)
|
||||
@@ -403,6 +412,7 @@ export function Provider({ children }: Props): ReactElement {
|
||||
chequebookAddress,
|
||||
chequebookBalance,
|
||||
error,
|
||||
Boolean(isDesktop),
|
||||
)
|
||||
|
||||
useEffect(() => {
|
||||
|
||||
Reference in New Issue
Block a user