Skip to content

Commit

Permalink
Simplify code: remove duplication function
Browse files Browse the repository at this point in the history
  • Loading branch information
csillag committed Feb 11, 2024
1 parent 5afbfe2 commit d45cb6b
Show file tree
Hide file tree
Showing 5 changed files with 12 additions and 20 deletions.
5 changes: 3 additions & 2 deletions src/app/components/LayerPicker/LayerDetails.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,8 @@ import { Layer } from '../../../oasis-nexus/api'
import { Link as RouterLink } from 'react-router-dom'
import { docs } from '../../utils/externalLinks'
import { TextList, TextListItem } from '../TextList'
import { getLayerLabels, getNetworkIcons } from '../../utils/content'
import { getNetworkIcons } from '../../utils/content'
import { getLayerNames } from '../../../types/layers'
import { getNameForScope } from '../../../types/searchScope'
import { useConsensusFreshness, useRuntimeFreshness } from '../OfflineBanner/hook'
import { LayerStatus } from '../LayerStatus'
Expand Down Expand Up @@ -185,7 +186,7 @@ export const LayerDetailsSection: FC<LayerDetailsSectionProps> = ({
const theme = useTheme()
const { isMobile, isTablet } = useScreenSize()
const labels = getNetworkNames(t)
const layerLabels = getLayerLabels(t)
const layerLabels = getLayerNames(t)
const icons = getNetworkIcons()

return (
Expand Down
7 changes: 3 additions & 4 deletions src/app/components/LayerPicker/LayerMenu.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,9 @@ import ListItemText from '@mui/material/ListItemText'
import Tooltip from '@mui/material/Tooltip'
import { COLORS } from '../../../styles/theme/colors'
import { Layer } from '../../../oasis-nexus/api'
import { getLayerLabels } from '../../utils/content'
import { RouteUtils } from '../../utils/route-utils'
import { Network } from '../../../types/network'
import { orderByLayer } from '../../../types/layers'
import { getLayerNames, isLayerHidden, orderByLayer } from '../../../types/layers'
import { useScreenSize } from '../../hooks/useScreensize'

type BaseLayerMenuItemProps = {
Expand All @@ -31,7 +30,7 @@ const LayerMenuItemCaption: FC<PropsWithChildren> = ({ children }) => (
export const DisabledLayerMenuItem: FC<BaseLayerMenuItemProps> = ({ divider, layer }) => {
const { isTablet } = useScreenSize()
const { t } = useTranslation()
const labels = getLayerLabels(t)
const labels = getLayerNames(t)

return (
<Tooltip arrow placement="top" title={t('layerPicker.comingSoonTitle')}>
Expand Down Expand Up @@ -65,7 +64,7 @@ export const LayerMenuItem: FC<LayerMenuItemProps> = ({
setSelectedLayer,
}) => {
const { t } = useTranslation()
const labels = getLayerLabels(t)
const labels = getLayerNames(t)
const activeLayerSelection = layer === selectedLayer

return (
Expand Down
7 changes: 4 additions & 3 deletions src/app/components/PageLayout/NetworkButton.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,8 @@ import { styled } from '@mui/material/styles'
import { COLORS } from '../../../styles/theme/colors'
import { Network } from '../../../types/network'
import { Layer } from '../../../oasis-nexus/api'
import { getLayerLabels, getNetworkIcons } from '../../utils/content'
import { getNetworkIcons } from '../../utils/content'
import { getLayerNames } from '../../../types/layers'
import { LayerStatus } from '../LayerStatus'

export const StyledNetworkButton = styled(Button)(({ theme }) => ({
Expand Down Expand Up @@ -77,7 +78,7 @@ type NetworkButtonProps = {

export const NetworkButton: FC<NetworkButtonProps> = ({ isOutOfDate, layer, network, onClick }) => {
const { t } = useTranslation()
const labels = getLayerLabels(t)
const labels = getLayerNames(t)
const icons = getNetworkIcons()

return (
Expand Down Expand Up @@ -115,7 +116,7 @@ export const StyledMobileNetworkButton = styled(Button)(({ theme }) => ({

export const MobileNetworkButton: FC<NetworkButtonProps> = ({ isOutOfDate, layer, network, onClick }) => {
const { t } = useTranslation()
const labels = getLayerLabels(t)
const labels = getLayerNames(t)

return (
<StyledMobileNetworkButton onClick={onClick}>
Expand Down
4 changes: 2 additions & 2 deletions src/app/pages/ParatimeDashboardPage/LearningMaterials.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { useTranslation } from 'react-i18next'
import Grid from '@mui/material/Unstable_Grid2'
import { docs } from '../../utils/externalLinks'
import { Layer } from '../../../oasis-nexus/api'
import { getLayerLabels } from '../../utils/content'
import { getLayerNames } from '../../../types/layers'
import { Network } from '../../../types/network'
import { SpecifiedPerEnabledRuntime } from '../../utils/route-utils'
import { SearchScope } from '../../../types/searchScope'
Expand All @@ -23,7 +23,7 @@ type LayerContent = {
tertiary: Content
}
const getContent = (t: TFunction) => {
const labels = getLayerLabels(t)
const labels = getLayerNames(t)

return {
[Network.mainnet]: {
Expand Down
9 changes: 0 additions & 9 deletions src/app/utils/content.tsx
Original file line number Diff line number Diff line change
@@ -1,17 +1,8 @@
import { ReactNode } from 'react'
import { TFunction } from 'i18next'
import { Layer } from '../../oasis-nexus/api'
import { Network } from '../../types/network'
import { MainnetIcon } from '../components/CustomIcons/Mainnet'
import { TestnetIcon } from '../components/CustomIcons/Testnet'

export const getLayerLabels = (t: TFunction): Record<Layer, string> => ({
[Layer.emerald]: t('common.emerald'),
[Layer.sapphire]: t('common.sapphire'),
[Layer.cipher]: t('common.cipher'),
[Layer.consensus]: t('common.consensus'),
})

export const getNetworkIcons = ({ size }: { size?: number } = {}): Record<Network, ReactNode> => ({
[Network.mainnet]: <MainnetIcon sx={{ fontSize: size }} />,
[Network.testnet]: <TestnetIcon sx={{ fontSize: size }} />,
Expand Down

0 comments on commit d45cb6b

Please sign in to comment.