Skip to content

Commit

Permalink
Fix: change screen (#203)
Browse files Browse the repository at this point in the history
  • Loading branch information
rickimoore authored Aug 16, 2023
1 parent 6a08be8 commit 5b1341e
Show file tree
Hide file tree
Showing 9 changed files with 52 additions and 6 deletions.
3 changes: 3 additions & 0 deletions src/App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import 'react-toastify/dist/ReactToastify.min.css'
import 'rodal/lib/rodal.css'
import SSELogProvider from './components/SSELogProvider/SSELogProvider'
import SyncPollingWrapper from './wrappers/SyncPollingWrapper'
import ChangeScreen from './views/ChangeScreen'

function App() {
const view = useRecoilValue(appView)
Expand All @@ -26,6 +27,8 @@ function App() {
)
case AppView.ONBOARD:
return <Onboard />
case AppView.CHANGE_SCREEN:
return <ChangeScreen />
default:
return <InitScreen />
}
Expand Down
2 changes: 1 addition & 1 deletion src/components/DeviceSelect/DeviceSelect.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ const DeviceSelect: FC<DeviceSelectProps> = ({ devices, value, uiMode, type }) =
const select = (selection: string) => {
if (devices?.[selection]) {
setDeviceKey(selection)
setAppView(AppView.INIT)
setAppView(AppView.CHANGE_SCREEN)
}
}
const toggleDropdown = () => toggle((prevState) => !prevState)
Expand Down
6 changes: 6 additions & 0 deletions src/components/StepChart/StepChart.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -139,6 +139,12 @@ const StepChart: FC<StepChartProps> = ({ data, stepSize, onClick, className }) =
}
}, [chartEl, data, hasAnimated, mode])

useEffect(() => {
return () => {
Chart.getChart('stepChart')?.destroy()
}
}, [])

return (
<div onClick={onClick} className={addClassString('w-full h-full relative', [className])}>
<canvas id='stepChart' ref={chartEl} />
Expand Down
1 change: 1 addition & 0 deletions src/constants/enums.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ export enum ContentView {
export enum AppView {
ONBOARD = 'ONBOARD',
DASHBOARD = 'DASHBOARD',
CHANGE_SCREEN = 'CHANGE_SCREEN',
INIT = 'INIT',
}

Expand Down
5 changes: 4 additions & 1 deletion src/hooks/useAtomCleanup.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ import {
validatorStateInfo,
validatorSyncInfo,
validatorVersionData,
validatorAliases,
} from '../recoil/atoms'
import { ContentView } from '../constants/enums'

Expand All @@ -38,6 +39,7 @@ const useAtomCleanup = () => {
const isValidatorNetworkError = useSetRecoilState(validatorNetworkError)
const setSessionAuthErrorCount = useSetRecoilState(sessionAuthErrorCount)
const setAlert = useSetRecoilState(alertLogs)
const setAliases = useSetRecoilState(validatorAliases)

const resetDashboardAtoms = () => {
setDashView(ContentView.MAIN)
Expand All @@ -55,8 +57,9 @@ const useAtomCleanup = () => {
setDeviceSettings(undefined as any)
setValSyncInfo(undefined as any)
setBeaconSyncInfo(undefined as any)
setValStateInfo(undefined as any)
setValStateInfo(undefined)
setAlert([])
setAliases(undefined)
}

return {
Expand Down
5 changes: 5 additions & 0 deletions src/hooks/usePollApi.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,11 @@ const usePollApi = ({
enabled: isReady && retries.current < maxErrors,
refetchInterval: time,
retry: 3,
cacheTime: 0,
initialData: undefined,
keepPreviousData: false,
refetchOnWindowFocus: false,
refetchOnMount: false,
onError: () => {
retries.current += 1
if (retries.current >= maxErrors) {
Expand Down
4 changes: 2 additions & 2 deletions src/hooks/useValidatorEpochBalance.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ const useValidatorEpochBalance = () => {
return validatorCacheData && activeValidators.length && Object.values(validatorCacheData).length
? activeValidators
.map(({ index, name }) => {
const data = validatorCacheData[index as any]
const data = validatorCacheData[index as any] || []
return {
index,
name,
Expand All @@ -34,7 +34,7 @@ const useValidatorEpochBalance = () => {

const formattedTimestamps = useMemo(() => {
const data = validatorCacheData && Object.values(validatorCacheData)[0]
return data
return data && genesisBlock
? data.map(({ epoch }) => {
const slot = epoch * slotsInEpoc

Expand Down
4 changes: 2 additions & 2 deletions src/recoil/atoms.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ export const beaconSyncInfo = atom<BeaconSyncResult>({
default: undefined,
})

export const validatorStateInfo = atom<BeaconValidatorResult[]>({
export const validatorStateInfo = atom<BeaconValidatorResult[] | undefined>({
key: 'validatorStateInfo',
default: undefined,
})
Expand Down Expand Up @@ -130,7 +130,7 @@ export const processingBlsValidators = atom<(string | number)[]>({
default: undefined,
})

export const validatorAliases = atom<ValAliases>({
export const validatorAliases = atom<ValAliases | undefined>({
key: 'validatorAliases',
default: undefined,
})
Expand Down
28 changes: 28 additions & 0 deletions src/views/ChangeScreen.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
import Spinner from '../components/Spinner/Spinner'
import { useSetRecoilState, useRecoilValue } from 'recoil'
import { appView, uiMode } from '../recoil/atoms'
import { AppView, UiMode } from '../constants/enums'
import { useLayoutEffect } from 'react'
import addClassString from '../utilities/addClassString'

const ChangeScreen = () => {
const mode = useRecoilValue(uiMode)
const className = addClassString('w-screen h-screen flex items-center justify-center', [
mode === UiMode.DARK && 'dark',
])
const setAppView = useSetRecoilState(appView)

useLayoutEffect(() => {
setAppView(AppView.INIT)
}, [])

return (
<div className={className}>
<div className='bg-white dark:bg-darkPrimary w-screen h-screen flex items-center justify-center'>
<Spinner />
</div>
</div>
)
}

export default ChangeScreen

0 comments on commit 5b1341e

Please sign in to comment.