Commit 21ce7c55 authored by tom goriunov's avatar tom goriunov Committed by GitHub

Merge pull request #97 from blockscout/more-env

envs for footer links and networks
parents ee521aea ef3a32cc
API_HOST=blockscout.com
API_BASE_PATH=/xdai/testnet/api
\ No newline at end of file
API_AUTHORIZATION_TOKEN=xxx API_AUTHORIZATION_TOKEN=xxx
\ No newline at end of file NEXT_PUBLIC_BLOCKSCOUT_VERSION=xxx
NEXT_PUBLIC_FOOTER_GITHUB_LINK=https://github.com/blockscout/blockscout
NEXT_PUBLIC_FOOTER_TWITTER_LINK=https://www.twitter.com/blockscoutcom
NEXT_PUBLIC_FOOTER_TELEGRAM_LINK=https://t.me/poa_network
NEXT_PUBLIC_FOOTER_ANALYTICS_LINK=https://duneanalytics.com/maxaleks/xdai-staking
NEXT_PUBLIC_SUPPORTED_NETWORKS=[{"name":"Gnosis Chain","type":"xdai","subType":"mainnet","group":"mainnets","isAccountSupported":true},{"name":"Optimism on Gnosis Chain","type":"xdai","subType":"optimism","group":"mainnets"},{"name":"Arbitrum on xDai","type":"xdai","subType":"aox","group":"mainnets"},{"name":"Ethereum","type":"eth","subType":"mainnet","group":"mainnets"},{"name":"Ethereum Classic","type":"etc","subType":"mainnet","group":"mainnets"},{"name":"POA","type":"poa","subType":"core","group":"mainnets"},{"name":"RSK","type":"rsk","subType":"mainnet","group":"mainnets"},{"name":"Gnosis Chain Testnet","type":"xdai","subType":"testnet","group":"testnets","isAccountSupported":true},{"name":"POA Sokol","type":"poa","subType":"sokol","group":"testnets"},{"name":"ARTIS Σ1","type":"artis","subType":"sigma1","group":"other"},{"name":"LUKSO L14","type":"lukso","subType":"l14","group":"other"}]
\ No newline at end of file
API_HOST=blockscout.com
API_BASE_PATH=/xdai/testnet/api
\ No newline at end of file
...@@ -9,7 +9,7 @@ export default function fetch(path: string, init?: RequestInit): Promise<Respons ...@@ -9,7 +9,7 @@ export default function fetch(path: string, init?: RequestInit): Promise<Respons
authorization: `Bearer ${ process.env.API_AUTHORIZATION_TOKEN }`, authorization: `Bearer ${ process.env.API_AUTHORIZATION_TOKEN }`,
'content-type': 'application/json', 'content-type': 'application/json',
}; };
const url = `https://${ process.env.API_HOST }${ process.env.API_BASE_PATH }${ path }`; const url = `https://blockscout.com${ path }`;
return nodeFetch(url, { return nodeFetch(url, {
headers, headers,
......
import type { NextApiRequest, NextApiResponse } from 'next'; import type { NextApiRequest, NextApiResponse } from 'next';
import fetch from 'lib/api/fetch'; import fetch from 'lib/api/fetch';
import * as cookies from 'lib/cookies';
type Methods = 'GET' | 'POST' | 'PUT' | 'DELETE'; type Methods = 'GET' | 'POST' | 'PUT' | 'DELETE';
...@@ -8,7 +9,16 @@ export default function handler<TRes>(getUrl: (_req: NextApiRequest) => string, ...@@ -8,7 +9,16 @@ export default function handler<TRes>(getUrl: (_req: NextApiRequest) => string,
return async(_req: NextApiRequest, res: NextApiResponse<TRes>) => { return async(_req: NextApiRequest, res: NextApiResponse<TRes>) => {
if (_req.method && allowedMethods.includes(_req.method as Methods)) { if (_req.method && allowedMethods.includes(_req.method as Methods)) {
const isBodyDisallowed = _req.method === 'GET' || _req.method === 'HEAD'; const isBodyDisallowed = _req.method === 'GET' || _req.method === 'HEAD';
const response = await fetch(getUrl(_req), { const networkType = _req.cookies[cookies.NAMES.NETWORK_TYPE];
const networkSubType = _req.cookies[cookies.NAMES.NETWORK_SUB_TYPE];
if (!networkType || !networkSubType) {
// eslint-disable-next-line no-console
console.error(`Incorrect network: NETWORK_TYPE=${ networkType } NETWORK_SUB_TYPE=${ networkSubType }`);
}
const url = `/${ networkType }/${ networkSubType }/api${ getUrl(_req) }`;
const response = await fetch(url, {
method: _req.method, method: _req.method,
body: isBodyDisallowed ? undefined : _req.body, body: isBodyDisallowed ? undefined : _req.body,
}); });
......
...@@ -4,7 +4,9 @@ import { Cookies } from 'typescript-cookie'; ...@@ -4,7 +4,9 @@ import { Cookies } from 'typescript-cookie';
import isBrowser from './isBrowser'; import isBrowser from './isBrowser';
export enum NAMES { export enum NAMES {
NAV_BAR_COLLAPSED='nav_bar_collapsed' NAV_BAR_COLLAPSED='nav_bar_collapsed',
NETWORK_TYPE='network_type',
NETWORK_SUB_TYPE='network_sub_type',
} }
export function get(name?: string | undefined | null) { export function get(name?: string | undefined | null) {
......
...@@ -10,88 +10,101 @@ import poaSokolIcon from 'icons/networks/poa-sokol.svg'; ...@@ -10,88 +10,101 @@ import poaSokolIcon from 'icons/networks/poa-sokol.svg';
import poaIcon from 'icons/networks/poa.svg'; import poaIcon from 'icons/networks/poa.svg';
import rskIcon from 'icons/networks/rsk.svg'; import rskIcon from 'icons/networks/rsk.svg';
export const NETWORKS: Array<Network> = [ // will change later when we agree how to host network icons
{ const ICONS: Record<string, React.FunctionComponent<React.SVGAttributes<SVGElement>>> = {
name: 'Gnosis Chain', 'xdai/mainnet': gnosisIcon,
type: 'xdai', 'xdai/optimism': optimismIcon,
subType: 'mainnet', 'xdai/aox': arbitrumIcon,
icon: gnosisIcon, 'eth/mainnet': ethereumIcon,
group: 'mainnets', 'etc/mainnet': ethereumClassicIcon,
isAccountSupported: true, 'poa/core': poaIcon,
isNewUiSupported: true, 'rsk/mainnet': rskIcon,
}, 'xdai/testnet': arbitrumIcon,
{ 'poa/sokol': poaSokolIcon,
name: 'Optimism on Gnosis Chain', 'artis/sigma1': artisIcon,
type: 'xdai', };
subType: 'optimism',
icon: optimismIcon, export const NETWORKS: Array<Network> = (() => {
group: 'mainnets', try {
}, const networksFromConfig: Array<Network> = JSON.parse(process.env.NEXT_PUBLIC_SUPPORTED_NETWORKS || '[]');
{ return networksFromConfig.map((network) => ({ ...network, icon: network.icon || ICONS[`${ network.type }/${ network.subType }`] }));
name: 'Arbitrum on xDai', } catch (error) {
type: 'xdai', return [];
subType: 'aox', }
icon: arbitrumIcon, })();
group: 'mainnets',
}, // for easy env creation
{ // const FOR_CONFIG = [
name: 'Ethereum', // {
type: 'eth', // name: 'Gnosis Chain',
subType: 'mainnet', // type: 'xdai',
icon: ethereumIcon, // subType: 'mainnet',
group: 'mainnets', // group: 'mainnets',
}, // isAccountSupported: true,
{ // },
name: 'Ethereum Classic', // {
type: 'etc', // name: 'Optimism on Gnosis Chain',
subType: 'mainnet', // type: 'xdai',
icon: ethereumClassicIcon, // subType: 'optimism',
group: 'mainnets', // group: 'mainnets',
}, // icon: 'https://www.fillmurray.com/60/60'
{ // },
name: 'POA', // {
type: 'poa', // name: 'Arbitrum on xDai',
subType: 'core', // type: 'xdai',
icon: poaIcon, // subType: 'aox',
group: 'mainnets', // group: 'mainnets',
}, // },
{ // {
name: 'RSK', // name: 'Ethereum',
type: 'rsk', // type: 'eth',
subType: 'mainnet', // subType: 'mainnet',
icon: rskIcon, // group: 'mainnets',
group: 'mainnets', // },
}, // {
{ // name: 'Ethereum Classic',
name: 'Gnosis Chain Testnet', // type: 'etc',
type: 'xdai', // subType: 'mainnet',
subType: 'testnet', // group: 'mainnets',
icon: arbitrumIcon, // },
group: 'testnets', // {
isAccountSupported: true, // name: 'POA',
isNewUiSupported: true, // type: 'poa',
}, // subType: 'core',
{ // group: 'mainnets',
name: 'POA Sokol', // },
type: 'poa', // {
subType: 'sokol', // name: 'RSK',
icon: poaSokolIcon, // type: 'rsk',
group: 'testnets', // subType: 'mainnet',
}, // group: 'mainnets',
{ // },
name: 'ARTIS Σ1', // {
type: 'artis', // name: 'Gnosis Chain Testnet',
subType: 'sigma1', // type: 'xdai',
icon: artisIcon, // subType: 'testnet',
group: 'other', // group: 'testnets',
}, // isAccountSupported: true,
{ // },
name: 'LUKSO L14', // {
type: 'lukso', // name: 'POA Sokol',
subType: 'l14', // type: 'poa',
group: 'other', // subType: 'sokol',
}, // group: 'testnets',
]; // },
// {
// name: 'ARTIS Σ1',
// type: 'artis',
// subType: 'sigma1',
// group: 'other',
// },
// {
// name: 'LUKSO L14',
// type: 'lukso',
// subType: 'l14',
// group: 'other',
// },
// ];
export const ACCOUNT_ROUTES = [ '/watchlist', '/private-tags', '/public-tags', '/api-keys', '/custom-abi' ]; export const ACCOUNT_ROUTES = [ '/watchlist', '/private-tags', '/public-tags', '/api-keys', '/custom-abi' ];
......
...@@ -11,7 +11,7 @@ module.exports = withReactSvg({ ...@@ -11,7 +11,7 @@ module.exports = withReactSvg({
return [ return [
{ {
source: '/', source: '/',
destination: '/xdai/mainnet', destination: '/xdai/testnet',
permanent: true, permanent: true,
}, },
]; ];
......
...@@ -8,7 +8,6 @@ export interface Network { ...@@ -8,7 +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;
isNewUiSupported?: boolean;
} }
...@@ -8,11 +8,14 @@ import twIcon from 'icons/social/tweet.svg'; ...@@ -8,11 +8,14 @@ import twIcon from 'icons/social/tweet.svg';
import getDefaultTransitionProps from 'theme/utils/getDefaultTransitionProps'; import getDefaultTransitionProps from 'theme/utils/getDefaultTransitionProps';
const SOCIAL_LINKS = [ const SOCIAL_LINKS = [
{ link: '#gh', icon: ghIcon }, { link: process.env.NEXT_PUBLIC_FOOTER_GITHUB_LINK, icon: ghIcon },
{ link: '#tw', icon: twIcon }, { link: process.env.NEXT_PUBLIC_FOOTER_TWITTER_LINK, icon: twIcon },
{ link: '#tg', icon: tgIcon }, { link: process.env.NEXT_PUBLIC_FOOTER_TELEGRAM_LINK, icon: tgIcon },
{ link: '#stats', icon: statsIcon }, { link: process.env.NEXT_PUBLIC_FOOTER_ANALYTICS_LINK, icon: statsIcon },
]; ].filter(({ link }) => link !== undefined);
const BLOCKSCOUT_VERSION = process.env.NEXT_PUBLIC_BLOCKSCOUT_VERSION;
const VERSION_URL = `https://github.com/blockscout/blockscout/tree/${ BLOCKSCOUT_VERSION }`;
interface Props { interface Props {
isCollapsed: boolean; isCollapsed: boolean;
...@@ -47,7 +50,7 @@ const NavFooter = ({ isCollapsed }: Props) => { ...@@ -47,7 +50,7 @@ const NavFooter = ({ isCollapsed }: Props) => {
<Text variant="secondary"> <Text variant="secondary">
Blockscout is a tool for inspecting and analyzing EVM based blockchains. Blockchain explorer for Ethereum Networks. Blockscout is a tool for inspecting and analyzing EVM based blockchains. Blockchain explorer for Ethereum Networks.
</Text> </Text>
<Text variant="secondary">Version: <Link>v4.2.1-beta</Link></Text> <Text variant="secondary">Version: <Link href={ VERSION_URL } target="_blank">{ BLOCKSCOUT_VERSION }</Link></Text>
</> </>
) } ) }
</VStack> </VStack>
......
...@@ -35,11 +35,11 @@ const Navigation = () => { ...@@ -35,11 +35,11 @@ const Navigation = () => {
]; ];
const accountNavItems = [ const accountNavItems = [
{ text: 'Watchlist', pathname: basePath + '/watchlist', icon: watchlistIcon }, { text: 'Watchlist', pathname: basePath + '/account/watchlist', icon: watchlistIcon },
{ text: 'Private tags', pathname: basePath + '/private-tags', icon: privateTagIcon }, { text: 'Private tags', pathname: basePath + '/account/private_tags', icon: privateTagIcon },
{ text: 'Public tags', pathname: basePath + '/public-tags', icon: publicTagIcon }, { text: 'Public tags', pathname: basePath + '/account/public_tags_request', icon: publicTagIcon },
{ text: 'API keys', pathname: basePath + '/api-keys', icon: apiKeysIcon }, { text: 'API keys', pathname: basePath + '/account/api_key', icon: apiKeysIcon },
{ text: 'Custom ABI', pathname: basePath + '/custom-abi', icon: abiIcon }, { text: 'Custom ABI', pathname: basePath + '/account/custom_abi', icon: abiIcon },
]; ];
const [ isCollapsed, setCollapsedState ] = React.useState(cookies.get(cookies.NAMES.NAV_BAR_COLLAPSED) === 'true'); const [ isCollapsed, setCollapsedState ] = React.useState(cookies.get(cookies.NAMES.NAV_BAR_COLLAPSED) === 'true');
......
import { Popover, PopoverTrigger, Icon, useColorModeValue, Button } from '@chakra-ui/react'; import { Popover, PopoverTrigger, Icon, useColorModeValue, Button } from '@chakra-ui/react';
import { useRouter } from 'next/router';
import React from 'react'; import React from 'react';
import networksIcon from 'icons/networks.svg'; import networksIcon from 'icons/networks.svg';
import * as cookies from 'lib/cookies';
import getDefaultTransitionProps from 'theme/utils/getDefaultTransitionProps'; import getDefaultTransitionProps from 'theme/utils/getDefaultTransitionProps';
import NetworkMenuPopup from './NetworkMenuPopup'; import NetworkMenuPopup from './NetworkMenuPopup';
...@@ -11,6 +13,19 @@ interface Props { ...@@ -11,6 +13,19 @@ interface Props {
} }
const NetworkMenu = ({ isCollapsed }: Props) => { const NetworkMenu = ({ isCollapsed }: Props) => {
const router = useRouter();
const networkType = router.query.network_type;
const networkSubType = router.query.network_sub_type;
React.useEffect(() => {
if (typeof networkType === 'string') {
cookies.set(cookies.NAMES.NETWORK_TYPE, networkType);
}
if (typeof networkSubType === 'string') {
cookies.set(cookies.NAMES.NETWORK_SUB_TYPE, networkSubType);
}
}, [ networkType, networkSubType ]);
return ( return (
<Popover openDelay={ 300 } placement="right-start" gutter={ 22 } isLazy> <Popover openDelay={ 300 } placement="right-start" gutter={ 22 } isLazy>
<PopoverTrigger> <PopoverTrigger>
......
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';
...@@ -15,7 +15,7 @@ interface Props extends Network { ...@@ -15,7 +15,7 @@ interface Props extends Network {
routeName: string; routeName: string;
} }
const NetworkMenuLink = ({ name, type, subType, icon, isActive, routeName, isAccountSupported, isNewUiSupported }: Props) => { const NetworkMenuLink = ({ name, type, subType, icon, isActive, routeName, isAccountSupported }: Props) => {
const isAccount = isAccountRoute(routeName); const isAccount = isAccountRoute(routeName);
const localPath = (() => { const localPath = (() => {
if (isAccount && isAccountSupported) { if (isAccount && isAccountSupported) {
...@@ -32,10 +32,20 @@ const NetworkMenuLink = ({ name, type, subType, icon, isActive, routeName, isAcc ...@@ -32,10 +32,20 @@ const NetworkMenuLink = ({ name, type, subType, icon, isActive, routeName, isAcc
const pathName = `/${ type }/${ subType }${ localPath }`; const pathName = `/${ type }/${ subType }${ localPath }`;
// will fix later after we agree on CI/CD workflow // will fix later after we agree on CI/CD workflow
const href = isNewUiSupported ? pathName : 'https://blockscout.com' + pathName; const href = type === 'xdai' && subType === 'testnet' ? pathName : 'https://blockscout.com' + pathName;
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"
......
...@@ -9,23 +9,26 @@ import { NETWORKS } from 'lib/networks'; ...@@ -9,23 +9,26 @@ import { NETWORKS } from 'lib/networks';
import NetworkMenuLink from './NetworkMenuLink'; import NetworkMenuLink from './NetworkMenuLink';
const TABS: Array<NetworkGroup> = [ 'mainnets', 'testnets', 'other' ]; const TABS: Array<NetworkGroup> = [ 'mainnets', 'testnets', 'other' ];
const availableTabs = TABS.filter((tab) => NETWORKS.some(({ group }) => group === tab));
const NetworkMenuPopup = () => { const NetworkMenuPopup = () => {
const router = useRouter(); const router = useRouter();
const routeName = router.pathname.replace('/[network_type]/[network_sub_type]', ''); const routeName = router.pathname.replace('/[network_type]/[network_sub_type]', '');
const selectedNetwork = NETWORKS.find((network) => router.query.network_type === network.type && router.query.network_sub_type === network.subType); const selectedNetwork = NETWORKS.find((network) => router.query.network_type === network.type && router.query.network_sub_type === network.subType);
const selectedTab = TABS.findIndex((tab) => selectedNetwork?.group === tab); const selectedTab = availableTabs.findIndex((tab) => selectedNetwork?.group === tab);
return ( return (
<PopoverContent w="382px"> <PopoverContent w="382px">
<PopoverBody> <PopoverBody>
<Text as="h4" fontSize="18px" lineHeight="30px" fontWeight="500">Networks</Text> <Text as="h4" fontSize="18px" lineHeight="30px" fontWeight="500">Networks</Text>
<Tabs variant="soft-rounded" mt={ 4 } isLazy defaultIndex={ selectedTab !== -1 ? selectedTab : undefined }> <Tabs variant="soft-rounded" mt={ 4 } isLazy defaultIndex={ selectedTab !== -1 ? selectedTab : undefined }>
<TabList> { availableTabs.length > 1 && (
{ TABS.map((tab) => <Tab key={ tab } textTransform="capitalize">{ tab }</Tab>) } <TabList>
</TabList> { availableTabs.map((tab) => <Tab key={ tab } textTransform="capitalize">{ tab }</Tab>) }
</TabList>
) }
<TabPanels mt={ 8 }> <TabPanels mt={ 8 }>
{ TABS.map((tab) => ( { availableTabs.map((tab) => (
<TabPanel key={ tab } p={ 0 }> <TabPanel key={ tab } p={ 0 }>
<VStack as="ul" spacing={ 2 } alignItems="stretch" mt={ 4 }> <VStack as="ul" spacing={ 2 } alignItems="stretch" mt={ 4 }>
{ NETWORKS { NETWORKS
......
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