Skip to content

Commit

Permalink
Add network switcher
Browse files Browse the repository at this point in the history
  • Loading branch information
mudrila committed Jan 18, 2024
1 parent c703419 commit 77f1329
Showing 1 changed file with 45 additions and 20 deletions.
65 changes: 45 additions & 20 deletions src/components/ui/menus/AccountDisplay/MenuItemNetwork.tsx
Original file line number Diff line number Diff line change
@@ -1,13 +1,23 @@
import { Box, Flex, Text } from '@chakra-ui/react';
import { Box, Flex, Select, Text } from '@chakra-ui/react';
import { useTranslation } from 'react-i18next';
import { useNetworkConfig } from '../../../../providers/NetworkConfig/NetworkConfigProvider';
import { useSwitchNetwork } from 'wagmi';
import {
supportedChains,
useNetworkConfig,
} from '../../../../providers/NetworkConfig/NetworkConfigProvider';

/**
* Network display for menu
*/
export function MenuItemNetwork() {
const { name, color } = useNetworkConfig();
const { t } = useTranslation('menu');
const { chainId } = useNetworkConfig();
const { switchNetwork } = useSwitchNetwork();

if (!switchNetwork) {
return null;
}

return (
<Box
cursor="default"
Expand All @@ -23,24 +33,39 @@ export function MenuItemNetwork() {
>
{t('network')}
</Text>
<Flex
padding={0}
alignItems="center"
gap="2"
<Select
mt={4}
width="100%"
bgColor="#2c2c2c"
borderColor="#4d4d4d"
rounded="sm"
cursor="pointer"
onChange={async e => {
e.preventDefault();
switchNetwork(Number(e.target.value));
}}
value={chainId}
>
<Box
w="1rem"
h="1rem"
bg={color}
rounded="full"
/>
<Text
data-testid="accountMenu-network"
textStyle="text-base-mono-medium"
>
{name}
</Text>
</Flex>
{supportedChains.map(chain => (
<option
key={chain.chainId}
value={chain.chainId}
>
<Box
w="1rem"
h="1rem"
bg={chain.color}
rounded="full"
/>
<Text
data-testid="accountMenu-network"
textStyle="text-base-mono-medium"
>
{chain.name}
</Text>
</option>
))}
</Select>
</Flex>
</Box>
);
Expand Down

0 comments on commit 77f1329

Please sign in to comment.