-
Notifications
You must be signed in to change notification settings - Fork 179
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
bf37666
commit ea7b778
Showing
6 changed files
with
176 additions
and
24 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
import { Box } from '@chakra-ui/react' | ||
import { useMemo } from 'react' | ||
import { useTranslate } from 'react-polyglot' | ||
import { useParams } from 'react-router' | ||
import { Main } from 'components/Layout/Main' | ||
import { SEO } from 'components/Layout/Seo' | ||
|
||
import { MarketsRow } from './components/MarketsRow' | ||
import type { MARKETS_CATEGORIES } from './constants' | ||
import { useRows } from './hooks/useRows' | ||
import { MarketsHeader } from './MarketsHeader' | ||
|
||
const containerPaddingX = { base: 4, xl: 0 } | ||
|
||
const ASSETS_LIMIT = 100 | ||
|
||
export const Category: React.FC = () => { | ||
const params: { category: MARKETS_CATEGORIES } = useParams() | ||
const translate = useTranslate() | ||
const headerComponent = useMemo(() => <MarketsHeader />, []) | ||
|
||
const allRows = useRows({ limit: ASSETS_LIMIT }) | ||
const row = allRows[params.category] | ||
|
||
const body = useMemo( | ||
() => ( | ||
<MarketsRow | ||
title={row.title} | ||
subtitle={row.subtitle} | ||
supportedChainIds={row.supportedChainIds} | ||
category={row.category} | ||
> | ||
{row.component} | ||
</MarketsRow> | ||
), | ||
[row.category, row.component, row.subtitle, row.supportedChainIds, row.title], | ||
) | ||
|
||
return ( | ||
<Main headerComponent={headerComponent} isSubPage> | ||
<SEO title={translate('navBar.markets')} /> | ||
<Box py={4} px={containerPaddingX}> | ||
{body} | ||
</Box> | ||
</Main> | ||
) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,76 @@ | ||
import { ArrowBackIcon } from '@chakra-ui/icons' | ||
import { Box, Flex, Heading, IconButton, Text } from '@chakra-ui/react' | ||
import type { ChainId } from '@shapeshiftoss/caip' | ||
import { KnownChainIds } from '@shapeshiftoss/types' | ||
import { useMemo, useState } from 'react' | ||
import { Link, useHistory, useParams } from 'react-router-dom' | ||
import { ChainDropdown } from 'components/ChainDropdown/ChainDropdown' | ||
import { selectFeatureFlag } from 'state/slices/selectors' | ||
import { useAppSelector } from 'state/store' | ||
|
||
import type { MARKETS_CATEGORIES } from '../constants' | ||
|
||
type RowProps = { | ||
title: string | ||
subtitle?: string | ||
supportedChainIds: ChainId[] | undefined | ||
category: MARKETS_CATEGORIES | ||
children: (selectedChainId: ChainId | undefined) => React.ReactNode | ||
} | ||
|
||
const backIcon = <ArrowBackIcon /> | ||
|
||
export const MarketsRow: React.FC<RowProps> = ({ | ||
title, | ||
subtitle, | ||
supportedChainIds, | ||
children, | ||
category, | ||
}) => { | ||
const params: { category?: MARKETS_CATEGORIES } = useParams() | ||
const history = useHistory() | ||
const handleBack = history.goBack | ||
const isCategoryRoute = params.category | ||
const [selectedChainId, setSelectedChainId] = useState<ChainId | undefined>(undefined) | ||
const isArbitrumNovaEnabled = useAppSelector(state => selectFeatureFlag(state, 'ArbitrumNova')) | ||
|
||
const chainIds = useMemo(() => { | ||
if (!supportedChainIds) | ||
return Object.values(KnownChainIds).filter(chainId => { | ||
if (!isArbitrumNovaEnabled && chainId === KnownChainIds.ArbitrumNovaMainnet) return false | ||
return true | ||
}) | ||
|
||
return supportedChainIds | ||
}, [isArbitrumNovaEnabled, supportedChainIds]) | ||
|
||
return ( | ||
<Box mb={8}> | ||
<Flex justify='space-between' align='center' mb={4}> | ||
<Box me={4}> | ||
<Flex direction='row'> | ||
{isCategoryRoute && ( | ||
<IconButton variant='ghost' aria-label='back' onClick={handleBack} icon={backIcon} /> | ||
)} | ||
<Heading size='md' mb={1}> | ||
<Link to={`/markets/category/${category}`}>{title}</Link> | ||
</Heading> | ||
</Flex> | ||
{subtitle && ( | ||
<Text fontSize='sm' color='gray.500'> | ||
{subtitle} | ||
</Text> | ||
)} | ||
</Box> | ||
<ChainDropdown | ||
chainIds={chainIds} | ||
chainId={selectedChainId} | ||
onClick={setSelectedChainId} | ||
showAll | ||
includeBalance | ||
/> | ||
</Flex> | ||
{children(selectedChainId)} | ||
</Box> | ||
) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters