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 CssBaseline from '@material-ui/core/CssBaseline'
|
||||||
import { ThemeProvider } from '@material-ui/core/styles'
|
import { ThemeProvider } from '@material-ui/core/styles'
|
||||||
import { SnackbarProvider } from 'notistack'
|
import { SnackbarProvider } from 'notistack'
|
||||||
import React, { ReactElement } from 'react'
|
import { ReactElement } from 'react'
|
||||||
import { HashRouter as Router } from 'react-router-dom'
|
import { HashRouter as Router } from 'react-router-dom'
|
||||||
import './App.css'
|
import './App.css'
|
||||||
import Dashboard from './layout/Dashboard'
|
import Dashboard from './layout/Dashboard'
|
||||||
@@ -47,7 +47,7 @@ const App = ({
|
|||||||
desktopUrl={desktopUrl}
|
desktopUrl={desktopUrl}
|
||||||
>
|
>
|
||||||
<TopUpProvider>
|
<TopUpProvider>
|
||||||
<BeeProvider>
|
<BeeProvider isDesktop={isDesktop}>
|
||||||
<BalanceProvider>
|
<BalanceProvider>
|
||||||
<StampsProvider>
|
<StampsProvider>
|
||||||
<FileProvider>
|
<FileProvider>
|
||||||
|
|||||||
@@ -1,12 +1,11 @@
|
|||||||
import CircularProgress from '@material-ui/core/CircularProgress'
|
import CircularProgress from '@material-ui/core/CircularProgress'
|
||||||
|
import { useSnackbar } from 'notistack'
|
||||||
import { ReactElement, useContext } from 'react'
|
import { ReactElement, useContext } from 'react'
|
||||||
import ExpandableList from '../../components/ExpandableList'
|
import ExpandableList from '../../components/ExpandableList'
|
||||||
import ExpandableListItemInput from '../../components/ExpandableListItemInput'
|
import ExpandableListItemInput from '../../components/ExpandableListItemInput'
|
||||||
import { Context as BeeContext } from '../../providers/Bee'
|
import { Context as BeeContext } from '../../providers/Bee'
|
||||||
import { Context as SettingsContext } from '../../providers/Settings'
|
import { Context as SettingsContext } from '../../providers/Settings'
|
||||||
import { useSnackbar } from 'notistack'
|
import { getDesktopConfiguration, restartBeeNode, setJsonRpcInDesktop } from '../../utils/desktop'
|
||||||
import { restartBeeNode, setJsonRpcInDesktop } from '../../utils/desktop'
|
|
||||||
import { BeeModes } from '@ethersphere/bee-js'
|
|
||||||
|
|
||||||
export default function SettingsPage(): ReactElement {
|
export default function SettingsPage(): ReactElement {
|
||||||
const {
|
const {
|
||||||
@@ -24,17 +23,17 @@ export default function SettingsPage(): ReactElement {
|
|||||||
desktopUrl,
|
desktopUrl,
|
||||||
setAndPersistJsonRpcProvider,
|
setAndPersistJsonRpcProvider,
|
||||||
} = useContext(SettingsContext)
|
} = useContext(SettingsContext)
|
||||||
const { refresh, nodeInfo } = useContext(BeeContext)
|
const { refresh } = useContext(BeeContext)
|
||||||
const { enqueueSnackbar, closeSnackbar } = useSnackbar()
|
const { enqueueSnackbar, closeSnackbar } = useSnackbar()
|
||||||
|
|
||||||
async function handleSetRpcUrl(value: string) {
|
async function handleSetRpcUrl(value: string) {
|
||||||
try {
|
try {
|
||||||
setAndPersistJsonRpcProvider(value)
|
setAndPersistJsonRpcProvider(value)
|
||||||
|
|
||||||
// We can't set the RPC URL to the `swap-endpoint` Bee config value unless the Bee node is already in
|
const shouldUpdateDesktop = isDesktop && (await getDesktopConfiguration(desktopUrl))['swap-endpoint']
|
||||||
// light mode as setting this config value, basically upgrades the node to light mode.
|
|
||||||
if (isDesktop && nodeInfo?.beeMode === BeeModes.LIGHT) {
|
if (shouldUpdateDesktop) {
|
||||||
await setJsonRpcInDesktop(desktopUrl, rpcProviderUrl)
|
await setJsonRpcInDesktop(desktopUrl, value)
|
||||||
const snackKey = enqueueSnackbar('RPC endpoint successfully changed, restarting Bee node...', {
|
const snackKey = enqueueSnackbar('RPC endpoint successfully changed, restarting Bee node...', {
|
||||||
variant: 'success',
|
variant: 'success',
|
||||||
})
|
})
|
||||||
@@ -48,7 +47,7 @@ export default function SettingsPage(): ReactElement {
|
|||||||
await refresh()
|
await refresh()
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
console.error(e) //eslint-disable-line
|
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,
|
chequebookAddress: ChequebookAddressResponse | null,
|
||||||
chequebookBalance: ChequebookBalance | null,
|
chequebookBalance: ChequebookBalance | null,
|
||||||
error: Error | null,
|
error: Error | null,
|
||||||
|
isDesktop: boolean,
|
||||||
): Status {
|
): Status {
|
||||||
const status: Status = { ...initialValues.status }
|
const status: Status = { ...initialValues.status }
|
||||||
|
|
||||||
// Version check
|
// Version check
|
||||||
status.version.isEnabled = true
|
status.version.isEnabled = !isDesktop
|
||||||
status.version.checkState =
|
status.version.checkState =
|
||||||
debugApiHealth &&
|
debugApiHealth &&
|
||||||
semver.satisfies(debugApiHealth.version, PackageJson.engines.bee, {
|
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
|
// 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
|
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 { beeApi, beeDebugApi } = useContext(SettingsContext)
|
||||||
const [apiHealth, setApiHealth] = useState<boolean>(false)
|
const [apiHealth, setApiHealth] = useState<boolean>(false)
|
||||||
const [debugApiHealth, setDebugApiHealth] = useState<Health | null>(null)
|
const [debugApiHealth, setDebugApiHealth] = useState<Health | null>(null)
|
||||||
@@ -403,6 +412,7 @@ export function Provider({ children }: Props): ReactElement {
|
|||||||
chequebookAddress,
|
chequebookAddress,
|
||||||
chequebookBalance,
|
chequebookBalance,
|
||||||
error,
|
error,
|
||||||
|
Boolean(isDesktop),
|
||||||
)
|
)
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
|
|||||||
Reference in New Issue
Block a user