1
0
mirror of https://github.com/kremalicious/metamask-extension.git synced 2024-11-26 12:29:06 +01:00

Ensure submission state is reset on onSubmit error

This commit is contained in:
Erik Marks 2020-11-11 12:28:20 -08:00
parent 53bf9cb766
commit a714da8069

View File

@ -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))) {
if (!(await this.validateChainIdOnSubmit(formChainId, chainId, rpcUrl))) {
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()
}
} 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()
}
}