diff --git a/ui/app/components/app/network.js b/ui/app/components/app/network.js index 51543c3a2..a156f676d 100644 --- a/ui/app/components/app/network.js +++ b/ui/app/components/app/network.js @@ -1,9 +1,42 @@ import PropTypes from 'prop-types' import React, { Component } from 'react' - import classnames from 'classnames' import NetworkDropdownIcon from './dropdowns/components/network-dropdown-icon' +function NetworkIndicator ({ disabled, children, hoverText, onClick, providerName }) { + return ( +
{ + if (!disabled) { + onClick(event) + } + }} + > +
+ {children} +
+
+
+ ) +} + +NetworkIndicator.propTypes = { + children: PropTypes.node.isRequired, + disabled: PropTypes.bool, + hoverText: PropTypes.string, + onClick: PropTypes.func, + providerName: PropTypes.string, +} + export default class Network extends Component { static contextTypes = { t: PropTypes.func, @@ -21,160 +54,113 @@ export default class Network extends Component { } render () { - const context = this.context - const networkNumber = this.props.network + const { + t, + } = this.context + + const { + disabled, + network: networkNumber, + onClick, + provider, + } = this.props + let providerName, providerNick, providerUrl - try { - providerName = this.props.provider.type - providerNick = this.props.provider.nickname || '' - providerUrl = this.props.provider.rpcTarget - } catch (e) { - providerName = null - } - const providerId = providerNick || providerName || providerUrl || null - let iconName - let hoverText - - if (providerName === 'mainnet') { - hoverText = context.t('mainnet') - iconName = 'ethereum-network' - } else if (providerName === 'ropsten') { - hoverText = context.t('ropsten') - iconName = 'ropsten-test-network' - } else if (providerName === 'kovan') { - hoverText = context.t('kovan') - iconName = 'kovan-test-network' - } else if (providerName === 'rinkeby') { - hoverText = context.t('rinkeby') - iconName = 'rinkeby-test-network' - } else if (providerName === 'goerli') { - hoverText = context.t('goerli') - iconName = 'goerli-test-network' - } else { - hoverText = providerId - iconName = 'private-network' + if (provider) { + providerName = provider.type + providerNick = provider.nickname || '' + providerUrl = provider.rpcTarget } - return ( -
{ - if (!this.props.disabled) { - this.props.onClick(event) - } - }} - > - {(function () { - switch (iconName) { - case 'ethereum-network': - return ( -
- -
- {context.t('mainnet')} -
-
-
- ) - case 'ropsten-test-network': - return ( -
- -
- {context.t('ropsten')} -
-
-
- ) - case 'kovan-test-network': - return ( -
- -
- {context.t('kovan')} -
-
-
- ) - case 'rinkeby-test-network': - return ( -
- -
- {context.t('rinkeby')} -
-
-
- ) - case 'goerli-test-network': - return ( -
- -
{context.t('goerli')}
-
-
- ) - default: - return ( -
- {networkNumber === 'loading' - ? ( - this.props.onClick(event)} - > - - - ) - : ( - - )} -
- { - providerName === 'localhost' - ? context.t('localhost') - : providerNick || context.t('privateNetwork') - } -
-
-
- ) - } - })()} -
- ) + switch (providerName) { + case 'mainnet': + return ( + + +
{t('mainnet')}
+
+ ) + + case 'ropsten': + return ( + + +
{t('ropsten')}
+
+ ) + + case 'kovan': + return ( + + +
{t('kovan')}
+
+ ) + + case 'rinkeby': + return ( + + +
{t('rinkeby')}
+
+ ) + + case 'goerli': + return ( + + +
{t('goerli')}
+
+ ) + + default: + return ( + + { + networkNumber === 'loading' + ? ( + onClick(event)}> + + + ) + : ( + + ) + } +
+ { + providerName === 'localhost' + ? t('localhost') + : providerNick || t('privateNetwork') + } +
+
+ ) + } } }