Commit 37ef8f18 authored by tom's avatar tom

icon can be passed in config

parent c64878a5
...@@ -27,7 +27,7 @@ const ICONS: Record<string, React.FunctionComponent<React.SVGAttributes<SVGEleme ...@@ -27,7 +27,7 @@ const ICONS: Record<string, React.FunctionComponent<React.SVGAttributes<SVGEleme
export const NETWORKS: Array<Network> = (() => { export const NETWORKS: Array<Network> = (() => {
try { try {
const networksFromConfig: Array<Network> = JSON.parse(process.env.NEXT_PUBLIC_SUPPORTED_NETWORKS || '[]'); const networksFromConfig: Array<Network> = JSON.parse(process.env.NEXT_PUBLIC_SUPPORTED_NETWORKS || '[]');
return networksFromConfig.map((network) => ({ ...network, icon: ICONS[`${ network.type }/${ network.subType }`] })); return networksFromConfig.map((network) => ({ ...network, icon: network.icon || ICONS[`${ network.type }/${ network.subType }`] }));
} catch (error) { } catch (error) {
return []; return [];
} }
...@@ -47,6 +47,7 @@ export const NETWORKS: Array<Network> = (() => { ...@@ -47,6 +47,7 @@ export const NETWORKS: Array<Network> = (() => {
// type: 'xdai', // type: 'xdai',
// subType: 'optimism', // subType: 'optimism',
// group: 'mainnets', // group: 'mainnets',
// icon: 'https://www.fillmurray.com/60/60'
// }, // },
// { // {
// name: 'Arbitrum on xDai', // name: 'Arbitrum on xDai',
......
...@@ -8,6 +8,6 @@ export interface Network { ...@@ -8,6 +8,6 @@ export interface Network {
type: string; type: string;
subType: string; subType: string;
group: 'mainnets' | 'testnets' | 'other'; group: 'mainnets' | 'testnets' | 'other';
icon?: FunctionComponent<SVGAttributes<SVGElement>>; icon?: FunctionComponent<SVGAttributes<SVGElement>> | string;
isAccountSupported?: boolean; isAccountSupported?: boolean;
} }
import { Box, Flex, Icon, Text } from '@chakra-ui/react'; import { Box, Flex, Icon, Text, Image } from '@chakra-ui/react';
import NextLink from 'next/link'; import NextLink from 'next/link';
import React from 'react'; import React from 'react';
...@@ -36,6 +36,16 @@ const NetworkMenuLink = ({ name, type, subType, icon, isActive, routeName, isAcc ...@@ -36,6 +36,16 @@ const NetworkMenuLink = ({ name, type, subType, icon, isActive, routeName, isAcc
const hasIcon = Boolean(icon); const hasIcon = Boolean(icon);
const colors = useColors({ hasIcon }); const colors = useColors({ hasIcon });
const iconEl = typeof icon === 'string' ? (
<Image w="30px" h="30px" src={ icon } alt={ `${ type } ${ subType } network icon` }/>
) : (
<Icon
as={ hasIcon ? icon : placeholderIcon }
boxSize="30px"
color={ isActive ? colors.icon.active : colors.icon.default }
/>
);
return ( return (
<Box as="li" listStyleType="none"> <Box as="li" listStyleType="none">
<NextLink href={ href } passHref> <NextLink href={ href } passHref>
...@@ -51,11 +61,7 @@ const NetworkMenuLink = ({ name, type, subType, icon, isActive, routeName, isAcc ...@@ -51,11 +61,7 @@ const NetworkMenuLink = ({ name, type, subType, icon, isActive, routeName, isAcc
bgColor={ isActive ? colors.bg.active : colors.bg.default } bgColor={ isActive ? colors.bg.active : colors.bg.default }
_hover={{ color: isActive ? colors.text.active : colors.text.hover }} _hover={{ color: isActive ? colors.text.active : colors.text.hover }}
> >
<Icon { iconEl }
as={ hasIcon ? icon : placeholderIcon }
boxSize="30px"
color={ isActive ? colors.icon.active : colors.icon.default }
/>
<Text <Text
marginLeft={ 3 } marginLeft={ 3 }
fontWeight="500" fontWeight="500"
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment