mirror of
https://github.com/kremalicious/metamask-extension.git
synced 2024-12-23 09:52:26 +01:00
Ensure submission state is reset on onSubmit error
This commit is contained in:
parent
53bf9cb766
commit
a714da8069
@ -134,51 +134,58 @@ export default class NetworkForm extends PureComponent {
|
|||||||
isSubmitting: true,
|
isSubmitting: true,
|
||||||
})
|
})
|
||||||
|
|
||||||
const {
|
try {
|
||||||
setRpcTarget,
|
const {
|
||||||
rpcUrl: propsRpcUrl,
|
setRpcTarget,
|
||||||
editRpc,
|
rpcUrl: propsRpcUrl,
|
||||||
rpcPrefs = {},
|
editRpc,
|
||||||
onClear,
|
rpcPrefs = {},
|
||||||
networksTabIsInAddMode,
|
onClear,
|
||||||
} = this.props
|
networksTabIsInAddMode,
|
||||||
const {
|
} = this.props
|
||||||
networkName,
|
const {
|
||||||
rpcUrl,
|
networkName,
|
||||||
chainId: stateChainId,
|
rpcUrl,
|
||||||
ticker,
|
chainId: stateChainId,
|
||||||
blockExplorerUrl,
|
ticker,
|
||||||
} = this.state
|
blockExplorerUrl,
|
||||||
|
} = this.state
|
||||||
|
|
||||||
const formChainId = stateChainId.trim().toLowerCase()
|
const formChainId = stateChainId.trim().toLowerCase()
|
||||||
// Ensure chainId is a 0x-prefixed, lowercase hex string
|
// Ensure chainId is a 0x-prefixed, lowercase hex string
|
||||||
let chainId = formChainId
|
let chainId = formChainId
|
||||||
if (!chainId.startsWith('0x')) {
|
if (!chainId.startsWith('0x')) {
|
||||||
chainId = `0x${new BigNumber(chainId, 10).toString(16)}`
|
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({
|
this.setState({
|
||||||
isSubmitting: false,
|
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…
x
Reference in New Issue
Block a user