2018-06-23 08:52:45 +02:00
|
|
|
import React, { Component } from 'react'
|
|
|
|
import PropTypes from 'prop-types'
|
|
|
|
import classnames from 'classnames'
|
|
|
|
import {
|
|
|
|
MAINNET_CODE,
|
|
|
|
ROPSTEN_CODE,
|
|
|
|
RINKEYBY_CODE,
|
|
|
|
KOVAN_CODE,
|
|
|
|
} from '../../../../app/scripts/controllers/network/enums'
|
|
|
|
|
|
|
|
const networkToClassHash = {
|
|
|
|
[MAINNET_CODE]: 'mainnet',
|
|
|
|
[ROPSTEN_CODE]: 'ropsten',
|
|
|
|
[RINKEYBY_CODE]: 'rinkeby',
|
|
|
|
[KOVAN_CODE]: 'kovan',
|
|
|
|
}
|
|
|
|
|
|
|
|
export default class NetworkDisplay extends Component {
|
2018-11-05 14:07:56 +01:00
|
|
|
static defaultProps = {
|
|
|
|
colored: true,
|
|
|
|
}
|
|
|
|
|
2018-06-23 08:52:45 +02:00
|
|
|
static propTypes = {
|
2018-11-05 14:07:56 +01:00
|
|
|
colored: PropTypes.bool,
|
2018-06-23 08:52:45 +02:00
|
|
|
network: PropTypes.string,
|
|
|
|
provider: PropTypes.object,
|
|
|
|
}
|
|
|
|
|
|
|
|
static contextTypes = {
|
|
|
|
t: PropTypes.func,
|
|
|
|
}
|
|
|
|
|
|
|
|
renderNetworkIcon () {
|
|
|
|
const { network } = this.props
|
|
|
|
const networkClass = networkToClassHash[network]
|
|
|
|
|
|
|
|
return networkClass
|
|
|
|
? <div className={`network-display__icon network-display__icon--${networkClass}`} />
|
|
|
|
: <div
|
|
|
|
className="i fa fa-question-circle fa-med"
|
|
|
|
style={{
|
|
|
|
margin: '0 4px',
|
|
|
|
color: 'rgb(125, 128, 130)',
|
|
|
|
}}
|
|
|
|
/>
|
|
|
|
}
|
|
|
|
|
|
|
|
render () {
|
2018-11-05 14:07:56 +01:00
|
|
|
const { colored, network, provider: { type, nickname } } = this.props
|
2018-06-23 08:52:45 +02:00
|
|
|
const networkClass = networkToClassHash[network]
|
|
|
|
|
|
|
|
return (
|
2018-11-05 14:07:56 +01:00
|
|
|
<div
|
|
|
|
className={classnames('network-display__container', {
|
|
|
|
'network-display__container--colored': colored,
|
|
|
|
['network-display__container--' + networkClass]: colored && networkClass,
|
|
|
|
})}
|
|
|
|
>
|
2018-06-23 08:52:45 +02:00
|
|
|
{
|
|
|
|
networkClass
|
|
|
|
? <div className={`network-display__icon network-display__icon--${networkClass}`} />
|
|
|
|
: <div
|
|
|
|
className="i fa fa-question-circle fa-med"
|
|
|
|
style={{
|
|
|
|
margin: '0 4px',
|
|
|
|
color: 'rgb(125, 128, 130)',
|
|
|
|
}}
|
|
|
|
/>
|
|
|
|
}
|
|
|
|
<div className="network-display__name">
|
2018-10-26 10:26:43 +02:00
|
|
|
{ type === 'rpc' && nickname ? nickname : this.context.t(type) }
|
2018-06-23 08:52:45 +02:00
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
)
|
|
|
|
}
|
|
|
|
}
|