mirror of
https://github.com/luxfi/market.git
synced 2026-09-24 00:25:57 +00:00
gray = mix of radix (grayDark) and Zach's selected values primary = slate secondary = slateDark Voila! Since all original code used the Radix guidelines (which I references and link to in the config file), it all just works. So removed most of my mods to colors from first PR (checking intent and result of each carefully). Did not touch light theme (TODO?) NOTE: using the $ notation within the theme itself seems to break, so I grabbed the actual hex values from Radix.
61 lines
2.1 KiB
TypeScript
61 lines
2.1 KiB
TypeScript
import { Text, Button, Flex } from '../primitives'
|
|
import { FontAwesomeIcon } from '@fortawesome/react-fontawesome'
|
|
import { faChevronDown } from '@fortawesome/free-solid-svg-icons'
|
|
import supportedChains from 'utils/chains'
|
|
import { useMediaQuery } from 'react-responsive'
|
|
import { useMounted } from 'hooks'
|
|
import { Dropdown, DropdownMenuItem } from 'components/primitives/Dropdown'
|
|
import { useContext } from 'react'
|
|
import { ChainContext } from 'context/ChainContextProvider'
|
|
|
|
const ChainSwitcher = () => {
|
|
const isMounted = useMounted()
|
|
const isSmallDevice = useMediaQuery({ maxWidth: 600 }) && isMounted
|
|
const { chain, switchCurrentChain } = useContext(ChainContext)
|
|
|
|
if (supportedChains.length === 1) {
|
|
return null
|
|
}
|
|
|
|
const supportedChain = supportedChains.find(
|
|
(supportedChain) => supportedChain.id === chain?.id
|
|
)
|
|
const mainnet = supportedChains.find((chain) => chain.id === 1)
|
|
const chainName = supportedChain ? supportedChain.name : mainnet?.name
|
|
const chainIcon = supportedChain ? supportedChain.iconUrl : mainnet?.iconUrl
|
|
|
|
const trigger = (
|
|
<Button color="gray3" size="small" css={{ py: '$3' }}>
|
|
<img style={{ height: 17 }} src={chainIcon} />
|
|
{isSmallDevice ? null : <Text css={{ color: '$gray12' }} style="body1">{chainName}</Text>}
|
|
<Text css={{ color: '$gray10' }}>
|
|
<FontAwesomeIcon icon={faChevronDown} width={16} height={16} />
|
|
</Text>
|
|
</Button>
|
|
)
|
|
|
|
return (
|
|
<Dropdown trigger={trigger} contentProps={{ sideOffset: 5 }}>
|
|
{supportedChains.map((chainOption) => {
|
|
return (
|
|
<DropdownMenuItem
|
|
key={chainOption.id}
|
|
onClick={() => {
|
|
switchCurrentChain(chainOption.id)
|
|
}}
|
|
>
|
|
<Flex align="center" css={{ cursor: 'pointer'}}>
|
|
<img style={{ width: 17 }} src={chainOption.iconUrl} />
|
|
<Text style="body1" css={{ ml: '$2' }}>
|
|
{chainOption.name}
|
|
</Text>
|
|
</Flex>
|
|
</DropdownMenuItem>
|
|
)
|
|
})}
|
|
</Dropdown>
|
|
)
|
|
}
|
|
|
|
export default ChainSwitcher
|