Skip to content

Commit

Permalink
Merge pull request #1686 from oasisprotocol/csillag/more-granular-config
Browse files Browse the repository at this point in the history
Support for more granular configuration for hiding layers
  • Loading branch information
csillag authored Jan 21, 2025
2 parents 9e48c15 + 6e6deb9 commit 3ce020e
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 14 deletions.
1 change: 1 addition & 0 deletions .changelog/1686.trivial.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Support for more granular configuration for hiding layers
8 changes: 6 additions & 2 deletions src/app/components/LayerPicker/LayerMenu.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import Tooltip from '@mui/material/Tooltip'
import { COLORS } from '../../../styles/theme/colors'
import { Layer } from '../../../oasis-nexus/api'
import { getLayerLabels } from '../../utils/content'
import { isLayerHidden, RouteUtils } from '../../utils/route-utils'
import { isScopeHidden, RouteUtils } from '../../utils/route-utils'
import { Network } from '../../../types/network'
import { orderByLayer } from '../../../types/layers'
import { useScreenSize } from '../../hooks/useScreensize'
Expand Down Expand Up @@ -113,7 +113,11 @@ export const LayerMenu: FC<LayerMenuProps> = ({
const [hoveredLayer, setHoveredLayer] = useState<undefined | Layer>()
const options = Object.values(Layer)
// Don't show hidden layers, unless we are already viewing them.
.filter(layer => !isLayerHidden(layer) || layer === currentScope?.layer)
.filter(
layer =>
!isScopeHidden({ network: selectedNetwork, layer }) ||
(layer === currentScope?.layer && selectedNetwork === currentScope?.network),
)
.map(layer => ({
layer,
enabled: RouteUtils.getAllLayersForNetwork(selectedNetwork || network).enabled.includes(layer),
Expand Down
11 changes: 6 additions & 5 deletions src/app/pages/ConsensusDashboardPage/ParaTimesCard.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,13 @@ import Grid from '@mui/material/Unstable_Grid2'
import { styled } from '@mui/material/styles'
import { Layer, Runtime } from '../../../oasis-nexus/api'
import { CardHeaderWithCounter } from '../../components/CardHeaderWithCounter'
import { isNotOnHiddenLayer, RouteUtils } from '../../utils/route-utils'
import { isNotInHiddenScope, RouteUtils } from '../../utils/route-utils'
import { SearchScope } from '../../../types/searchScope'
import { EnabledRuntimePreview, DisabledRuntimePreview } from './RuntimePreview'
import { Network } from '../../../types/network'

function shouldIncludeLayer(layer: Layer) {
return layer !== Layer.consensus && isNotOnHiddenLayer({ layer })
function shouldIncludeLayer(network: Network, layer: Layer) {
return layer !== Layer.consensus && isNotInHiddenScope({ network, layer })
}

const StyledInnerGrid = styled(Grid)(({ theme }) => ({
Expand All @@ -40,8 +41,8 @@ export const ParaTimesCard: FC<ParaTimesCardProps> = ({ scope }) => {
const { t } = useTranslation()
const { network } = scope
const { enabled, disabled } = RouteUtils.getAllLayersForNetwork(network)
const enabledRuntimes = enabled.filter(shouldIncludeLayer) as Runtime[]
const disabledRuntimes = disabled.filter(shouldIncludeLayer) as Runtime[]
const enabledRuntimes = enabled.filter(layer => shouldIncludeLayer(network, layer)) as Runtime[]
const disabledRuntimes = disabled.filter(layer => shouldIncludeLayer(network, layer)) as Runtime[]
const runtimesNumber = enabledRuntimes.length + disabledRuntimes.length
const [firstEnabledRuntime, ...restEnabledRuntimes] = enabledRuntimes
const spaceForSecondaryParaTimes = enabledRuntimes.length > 2
Expand Down
18 changes: 11 additions & 7 deletions src/app/utils/route-utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,11 @@ import { LoaderFunctionArgs } from 'react-router-dom'
import { isValidProposalId, isValidTxHash, isValidTxOasisHash } from './helpers'
import { isValidBlockHeight, isValidOasisAddress, isValidEthAddress } from './helpers'
import { AppError, AppErrors } from '../../types/errors'
import { EvmTokenType, Layer } from '../../oasis-nexus/api'
import { EvmTokenType, HasScope, Layer } from '../../oasis-nexus/api'
import { Network } from '../../types/network'
import { SearchScope } from '../../types/searchScope'
import { specialScopePaths } from '../../config'
import { getSearchTermFromRequest } from '../components/Search/search-utils'
import type { HasLayer } from '../../types/layers'
import { toChecksumAddress } from '@ethereumjs/util'
import { orderByLayer } from '../../types/layers'

Expand Down Expand Up @@ -67,11 +66,16 @@ function invertSpecialScopePaths() {

invertSpecialScopePaths()

export const hiddenLayers: Layer[] = [Layer.pontusxdev]
export const hiddenScopes: SearchScope[] = [
{ network: Network.testnet, layer: Layer.pontusxdev },
{ network: Network.mainnet, layer: Layer.pontusxdev },
// { network: Network.mainnet, layer: Layer.sapphire }, // This is only for testing
]

export const isLayerHidden = (layer: Layer): boolean => hiddenLayers.includes(layer)
export const isScopeHidden = (scope: SearchScope): boolean =>
!!hiddenScopes.find(s => s.network === scope.network && s.layer === scope.layer)

export const isNotOnHiddenLayer = (item: HasLayer) => !isLayerHidden(item.layer)
export const isNotInHiddenScope = (item: HasScope) => !isScopeHidden(item)

export abstract class RouteUtils {
private static ENABLED_LAYERS_FOR_NETWORK = {
Expand Down Expand Up @@ -202,7 +206,7 @@ export abstract class RouteUtils {

static getVisibleLayersForNetwork(network: Network, currentScope: SearchScope | undefined): Layer[] {
return this.getAllLayersForNetwork(network).enabled.filter(
layer => !isLayerHidden(layer) || layer === currentScope?.layer,
layer => !isScopeHidden({ network, layer }) || layer === currentScope?.layer,
)
}

Expand All @@ -222,7 +226,7 @@ export abstract class RouteUtils {

static getVisibleScopes(currentScope: SearchScope | undefined): SearchScope[] {
return RouteUtils.getEnabledScopes().filter(
({ network, layer }) => !isLayerHidden(layer) || layer === currentScope?.layer,
scope => !isScopeHidden(scope) || scope.layer === currentScope?.layer,
)
}

Expand Down

0 comments on commit 3ce020e

Please sign in to comment.