Skip to content

Commit

Permalink
Add support for merging all networks in the layer selector
Browse files Browse the repository at this point in the history
  • Loading branch information
csillag committed Jan 14, 2025
1 parent 77af483 commit da0e6b4
Show file tree
Hide file tree
Showing 5 changed files with 18 additions and 4 deletions.
9 changes: 9 additions & 0 deletions src/app/components/LayerPicker/LayerDetails.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import { getNameForScope, SearchScope } from '../../../types/searchScope'
import { useConsensusFreshness, useRuntimeFreshness } from '../OfflineBanner/hook'
import { LayerStatus } from '../LayerStatus'
import { useScreenSize } from '../../hooks/useScreensize'
import { mergeNetworksInLayerSelector } from '../../utils/route-utils'

type LayerDetailsContent = {
description: string
Expand Down Expand Up @@ -154,6 +155,7 @@ const RuntimeDetails: FC<LayerDetailsProps> = props => {
const { handleConfirm, selectedScope } = props
const isOutOfDate = useRuntimeFreshness(selectedScope).outOfDate
const details = getDetails(t)[selectedScope.network]?.[selectedScope.layer]
const networkNames = getNetworkNames(t)

return (
<LayerDetailsSection
Expand All @@ -162,6 +164,13 @@ const RuntimeDetails: FC<LayerDetailsProps> = props => {
isOutOfDate={isOutOfDate}
selectedScope={selectedScope}
>
{mergeNetworksInLayerSelector && (
<Typography sx={{ fontSize: '14px', color: COLORS.brandExtraDark, pb: 4 }}>
{t('layerPicker.hostedOn', {
network: networkNames[selectedScope.network],
})}
</Typography>
)}
{details?.description && (
<Typography sx={{ fontSize: '14px', color: COLORS.brandExtraDark, pb: 4 }}>
{details.description}
Expand Down
6 changes: 4 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 { isScopeHidden, RouteUtils } from '../../utils/route-utils'
import { isScopeHidden, mergeNetworksInLayerSelector, RouteUtils } from '../../utils/route-utils'
import { Network } from '../../../types/network'
import { orderByLayer } from '../../../types/layers'
import { useScreenSize } from '../../hooks/useScreensize'
Expand Down Expand Up @@ -123,7 +123,9 @@ const getOptionsForNetwork = (network: Network, activeScope?: SearchScope | unde
export const LayerMenu: FC<LayerMenuProps> = ({ selectedNetwork, selectedScope, setSelectedScope }) => {
const activeScope = useScopeParam()!
const [hoveredScope, setHoveredScope] = useState<undefined | SearchScope>()
const options = getOptionsForNetwork(selectedNetwork ?? activeScope.network)
const options = mergeNetworksInLayerSelector
? RouteUtils.getVisibleScopes(activeScope).map(scope => ({ scope, enabled: true }))
: getOptionsForNetwork(selectedNetwork ?? activeScope.network)

return (
<MenuList>
Expand Down
4 changes: 2 additions & 2 deletions src/app/components/LayerPicker/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import { useRequiredScopeParam } from '../../hooks/useScopeParam'
import { NetworkMenu } from './NetworkMenu'
import { LayerMenu } from './LayerMenu'
import { LayerDetails } from './LayerDetails'
import { scopeFreedom, RouteUtils } from '../../utils/route-utils'
import { scopeFreedom, RouteUtils, mergeNetworksInLayerSelector } from '../../utils/route-utils'
import { styled } from '@mui/material/styles'
import KeyboardArrowLeft from '@mui/icons-material/KeyboardArrowLeft'
import { useScreenSize } from '../../hooks/useScreensize'
Expand Down Expand Up @@ -146,7 +146,7 @@ const LayerPickerContent: FC<LayerPickerContentProps> = ({ isOutOfDate, onClose,
<Divider />
<StyledContent>
<Grid container>
{scopeFreedom !== 'layer' &&
{!(scopeFreedom === 'layer' || mergeNetworksInLayerSelector) &&
(!isTablet || (isTablet && tabletStep === LayerPickerTabletStep.Network)) && (
<Grid xs={12} md={3}>
<NetworkMenu
Expand Down
2 changes: 2 additions & 0 deletions src/app/utils/route-utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,8 @@ export const hiddenScopes: SearchScope[] = [
// { network: Network.mainnet, layer: Layer.sapphire }, // This is only for testing
]

export const mergeNetworksInLayerSelector = false

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

Expand Down
1 change: 1 addition & 0 deletions src/locales/en/translation.json
Original file line number Diff line number Diff line change
Expand Up @@ -544,6 +544,7 @@
"consensus": "The consensus layer is a scalable, high-throughput, secure, proof-of-stake consensus run by a decentralized set of validator nodes.",
"goToDashboard": "Go to dashboard",
"hex": "Hex: {{ id }}",
"hostedOn": "Hosted on {{ network }}",
"readMore": "Read more about {{ layer }} on {{ network }} in Oasis Docs",
"rpcHttp": "RPC HTTP endpoint: {{ endpoint }}",
"rpcWebSockets": "RPC WebSockets endpoint: {{ endpoint }}",
Expand Down

0 comments on commit da0e6b4

Please sign in to comment.