Ensure submission state is reset on onSubmit error

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

@ -134,51 +134,58 @@ export default class NetworkForm extends PureComponent {
isSubmitting: true,
})
const {
setRpcTarget,
rpcUrl: propsRpcUrl,
editRpc,
rpcPrefs = {},
onClear,
networksTabIsInAddMode,
} = this.props
const {
networkName,
rpcUrl,
chainId: stateChainId,
ticker,
blockExplorerUrl,
} = this.state
try {
const {
setRpcTarget,
rpcUrl: propsRpcUrl,
editRpc,
rpcPrefs = {},
onClear,
networksTabIsInAddMode,
} = this.props
const {
networkName,
rpcUrl,
chainId: stateChainId,
ticker,
blockExplorerUrl,
} = this.state
const formChainId = stateChainId.trim().toLowerCase()
// Ensure chainId is a 0x-prefixed, lowercase hex string
let chainId = formChainId
if (!chainId.startsWith('0x')) {
chainId = `0x${new BigNumber(chainId, 10).toString(16)}`
}
const formChainId = stateChainId.trim().toLowerCase()
// Ensure chainId is a 0x-prefixed, lowercase hex string
let chainId = formChainId
if (!chainId.startsWith('0x')) {
chainId = `0x${new BigNumber(chainId, 10).toString(16)}`
}
if (!(await this.validateChainIdOnSubmit(formChainId, chainId, rpcUrl))) {
this.setState({
isSubmitting: false,
})
return
}
if (!(await this.validateChainIdOnSubmit(formChainId, chainId, rpcUrl))) {
// After this point, isSubmitting will be reset in componentDidUpdate
if (propsRpcUrl && rpcUrl !== propsRpcUrl) {
await editRpc(propsRpcUrl, rpcUrl, chainId, ticker, networkName, {
...rpcPrefs,
blockExplorerUrl: blockExplorerUrl || rpcPrefs.blockExplorerUrl,
})
} else {
await setRpcTarget(rpcUrl, chainId, ticker, networkName, {
...rpcPrefs,
blockExplorerUrl: blockExplorerUrl || rpcPrefs.blockExplorerUrl,
})
}
if (networksTabIsInAddMode) {
onClear()
}
} catch (error) {
log.error('Unexpected error during form submission.', error)
this.setState({
isSubmitting: false,
})
return
}
// After this point, isSubmitting will be reset in componentDidUpdate
if (propsRpcUrl && rpcUrl !== propsRpcUrl) {
await editRpc(propsRpcUrl, rpcUrl, chainId, ticker, networkName, {
...rpcPrefs,
blockExplorerUrl: blockExplorerUrl || rpcPrefs.blockExplorerUrl,
})
} else {
await setRpcTarget(rpcUrl, chainId, ticker, networkName, {
...rpcPrefs,
blockExplorerUrl: blockExplorerUrl || rpcPrefs.blockExplorerUrl,
})
}
if (networksTabIsInAddMode) {
onClear()
}
}

Loading…
Cancel
Save