diff --git a/src/components/AppLayout/Header/components/Layout.tsx b/src/components/AppLayout/Header/components/Layout.tsx index 0e7bc554..e7c3a7ea 100644 --- a/src/components/AppLayout/Header/components/Layout.tsx +++ b/src/components/AppLayout/Header/components/Layout.tsx @@ -5,12 +5,9 @@ import Popper from '@material-ui/core/Popper' import { withStyles } from '@material-ui/core/styles' import * as React from 'react' import { Link } from 'react-router-dom' -import styled from 'styled-components' -import { Divider, Icon } from '@gnosis.pm/safe-react-components' import Provider from './Provider' import NetworkSelector from './NetworkSelector' -import NetworkLabel from './NetworkLabel' import Spacer from 'src/components/Spacer' import Col from 'src/components/layout/Col' @@ -21,22 +18,6 @@ import { useStateHandler } from 'src/logic/hooks/useStateHandler' import SafeLogo from '../assets/gnosis-safe-multisig-logo.svg' import { getNetworkName, getNetworks } from 'src/config' -import { sameString } from 'src/utils/strings' - -const StyledDivider = styled(Divider)` - margin: 0; -` -const StyledLink = styled.a` - margin: 0; - text-decoration: none; - display: flex; - justify-content: space-between; - padding: 14px 16px 14px 0; - - :hover { - background-color: ${({ theme }) => theme.colors.background}; - } -` const styles = () => ({ root: { @@ -123,39 +104,10 @@ const Layout = ({ classes, providerDetails, providerInfo }) => { /> ( - - {({ TransitionProps }) => ( - - <> - - - {networks.map((network) => ( - - - - {sameString(networkName, network.label.toLowerCase()) && ( - - )} - - - - ))} - - - - - )} - - )} + clickAway={clickAwayNetworks} /> ) diff --git a/src/components/AppLayout/Header/components/NetworkLabel.tsx b/src/components/AppLayout/Header/components/NetworkLabel.tsx index a4561da8..7ead9113 100644 --- a/src/components/AppLayout/Header/components/NetworkLabel.tsx +++ b/src/components/AppLayout/Header/components/NetworkLabel.tsx @@ -32,7 +32,7 @@ const NetworkLabel = ({ networkName, networkInfo, }: { - networkName: string + networkName?: string networkInfo?: Partial }): React.ReactElement => { const selectedNetwork = networkInfo || currentNetworkInfo diff --git a/src/components/AppLayout/Header/components/NetworkSelector.tsx b/src/components/AppLayout/Header/components/NetworkSelector.tsx index eb98868e..0202fd64 100644 --- a/src/components/AppLayout/Header/components/NetworkSelector.tsx +++ b/src/components/AppLayout/Header/components/NetworkSelector.tsx @@ -1,15 +1,25 @@ +import * as React from 'react' +import styled from 'styled-components' +import { makeStyles } from '@material-ui/core/styles' +import ClickAwayListener from '@material-ui/core/ClickAwayListener' +import Grow from '@material-ui/core/Grow' +import List from '@material-ui/core/List' +import Popper from '@material-ui/core/Popper' import IconButton from '@material-ui/core/IconButton' import { withStyles } from '@material-ui/core/styles' import ExpandLess from '@material-ui/icons/ExpandLess' import ExpandMore from '@material-ui/icons/ExpandMore' -import * as React from 'react' +import { Divider, Icon } from '@gnosis.pm/safe-react-components' import NetworkLabel from './NetworkLabel' import Col from 'src/components/layout/Col' -import Divider from 'src/components/layout/Divider' import { screenSm, sm } from 'src/theme/variables' -const styles = () => ({ +import { sameString } from 'src/utils/strings' +import { ReturnValue } from 'src/logic/hooks/useStateHandler' +import { NetworkSettings } from 'src/config/networks/network' + +const styles = { root: { alignItems: 'center', display: 'flex', @@ -34,35 +44,86 @@ const styles = () => ({ height: '30px', width: '30px', }, -}) + popper: { + zIndex: 2000, + }, + network: { + backgroundColor: 'white', + borderRadius: sm, + boxShadow: '0 0 10px 0 rgba(33, 48, 77, 0.1)', + marginTop: '11px', + minWidth: '180px', + padding: '0', + }, +} -class NetworkSelector extends React.Component { - myRef +const useStyles = makeStyles(styles) - constructor(props) { - super(props) +const StyledLink = styled.a` + margin: 0; + text-decoration: none; + display: flex; + justify-content: space-between; + padding: 14px 16px 14px 0; - this.myRef = React.createRef() + :hover { + background-color: ${({ theme }) => theme.colors.background}; } +` +const StyledDivider = styled(Divider)` + margin: 0; +` - render() { - const { render, classes, open, toggle, selected } = this.props +type NetworkSelectorProps = ReturnValue & { + selected: string + networks: (Partial & { safeUrl: string })[] +} - return ( - <> -
- - - - {open ? : } - - - -
- {render(this.myRef)} - - ) - } +const NetworkSelector = ({ open, toggle, selected, networks, clickAway }: NetworkSelectorProps): React.ReactElement => { + const networkRef = React.useRef(null) + const classes = useStyles() + return ( + <> +
+ + + + {open ? : } + + + +
+ + {({ TransitionProps }) => ( + + <> + + + {networks.map((network) => ( + + + + {sameString(selected, network.label?.toLowerCase()) && ( + + )} + + + + ))} + + + + + )} + + + ) } export default withStyles(styles as any)(NetworkSelector) diff --git a/src/components/AppLayout/Header/components/ProviderDetails/UserDetails.tsx b/src/components/AppLayout/Header/components/ProviderDetails/UserDetails.tsx index 80482423..83e832ee 100644 --- a/src/components/AppLayout/Header/components/ProviderDetails/UserDetails.tsx +++ b/src/components/AppLayout/Header/components/ProviderDetails/UserDetails.tsx @@ -1,10 +1,10 @@ +import * as React from 'react' +import styled from 'styled-components' +import classNames from 'classnames' import { makeStyles } from '@material-ui/core/styles' import Dot from '@material-ui/icons/FiberManualRecord' -import classNames from 'classnames' -import * as React from 'react' import { EthHashInfo, Identicon, Card } from '@gnosis.pm/safe-react-components' import { createStyles } from '@material-ui/core' -import styled from 'styled-components' import Spacer from 'src/components/Spacer' import Block from 'src/components/layout/Block' diff --git a/src/config/index.ts b/src/config/index.ts index d22ba594..941c249a 100644 --- a/src/config/index.ts +++ b/src/config/index.ts @@ -67,7 +67,7 @@ const configuration = (): NetworkSpecificConfiguration => { const getConfig: () => NetworkSpecificConfiguration = ensureOnce(configuration) -export const getNetworks = (): { id: number; label: string; backgroundColor: string; safeUrl: string }[] => { +export const getNetworks = (): Partial & { safeUrl: string }[] => { const { local, ...usefulNetworks } = networks return Object.values(usefulNetworks).map((networkObj) => ({ id: networkObj.network.id, diff --git a/src/logic/hooks/useStateHandler.tsx b/src/logic/hooks/useStateHandler.tsx index a417e0dc..2b6ad433 100644 --- a/src/logic/hooks/useStateHandler.tsx +++ b/src/logic/hooks/useStateHandler.tsx @@ -1,6 +1,6 @@ import { useState } from 'react' -type ReturnValue = { +export type ReturnValue = { open: boolean toggle: () => void clickAway: () => void