@ -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 ,
@ -109,6 +101,9 @@ export default class NetworksTab extends PureComponent {
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,31 +215,39 @@ 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 ( ) }
< div className = "networks-tab__content" >
{ this . renderNetworksTabContent ( ) }
{ this . renderNetworksTabContent ( ) }
{ ! networkIsSelected && ! networksTabIsInAddMode
{ ! isFullScreen && ! shouldRenderNetworkForm
? (
? (
< div className = "networks-tab__add-network-button-wrapp er" >
< div className = "networks-tab__networks-list-popup-foot er" >
< Button
< Button
type = "primary"
type = "primary"
onClick = { ( event ) => {
onClick = { ( event ) => {
event . preventDefault ( )
event . preventDefault ( )
setSelectedSettingsRpcUrl ( null )
setSelectedSettingsRpcUrl ( '' )
setNetworksTabAddMode ( true )
setNetworksTabAddMode ( true )
history . push ( NETWORKS _FORM _ROUTE )
} }
} }
>
>
{ this . context . t ( 'addNetwork' ) }
{ this . context . t ( 'addNetwork' ) }
@ -252,6 +257,7 @@ export default class NetworksTab extends PureComponent {
: null
: null
}
}
< / d i v >
< / d i v >
< / d i v >
)
)
}
}
}
}