Skip to content
Permalink
Browse files

fix(onboarding): prevent state update during render

  • Loading branch information...
korhaliv committed Apr 10, 2019
1 parent d82065e commit f32e6b21eacd6022a2c8639c0f56f56d988da0c2
Showing with 17 additions and 6 deletions.
  1. +6 −3 renderer/components/Onboarding/Onboarding.js
  2. +11 −3 renderer/components/Onboarding/Steps/Network.js
@@ -80,13 +80,12 @@ class Onboarding extends React.Component {
* @return {{key: string}[]} Modified list of form steps.
*/
removeAutopilotStepIfMainnet = formSteps => {
const { network, setAutopilot } = this.props
const { network } = this.props
if (network === 'mainnet') {
const index = formSteps.findIndex(s => s.key === 'Autopilot')
if (index >= 0) {
formSteps.splice(index, 1)
}
setAutopilot(false)
}
return formSteps
}
@@ -158,7 +157,11 @@ class Onboarding extends React.Component {
<Wizard.Step key="SeedConfirm" component={SeedConfirm} {...{ seed }} />,
<Wizard.Step key="Password" component={Password} {...{ setPassword }} />,
<Wizard.Step key="Name" component={Name} {...{ name, setName }} />,
<Wizard.Step key="Network" component={Network} {...{ network, setNetwork }} />,
<Wizard.Step
key="Network"
component={Network}
{...{ network, setNetwork, setAutopilot }}
/>,
<Wizard.Step key="Autopilot" component={Autopilot} {...{ autopilot, setAutopilot }} />,
<Wizard.Step key="WalletCreate" component={WalletCreate} {...{ createNewWallet }} />,
]
@@ -7,6 +7,7 @@ import messages from './messages'
class Network extends React.Component {
static propTypes = {
network: PropTypes.string, // eslint-disable-line react/boolean-prop-naming
setAutopilot: PropTypes.func.isRequired,
setNetwork: PropTypes.func.isRequired,
wizardApi: PropTypes.object,
wizardState: PropTypes.object,
@@ -18,16 +19,23 @@ class Network extends React.Component {
}

handleSubmit = values => {
const { setNetwork } = this.props
setNetwork(values.network)
const { setNetwork, setAutopilot } = this.props
const { network } = values
setNetwork(network)

// It is currently not recommended to use autopilot on mainnet.
// If user has selected mainnet, disable it
if (network === 'mainnet') {
setAutopilot(false)
}
}

setFormApi = formApi => {
this.formApi = formApi
}

render() {
const { wizardApi, wizardState, network, setNetwork, ...rest } = this.props
const { wizardApi, wizardState, network, setNetwork, setAutopilot, ...rest } = this.props
const { getApi, onChange, onSubmit, onSubmitFailure } = wizardApi
const { currentItem } = wizardState
return (

0 comments on commit f32e6b2

Please sign in to comment.
You can’t perform that action at this time.