Disable save button while submitting

feature/default_network_editable
Erik Marks 4 years ago
parent 4db9c8b36f
commit 53bf9cb766
  1. 54
      ui/app/pages/settings/networks-tab/network-form/network-form.component.js

@ -9,6 +9,14 @@ import Tooltip from '../../../../components/ui/tooltip'
import { isPrefixedFormattedHexString } from '../../../../../../app/scripts/lib/util' import { isPrefixedFormattedHexString } from '../../../../../../app/scripts/lib/util'
import { jsonRpcRequest } from '../../../../helpers/utils/util' import { jsonRpcRequest } from '../../../../helpers/utils/util'
const FORM_STATE_KEYS = [
'rpcUrl',
'chainId',
'ticker',
'networkName',
'blockExplorerUrl',
]
export default class NetworkForm extends PureComponent { export default class NetworkForm extends PureComponent {
static contextTypes = { static contextTypes = {
t: PropTypes.func.isRequired, t: PropTypes.func.isRequired,
@ -40,21 +48,12 @@ export default class NetworkForm extends PureComponent {
networkName: this.props.networkName, networkName: this.props.networkName,
blockExplorerUrl: this.props.blockExplorerUrl, blockExplorerUrl: this.props.blockExplorerUrl,
errors: {}, errors: {},
isSubmitting: false,
} }
componentDidUpdate(prevProps) { componentDidUpdate(prevProps) {
const { const { networksTabIsInAddMode: prevAddMode } = prevProps
rpcUrl: prevRpcUrl, const { networksTabIsInAddMode } = this.props
networksTabIsInAddMode: prevAddMode,
} = prevProps
const {
rpcUrl,
chainId,
ticker,
networkName,
networksTabIsInAddMode,
blockExplorerUrl,
} = this.props
if (!prevAddMode && networksTabIsInAddMode) { if (!prevAddMode && networksTabIsInAddMode) {
this.setState({ this.setState({
@ -64,16 +63,15 @@ export default class NetworkForm extends PureComponent {
networkName: '', networkName: '',
blockExplorerUrl: '', blockExplorerUrl: '',
errors: {}, errors: {},
isSubmitting: false,
}) })
} else if (prevRpcUrl !== rpcUrl) { } else {
this.setState({ for (const key of FORM_STATE_KEYS) {
rpcUrl, if (prevProps[key] !== this.props[key]) {
chainId: this.getDisplayChainId(chainId), this.resetForm()
ticker, break
networkName, }
blockExplorerUrl, }
errors: {},
})
} }
} }
@ -109,6 +107,7 @@ export default class NetworkForm extends PureComponent {
networkName, networkName,
blockExplorerUrl, blockExplorerUrl,
errors: {}, errors: {},
isSubmitting: false,
}) })
} }
@ -131,6 +130,10 @@ export default class NetworkForm extends PureComponent {
} }
onSubmit = async () => { onSubmit = async () => {
this.setState({
isSubmitting: true,
})
const { const {
setRpcTarget, setRpcTarget,
rpcUrl: propsRpcUrl, rpcUrl: propsRpcUrl,
@ -155,9 +158,13 @@ export default class NetworkForm extends PureComponent {
} }
if (!(await this.validateChainIdOnSubmit(formChainId, chainId, rpcUrl))) { if (!(await this.validateChainIdOnSubmit(formChainId, chainId, rpcUrl))) {
this.setState({
isSubmitting: false,
})
return return
} }
// After this point, isSubmitting will be reset in componentDidUpdate
if (propsRpcUrl && rpcUrl !== propsRpcUrl) { if (propsRpcUrl && rpcUrl !== propsRpcUrl) {
await editRpc(propsRpcUrl, rpcUrl, chainId, ticker, networkName, { await editRpc(propsRpcUrl, rpcUrl, chainId, ticker, networkName, {
...rpcPrefs, ...rpcPrefs,
@ -196,6 +203,10 @@ export default class NetworkForm extends PureComponent {
}) })
} }
isSubmitting() {
return this.state.isSubmitting
}
stateIsUnchanged() { stateIsUnchanged() {
const { const {
rpcUrl, rpcUrl,
@ -423,6 +434,7 @@ export default class NetworkForm extends PureComponent {
!networksTabIsInAddMode && !isCurrentRpcTarget && !viewOnly !networksTabIsInAddMode && !isCurrentRpcTarget && !viewOnly
const isSubmitDisabled = const isSubmitDisabled =
this.isSubmitting() ||
this.stateIsUnchanged() || this.stateIsUnchanged() ||
!rpcUrl || !rpcUrl ||
!chainId || !chainId ||

Loading…
Cancel
Save