Skip to content

Commit

Permalink
Merge pull request #1323 from decent-dao/feature/in-app-network-change
Browse files Browse the repository at this point in the history
Add network switcher
  • Loading branch information
mudrila authored Jan 18, 2024
2 parents c703419 + 77f1329 commit 929a2db
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 929a2db

Please sign in to comment.