|
|
@ -1,10 +1,10 @@ |
|
|
|
import React, { PureComponent } from 'react' |
|
|
|
import React, { PureComponent } from 'react' |
|
|
|
import PropTypes from 'prop-types' |
|
|
|
import PropTypes from 'prop-types' |
|
|
|
import validUrl from 'valid-url' |
|
|
|
import validUrl from 'valid-url' |
|
|
|
import PageContainerFooter from '../../../../components/ui/page-container/page-container-footer' |
|
|
|
|
|
|
|
import TextField from '../../../../components/ui/text-field' |
|
|
|
import TextField from '../../../../components/ui/text-field' |
|
|
|
|
|
|
|
import Button from '../../../../components/ui/button' |
|
|
|
|
|
|
|
|
|
|
|
export default class NetworksTab extends PureComponent { |
|
|
|
export default class NetworkForm extends PureComponent { |
|
|
|
static contextTypes = { |
|
|
|
static contextTypes = { |
|
|
|
t: PropTypes.func.isRequired, |
|
|
|
t: PropTypes.func.isRequired, |
|
|
|
metricsEvent: PropTypes.func.isRequired, |
|
|
|
metricsEvent: PropTypes.func.isRequired, |
|
|
@ -12,6 +12,7 @@ export default class NetworksTab extends PureComponent { |
|
|
|
|
|
|
|
|
|
|
|
static propTypes = { |
|
|
|
static propTypes = { |
|
|
|
editRpc: PropTypes.func.isRequired, |
|
|
|
editRpc: PropTypes.func.isRequired, |
|
|
|
|
|
|
|
delRpcTarget: PropTypes.func.isRequired, |
|
|
|
rpcUrl: PropTypes.string, |
|
|
|
rpcUrl: PropTypes.string, |
|
|
|
chainId: PropTypes.string, |
|
|
|
chainId: PropTypes.string, |
|
|
|
ticker: PropTypes.string, |
|
|
|
ticker: PropTypes.string, |
|
|
@ -20,6 +21,7 @@ export default class NetworksTab extends PureComponent { |
|
|
|
onClear: PropTypes.func.isRequired, |
|
|
|
onClear: PropTypes.func.isRequired, |
|
|
|
setRpcTarget: PropTypes.func.isRequired, |
|
|
|
setRpcTarget: PropTypes.func.isRequired, |
|
|
|
networksTabIsInAddMode: PropTypes.bool, |
|
|
|
networksTabIsInAddMode: PropTypes.bool, |
|
|
|
|
|
|
|
isCurrentRpcTarget: PropTypes.bool, |
|
|
|
blockExplorerUrl: PropTypes.string, |
|
|
|
blockExplorerUrl: PropTypes.string, |
|
|
|
rpcPrefs: PropTypes.object, |
|
|
|
rpcPrefs: PropTypes.object, |
|
|
|
} |
|
|
|
} |
|
|
@ -70,6 +72,71 @@ export default class NetworksTab extends PureComponent { |
|
|
|
}) |
|
|
|
}) |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
resetForm () { |
|
|
|
|
|
|
|
const { |
|
|
|
|
|
|
|
rpcUrl, |
|
|
|
|
|
|
|
chainId, |
|
|
|
|
|
|
|
ticker, |
|
|
|
|
|
|
|
networkName, |
|
|
|
|
|
|
|
blockExplorerUrl, |
|
|
|
|
|
|
|
} = this.props |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
this.setState({ rpcUrl, chainId, ticker, networkName, blockExplorerUrl, errors: {} }) |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
onSubmit = () => { |
|
|
|
|
|
|
|
const { |
|
|
|
|
|
|
|
setRpcTarget, |
|
|
|
|
|
|
|
rpcUrl: propsRpcUrl, |
|
|
|
|
|
|
|
editRpc, |
|
|
|
|
|
|
|
rpcPrefs = {}, |
|
|
|
|
|
|
|
onClear, |
|
|
|
|
|
|
|
networksTabIsInAddMode, |
|
|
|
|
|
|
|
} = this.props |
|
|
|
|
|
|
|
const { |
|
|
|
|
|
|
|
networkName, |
|
|
|
|
|
|
|
rpcUrl, |
|
|
|
|
|
|
|
chainId, |
|
|
|
|
|
|
|
ticker, |
|
|
|
|
|
|
|
blockExplorerUrl, |
|
|
|
|
|
|
|
} = this.state |
|
|
|
|
|
|
|
if (propsRpcUrl && rpcUrl !== propsRpcUrl) { |
|
|
|
|
|
|
|
editRpc(propsRpcUrl, rpcUrl, chainId, ticker, networkName, { |
|
|
|
|
|
|
|
blockExplorerUrl: blockExplorerUrl || rpcPrefs.blockExplorerUrl, |
|
|
|
|
|
|
|
...rpcPrefs, |
|
|
|
|
|
|
|
}) |
|
|
|
|
|
|
|
} else { |
|
|
|
|
|
|
|
setRpcTarget(rpcUrl, chainId, ticker, networkName, { |
|
|
|
|
|
|
|
blockExplorerUrl: blockExplorerUrl || rpcPrefs.blockExplorerUrl, |
|
|
|
|
|
|
|
...rpcPrefs, |
|
|
|
|
|
|
|
}) |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (networksTabIsInAddMode) { |
|
|
|
|
|
|
|
onClear() |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
onCancel = () => { |
|
|
|
|
|
|
|
const { |
|
|
|
|
|
|
|
networksTabIsInAddMode, |
|
|
|
|
|
|
|
onClear, |
|
|
|
|
|
|
|
} = this.props |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (networksTabIsInAddMode) { |
|
|
|
|
|
|
|
onClear() |
|
|
|
|
|
|
|
} else { |
|
|
|
|
|
|
|
this.resetForm() |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
onDelete = () => { |
|
|
|
|
|
|
|
const { delRpcTarget, rpcUrl, onClear } = this.props |
|
|
|
|
|
|
|
delRpcTarget(rpcUrl) |
|
|
|
|
|
|
|
this.resetForm() |
|
|
|
|
|
|
|
onClear() |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
stateIsUnchanged () { |
|
|
|
stateIsUnchanged () { |
|
|
|
const { |
|
|
|
const { |
|
|
|
rpcUrl, |
|
|
|
rpcUrl, |
|
|
@ -152,16 +219,23 @@ export default class NetworksTab extends PureComponent { |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
render () { |
|
|
|
render () { |
|
|
|
const { setRpcTarget, viewOnly, rpcUrl: propsRpcUrl, editRpc, rpcPrefs = {} } = this.props |
|
|
|
const { t } = this.context |
|
|
|
|
|
|
|
const { |
|
|
|
|
|
|
|
viewOnly, |
|
|
|
|
|
|
|
isCurrentRpcTarget, |
|
|
|
|
|
|
|
networksTabIsInAddMode, |
|
|
|
|
|
|
|
} = this.props |
|
|
|
const { |
|
|
|
const { |
|
|
|
networkName, |
|
|
|
networkName, |
|
|
|
rpcUrl, |
|
|
|
rpcUrl, |
|
|
|
chainId, |
|
|
|
chainId = '', |
|
|
|
ticker, |
|
|
|
ticker, |
|
|
|
blockExplorerUrl, |
|
|
|
blockExplorerUrl, |
|
|
|
errors, |
|
|
|
errors, |
|
|
|
} = this.state |
|
|
|
} = this.state |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
const isSubmitDisabled = viewOnly || this.stateIsUnchanged() || Object.values(errors).some(x => x) || !rpcUrl |
|
|
|
|
|
|
|
const deletable = !networksTabIsInAddMode && !isCurrentRpcTarget && !viewOnly |
|
|
|
|
|
|
|
|
|
|
|
return ( |
|
|
|
return ( |
|
|
|
<div className="networks-tab__network-form"> |
|
|
|
<div className="networks-tab__network-form"> |
|
|
@ -198,26 +272,32 @@ export default class NetworksTab extends PureComponent { |
|
|
|
blockExplorerUrl, |
|
|
|
blockExplorerUrl, |
|
|
|
'optionalBlockExplorerUrl', |
|
|
|
'optionalBlockExplorerUrl', |
|
|
|
)} |
|
|
|
)} |
|
|
|
<PageContainerFooter |
|
|
|
<div className="network-form__footer"> |
|
|
|
cancelText={this.context.t('cancel')} |
|
|
|
{ |
|
|
|
hideCancel={true} |
|
|
|
deletable && ( |
|
|
|
onSubmit={() => { |
|
|
|
<Button |
|
|
|
if (propsRpcUrl && rpcUrl !== propsRpcUrl) { |
|
|
|
type="danger" |
|
|
|
editRpc(propsRpcUrl, rpcUrl, chainId, ticker, networkName, { |
|
|
|
onClick={this.onDelete} |
|
|
|
blockExplorerUrl: blockExplorerUrl || rpcPrefs.blockExplorerUrl, |
|
|
|
> |
|
|
|
...rpcPrefs, |
|
|
|
{ t('delete') } |
|
|
|
}) |
|
|
|
</Button> |
|
|
|
} else { |
|
|
|
) |
|
|
|
setRpcTarget(rpcUrl, chainId, ticker, networkName, { |
|
|
|
|
|
|
|
blockExplorerUrl: blockExplorerUrl || rpcPrefs.blockExplorerUrl, |
|
|
|
|
|
|
|
...rpcPrefs, |
|
|
|
|
|
|
|
}) |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
}} |
|
|
|
<Button |
|
|
|
submitText={this.context.t('save')} |
|
|
|
type="default" |
|
|
|
submitButtonType={'confirm'} |
|
|
|
onClick={this.onCancel} |
|
|
|
disabled={viewOnly || this.stateIsUnchanged() || Object.values(errors).some(x => x) || !rpcUrl} |
|
|
|
disabled={viewOnly || this.stateIsUnchanged()} |
|
|
|
/> |
|
|
|
> |
|
|
|
|
|
|
|
{ t('cancel') } |
|
|
|
|
|
|
|
</Button> |
|
|
|
|
|
|
|
<Button |
|
|
|
|
|
|
|
type="secondary" |
|
|
|
|
|
|
|
disabled={isSubmitDisabled} |
|
|
|
|
|
|
|
onClick={this.onSubmit} |
|
|
|
|
|
|
|
> |
|
|
|
|
|
|
|
{ t('save') } |
|
|
|
|
|
|
|
</Button> |
|
|
|
|
|
|
|
</div> |
|
|
|
</div> |
|
|
|
</div> |
|
|
|
) |
|
|
|
) |
|
|
|
} |
|
|
|
} |
|
|
|