diff --git a/src/app/components/LayerPicker/LayerMenu.tsx b/src/app/components/LayerPicker/LayerMenu.tsx index a8420a0368..ec0dca8854 100644 --- a/src/app/components/LayerPicker/LayerMenu.tsx +++ b/src/app/components/LayerPicker/LayerMenu.tsx @@ -112,7 +112,7 @@ export const LayerMenu: FC = ({ .filter(layer => !isLayerHidden(layer)) .map(layer => ({ layer, - enabled: RouteUtils.getEnabledLayersForNetwork(selectedNetwork || network).includes(layer), + enabled: RouteUtils.getAllLayersForNetwork(selectedNetwork || network).enabled.includes(layer), })) .sort(orderByLayer) diff --git a/src/app/components/LayerPicker/index.tsx b/src/app/components/LayerPicker/index.tsx index 27bae487ab..102d183b19 100644 --- a/src/app/components/LayerPicker/index.tsx +++ b/src/app/components/LayerPicker/index.tsx @@ -89,7 +89,7 @@ const LayerPickerContent: FC = ({ isOutOfDate, onClose, const [selectedNetwork, setSelectedNetwork] = useState(network) const [tabletStep, setTabletStep] = useState(LayerPickerTabletStep.ParaTimeDetails) const selectNetwork = (newNetwork: Network) => { - const enabledLayers = RouteUtils.getEnabledLayersForNetwork(newNetwork) + const enabledLayers = RouteUtils.getAllLayersForNetwork(newNetwork).enabled const targetLayer = enabledLayers.includes(selectedLayer) ? selectedLayer : enabledLayers[0] setSelectedNetwork(newNetwork) setSelectedLayer(targetLayer) diff --git a/src/app/pages/ConsensusDashboardPage/ParaTimesCard.tsx b/src/app/pages/ConsensusDashboardPage/ParaTimesCard.tsx index 88cfb8ada7..55430e42c5 100644 --- a/src/app/pages/ConsensusDashboardPage/ParaTimesCard.tsx +++ b/src/app/pages/ConsensusDashboardPage/ParaTimesCard.tsx @@ -5,6 +5,8 @@ import Card from '@mui/material/Card' import CardHeader from '@mui/material/CardHeader' import CardContent from '@mui/material/CardContent' import { styled } from '@mui/material/styles' +import { Layer, Runtime } from '../../../oasis-nexus/api' +import { isNotOnHiddenLayer } from '../../../types/layers' import { COLORS } from '../../../styles/theme/colors' import { CardHeaderWithCounter } from '../../components/CardHeaderWithCounter' import { RouteUtils } from '../../utils/route-utils' @@ -33,14 +35,19 @@ const StyledBox = styled(Box)(({ theme }) => ({ }, })) +function shouldIncludeLayer(layer: Layer) { + return layer !== Layer.consensus && isNotOnHiddenLayer({ layer }) +} + type ParaTimesCardProps = { scope: SearchScope } export const ParaTimesCard: FC = ({ scope }) => { const { t } = useTranslation() const { network } = scope - const enabledRuntimes = RouteUtils.getEnabledRuntimesForNetwork(network) - const disabledRuntimes = RouteUtils.getDisabledRuntimesForNetwork(network) - const runtimesNumber = enabledRuntimes.length + disabledRuntimes.length + const { enabled, disabled } = RouteUtils.getAllLayersForNetwork(network) + const enabledOasisRuntimes = enabled.filter(shouldIncludeLayer) as Runtime[] + const disabledOasisRuntimes = disabled.filter(shouldIncludeLayer) as Runtime[] + const runtimesNumber = enabledOasisRuntimes.length + disabledOasisRuntimes.length return ( @@ -57,12 +64,12 @@ export const ParaTimesCard: FC = ({ scope }) => { /> - {!!enabledRuntimes.length && - enabledRuntimes.map(runtime => ( + {!!enabledOasisRuntimes.length && + enabledOasisRuntimes.map(runtime => ( ))} - {!!disabledRuntimes.length && - disabledRuntimes.map(runtime => ( + {!!disabledOasisRuntimes.length && + disabledOasisRuntimes.map(runtime => ( ))} diff --git a/src/app/pages/HomePage/Graph/Graph/index.tsx b/src/app/pages/HomePage/Graph/Graph/index.tsx index 0def0bfe0b..d8213142e7 100644 --- a/src/app/pages/HomePage/Graph/Graph/index.tsx +++ b/src/app/pages/HomePage/Graph/Graph/index.tsx @@ -290,7 +290,7 @@ const GraphCmp: ForwardRefRenderFunction = ( }, [network]) const isLayerDisabled = (Layer: Layer) => { - return !RouteUtils.getEnabledLayersForNetwork(network).includes(Layer) + return !RouteUtils.getAllLayersForNetwork(network).enabled.includes(Layer) } const disabledMap: Partial> = { @@ -300,7 +300,7 @@ const GraphCmp: ForwardRefRenderFunction = ( [Layer.sapphire]: isLayerDisabled(Layer.sapphire), } - const enabledLayers: Layer[] = useMemo(() => RouteUtils.getEnabledLayersForNetwork(network), [network]) + const enabledLayers: Layer[] = useMemo(() => RouteUtils.getAllLayersForNetwork(network).enabled, [network]) const onSelectLayer = (layer: Layer) => { if (isMobile && isZoomedIn) { @@ -312,7 +312,7 @@ const GraphCmp: ForwardRefRenderFunction = ( if ( ((!isMobile && !isZoomedIn) || layer === selectedLayer) && - RouteUtils.getEnabledLayersForNetwork(network).includes(layer) + RouteUtils.getAllLayersForNetwork(network).enabled.includes(layer) ) { navigate(RouteUtils.getDashboardRoute({ network, layer })) diff --git a/src/app/pages/HomePage/Graph/GraphTooltipMobile/index.tsx b/src/app/pages/HomePage/Graph/GraphTooltipMobile/index.tsx index c84160e8b2..804328343c 100644 --- a/src/app/pages/HomePage/Graph/GraphTooltipMobile/index.tsx +++ b/src/app/pages/HomePage/Graph/GraphTooltipMobile/index.tsx @@ -141,10 +141,10 @@ const layerTooltipBodyCaption = (t: TFunction, layer: Layer, enabled: boolean, o } const useLayerTooltipMap = (network: Network): Partial> => { - const isSapphireEnabled = RouteUtils.getEnabledLayersForNetwork(network).includes(Layer.sapphire) - const isEmeraldEnabled = RouteUtils.getEnabledLayersForNetwork(network).includes(Layer.emerald) - const isCipherEnabled = RouteUtils.getEnabledLayersForNetwork(network).includes(Layer.cipher) - const isConsensusEnabled = RouteUtils.getEnabledLayersForNetwork(network).includes(Layer.consensus) + const isSapphireEnabled = RouteUtils.getAllLayersForNetwork(network).enabled.includes(Layer.sapphire) + const isEmeraldEnabled = RouteUtils.getAllLayersForNetwork(network).enabled.includes(Layer.emerald) + const isCipherEnabled = RouteUtils.getAllLayersForNetwork(network).enabled.includes(Layer.cipher) + const isConsensusEnabled = RouteUtils.getAllLayersForNetwork(network).enabled.includes(Layer.consensus) const isEmeraldOutOfDate = useRuntimeFreshness({ network, layer: Layer.emerald }).outOfDate const isSapphireOutOfDate = useRuntimeFreshness({ network, layer: Layer.sapphire }).outOfDate diff --git a/src/app/pages/SearchResultsPage/hooks.ts b/src/app/pages/SearchResultsPage/hooks.ts index 2e029472df..d02c4dcbd3 100644 --- a/src/app/pages/SearchResultsPage/hooks.ts +++ b/src/app/pages/SearchResultsPage/hooks.ts @@ -175,7 +175,7 @@ export function useNetworkProposalsConditionally( nameFragment: string | undefined, ): ConditionalResults { const queries = RouteUtils.getEnabledNetworks() - .filter(network => RouteUtils.getEnabledLayersForNetwork(network).includes(Layer.consensus)) + .filter(network => RouteUtils.getAllLayersForNetwork(network).enabled.includes(Layer.consensus)) .map(network => // eslint-disable-next-line react-hooks/rules-of-hooks useGetConsensusProposalsByName(network, nameFragment), diff --git a/src/app/utils/route-utils.ts b/src/app/utils/route-utils.ts index c3b3046fe6..921d908701 100644 --- a/src/app/utils/route-utils.ts +++ b/src/app/utils/route-utils.ts @@ -2,7 +2,7 @@ import { LoaderFunctionArgs } from 'react-router-dom' import { isValidProposalId, isValidTxHash } from './helpers' import { isValidBlockHeight, isValidOasisAddress, isValidEthAddress } from './helpers' import { AppError, AppErrors } from '../../types/errors' -import { EvmTokenType, Layer, Runtime } from '../../oasis-nexus/api' +import { EvmTokenType, Layer } from '../../oasis-nexus/api' import { Network } from '../../types/network' import { SearchScope } from '../../types/searchScope' import { isStableDeploy } from '../../config' @@ -126,22 +126,18 @@ export abstract class RouteUtils { contractAddress, )}/instance/${encodeURIComponent(instanceId)}` - static getEnabledLayersForNetwork(network: Network): Layer[] { - return Object.values(Layer).filter(layer => RouteUtils.ENABLED_LAYERS_FOR_NETWORK[network][layer]) - } + static getAllLayersForNetwork(network: Network): { enabled: Layer[]; disabled: Layer[] } { + const enabled: Layer[] = [] + const disabled: Layer[] = [] - static getRuntimesForNetwork(network: Network, isEnabled: boolean): Runtime[] { - return Object.values(Runtime).filter( - runtime => RouteUtils.ENABLED_LAYERS_FOR_NETWORK[network][runtime] === isEnabled, + Object.values(Layer).forEach(layer => + RouteUtils.ENABLED_LAYERS_FOR_NETWORK[network][layer] ? enabled.push(layer) : disabled.push(layer), ) - } - - static getEnabledRuntimesForNetwork(network: Network): Runtime[] { - return RouteUtils.getRuntimesForNetwork(network, true) - } - static getDisabledRuntimesForNetwork(network: Network): Runtime[] { - return RouteUtils.getRuntimesForNetwork(network, false) + return { + enabled, + disabled, + } } static getProposalsRoute = (network: Network) => { @@ -154,19 +150,19 @@ export abstract class RouteUtils { static getEnabledScopes(): SearchScope[] { return RouteUtils.getEnabledNetworks().flatMap(network => - RouteUtils.getEnabledLayersForNetwork(network).map(layer => ({ network, layer })), + RouteUtils.getAllLayersForNetwork(network).enabled.map(layer => ({ network, layer })), ) } static getEnabledNetworks(): Network[] { return Object.values(Network).filter(network => { - return RouteUtils.getEnabledLayersForNetwork(network).length > 0 + return RouteUtils.getAllLayersForNetwork(network).enabled.length > 0 }) } static getEnabledSearchScopes(): SearchScope[] { return RouteUtils.getEnabledNetworks().flatMap(network => - RouteUtils.getEnabledLayersForNetwork(network).map(layer => ({ network, layer })), + RouteUtils.getAllLayersForNetwork(network).enabled.map(layer => ({ network, layer })), ) } } @@ -261,7 +257,7 @@ export const assertEnabledScope = ({ if ( !layer || // missing param - !RouteUtils.getEnabledLayersForNetwork(network as Network).includes(layer as Layer) // unsupported on network + !RouteUtils.getAllLayersForNetwork(network as Network).enabled.includes(layer as Layer) // unsupported on network ) { throw new AppError(AppErrors.UnsupportedLayer) }