From 1943100f7f3d87bc264362069158031c02304df7 Mon Sep 17 00:00:00 2001 From: apanizo Date: Thu, 30 Aug 2018 17:02:26 +0200 Subject: [PATCH] Creating Provider Component with its owen React Portal refence --- .../Header/component/Provider/index.jsx | 90 +++++++++++++++++++ 1 file changed, 90 insertions(+) create mode 100644 src/components/Header/component/Provider/index.jsx diff --git a/src/components/Header/component/Provider/index.jsx b/src/components/Header/component/Provider/index.jsx new file mode 100644 index 00000000..9a444ecc --- /dev/null +++ b/src/components/Header/component/Provider/index.jsx @@ -0,0 +1,90 @@ +// @flow +import * as React from 'react' +import { withStyles } from '@material-ui/core/styles' +import IconButton from '@material-ui/core/IconButton' +import ExpandLess from '@material-ui/icons/ExpandLess' +import ExpandMore from '@material-ui/icons/ExpandMore' +import Paragraph from '~/components/layout/Paragraph' +import Col from '~/components/layout/Col' +import { type Open } from '~/components/hoc/OpenHoc' +import { sm, md } from '~/theme/variables' + +import Identicon from '~/components/Identicon' + +type Props = Open & { + provider: string, + network: string, + classes: Object, + userAddress: string, + connected: boolean, + children: Function, +} + +const styles = () => ({ + root: { + height: '100%', + display: 'center', + }, + provider: { + padding: `${sm} ${md}`, + alignItems: 'center', + flex: '0 1 auto', + display: 'flex', + cursor: 'pointer', + }, + account: { + padding: `0 ${md} 0 ${sm}`, + display: 'flex', + flexDirection: 'column', + justifyContent: 'center', + }, + expand: { + width: '30px', + height: '30px', + }, +}) + +type ProviderRef = { current: null | HTMLDivElement } + +class Provider extends React.Component { + constructor(props: Props) { + super(props) + + this.myRef = React.createRef() + } + + myRef: ProviderRef + + render() { + const { + open, toggle, provider, network, userAddress, connected, children, classes, + } = this.props + + const providerText = connected ? `${provider} [${network}]` : 'Not connected' + const cutAddress = connected ? `${userAddress.substring(0, 8)}...${userAddress.substring(36)}` : '' + + return ( + +
+ + { connected && } + + {providerText} + {cutAddress} + + + { open ? : } + + +
+ { children(this.myRef) } +
+ ) + } +} + +export default withStyles(styles)(Provider)