Skip to content

Commit

Permalink
refactor: move static tag to the navItem conf array
Browse files Browse the repository at this point in the history
  • Loading branch information
compojoom committed May 29, 2024
1 parent bcb9672 commit 25d775a
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 7 deletions.
3 changes: 3 additions & 0 deletions src/components/sidebar/SidebarNavigation/config.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,13 @@ import AppsIcon from '@/public/images/apps/apps-icon.svg'
import SettingsIcon from '@/public/images/sidebar/settings.svg'
import SwapIcon from '@/public/images/common/swap.svg'
import { SvgIcon } from '@mui/material'
import Chip from '@mui/material/Chip'

export type NavItem = {
label: string
icon?: ReactElement
href: string
tag?: ReactElement
}

export const navItems: NavItem[] = [
Expand All @@ -31,6 +33,7 @@ export const navItems: NavItem[] = [
label: 'Swap',
icon: <SvgIcon component={SwapIcon} inheritViewBox />,
href: AppRoutes.swap,
tag: <Chip label="New" color="success" sx={{ ml: 1 }} />,
},
{
label: 'Transactions',
Expand Down
10 changes: 3 additions & 7 deletions src/components/sidebar/SidebarNavigation/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ import { FeatureRoutes, hasFeature } from '@/utils/chains'
import { trackEvent } from '@/services/analytics'
import { SWAP_EVENTS, SWAP_LABELS } from '@/services/analytics/events/swaps'
import useIsCounterfactualSafe from '@/features/counterfactual/hooks/useIsCounterfactualSafe'
import Chip from '@mui/material/Chip'

const getSubdirectory = (pathname: string): string => {
return pathname.split('/')[1]
Expand All @@ -32,17 +31,14 @@ const isRouteEnabled = (route: string, chain?: ChainInfo) => {
return !featureRoute || hasFeature(chain, featureRoute)
}

const NavItemLabel = ({ item }: { item: NavItem }) => {
const NavItemTag = ({ item }: { item: NavItem }) => {
const queueSize = useQueuedTxsLength()

if (item.href === AppRoutes.transactions.history) {
return <SidebarListItemCounter count={queueSize} />
}

if (item.href === AppRoutes.swap) {
return <Chip label="New" color="success" sx={{ ml: 1 }} />
}
return null
return item.tag
}

const Navigation = (): ReactElement => {
Expand Down Expand Up @@ -105,7 +101,7 @@ const Navigation = (): ReactElement => {
<SidebarListItemText data-testid="sidebar-list-item" bold>
{item.label}

<NavItemLabel item={item} />
<NavItemTag item={item} />
</SidebarListItemText>
</SidebarListItemButton>
</ListItem>
Expand Down

0 comments on commit 25d775a

Please sign in to comment.