@ -1,11 +1,12 @@
import React , { PureComponent } from 'react'
import React , { PureComponent } from 'react'
import PropTypes from 'prop-types'
import PropTypes from 'prop-types'
import classnames from 'classnames'
import classnames from 'classnames'
import { SETTINGS _ROUTE } from '../../../helpers/constants/routes'
import { ENVIRONMENT _TYPE _POPUP } from '../../../../../app/scripts/lib/enums'
import { getEnvironmentType } from '../../../../../app/scripts/lib/util'
import Button from '../../../components/ui/button'
import Button from '../../../components/ui/button'
import LockIcon from '../../../components/ui/lock-icon'
import LockIcon from '../../../components/ui/lock-icon'
import {
NETWORKS _ROUTE ,
NETWORKS _FORM _ROUTE ,
} from '../../../helpers/constants/routes'
import NetworkDropdownIcon from '../../../components/app/dropdowns/components/network-dropdown-icon'
import NetworkDropdownIcon from '../../../components/app/dropdowns/components/network-dropdown-icon'
import NetworkForm from './network-form'
import NetworkForm from './network-form'
@ -17,7 +18,6 @@ export default class NetworksTab extends PureComponent {
static propTypes = {
static propTypes = {
editRpc : PropTypes . func . isRequired ,
editRpc : PropTypes . func . isRequired ,
history : PropTypes . object . isRequired ,
location : PropTypes . object . isRequired ,
location : PropTypes . object . isRequired ,
networkIsSelected : PropTypes . bool ,
networkIsSelected : PropTypes . bool ,
networksTabIsInAddMode : PropTypes . bool ,
networksTabIsInAddMode : PropTypes . bool ,
@ -30,10 +30,13 @@ export default class NetworksTab extends PureComponent {
providerUrl : PropTypes . string ,
providerUrl : PropTypes . string ,
providerType : PropTypes . string ,
providerType : PropTypes . string ,
networkDefaultedToProvider : PropTypes . bool ,
networkDefaultedToProvider : PropTypes . bool ,
history : PropTypes . object . isRequired ,
shouldRenderNetworkForm : PropTypes . bool . isRequired ,
isFullScreen : PropTypes . bool . isRequired ,
}
}
UNSAFE _componentWillMount ( ) {
componentWillUnm ount ( ) {
this . props . setSelectedSettingsRpcUrl ( null )
this . props . setSelectedSettingsRpcUrl ( '' )
}
}
isCurrentPath ( pathname ) {
isCurrentPath ( pathname ) {
@ -42,32 +45,19 @@ export default class NetworksTab extends PureComponent {
renderSubHeader ( ) {
renderSubHeader ( ) {
const {
const {
networkIsSelected ,
setSelectedSettingsRpcUrl ,
setSelectedSettingsRpcUrl ,
setNetworksTabAddMode ,
setNetworksTabAddMode ,
networksTabIsInAddMode ,
networkDefaultedToProvider ,
} = this . props
} = this . props
return (
return (
< div className = "settings-page__sub-header" >
< div className = "settings-page__sub-header" >
< div
className = "networks-tab__back-button"
onClick = { ( networkIsSelected && ! networkDefaultedToProvider ) || networksTabIsInAddMode
? ( ) => {
setNetworksTabAddMode ( false )
setSelectedSettingsRpcUrl ( null )
}
: ( ) => this . props . history . push ( SETTINGS _ROUTE )
}
/ >
< span className = "settings-page__sub-header-text" > { this . context . t ( 'networks' ) } < / s p a n >
< span className = "settings-page__sub-header-text" > { this . context . t ( 'networks' ) } < / s p a n >
< div className = "networks-tab__add-network-header-button-wrapper" >
< div className = "networks-tab__add-network-header-button-wrapper" >
< Button
< Button
type = "secondary"
type = "secondary"
onClick = { ( event ) => {
onClick = { ( event ) => {
event . preventDefault ( )
event . preventDefault ( )
setSelectedSettingsRpcUrl ( null )
setSelectedSettingsRpcUrl ( '' )
setNetworksTabAddMode ( true )
setNetworksTabAddMode ( true )
} }
} }
>
>
@ -86,6 +76,8 @@ export default class NetworksTab extends PureComponent {
providerUrl ,
providerUrl ,
providerType ,
providerType ,
networksTabIsInAddMode ,
networksTabIsInAddMode ,
history ,
isFullScreen ,
} = this . props
} = this . props
const {
const {
border ,
border ,
@ -106,9 +98,12 @@ export default class NetworksTab extends PureComponent {
< div
< div
key = { ` settings-network-list-item: ${ rpcUrl } ` }
key = { ` settings-network-list-item: ${ rpcUrl } ` }
className = "networks-tab__networks-list-item"
className = "networks-tab__networks-list-item"
onClick = { ( ) => {
onClick = { ( ) => {
setNetworksTabAddMode ( false )
setNetworksTabAddMode ( false )
setSelectedSettingsRpcUrl ( rpcUrl )
setSelectedSettingsRpcUrl ( rpcUrl )
if ( ! isFullScreen ) {
history . push ( NETWORKS _FORM _ROUTE )
}
} }
} }
>
>
< NetworkDropdownIcon
< NetworkDropdownIcon
@ -186,16 +181,15 @@ export default class NetworksTab extends PureComponent {
} ,
} ,
networksTabIsInAddMode ,
networksTabIsInAddMode ,
editRpc ,
editRpc ,
networkDefaultedToProvider ,
providerUrl ,
providerUrl ,
networksToRender ,
networksToRender ,
history ,
isFullScreen ,
shouldRenderNetworkForm ,
} = this . props
} = this . props
const envIsPopup = getEnvironmentType ( ) === ENVIRONMENT _TYPE _POPUP
const shouldRenderNetworkForm = networksTabIsInAddMode || ! envIsPopup || ( envIsPopup && ! networkDefaultedToProvider )
return (
return (
< div className = "networks-tab__content" >
< >
{ this . renderNetworksList ( ) }
{ this . renderNetworksList ( ) }
{
{
shouldRenderNetworkForm
shouldRenderNetworkForm
@ -208,9 +202,12 @@ export default class NetworksTab extends PureComponent {
rpcUrl = { rpcUrl }
rpcUrl = { rpcUrl }
chainId = { chainId }
chainId = { chainId }
ticker = { ticker }
ticker = { ticker }
onClear = { ( ) => {
onClear = { ( shouldUpdateHistory = true ) => {
setNetworksTabAddMode ( false )
setNetworksTabAddMode ( false )
setSelectedSettingsRpcUrl ( null )
setSelectedSettingsRpcUrl ( '' )
if ( shouldUpdateHistory && ! isFullScreen ) {
history . push ( NETWORKS _ROUTE )
}
} }
} }
showConfirmDeleteNetworkModal = { showConfirmDeleteNetworkModal }
showConfirmDeleteNetworkModal = { showConfirmDeleteNetworkModal }
viewOnly = { viewOnly }
viewOnly = { viewOnly }
@ -218,39 +215,48 @@ export default class NetworksTab extends PureComponent {
networksTabIsInAddMode = { networksTabIsInAddMode }
networksTabIsInAddMode = { networksTabIsInAddMode }
rpcPrefs = { rpcPrefs }
rpcPrefs = { rpcPrefs }
blockExplorerUrl = { blockExplorerUrl }
blockExplorerUrl = { blockExplorerUrl }
cancelText = { t ( 'cancel' ) }
isFullScreen = { isFullScreen }
/ >
/ >
)
)
: null
: null
}
}
< / d i v >
< / >
)
)
}
}
render ( ) {
render ( ) {
const { setNetworksTabAddMode , setSelectedSettingsRpcUrl , networkIsSelected , networksTabIsInAddMode } = this . props
const {
setNetworksTabAddMode ,
setSelectedSettingsRpcUrl ,
history ,
isFullScreen ,
shouldRenderNetworkForm ,
} = this . props
return (
return (
< div className = "networks-tab__body" >
< div className = "networks-tab__body" >
{ this . renderSubHeader ( ) }
{ isFullScreen && this . renderSubHeader ( ) }
{ this . renderNetworksTabContent ( ) }
< div className = "networks-tab__content" >
{ ! networkIsSelected && ! networksTabIsInAddMode
{ this . renderNetworksTabContent ( ) }
? (
{ ! isFullScreen && ! shouldRenderNetworkForm
< div className = "networks-tab__add-network-button-wrapper" >
? (
< Button
< div className = "networks-tab__networks-list-popup-footer" >
type = "primary"
< Button
onClick = { ( event ) => {
type = "primary"
event . preventDefault ( )
onClick = { ( event ) => {
setSelectedSettingsRpcUrl ( null )
event . preventDefault ( )
setNetworksTabAddMode ( true )
setSelectedSettingsRpcUrl ( '' )
} }
setNetworksTabAddMode ( true )
>
history . push ( NETWORKS _FORM _ROUTE )
{ this . context . t ( 'addNetwork' ) }
} }
< / B u t t o n >
>
< / d i v >
{ this . context . t ( 'addNetwork' ) }
)
< / B u t t o n >
: null
< / d i v >
}
)
: null
}
< / d i v >
< / d i v >
< / d i v >
)
)
}
}